/* =========================================================
   Receipt Cockpit PWA – single global CSS (mobile-first)
   Tokens + layout + components. No box-in-box.
   ========================================================= */

:root {
  /* spacing */
  --s0: 0;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* type */
  --fs-12: 12px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-22: 22px;
  line-height: 1.4;

  /* layout */
  --topbar-h: 52px;
  --bottomnav-h: 56px;
  --gutter: 16px;

  /* colors – serious fintech, WCAG contrast */
  --bg: #0f1419;
  --surface: #1a2129;
  --text: #e8eef4;
  --muted: #8b9aaa;
  --divider: rgba(232, 238, 244, 0.12);
  --accent: #4da6ff;
  --accent-dim: #2d7acc;
  --success: #34c759;
  --warn: #ffc107;
  --danger: #ff453a;
  --radius: 8px;
}

/* base */
html { font-size: 16px; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--bottomnav-h) + var(--s4));
}

/* layout */
.l-page { padding: 0 var(--gutter) var(--s4); }
.l-topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.l-section {
  padding: var(--s4) 0;
  border-top: 1px solid var(--divider);
}
.l-section:first-child { border-top: none; }

/* components – no nested cards */
.c-topbar-title { font-size: var(--fs-18); font-weight: 600; }
.c-kpi-row {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  padding: var(--s2) 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.c-kpi-row::-webkit-scrollbar { display: none; }
.c-kpi-chip {
  flex: 0 0 auto;
  min-width: 132px;
  min-height: 40px;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--divider);
  overflow: visible;
}
/* Forbrug chip has label + value + delta (3 lines) – extra height + padding so delta is never clipped on mobile */
.c-kpi-row .c-kpi-chip:first-child {
  min-height: 64px;
  padding-bottom: var(--s3);
}
.c-kpi-chip .label { font-size: var(--fs-12); color: var(--muted); }
.c-kpi-chip .value { font-size: var(--fs-16); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; }
.c-kpi-chip .delta { font-size: var(--fs-12); margin-top: 2px; line-height: 1.2; flex-shrink: 0; }
.c-kpi-chip .delta.positive { color: var(--success); }
.c-kpi-chip .delta.negative { color: var(--danger); }

/* Mobile: all 3 KPI chips fit in one row, no scroll – third chip "168 kr" never cut off */
@media (max-width: 768px) {
  .c-kpi-row {
    overflow: visible;
    padding-inline-end: 0;
  }
  .c-kpi-chip {
    flex: 1 1 0;
    min-width: 0;
    padding-left: var(--s2);
    padding-right: var(--s2);
  }
  .c-kpi-chip .value {
    font-size: var(--fs-14);
  }
  .c-kpi-row .c-kpi-chip:first-child {
    min-height: 72px;
    padding-bottom: var(--s4);
  }
}

.c-alert-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  padding: var(--s2) 0;
}
.c-alert-item {
  font-size: var(--fs-14);
  padding: var(--s1) var(--s2);
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--divider);
}
.c-alert-item.warn { border-color: var(--warn); color: var(--warn); }
.c-alert-item.danger { border-color: var(--danger); color: var(--danger); }

.c-list { list-style: none; padding: 0; margin: 0; }
.c-list-item {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) 0;
  border-top: 1px solid var(--divider);
}
.c-list-item:first-child { border-top: none; }
.c-list-item .amount { font-variant-numeric: tabular-nums; font-weight: 500; }
.c-badge {
  font-size: var(--fs-12);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.c-badge.approved { background: rgba(52, 199, 89, 0.2); color: var(--success); }
.c-badge.needs_review { background: rgba(255, 193, 7, 0.2); color: var(--warn); }
.c-badge.draft { background: rgba(139, 154, 170, 0.3); color: var(--muted); }
.c-badge.failed { background: rgba(255, 69, 58, 0.2); color: var(--danger); }
.c-badge.pending { background: rgba(77, 166, 255, 0.2); color: var(--accent); }

.c-bar-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-top: 1px solid var(--divider);
}
.c-bar-row .label { flex: 1; font-size: var(--fs-14); min-width: 0; }
.c-bar-row .amount { font-variant-numeric: tabular-nums; font-size: var(--fs-14); }
.c-bar-row .pct { font-size: var(--fs-12); color: var(--muted); width: 3em; text-align: right; }
.c-bar-track {
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  flex: 0 0 80px;
}
.c-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }

