/* Expense Manager — Apple-flavoured design system.
   Follows iOS/macOS Human Interface conventions: SF system font stack, large rounded
   "grouped inset" list cards on a recessed background, hairline separators inset to the
   text (not the card edge), translucent chrome, restrained system palette, and generous
   touch targets. */

:root {
  /* Recessed grey background with white cards is the iOS grouped-table look. */
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-tap: #e5e5ea;

  --sep: rgba(60, 60, 67, 0.14);
  --sep-strong: rgba(60, 60, 67, 0.29);

  --label: #000000;
  /* Apple's secondaryLabel is 0.6 alpha, which composites to 3.44:1 on a white card —
     under the 4.5:1 normal text needs. In a ledger the merchant name and the date are not
     decoration, so they are darkened until they are actually readable. */
  --label-2: rgba(60, 60, 67, 0.76);
  /* Marks only — separators, the sheet grabber, a disabled arrow. Never words:
     everything that carries text uses --label-2 or darker. */
  --label-3: rgba(60, 60, 67, 0.45);

  /* Apple system colours */
  --blue: #007aff;
  --blue-dark: #0062cc;
  --blue-tint: rgba(0, 122, 255, 0.1);
  --green: #34c759;
  --green-tint: rgba(52, 199, 89, 0.15);
  --orange: #ff9500;
  --orange-tint: rgba(255, 149, 0, 0.16);
  --red: #ff3b30;
  --red-tint: rgba(255, 59, 48, 0.12);
  --grey-tint: rgba(120, 120, 128, 0.12);

  /* Text-safe variants of the semantic colours.
     Apple's system green and orange are tuned as *fills*; used as 11px uppercase text on
     white they measure about 2.2:1, well under the 4.5:1 needed to be readable. The vivid
     values stay for tints and fills; these darker ones carry text. */
  --green-text: #0f7a35;
  --orange-text: #9a5b00;
  --red-text: #c81e14;
  --blue-text: #0062cc;

  --r-card: 16px;
  --r-ctl: 12px;
  --r-lg: 24px;
  --r-pill: 999px;

  /* Elevation. Two shadows per level: a tight contact shadow that defines the edge, and a
     wide soft one that suggests height. One alone reads as either a sticker or a smudge. */
  --e1: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --e2: 0 2px 4px rgba(16, 24, 40, .04), 0 6px 16px -6px rgba(16, 24, 40, .12);
  --e3: 0 4px 8px rgba(16, 24, 40, .05), 0 16px 32px -12px rgba(16, 24, 40, .18);
  --e4: 0 8px 16px rgba(16, 24, 40, .06), 0 28px 56px -20px rgba(16, 24, 40, .26);

  /* Motion. The emphasized curve accelerates slowly and settles hard — Material 3's
     expressive default, and much closer to iOS spring feel than a plain ease-out. */
  --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --ease-exit: cubic-bezier(0.3, 0, 0.8, 0.15);
  --t-fast: 120ms;
  --t-base: 220ms;
  --t-slow: 380ms;

  /* State layer opacities (Material): the same overlay for every interactive surface, so
     hover and press feel identical everywhere rather than being restyled per component. */
  --state-hover: 0.06;
  --state-press: 0.11;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* Dark theme.
   Three viewer states, not two: an explicit choice stamps data-theme on <html>, and the
   default "system" setting stamps nothing — so the media query has to win when nothing is
   stamped, and lose to an explicit light choice. The token list is repeated once for the
   explicit-dark case because a media query cannot be combined with an attribute selector
   in a single rule; check_theme.mjs asserts the two stay identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --card-tap: #2c2c2e;
    --sep: rgba(84, 84, 88, 0.5);
    --sep-strong: rgba(84, 84, 88, 0.65);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.72);
    --label-3: rgba(235, 235, 245, 0.45);
    --blue: #0a84ff;
    --blue-tint: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --grey-tint: rgba(120, 120, 128, 0.24);

    /* On a dark ground the bright system colours are already high contrast; darkening
       them here would make them harder to read, not easier. */
    --green-text: #30d158;
    --orange-text: #ff9f0a;
    --red-text: #ff6961;
    --blue-text: #6cb6ff;

    /* Shadows barely read on a black ground, so dark mode leans on a lifted surface
       colour instead and keeps only a faint contact shadow. */
    --e1: 0 1px 2px rgba(0, 0, 0, .5);
    --e2: 0 2px 6px rgba(0, 0, 0, .55);
    --e3: 0 6px 20px rgba(0, 0, 0, .6);
    --e4: 0 12px 40px rgba(0, 0, 0, .7);

    --state-hover: 0.08;
    --state-press: 0.14;
  }
}

