/* ============================================================================
   Receipt Capture — design system (no build step, vanilla).
   "Gem" identity: indigo→cyan gradient reserved for brand moments.
   Auto light/dark. Phone-first, installable (PWA) card app.
   ============================================================================ */

:root {
  --bg: #0d1016; --panel: #161b23; --panel-2: #1d232d; --panel-3: #232c38;
  --line: #29323f; --text: #e8edf4; --muted: #8a97a9; --faint: #5f6b7c;
  --accent: #5b8cff; --accent-2: #3d6ff0; --accent-soft: #172239;
  --good: #22c55e; --good-soft: #123020; --good-text: #63e6a2;
  --warn: #f59e0b; --warn-soft: #362a12; --warn-text: #f5c451;
  --bad: #f26060; --bad-soft: #38191d; --bad-text: #f79a97;
  --brand-1: #6a7dff; --brand-2: #38bdf8; --brand-grad: linear-gradient(120deg, #6a7dff, #38bdf8);
  --glow: radial-gradient(1100px 600px at 78% -8%, rgba(90,140,255,.14), transparent 60%),
          radial-gradient(900px 520px at 12% 2%, rgba(56,189,248,.09), transparent 55%);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 22px rgba(0,0,0,.22);
  --shadow-lift: 0 2px 4px rgba(0,0,0,.35), 0 14px 38px rgba(0,0,0,.34);
  --shadow-lg: 0 18px 52px rgba(0,0,0,.55);
  --ring: 0 0 0 3px rgba(90,140,255,.28);
  --hair: inset 0 1px 0 rgba(255,255,255,.04);
  --radius: 18px; --radius-sm: 12px; --radius-xs: 9px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f8; --panel: #ffffff; --panel-2: #f3f6fb; --panel-3: #e8edf5;
    --line: #e3e9f1; --text: #131c2b; --muted: #63718a; --faint: #97a3b6;
    --accent: #2f6bff; --accent-2: #1f57e6; --accent-soft: #e9f0ff;
    --good: #15a34a; --good-soft: #e6f7ec; --good-text: #157f3b;
    --warn: #d97706; --warn-soft: #fdf1dd; --warn-text: #b45309;
    --bad: #e0393b; --bad-soft: #fdeaea; --bad-text: #b91c1c;
    --brand-1: #4f6bff; --brand-2: #22a7e0; --brand-grad: linear-gradient(120deg, #4f6bff, #22a7e0);
    --glow: radial-gradient(1100px 620px at 80% -10%, rgba(79,107,255,.10), transparent 60%),
            radial-gradient(900px 520px at 10% 0%, rgba(34,167,224,.08), transparent 55%);
    --shadow: 0 1px 2px rgba(20,35,60,.05), 0 6px 20px rgba(20,35,60,.07);
    --shadow-lift: 0 2px 6px rgba(20,35,60,.08), 0 16px 40px rgba(20,35,60,.14);
    --shadow-lg: 0 20px 54px rgba(20,35,60,.24);
    --ring: 0 0 0 3px rgba(47,107,255,.18);
    --hair: inset 0 1px 0 rgba(255,255,255,.7);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  background-image: var(--glow); background-attachment: fixed; background-repeat: no-repeat;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.amt { font-variant-numeric: tabular-nums; }

/* ---- App chrome ---- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: saturate(150%) blur(14px); -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 16px; font-weight: 750; letter-spacing: .2px; }
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: 9px; font-size: 16px; background: var(--brand-grad);
  box-shadow: 0 4px 12px rgba(90,140,255,.35), var(--hair);
}
.brand .name { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .tag { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; }
.appbar .who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.appbar .who .email { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Desktop top nav (pills) — hidden on mobile where the bottom bar takes over */
.topnav { display: none; gap: 6px; padding: 10px 18px 0; max-width: 900px; margin: 0 auto; width: 100%; }
.topnav .navbtn {
  padding: 9px 18px; border-radius: 999px; cursor: pointer; color: var(--muted);
  font-weight: 650; font-size: 14px; border: 1px solid transparent; user-select: none;
  display: inline-flex; align-items: center; gap: 7px; transition: background .15s, color .15s;
}
.topnav .navbtn:hover { color: var(--text); background: var(--panel-2); }
.topnav .navbtn.on { background: var(--brand-grad); color: #fff; box-shadow: 0 6px 18px rgba(90,140,255,.35), var(--hair); }

main { flex: 1; width: 100%; max-width: 900px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px); }
@media (min-width: 760px) { main { padding-bottom: 28px; } }

/* Bottom tab bar (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: saturate(150%) blur(16px); -webkit-backdrop-filter: saturate(150%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar .navbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 9px 4px; height: var(--nav-h); cursor: pointer; color: var(--muted);
  font-size: 11px; font-weight: 600; user-select: none; position: relative;
}
.tabbar .navbtn .ic { font-size: 21px; line-height: 1; }
.tabbar .navbtn.on { color: var(--accent); }
.tabbar .navbtn.on .ic { transform: translateY(-1px); }
.tabbar .navbtn .badge {
  position: absolute; top: 7px; left: 50%; margin-left: 4px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--panel);
}
@media (min-width: 760px) {
  .tabbar { display: none; }
  .topnav { display: flex; }
}
@media (max-width: 480px) {
  .brand { font-size: 15px; white-space: nowrap; }
  .appbar .who .email { display: none; }
}

/* ---- Section headers ---- */
.section-h { display: flex; align-items: center; gap: 9px; margin: 22px 4px 10px; }
.section-h:first-child { margin-top: 6px; }
.section-h h2 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.section-h .count { font-size: 11px; font-weight: 800; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.section-h.danger h2 { color: var(--bad); }

/* ---- Cards ---- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow), var(--hair); margin-bottom: 12px; overflow: hidden;
}
.card.act { border-left: 3px solid transparent; border-image: var(--brand-grad) 1; }
.card.danger { border-left: 3px solid var(--bad); }

/* Hero receipt card (inbox) */
.rc { display: flex; gap: 14px; padding: 16px; align-items: flex-start; }
.rc .shot {
  width: 76px; height: 76px; flex: 0 0 76px; border-radius: var(--radius-sm); object-fit: cover;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; display: block;
}
.rc .shot.ph { display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--faint); cursor: default; }
.rc .body { flex: 1; min-width: 0; }
.rc .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rc .vendor { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc .amount { font-size: 21px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rc .meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.rc .who-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.dot { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }

/* Avatar (gradient initials) */
.avatar {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 22px; color: #fff; font-size: 10px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; background: var(--brand-grad); letter-spacing: .2px;
}
.avatar.lg { width: 46px; height: 46px; flex-basis: 46px; font-size: 17px; border-radius: 13px; }

/* Card action row */
.rc-actions { display: flex; gap: 8px; align-items: center; padding: 0 16px 14px 106px; flex-wrap: wrap; }
@media (max-width: 520px) { .rc-actions { padding-left: 16px; } }

/* ---- Job # smart input ---- */
.jobwrap { position: relative; flex: 1 1 130px; min-width: 120px; }
.job-input { width: 100%; padding: 9px 26px 9px 11px; font-size: 14px; font-variant-numeric: tabular-nums; }
.job-input.ok { border-color: var(--good); }
.job-input.no { border-color: var(--bad); }
.job-mark { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 13px; font-weight: 800; pointer-events: none; }
.job-mark.ok { color: var(--good); } .job-mark.no { color: var(--bad); }
.suggests {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-xs);
  box-shadow: var(--shadow-lg); overflow: hidden; display: none;
}
.suggests.show { display: block; }
.suggests div { padding: 9px 12px; cursor: pointer; font-size: 14px; font-variant-numeric: tabular-nums; }
.suggests div:hover, .suggests div.hi { background: var(--accent-soft); color: var(--accent); }

/* ---- Buttons ---- */
button {
  background: var(--brand-grad); color: #fff; border: none; border-radius: 10px;
  padding: 9px 16px; font: inherit; font-weight: 650; cursor: pointer;
  box-shadow: 0 4px 12px rgba(90,140,255,.28), var(--hair); transition: filter .12s, transform .08s, box-shadow .12s;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button.ghost { background: var(--panel); border: 1px solid var(--line); color: var(--text); box-shadow: none; }
button.ghost:hover { background: var(--panel-2); filter: none; border-color: color-mix(in srgb, var(--brand-1) 40%, var(--line)); }
button.danger { background: transparent; border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line)); color: var(--bad); box-shadow: none; }
button.danger:hover { background: var(--bad-soft); filter: none; }
button.small { padding: 8px 13px; font-size: 13px; border-radius: 9px; }
button.icon { padding: 8px 11px; }
button.subtle { color: var(--muted); border-color: transparent; }
button.subtle:hover { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
.arow-actions { display: flex; gap: 4px; flex: 0 0 auto; }

/* ---- Pills ---- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.awaiting_receipt, .pill.reminded { background: var(--warn-soft); color: var(--warn-text); }
.pill.escalated, .pill.failed, .pill.needs_job { background: var(--bad-soft); color: var(--bad-text); }
.pill.synced, .pill.no_job { background: var(--good-soft); color: var(--good-text); }
.pill.ocr_done { background: var(--accent-soft); color: var(--accent); }
.pill.dismissed { background: var(--panel-3); color: var(--faint); }
.flag { color: var(--warn); font-weight: 700; }

/* ---- Compact activity row ---- */
.arow { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.arow:last-child { border-bottom: none; }
.arow .shot-sm { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 10px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.arow .shot-sm.ph { display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--faint); cursor: default; }
.arow .mid { flex: 1; min-width: 0; }
.arow .mid .l1 { display: flex; justify-content: space-between; gap: 10px; }
.arow .mid .v { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arow .mid .a { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.arow .mid .l2 { display: flex; align-items: center; gap: 8px; margin-top: 3px; color: var(--muted); font-size: 12.5px; }

/* ---- Conversation ---- */
.convo-slot { padding: 6px 16px 14px; border-top: 1px solid var(--line); background: var(--panel-2); }
.convo { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 13px; line-height: 1.4; }
.bubble.in { align-self: flex-start; background: var(--panel-3); border-bottom-left-radius: 4px; }
.bubble .t { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble .ph-link { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }

/* ---- Filter bar ---- */
.filterbar { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 10; padding: 8px 0 10px; background: linear-gradient(var(--bg) 78%, transparent); }
.filterbar input.search { margin-bottom: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.fchip { font-size: 12px; font-weight: 650; padding: 6px 12px; border-radius: 999px; cursor: pointer; border: 1px solid var(--line); color: var(--muted); background: var(--panel); user-select: none; transition: color .12s, background .12s, border-color .12s; white-space: nowrap; }
.fchip:hover { color: var(--text); }
.fchip.on { background: var(--brand-grad); color: #fff; border-color: transparent; box-shadow: 0 3px 10px rgba(90,140,255,.3); }
/* Assignee dropdown styled to sit in the chips row */
.person-filter {
  width: auto; padding: 6px 30px 6px 13px; border-radius: 999px; font-size: 12px; font-weight: 650;
  color: var(--text); background-color: var(--panel); border: 1px solid var(--line); cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a97a9' stroke-width='3' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.person-filter:focus { box-shadow: var(--ring); border-color: var(--accent); }

/* ---- Forms ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow), var(--hair); padding: 18px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
input, select, textarea { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%; }
textarea { resize: vertical; min-height: 58px; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 5px; font-weight: 600; }
.field { margin-bottom: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-check { display: flex; align-items: center; gap: 8px; }
.inline-check input { width: auto; }
details.mgroup { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; background: var(--panel-2); }
details.mgroup > summary { cursor: pointer; padding: 12px 14px; font-weight: 650; font-size: 13px; list-style: none; display: flex; align-items: center; gap: 8px; }
details.mgroup > summary::-webkit-details-marker { display: none; }
details.mgroup > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.mgroup[open] > summary::before { transform: rotate(90deg); }
details.mgroup .mbody { padding: 0 14px 12px; }

/* ---- Team ---- */
.person { padding: 14px 16px; }
.person .head { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.person .head .info { flex: 1; min-width: 0; }
.person .head .nm { font-weight: 700; font-size: 15px; }
.person .head .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.person .head .cnt { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.person .edit { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.chev { color: var(--faint); transition: transform .15s; }
.person.open .chev { transform: rotate(90deg); }

/* ---- Empty / loading ---- */
.empty-hero { text-align: center; padding: 44px 20px; }
.empty-hero .big { font-size: 52px; line-height: 1; margin-bottom: 12px; }
.empty-hero .t { font-size: 18px; font-weight: 750; }
.empty-hero .s { color: var(--muted); margin-top: 4px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.skeleton { height: 76px; border-radius: var(--radius); background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 37%, var(--panel-2) 63%); background-size: 400% 100%; animation: sh 1.2s ease infinite; margin-bottom: 12px; }
@keyframes sh { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* ---- Lightbox ---- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .18s; }
.lightbox.show { opacity: 1; pointer-events: auto; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 12px; box-shadow: var(--shadow-lg); }
.lightbox .lb-bar { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px; display: flex; gap: 10px; }
.lightbox .lb-bar a, .lightbox .lb-bar button { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; border-radius: 9px; padding: 9px 15px; font-weight: 600; backdrop-filter: blur(4px); }

/* ---- Toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); padding: 11px 18px; border-radius: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 120; box-shadow: var(--shadow-lg); max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.err { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); color: var(--bad); }
@media (min-width: 760px) { .toast { bottom: 24px; } }

/* ---- Login ---- */
.login-wrap { max-width: 400px; margin: 13vh auto; padding: 0 18px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow), var(--hair); padding: 30px 26px; text-align: center; }
.login-card .gem { width: 58px; height: 58px; margin: 0 auto 14px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 30px; background: var(--brand-grad); box-shadow: 0 10px 28px rgba(90,140,255,.4), var(--hair); }
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.3px; background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card p { color: var(--muted); margin-top: 0; }
.login-card .field { text-align: left; margin-top: 16px; }