.c-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 48px;
  padding: 0 var(--s4);
  font-size: var(--fs-16);
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.c-btn-primary { background: var(--accent); color: var(--bg); }
.c-btn-primary:hover { background: var(--accent-dim); }
.c-btn-ghost { background: transparent; color: var(--text); }
.c-btn-ghost:hover { background: var(--surface); }

/* PWA install strip (flat, no card) */
.c-pwa-install-strip {
  padding: var(--s3) 0;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}
.c-pwa-install-strip[hidden] { display: none !important; }
.c-pwa-install-fallback { margin: var(--s2) 0 0; }
.c-pwa-install-fallback[hidden] { display: none !important; }
.c-pwa-install-inner {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}
.c-pwa-install-text {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-14);
  color: var(--muted);
}
.c-pwa-install-strip .c-btn { flex-shrink: 0; }

/* Install app page: headings + instruction list */
.c-heading { margin: 0 0 var(--s2); font-weight: 600; color: var(--text); }
.c-heading-section { font-size: var(--fs-18); margin-bottom: var(--s3); }
.c-heading-sub { font-size: var(--fs-16); margin-top: var(--s4); margin-bottom: var(--s2); }
.c-list-instructions {
  list-style: decimal;
  padding-left: 1.25rem;
  margin: 0 0 var(--s4);
}
.c-list-instructions li { margin-bottom: var(--s2); font-size: var(--fs-14); line-height: 1.5; }

/* bottom nav */
.c-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  background: var(--surface);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 20;
}
.c-bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--s2);
  min-width: 48px;
  min-height: 48px;
  color: var(--muted);
  text-decoration: none;
  font-size: var(--fs-12);
}
.c-bottom-nav a:hover, .c-bottom-nav a.active { color: var(--accent); }

/* Camera FAB – half-rounded center button, larger and neutral */
.c-fab-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 80px;
}
.c-fab {
  width: 72px;
  height: 38px;
  border-radius: 36px 36px 0 0;
  border: 2px solid var(--divider);
  border-bottom: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.5rem;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.c-fab:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--muted);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.25);
}
.c-fab:active { background: rgba(255,255,255,0.08); }
.c-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Receipt upload modal */
.c-receipt-upload-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  pointer-events: none;
}
.c-receipt-upload-modal[hidden] { display: none !important; }
.c-receipt-upload-modal:not([hidden]) { pointer-events: auto; }
.c-receipt-upload-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.c-receipt-upload-dialog {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--s5);
  padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  align-items: center;
}
.c-receipt-upload-title { margin: 0; font-size: var(--fs-18); font-weight: 600; }
.c-receipt-upload-hint { margin: 0; font-size: var(--fs-14); color: var(--muted); }
.c-receipt-upload-actions {
  display: flex;
  gap: var(--s4);
  width: 100%;
  justify-content: center;
}
.c-receipt-upload-btn {
  flex: 1;
  max-width: 140px;
  flex-direction: column;
  gap: var(--s2);
  min-height: 72px;
  padding: var(--s3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  font-size: var(--fs-14);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.c-receipt-upload-btn:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--muted);
}
.c-receipt-upload-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.c-receipt-upload-icon { font-size: 1.5rem; opacity: 0.9; }

/* Image pool: thumbnails + upload all */
.c-receipt-pool {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  justify-content: center;
  min-height: 0;
}
.c-receipt-pool-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--divider);
  flex-shrink: 0;
}
.c-receipt-pool-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.c-receipt-pool-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.c-receipt-pool-remove:hover { background: var(--danger); }
.c-receipt-upload-all {
  width: 100%;
  margin-top: var(--s2);
}
.c-receipt-pool-count { font-size: var(--fs-12); color: var(--muted); margin-top: var(--s1); }

/* utilities */
.u-muted { color: var(--muted); }
.u-tabular { font-variant-numeric: tabular-nums; }
.u-fs-12 { font-size: var(--fs-12); }
.u-fs-14 { font-size: var(--fs-14); }

/* focus */
a:focus-visible, button:focus-visible, .c-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