:root[data-theme="dark"] {
    --bg: #000000;
    --card: #1c1c1e;
    --card-tap: #2c2c2e;
    --sep: rgba(84, 84, 88, 0.5);
    --sep-strong: rgba(84, 84, 88, 0.65);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.72);
    --label-3: rgba(235, 235, 245, 0.45);
    --blue: #0a84ff;
    --blue-tint: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --grey-tint: rgba(120, 120, 128, 0.24);

    /* On a dark ground the bright system colours are already high contrast; darkening
       them here would make them harder to read, not easier. */
    --green-text: #30d158;
    --orange-text: #ff9f0a;
    --red-text: #ff6961;
    --blue-text: #6cb6ff;

    /* Shadows barely read on a black ground, so dark mode leans on a lifted surface
       colour instead and keeps only a faint contact shadow. */
    --e1: 0 1px 2px rgba(0, 0, 0, .5);
    --e2: 0 2px 6px rgba(0, 0, 0, .55);
    --e3: 0 6px 20px rgba(0, 0, 0, .6);
    --e4: 0 12px 40px rgba(0, 0, 0, .7);

    --state-hover: 0.08;
    --state-press: 0.14;
  }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  letter-spacing: -0.011em;
  font-feature-settings: "cv05" 1, "ss01" 1, "cv11" 1;  /* single-storey l, disambiguated I/l */
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.021em; line-height: 1.2; }
/* Money and dates line up in columns only if the digits are the same width. */
.exp-amount, .amt, .amt-sub, .stat-value, .row-amount, .exp-date, .breakdown-row {
  font-variant-numeric: tabular-nums;
}
svg { display: block; }
.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 17px; height: 17px; }

/* ---------- Login ---------- */

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--card); border-radius: var(--r-lg);
  padding: 40px 28px; max-width: 340px; width: 100%; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}
.brand-mark {
  width: 72px; height: 72px; border-radius: 17px;  /* iOS "squircle" proportion */
  margin: 0 auto 20px;
  background: linear-gradient(180deg, #0a84ff, #0060df);
  color: #fff; display: grid; place-items: center;
  font-size: 34px; font-weight: 600; letter-spacing: -0.02em;
  box-shadow: 0 8px 20px rgba(0, 122, 255, 0.32);
}
.login-card h1 { font-size: 26px; letter-spacing: -0.032em; margin-bottom: 8px; }
.login-card p { color: var(--label-2); font-size: 15px; line-height: 1.4; margin: 0 0 28px; }

/* ---------- Shell ---------- */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

/* Large title that collapses — the iOS navigation bar pattern */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid transparent;
  padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between; min-height: 44px;
}
.topbar[data-scrolled="true"] { border-bottom-color: var(--sep); }
.topbar-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--blue);
  width: 44px; height: 44px; border-radius: 50%;   /* 44pt minimum touch target */
  display: grid; place-items: center; padding: 0;
}
.icon-btn:active { background: var(--grey-tint); }

/* Tab bar (iOS) on phones, sidebar (macOS) on wide screens */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  padding: 6px 0 calc(6px + var(--safe-b));
}
.nav-btn {
  background: none; border: none; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 0; flex: 1;
  font-size: 10px; font-weight: 500; letter-spacing: -0.01em;
  color: var(--label-2);
}
.nav-btn[aria-selected="true"] { color: var(--blue); }
.nav-btn:active { opacity: 0.55; }
.nav-brand, .nav-logout { display: none; }

.content { flex: 1; width: 100%; }
.main { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + var(--safe-b)); }

