/* Layout: phone-first ledger — header, scrolling content, bottom tab bar with a centre "Add" key; sidebar on desktop. */
:root {
  --bg: #eef3f6; --surface: #ffffff; --surface-2: #f5f8fa; --line: #dbe4ea;
  --ink: #0f2533; --muted: #5d7180; --navy: #00304e; --blue: #126084; --green: #3f9a3d; --green-bright: #4caf4a;
  --red: #c2413a; --red-soft: #fbe9e7; --amber: #b7791f; --amber-soft: #fdf3e1; --green-soft: #e6f4e5; --blue-soft: #e3f0f6;
  --on-navy: #ffffff; --shadow: 0 1px 2px rgba(0, 40, 64, .06), 0 6px 18px rgba(0, 40, 64, .06);
  --f-display: "Sora", "Segoe UI", system-ui, sans-serif; --f-body: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif; --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --r: 14px; --tab-h: 64px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0a1620; --surface: #10212d; --surface-2: #142836; --line: #21394a; --ink: #e3edf3; --muted: #93a8b6; --navy: #4f9cc4; --blue: #5fb0d6;
  --green: #66c163; --green-bright: #4caf4a; --red: #f07a70; --red-soft: #3a1e1e; --amber: #e8b257; --amber-soft: #352a15; --green-soft: #17331b; --blue-soft: #14303f;
  --on-navy: #06131c; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #0a1620; --surface: #10212d; --surface-2: #142836; --line: #21394a; --ink: #e3edf3; --muted: #93a8b6; --navy: #4f9cc4; --blue: #5fb0d6;
  --green: #66c163; --green-bright: #4caf4a; --red: #f07a70; --red-soft: #3a1e1e; --amber: #e8b257; --amber-soft: #352a15; --green-soft: #17331b; --blue-soft: #14303f;
  --on-navy: #06131c; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.num, .amt { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--f-mono); font-size: .86em; letter-spacing: .01em; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance; letter-spacing: -.01em; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--navy); }

/* ---- shell ---- */
.shell { min-height: 100%; display: grid; grid-template-columns: 1fr; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--navy); color: var(--on-navy);
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px)); display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--green-bright); display: grid; place-items: center; font: 700 13px var(--f-display); color: #fff; flex: none; }
.brand b { font: 700 16px var(--f-display); letter-spacing: -.01em; }
.brand small { display: block; font-size: 11.5px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sp { flex: 1; }
.mode-pill { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: rgba(255, 255, 255, .16); white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .18); border: 0; color: inherit; font-weight: 700; font-size: 13px; }
main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(var(--tab-h) + 32px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); max-width: 980px; width: 100%; margin: 0 auto; display: grid; gap: 16px; align-content: start; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; }
.tab { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--blue); }
.tab-add { justify-self: center; width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--green-bright); color: #fff; display: grid; place-items: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(76, 175, 74, .45); }
.tab-add svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 232px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .tabbar { position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); grid-template-columns: 1fr; grid-auto-rows: min-content; align-items: stretch; gap: 4px; border-top: 0; border-right: 1px solid var(--line); padding: 16px 12px; background: var(--surface); }
  .tab { grid-template-columns: 24px 1fr; justify-items: start; align-items: center; gap: 10px; font-size: 14px; padding: 10px 12px; border-radius: 10px; }
  .tab.on { background: var(--blue-soft); }
  .tab-add { order: -1; width: 100%; height: 46px; border-radius: 12px; margin: 0 0 10px; grid-template-columns: auto auto; gap: 8px; font-weight: 700; }
  .tab-add::after { content: "Add expense"; }
  main { padding-bottom: 40px; }
}