.view { display: none; }
.view[aria-hidden="false"] { display: block; animation: fade 0.22s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* iOS large title */
.page-title { font-size: 34px; font-weight: 700; letter-spacing: -0.04em; padding: 4px 4px 12px; }

@media (min-width: 860px) {
  .app-shell { flex-direction: row; }
  .topbar { display: none; }
  .nav {
    position: sticky; top: 0; bottom: auto;
    flex-direction: column; justify-content: flex-start; align-items: stretch;
    width: 260px; height: 100vh; flex-shrink: 0; gap: 2px;
    border-top: none; border-right: 0.5px solid var(--sep);
    padding: 20px 12px; background: color-mix(in srgb, var(--bg) 70%, transparent);
  }
  .nav-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 22px; font-size: 20px; font-weight: 700; letter-spacing: -0.03em;
  }
  .nav-brand .brand-mark-sm {
    width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(180deg, #0a84ff, #0060df); color: #fff;
    display: grid; place-items: center; font-size: 16px; font-weight: 600;
  }
  .nav-btn {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 9px 10px; border-radius: 8px; font-size: 15px; font-weight: 500;
    color: var(--label);
  }
  .nav-btn:hover { background: var(--grey-tint); }
  .nav-btn[aria-selected="true"] { background: var(--blue); color: #fff; }
  .nav-logout { display: flex; margin-top: auto; color: var(--label-2); }
  .main { max-width: 720px; margin: 0; padding: 28px 32px 48px; }
  .page-title { padding-top: 0; }
  .fab { right: 32px; bottom: 32px; }
}

/* ---------- Summary tiles ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: var(--r-card); padding: 14px 12px; }
.stat-label {
  font-size: 12px; font-weight: 600; color: var(--label-2);
  text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 5px;
}
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

/* ---------- Grouped inset list (the core iOS card) ---------- */

.section-label {
  font-size: 13px; font-weight: 400; color: var(--label-2);
  text-transform: uppercase; letter-spacing: 0.01em;
  padding: 0 16px 7px; margin-top: 26px;
}
.section-label-row { display: flex; justify-content: space-between; align-items: baseline; }
/* `hidden` must win over any display rule, otherwise zero-state sections still render. */
[hidden] { display: none !important; }

.card { background: var(--card); border-radius: var(--r-card); overflow: hidden; margin-bottom: 8px; }
.card-body { padding: 16px; }
.card-head { display: none; }  /* replaced by .section-label above the card */

.hint { color: var(--label-2); font-size: 13px; line-height: 1.42; margin: 0 0 14px; padding: 0 4px; }
.hint:last-child { margin-bottom: 0; }
.hint strong { color: var(--label); font-weight: 600; }
.footnote { color: var(--label-2); font-size: 13px; line-height: 1.4; padding: 8px 16px 0; }

/* Rows: separator inset to align with the text, not the card edge — an iOS hallmark */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; position: relative; min-height: 44px; }
.row:not(:last-child)::after {
  content: ""; position: absolute; left: 60px; right: 0; bottom: 0;
  height: 0.5px; background: var(--sep);
}
.row:active { background: var(--card-tap); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--blue-tint); color: var(--blue);
  display: grid; place-items: center; font-weight: 600; font-size: 14px; letter-spacing: -0.02em;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; font-weight: 400; letter-spacing: -0.022em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; font-size: 13px; color: var(--label-2); }
.row-amount { text-align: right; flex-shrink: 0; }
.amt { font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.022em; }
.amt-sub { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 44px 20px; color: var(--label-2); }
.empty svg { margin: 0 auto 12px; width: 32px; height: 32px; stroke: var(--label-3); }
.empty-title { font-size: 17px; font-weight: 500; color: var(--label-2); }
.empty-sub { font-size: 14px; margin-top: 3px; color: var(--label-3); }


/* ---------- Expense cards (card per expense, receipt thumbnail, split footer) ---------- */

.filter-bar { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--sep-strong); border-radius: 999px;
  padding: 9px 14px; font-size: 14px; color: var(--label); cursor: pointer;
  position: relative;
}
.filter-chip label { margin: 0; font-size: 14px; color: var(--label-2); font-weight: 400; }
.filter-chip select {
  border: none; background: none; font: inherit; font-size: 14px; font-weight: 500;
  color: var(--label); padding: 0 18px 0 0; width: auto; border-radius: 0;
  background-position: right 0 center;
}
.filter-chip select:focus { outline: none; }

/* Attention block: things that need action, grouped like a notice card */
.alerts { background: var(--card); border-radius: var(--r-card); overflow: hidden; margin-bottom: 16px; }
.alert-row {
  display: flex; align-items: center; gap: 12px; padding: 15px 16px;
  cursor: pointer; position: relative;
}
.alert-row:not(:last-child)::after {
  content: ""; position: absolute; left: 52px; right: 0; bottom: 0; height: 0.5px; background: var(--sep);
}
.alert-row .icon { width: 24px; height: 24px; flex-shrink: 0; }
.alert-row .alert-text { flex: 1; font-size: 16px; font-weight: 500; }
.alert-row .chev { color: var(--label-3); width: 18px; height: 18px; transform: rotate(180deg); }
.alert-amber .icon, .alert-amber .alert-text { color: var(--orange); }
.alert-red .icon, .alert-red .alert-text { color: var(--red); }

.exp-card {
  background: var(--card); border-radius: var(--r-card); margin-bottom: 12px;
  overflow: hidden; cursor: pointer;
}
.exp-card:active { background: var(--card-tap); }
.exp-top { display: flex; gap: 14px; padding: 16px 16px 14px; }
.exp-thumb {
  width: 74px; height: 84px; border-radius: 8px; flex-shrink: 0;
  background: var(--grey-tint); overflow: hidden;
  display: grid; place-items: center;
}
.exp-thumb { position: relative; }
.exp-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.exp-thumb .ph { display: grid; place-items: center; gap: 3px; color: var(--label-2); }
.exp-thumb .ph svg { width: 26px; height: 26px; }
.exp-thumb .ph span { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; }

.exp-main { flex: 1; min-width: 0; }
.exp-badges { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tag {
  border: 1px solid currentColor; border-radius: 4px; padding: 2px 8px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
.tag-amber { color: var(--orange-text); }
.tag-grey { color: var(--label-2); }
.tag-green { color: var(--green-text); }
.tag-red { color: var(--red-text); }
.tag-blue { color: var(--blue-text); }
.exp-flags { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--label-2); }
.flag-box {
  width: 20px; height: 20px; border: 1.5px solid currentColor; border-radius: 3px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.exp-title {
  font-size: 17px; font-weight: 500; letter-spacing: -0.02em; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.exp-merchant { font-size: 14px; color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-merchant b { font-weight: 400; color: var(--label-2); }
.exp-sub { font-size: 13px; color: var(--label-2); margin-bottom: 3px; }
.exp-desc {
  font-size: 13px; color: var(--label-2); margin-top: 4px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.exp-file {
  display: flex; align-items: center; gap: 5px; margin-top: 5px;
  font-size: 12px; color: var(--label-2); overflow: hidden;
}
.exp-file span, .exp-file { text-overflow: ellipsis; white-space: nowrap; }

.exp-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 14px; margin: 0 16px; border-top: 1px dashed var(--sep-strong);
  padding-left: 0; padding-right: 0;
}
.exp-date { font-size: 15px; color: var(--label-2); }
.exp-amount { font-size: 19px; font-weight: 650; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.exp-amount .sub { display: block; font-size: 12px; font-weight: 400; color: var(--label-2); text-align: right; }

.exp-inline-assign { padding: 0 16px 14px; }
.report-thumb { background: var(--blue-tint); }
.report-thumb .ph { color: var(--blue); }

/* ---------- Badges & chips ---------- */

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap;
}
.badge-green { background: var(--green-tint); color: var(--green-text); }
.badge-amber { background: var(--orange-tint); color: var(--orange-text); }
.badge-red { background: var(--red-tint); color: var(--red-text); }
.badge-grey { background: var(--grey-tint); color: var(--label-2); }
.badge-blue { background: var(--blue-tint); color: var(--blue-text); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--grey-tint); border-radius: 999px;
  padding: 6px 6px 6px 14px; font-size: 15px;
}
.chip button {
  background: none; border: none; cursor: pointer; color: var(--label-2);
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; padding: 0;
}
.chip button:active { color: var(--red); }

/* ---------- Forms ---------- */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--label-2); margin-bottom: 6px; }

input, select, textarea {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 17px;
  color: var(--label); background: var(--bg);
  border: none; border-radius: var(--r-ctl);
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%238e8e93'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
  padding-right: 32px;
}
input::placeholder { color: var(--label-3); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -2px; }
input:disabled { color: var(--label-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Buttons: iOS filled / tinted / plain */
.btn-primary, .btn-secondary, .btn-ghost {
  font: inherit; font-size: 17px; font-weight: 600; letter-spacing: -0.022em;
  border-radius: var(--r-ctl); cursor: pointer; border: none;
  padding: 13px 18px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: opacity 0.12s;
}
.btn-primary { background: var(--blue); color: #fff; width: 100%; }
/* Blue-on-blue-tint measures 3.53:1; the text-safe blue clears AA on the same tint. */
.btn-secondary { background: var(--blue-tint); color: var(--blue-text); }
.btn-ghost { background: none; color: var(--blue-text); padding: 8px 10px; min-height: 0; font-weight: 500; }
.btn-primary:active, .btn-secondary:active, .btn-ghost:active { opacity: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm { font-size: 15px; padding: 8px 14px; min-height: 36px; font-weight: 500; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { flex: 1; }
.inline-form .btn-secondary { flex-shrink: 0; }

/* Upload tiles */
.upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.upload-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 18px 8px; text-align: center; cursor: pointer;
  background: var(--bg); border-radius: var(--r-ctl);
  font-size: 13px; font-weight: 500; color: var(--blue);
}
.upload-tile:active { opacity: 0.6; }
.upload-tile svg { width: 24px; height: 24px; }

.progress { margin-top: 14px; display: flex; flex-direction: column; gap: 7px; }
.progress-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--label-2); }
.progress-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Native picker layered invisibly over our own formatted display. The native control
   still receives the tap (so Android's picker opens) and still holds the real value. */
.picker-field { position: relative; }
.picker-display { width: 100%; pointer-events: none; }
.picker-native {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; padding: 0; margin: 0; border: none;
  -webkit-appearance: none; appearance: none;
}
.picker-field:focus-within .picker-display {
  outline: 2px solid var(--blue); outline-offset: -2px;
}

/* ---------- Floating action button ---------- */

.fab {
  /* Above the tab bar (30) and the top bar (20), below the sheets (50) it opens. It sat at
     25 — behind the tab bar — so on a short screen the button you press most was partly
     covered by the thing it is meant to float over. */
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 50%; z-index: 40;
  background: var(--blue); color: #fff; border: none; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.42);
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }

/* ---------- Sheets ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.4);
  display: none; align-items: flex-end; justify-content: center;
}
.overlay[aria-hidden="false"] { display: flex; animation: fade 0.2s ease-out; }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: sheet-up 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: var(--safe-b);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 0.5px solid var(--sep); min-height: 52px;
}
.sheet-head h2 { font-size: 17px; font-weight: 600; }
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-body .card { margin-bottom: 14px; }
.sheet-foot { padding: 12px 16px 16px; }

@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: var(--r-lg); }
  @keyframes sheet-up { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* ---------- Line items ---------- */

.li-row { display: grid; grid-template-columns: 1fr 100px 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
.li-row .icon-btn { width: 32px; height: 32px; color: var(--red); }

/* ---------- Reports ---------- */

.report { padding: 14px 16px; position: relative; }
.report:not(:last-child)::after {
  content: ""; position: absolute; left: 16px; right: 0; bottom: 0; height: 0.5px; background: var(--sep);
}
.report-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.report-title { font-size: 17px; font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.report-sub { font-size: 13px; color: var(--label-2); margin-top: 3px; }
.report-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Per diem breakdown table inside the sheet */
.breakdown { font-size: 14px; }
.breakdown-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 0.5px solid var(--sep); }
.breakdown-row:last-child { border-bottom: none; font-weight: 600; }
.breakdown-row .pct { color: var(--label-2); font-variant-numeric: tabular-nums; }

/* ---------- Connectors ---------- */

.callout {
  background: var(--orange-tint); border-radius: var(--r-ctl);
  padding: 14px; font-size: 14px; line-height: 1.45; color: var(--label); margin-bottom: 14px;
}
.callout strong { font-weight: 600; }
.callout ol { margin: 8px 0 0; padding-left: 20px; }
.callout li { margin-bottom: 5px; }
.callout code { font-size: 12px; word-break: break-all; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; transform: translate(-50%, 10px);
  bottom: calc(92px + var(--safe-b)); z-index: 60;
  background: rgba(28, 28, 30, 0.92);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 15px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.24s, transform 0.24s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast[data-show="true"] { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 860px) { .toast { bottom: 28px; } }

/* Shown when a PDF has no rendered first page (thumbnail generation failed or the
   receipt predates thumbnails) — better than an <img> that silently shows nothing. */
.pdf-fallback {
  padding: 30px 20px;
  border: 1px dashed var(--sep);
  border-radius: 12px;
  color: var(--label-2);
}
.pdf-fallback svg { width: 30px; height: 30px; opacity: 0.5; }
.pdf-fallback-name { margin-top: 8px; font-size: 13px; word-break: break-all; }


/* ---------- Search + sort toolbar (expenses) ---------- */

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar-search {
  flex: 1 1 auto; min-width: 0; position: relative;
  display: flex; align-items: center;
}
.toolbar-search svg {
  position: absolute; left: 12px; color: var(--label-3);
  pointer-events: none;
}
.toolbar-search input {
  width: 100%; padding-left: 36px; margin: 0;
}
.toolbar select { flex: 0 1 190px; margin: 0; }
@media (max-width: 520px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar select { flex: 1 1 100%; }
}

.field-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px;
}
.field-head label { margin: 0; }

/* ---------- Card depth and pointer feedback ----------
   Touch has no hover, so the lift is gated behind a real pointer; on a phone the press
   state alone does the work. Transitions are dropped for anyone who asked for reduced
   motion. */

.card, .exp-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 1px rgba(0, 0, 0, 0.03);
  transition: box-shadow 160ms ease, transform 160ms ease, background-color 120ms ease;
}
:root:not([data-theme="light"]) .card,
:root:not([data-theme="light"]) .exp-card,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .exp-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

@media (hover: hover) and (pointer: fine) {
  .exp-card:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1), 0 2px 5px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
  }
  .exp-card:hover .exp-thumb { transform: scale(1.03); }
  .exp-thumb { transition: transform 200ms ease; }
  .row[onclick]:hover, .alert-row:hover { background: var(--card-tap); }
}

.exp-card:active {
  transform: translateY(0) scale(0.994);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  background: var(--card-tap);
}

/* Keyboard users get the same affordance as the hover lift. */
.exp-card:focus-visible, .card:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .card, .exp-card, .exp-thumb { transition: none; }
  .exp-card:hover, .exp-card:active { transform: none; }
}


/* ---------- Environment identity ----------
   Dev is the same build as production pointing at a different stack, so it has to be
   unmistakable at a glance. The accent colour is swapped wholesale: blue means the real
   records, amber means a copy. Both palettes stay legible in light and dark. */

:root[data-env="dev"] {
  --blue: #b45309;
  --blue-dark: #92400e;
  --blue-tint: rgba(180, 83, 9, 0.12);
}
:root[data-env="dev"]:not([data-theme="light"]) {
  --blue: #f59e0b;
  --blue-dark: #d97706;
  --blue-tint: rgba(245, 158, 11, 0.16);
}
@media (prefers-color-scheme: dark) {
  :root[data-env="dev"]:not([data-theme="light"]) {
    --blue: #f59e0b;
    --blue-dark: #d97706;
    --blue-tint: rgba(245, 158, 11, 0.16);
  }
}

.env-banner {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 7px 14px;
  background: repeating-linear-gradient(
    135deg, #b45309, #b45309 12px, #92400e 12px, #92400e 24px
  );
  color: #fff; font-size: 13px; line-height: 1.3; text-align: center;
}
.env-banner strong {
  font-weight: 700; letter-spacing: 0.1em;
  border: 1.5px solid currentColor; border-radius: 4px; padding: 1px 7px;
}
@media (max-width: 520px) {
  .env-banner span { font-size: 12px; }
}

.env-tag {
  display: inline-block; margin-left: 8px; vertical-align: middle;
  padding: 1px 7px; border-radius: 4px;
  background: var(--blue); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em;
}

/* The top bar is sticky too; it has to sit below the banner rather than over it. */
:root[data-env="dev"] .topbar { top: 34px; }

/* ---------- Stepping between reports ---------- */

.report-nav {
  display: flex; align-items: center; gap: 6px;
  padding-top: 6px;
}
.report-nav .page-title {
  flex: 1 1 auto; min-width: 0; padding-top: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.report-nav .icon-btn { flex: 0 0 auto; }
.report-nav .icon-btn:disabled { opacity: 0.25; pointer-events: none; }
.icon-flip { transform: scaleX(-1); }

.report-pos {
  font-family: inherit; font-size: 12px; color: var(--label-3);
  letter-spacing: 0.02em; margin: 0 0 10px 2px; min-height: 15px;
}

/* Direction of travel, so a swipe reads as movement rather than a redraw. */
#reportDetail[data-slide], #expenseDetail[data-slide] { animation: report-in 200ms ease-out; }
#reportDetail[data-slide="right"], #expenseDetail[data-slide="right"] { animation-name: report-in-right; }

@keyframes report-in      { from { opacity: 0; transform: translateX(16px); } }
@keyframes report-in-right{ from { opacity: 0; transform: translateX(-16px); } }

@media (prefers-reduced-motion: reduce) {
  #reportDetail[data-slide], #expenseDetail[data-slide] { animation: none; }
}

/* =====================================================================================
   Interface refinement pass
   -------------------------------------------------------------------------------------
   The base above is Apple's grouped-list structure. This layer adds what makes an
   interface feel finished rather than merely laid out: consistent depth, one motion
   language, and a single state layer so every touchable thing responds the same way.

   The rule throughout: feedback is immediate, transitions are short, and nothing moves
   that does not need to. Everything here collapses under prefers-reduced-motion.
   ===================================================================================== */

/* ---------- One state layer for everything touchable ----------
   Rather than restyling hover and press per component, an overlay of the element's own
   colour sits on top at a fixed opacity. Consistent by construction, and it reads the same
   on a card, a row, a nav tab and a button. */

.exp-card, .card, .row[onclick], .alert-row, .nav-btn, .icon-btn,
.btn-primary, .btn-secondary, .btn-ghost, .upload-tile, .fab {
  position: relative;
  isolation: isolate;
}
.exp-card::after, .row[onclick]::after, .alert-row::after, .nav-btn::after,
.icon-btn::after, .btn-primary::after, .btn-secondary::after, .btn-ghost::after,
.upload-tile::after, .fab::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease-emphasized);
  z-index: -1;
}
@media (hover: hover) and (pointer: fine) {
  .exp-card:hover::after, .row[onclick]:hover::after, .alert-row:hover::after,
  .nav-btn:hover::after, .icon-btn:hover::after, .btn-primary:hover::after,
  .btn-secondary:hover::after, .btn-ghost:hover::after, .upload-tile:hover::after,
  .fab:hover::after { opacity: var(--state-hover); }
}
.exp-card:active::after, .row[onclick]:active::after, .alert-row:active::after,
.nav-btn:active::after, .icon-btn:active::after, .btn-primary:active::after,
.btn-secondary:active::after, .btn-ghost:active::after, .upload-tile:active::after,
.fab:active::after { opacity: var(--state-press); }