/* ---- generic ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.label { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 10px 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center; min-height: 42px; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.btn.go { background: var(--green-bright); border-color: var(--green-bright); color: #fff; }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.btn.sm { min-height: 34px; padding: 6px 11px; font-size: 13.5px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.chip.on { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.seg { display: inline-grid; grid-auto-flow: column; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 44px; font-size: 16px; }
textarea.input { min-height: 70px; resize: vertical; }
.input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-family: var(--f-display); margin-bottom: 4px; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.section-h h2 { font-size: 17px; }

/* ---- balance cards ---- */
.bal { display: grid; gap: 12px; }
.bal .big { font: 700 30px/1.1 var(--f-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bal .big small { font: 600 14px var(--f-body); color: var(--muted); margin-right: 4px; letter-spacing: 0; }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; display: flex; }
.meter i { display: block; height: 100%; background: var(--blue); border-radius: 99px; transition: width .4s; }
.meter i.warn { background: var(--amber); } .meter i.over { background: var(--red); }
.kv3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv3 div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.kv3 b { display: block; font-variant-numeric: tabular-nums; font-size: 15px; }
.kv3 span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.due { display: block; background: var(--red-soft); color: var(--red); border-radius: 11px; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.due.ok { background: var(--green-soft); color: var(--green); }
.due.amber { background: var(--amber-soft); color: var(--amber); }

/* ---- entry list ---- */
.list { display: grid; }
.day { font-size: 12px; font-weight: 700; color: var(--muted); padding: 12px 2px 6px; letter-spacing: .04em; text-transform: uppercase; }
.entry { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; }
.entry:last-child { border-bottom: 0; }
.cat-dot { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font: 700 14px var(--f-display); color: #fff; }
.entry .t { min-width: 0; }
.entry .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.entry .t span span { display: inline; }
.entry .t > span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .a { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.entry .a small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.entry.cashin .a { color: var(--green); }
.thumb-badge { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green-bright); margin-left: 6px; vertical-align: middle; }

/* ---- category breakdown ---- */
.cats { display: grid; gap: 12px; }
.catrow { display: grid; gap: 6px; }
.catrow .row { justify-content: space-between; flex-wrap: nowrap; }
.catrow .row b { font-variant-numeric: tabular-nums; }
.catbar { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.catbar i { display: block; height: 100%; border-radius: 99px; }
.subs { display: grid; gap: 4px; padding-left: 14px; border-left: 2px solid var(--line); margin-left: 4px; }
.subs .row { font-size: 13.5px; }
.itemlist { font-size: 12.5px; color: var(--muted); padding-left: 2px; }

/* ---- quick add ---- */
.quick { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; }
.quick-hint { font-size: 12.5px; color: var(--muted); min-height: 18px; }
@media (max-width: 420px) { .quick { grid-template-columns: 1fr 92px; } .quick .btn { grid-column: 1 / -1; } }

/* ---- sheet (editor / dialogs) ---- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(4, 18, 28, .5); display: grid; align-items: end; justify-items: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: calc(100% - env(safe-area-inset-top, 0px) - 12px); overflow-y: auto; border-radius: 20px 20px 0 0; padding: 0 0 calc(20px + env(safe-area-inset-bottom, 0px)); -webkit-overflow-scrolling: touch; }
@media (min-width: 760px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; max-height: 92vh; } }
.sheet-h { position: sticky; top: 0; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 10px; padding: 14px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); }
.sheet-h h2 { font-size: 17px; flex: 1; }
.sheet-b { padding: 14px max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 14px; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; color: var(--muted); }
.scanprev { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; }
.scanprev img { width: 96px; height: 124px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.ocr-status { font-size: 13.5px; display: grid; gap: 6px; }
.prog { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; background: var(--green-bright); transition: width .3s; }
.taxline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.taxline div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.taxline span { font-size: 11.5px; color: var(--muted); font-weight: 600; display: block; }
.taxline b { font-variant-numeric: tabular-nums; }
.items { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 1fr 64px 84px 92px 30px; gap: 6px; align-items: center; }
.item .input { min-height: 38px; padding: 7px 8px; font-size: 15px; }
.item .catsel { grid-column: 1 / -2; font-size: 12.5px; min-height: 32px; padding: 4px 8px; border-radius: 99px; background: var(--surface-2); }
.item-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: grid; gap: 6px; }
.items-h { display: grid; grid-template-columns: 1fr 64px 84px 92px 30px; gap: 6px; font-size: 11.5px; color: var(--muted); font-weight: 700; padding: 0 9px; }
@media (max-width: 560px) { .item { grid-template-columns: 1fr 1fr 1fr 30px; } .item [data-f=desc] { grid-column: 1 / -1; } .item .catsel { grid-column: 1 / -1; } .items-h { grid-template-columns: 1fr 1fr 1fr 30px; } .items-h span:first-child { display: none; }
  .item [data-f=qty]::placeholder { color: var(--muted); } }
.icon-btn { border: 0; background: none; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; font-size: 18px; }
.warnbox { background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 9px 12px; font-size: 13.5px; font-weight: 600; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding-top: 14px; display: flex; gap: 10px; }
.sticky-actions .btn { flex: 1; }

/* ---- people ---- */
.person { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.pav { width: 40px; height: 40px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; font-weight: 700; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; font-weight: 600; }
.toggle input { width: 20px; height: 20px; accent-color: var(--green-bright); }
.lh-prev { position: relative; width: 100%; max-width: 300px; aspect-ratio: 210 / 297; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.lh-prev img { width: 100%; height: 100%; object-fit: fill; display: block; }
.lh-prev .area { position: absolute; border: 1.5px dashed #4caf4a; background: rgba(76, 175, 74, .08); display: grid; place-items: center; color: #3f9a3d; font-size: 11px; font-weight: 700; }
.lh-row { display: grid; grid-template-columns: minmax(0, 260px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 560px) { .lh-row { grid-template-columns: 1fr; } }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); background: linear-gradient(180deg, var(--navy) 0 38%, var(--bg) 38%); }
.login .card { width: 100%; max-width: 400px; display: grid; gap: 14px; padding: 22px; }
.login h1 { font-size: 24px; }
.demo-users { display: grid; gap: 8px; }
.demo-users button { text-align: left; display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 26px + env(safe-area-inset-bottom, 0px)); z-index: 90; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }

/* ---- scanner (always dark) ---- */
.scanner { position: fixed; inset: 0; z-index: 80; background: #05121b; color: #fff; display: grid; grid-template-rows: auto 1fr auto auto; padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.scn-top { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; padding: 10px 12px; }
.scn-title { font-weight: 700; text-align: center; }
.scn-x { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .12); color: #fff; font-size: 18px; }
.scn-auto { font-size: 13px; display: flex; gap: 6px; align-items: center; }
.scn-auto input { accent-color: #4caf4a; }
.scn-stage { position: relative; overflow: hidden; min-height: 0; }
.scn-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scn-overlay, .scn-edit { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.scn-loupe { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, .5); pointer-events: none; background: #000; }
.scn-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: rgba(0, 0, 0, .55); padding: 7px 14px; border-radius: 99px; font-size: 13.5px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
.scn-stage.result { display: grid; place-items: center; padding: 12px; }
.scn-stage.result img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 6px 30px rgba(0, 0, 0, .5); }
.scn-busy { position: absolute; color: #cfe3ee; }
.scn-tools { display: flex; gap: 8px; justify-content: center; padding: 10px 12px 0; flex-wrap: wrap; }
.scn-tools .chip { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .18); color: #fff; }
.scn-tools .chip.on { background: #4caf4a; border-color: #4caf4a; }
.scn-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 14px 16px 18px; }
.scn-bar > :first-child { justify-self: start; } .scn-bar > :last-child { justify-self: end; }
.scn-shutter { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: #4caf4a; box-shadow: 0 0 0 3px rgba(76, 175, 74, .4); }
.scn-shutter:disabled { opacity: .35; }
.scn-btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; color: #fff; background: rgba(255, 255, 255, .12); cursor: pointer; }
.scn-btn.primary { background: #4caf4a; }
.scn-bar:has(.primary) { grid-template-columns: 1fr 1fr; }

.viewer { position: fixed; inset: 0; z-index: 85; background: rgba(0, 0, 0, .92); display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer button { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- v2: smart "what did you buy?" box ---- */
.smart { display: grid; gap: 12px; position: relative; overflow: hidden; }
.smart::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: linear-gradient(90deg, var(--blue), var(--green-bright)); }
.smart h2 { font-size: 18px; }
.smart-in { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.smart-in .input { font-size: 17px; }
.smart-inline { display: grid; gap: 8px; background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 10px; }
.tries { display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip.try { font-weight: 500; font-size: 12.5px; padding: 5px 10px; background: var(--surface-2); }
.shelf { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 4px 1px; -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent); mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent); }
.shelf-pill { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 99px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); transition: background .25s, color .25s, border-color .25s, transform .25s; }
.shelf-pill b { font-size: 11px; }
.shelf-pill.hit { background: var(--c); border-color: var(--c); color: #fff; }
.shelf-pill.pop { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.sorted { display: grid; gap: 6px; }
.sorted-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); border-left: 3px solid var(--c); animation: slidein .3s ease-out both; }
@keyframes slidein { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
.sorted-row .t { min-width: 0; }
.sorted-row .t b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sorted-row .t span { display: block; font-size: 12.5px; color: var(--muted); }
.sorted-row .a { font-weight: 700; font-variant-numeric: tabular-nums; }
.sorted-row .a.missing { color: var(--amber); font-weight: 600; font-size: 12.5px; }
.sorted-row mark { background: color-mix(in srgb, var(--c) 28%, transparent); color: inherit; border-radius: 4px; padding: 0 2px; }
.cat-dot.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 11.5px; }
.smart-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.seg.sm button { padding: 5px 10px; font-size: 13px; }

/* ---- alerts ---- */
.alert-banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent); border-radius: var(--r); padding: 12px 14px; }
.alert-banner p { margin: 2px 0 0; font-weight: 600; }

/* ---- insights ---- */
.insights { display: grid; gap: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.spark-wrap { position: relative; display: grid; gap: 4px; }
.spark { width: 100%; height: 120px; display: block; }
.ax-max { position: absolute; right: 0; top: -4px; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); padding-left: 4px; }
.ax-row { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.topcats { display: grid; gap: 7px; }
.tc { display: grid; grid-template-columns: 110px 1fr 74px; gap: 10px; align-items: center; font-size: 13px; }
.tc b { text-align: right; }

/* ---- filters + tables ---- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-top: 10px; }
@media (max-width: 480px) { .filters { grid-template-columns: 1fr; } }
.tbl-wrap { overflow-x: auto; margin-top: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 460px; }
.tbl th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.linkish { border: 0; background: none; padding: 0; color: var(--blue); font-weight: 600; text-align: left; }
.learned { display: flex; flex-wrap: wrap; gap: 8px; }
.lw { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; background: var(--surface-2); }
.lw .icon-btn { width: 24px; height: 24px; font-size: 13px; }
.lh-prev img.hdr { height: auto; object-fit: contain; }
.scn-size { text-align: center; font-size: 12.5px; color: #b9d6e4; padding: 8px 12px 0; }
.scn-link { border: 0; background: none; color: #7ed67b; font-weight: 700; text-decoration: underline; padding: 0; font-size: inherit; cursor: pointer; }
.scn-hint:has(.scn-link) { white-space: normal; text-align: center; }
.attach { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.attach b { display: block; }
.attach.chooser { display: grid; gap: 10px; justify-content: stretch; }
.noinv { color: var(--amber); font-weight: 600; }
.ocr-status .warnbox { margin-top: 6px; }

/* ---- v3: projects, letterhead preview, periods ---- */
.projrow { display: grid; gap: 6px; width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 12px; padding: 8px; margin: -4px -8px; width: calc(100% + 16px); }
.projrow:hover { background: var(--surface-2); }
.projrow.on { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.projtag { color: var(--blue); font-weight: 600; }
.smart-proj { margin-top: 2px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.lh-prev .area { display: block; padding: 6% 5%; overflow: hidden; transition: all .15s; }
.lh-prev .mock { display: grid; gap: 7px; width: 100%; align-content: start; }
.lh-prev .mock i { display: block; width: 100%; height: 4px; border-radius: 2px; background: rgba(0, 48, 78, .25); }
.lh-prev .mock i.mt { width: 55%; height: 7px; background: rgba(0, 48, 78, .6); }
.lh-prev .mock i.mh { height: 6px; background: rgba(0, 48, 78, .5); }
.lh-prev img.hdr { position: absolute; top: 0; left: 0; width: 100%; height: auto; }