/* The previous per-component press colours would now stack with the state layer. */
.icon-btn:active { background: none; }
.exp-card:active { background: var(--card); }
.upload-tile:active { opacity: 1; }

/* ---------- Focus: visible for keyboards, invisible for taps ---------- */

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
:where(button, a, input, select, textarea):focus:not(:focus-visible) { outline: none; }

/* ---------- Depth ---------- */

.card { box-shadow: var(--e1); }
.stat { box-shadow: var(--e1); }
.exp-card {
  box-shadow: var(--e1);
  border-radius: var(--r-card);
  transition: box-shadow var(--t-base) var(--ease-emphasized),
              transform var(--t-base) var(--ease-emphasized);
}
@media (hover: hover) and (pointer: fine) {
  .exp-card:hover { box-shadow: var(--e3); transform: translateY(-2px); }
  .exp-card:hover .exp-thumb { transform: scale(1.04); }
}
.exp-card:active { transform: translateY(0) scale(0.995); box-shadow: var(--e1); }
.exp-thumb { border-radius: 12px; transition: transform var(--t-slow) var(--ease-emphasized); }

/* ---------- Type ----------
   Fewer sizes, each with a job. Large text takes tighter tracking because Inter opens up
   as it grows; small uppercase labels take positive tracking so they stay readable. */

.page-title {
  font-size: clamp(28px, 6vw, 34px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
  text-wrap: balance;
}
.section-label {
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--label-2);
  padding: 0 4px 8px; margin-top: 28px;
}
.exp-title { letter-spacing: -0.014em; }
.stat-value { letter-spacing: -0.028em; }
.hint { line-height: 1.5; }

/* ---------- Controls ---------- */

input, select, textarea {
  border-radius: var(--r-ctl);
  transition: border-color var(--t-fast) var(--ease-emphasized),
              box-shadow var(--t-fast) var(--ease-emphasized);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-tint);
  outline: none;
}

.btn-primary, .btn-secondary, .btn-ghost, .btn-sm {
  border-radius: var(--r-pill);
  font-weight: 600; letter-spacing: -0.01em;
  transition: transform var(--t-fast) var(--ease-emphasized),
              box-shadow var(--t-base) var(--ease-emphasized);
}
.btn-primary { box-shadow: var(--e1); }
.btn-primary:active, .btn-secondary:active, .btn-ghost:active { transform: scale(0.975); }

/* ---------- Navigation ----------
   A pill behind the active tab, so which tab is live does not rest on colour alone. */

.nav-btn { transition: color var(--t-base) var(--ease-emphasized); }
.nav-btn::before {
  content: "";
  position: absolute; left: 50%; top: 2px;
  width: 56px; height: 30px; margin-left: -28px;
  border-radius: var(--r-pill);
  background: var(--blue-tint);
  opacity: 0; transform: scaleX(0.7);
  transition: opacity var(--t-base) var(--ease-emphasized),
              transform var(--t-base) var(--ease-emphasized);
}
.nav-btn[aria-selected="true"]::before { opacity: 1; transform: scaleX(1); }

/* ---------- Floating action button ---------- */

.fab {
  border-radius: var(--r-lg);
  box-shadow: var(--e3);
  transition: transform var(--t-base) var(--ease-emphasized),
              box-shadow var(--t-base) var(--ease-emphasized);
}
.fab:active { transform: scale(0.92); box-shadow: var(--e2); }
@media (hover: hover) and (pointer: fine) {
  .fab:hover { transform: translateY(-2px); box-shadow: var(--e4); }
}

/* ---------- Sheets ----------
   A grabber and a settled rise, so a sheet reads as a surface being pulled up rather than
   a box appearing. */

.sheet {
  box-shadow: var(--e4);
  animation: sheet-rise var(--t-slow) var(--ease-emphasized);
}
.sheet::before {
  content: "";
  display: block; width: 36px; height: 4px;
  margin: 8px auto 0;
  border-radius: var(--r-pill);
  background: var(--label-3);
}
@keyframes sheet-rise {
  from { transform: translateY(28px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---------- Active filter notice ----------
   A remembered filter that hides rows has to announce itself. Without this, a preference
   set last week silently makes receipts look missing. */

.filter-note {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--blue-tint);
  border-radius: var(--r-ctl);
  padding: 9px 10px 9px 14px;
  margin-bottom: 12px;
  font-size: 13.5px; color: var(--label);
  animation: fade var(--t-base) var(--ease-emphasized);
}
.filter-note span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.filter-note .btn-ghost { flex: 0 0 auto; color: var(--blue); margin: 0; padding: 4px 10px; }

/* ---------- Toolbar ---------- */

.toolbar-search input, .toolbar select { border-radius: var(--r-pill); }
.toolbar-search input { padding-left: 40px; }
.toolbar-search svg { left: 14px; }

/* ---------- List entry ----------
   A short stagger as cards arrive, capped at eight so a long list does not become a slow
   cascade every time a search re-renders it. */

.exp-card { animation: card-in var(--t-base) var(--ease-emphasized) backwards; }
.exp-card:nth-child(1) { animation-delay: 0ms; }
.exp-card:nth-child(2) { animation-delay: 20ms; }
.exp-card:nth-child(3) { animation-delay: 40ms; }
.exp-card:nth-child(4) { animation-delay: 60ms; }
.exp-card:nth-child(5) { animation-delay: 80ms; }
.exp-card:nth-child(6) { animation-delay: 100ms; }
.exp-card:nth-child(7) { animation-delay: 120ms; }
.exp-card:nth-child(n + 8) { animation-delay: 140ms; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Empty states ---------- */

.empty { padding: 44px 24px; text-align: center; }
.empty svg { width: 40px; height: 40px; margin: 0 auto 14px; color: var(--label-3); stroke-width: 1.4; }
.empty-title { font-size: 17px; font-weight: 650; letter-spacing: -0.015em; margin-bottom: 4px; }
.empty-sub { font-size: 14px; color: var(--label-2); line-height: 1.45; }

/* ---------- Chrome ---------- */

.topbar { transition: border-color var(--t-base) var(--ease-emphasized); }
.brand-mark, .brand-mark-sm { border-radius: 22.37%; }  /* the iOS squircle ratio */

/* ---------- Reduced motion ----------
   Everything above is decoration. Someone who has asked for less movement gets the same
   interface — nothing here carries meaning the motion alone conveys. */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .exp-card:hover, .exp-card:active, .fab:hover, .fab:active,
  .btn-primary:active, .btn-secondary:active, .btn-ghost:active { transform: none; }
}

/* ---------- Contrast corrections ----------
   Measured, not guessed: white on Apple's #007AFF is 4.02:1, under the 4.5:1 that normal
   text needs. The deeper fill reaches 4.9:1 and is still unmistakably the same blue. */
.btn-primary { background: var(--blue-text); }
/* White on #0a84ff measures 2.15:1. In a dark theme the primary surface is the light
   tone and the label on it is dark — the same inversion Material 3 makes. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { background: var(--blue); color: #04243f; }
  :root:not([data-theme="light"]) .fab { color: #04243f; }
}
:root[data-theme="dark"] .btn-primary { background: var(--blue); color: #04243f; }
:root[data-theme="dark"] .fab { color: #04243f; }
.filter-note .btn-ghost { color: var(--blue-text); }


/* ---------- Fitting the viewport ----------
   Two faults, both of which made a sheet run off the bottom of the screen.

   A flex child will not shrink below its content unless it is told it may, so the sheet
   body ignored its own overflow-y and pushed the sheet past its max-height instead of
   scrolling inside it.

   And on a phone 100vh is the viewport with the browser chrome hidden — larger than what
   you can actually see. dvh tracks the real visible height, with vh kept first as the
   fallback for anything that does not support it. */

.sheet {
  max-height: 92vh;
  max-height: 92dvh;
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;          /* the fix: allow the body to shrink so it can scroll */
  overscroll-behavior: contain;
}
.sheet-head, .sheet-foot { flex: 0 0 auto; }

.login-screen { min-height: 100vh; min-height: 100dvh; }
.app-shell { min-height: 100vh; min-height: 100dvh; }

@media (min-width: 860px) {
  .nav { height: 100vh; height: 100dvh; }
}

/* Long report names must not push the arrows off the edge. */
.report-nav { min-width: 0; }
.report-pos {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The grabber belongs to the sheet, not to a dialog that already has a titled header. */
.sheet:has(.sheet-head)::before { margin-bottom: 2px; }


/* ---------- Line-item settlement ----------
   A line is a description, an amount, a remove button and how it is settled. The settle
   control wraps to its own row rather than squeezing the description, which on a phone is
   the field that actually needs the width. */

.li-row {
  grid-template-columns: 1fr 100px 32px;
  grid-auto-flow: row;
}
.li-settle { grid-column: 1 / -1; }
.li-settle select {
  width: 100%; margin: 0;
  font-size: 13px; padding: 6px 10px; min-height: 34px;
}


/* ---------- Theme control ----------
   A three-way choice, because "follow the system" is a real preference and not the absence
   of one — someone whose phone switches at sunset wants the app to switch with it. */

.theme-picker { display: flex; gap: 6px; }
.theme-option {
  flex: 1; font: inherit; font-size: 14px; font-weight: 500;
  padding: 10px 8px; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1px solid var(--sep-strong); border-radius: var(--r-ctl);
  background: var(--card); color: var(--label); cursor: pointer;
  transition: border-color var(--t-fast) var(--ease-emphasized),
              background-color var(--t-fast) var(--ease-emphasized);
}
.theme-option svg { width: 20px; height: 20px; }
.theme-option[aria-pressed="true"] {
  border-color: var(--blue); background: var(--blue-tint); color: var(--blue-text);
}
.theme-option:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
