:root {
  --bg: #f5f3ec; --card: #ffffff; --ink: #16201d; --muted: #59625e; --line: #d9d4c7; --line-soft: #ece8de;
  --brand: #0f6b63; --brand-ink: #ffffff; --brand-soft: #e3eee9;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace;
  --pos: #0b7a4b; --neg: #b42318; --warn-bg: #fff4d6; --warn-ink: #6b4b00; --info-bg: #e3f0fb; --info-ink: #0b3f6b; --danger-bg: #fde4e1; --danger-ink: #7a1710;
  --shadow: none;
  --radius: 8px; --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f; --card: #1b1a17; --ink: #ece8de; --muted: #a9a291; --line: #34322c; --line-soft: #26241f;
    --brand: #2dd4bf; --brand-ink: #04211e; --brand-soft: #123a36;
    --pos: #4ade80; --neg: #ff8a80; --warn-bg: #3a2f10; --warn-ink: #ffe29a; --info-bg: #10304a; --info-ink: #b9defa; --danger-bg: #4a1a16; --danger-ink: #ffc9c3;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body.modal-open { overflow: hidden; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
a { color: var(--brand); }
p { margin: .4rem 0 .8rem; }
.muted { color: var(--muted); } .s { font-size: .82rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* shell */
.shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
.shell > * { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: .55rem 1rem; padding-top: max(.55rem, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.1rem; }
.logo { display: inline-block; width: 30px; height: 30px; line-height: 0; }
.logo svg { width: 100%; height: 100%; display: block; }
.logo.big { width: 64px; height: 64px; margin: 0 auto 1rem; display: block; }
.edition-tag { font-size: .65rem; background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: 2px 6px; letter-spacing: .06em; }
.content { padding: 1rem 1rem calc(var(--tab-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
.sidebar { display: none; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; min-height: 44px; }
.tab-ic { font-size: 1.25rem; line-height: 1; }
.tab.active { color: var(--brand); font-weight: 700; }
.tab-add .tab-ic { background: var(--brand); color: var(--brand-ink); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem; margin-top: -14px; box-shadow: var(--shadow); }
.tab-add.active { color: var(--muted); }
@media (min-width: 900px) {
  .shell { grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .sidebar { display: block; padding: 1rem .6rem; border-right: 1px solid var(--line); background: var(--card); position: sticky; top: 56px; height: calc(100vh - 56px); align-self: start; }
  .nav-item { display: flex; gap: .7rem; align-items: center; padding: .65rem .8rem; border-radius: 10px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
  .nav-item:hover { background: var(--bg); } .nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
  .nav-ic { width: 1.2rem; text-align: center; }
  .tabbar { display: none; }
  .content { padding-bottom: 3rem; }
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin: .4rem 0 1rem; }

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.empty { text-align: center; color: var(--muted); }
.card.empty h2 { color: var(--ink); }
.card.empty .field { text-align: left; max-width: 360px; margin-left: auto; margin-right: auto; }
a.card { display: block; color: inherit; text-decoration: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn.small { min-height: 36px; padding: .25rem .7rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; margin: .5rem 0; }
.icon-btn { border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--muted); min-width: 44px; min-height: 44px; cursor: pointer; }
.banners { display: grid; gap: .5rem; margin-bottom: .75rem; }
.banner { padding: .65rem .9rem; border-radius: 10px; font-size: .92rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); } .banner.info { background: var(--info-bg); color: var(--info-ink); } .banner.danger { background: var(--danger-bg); color: var(--danger-ink); }
.banner a { color: inherit; font-weight: 600; }
.banner .btn { margin-left: .4rem; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); text-transform: capitalize; white-space: nowrap; }
.st-sold { background: var(--brand-soft); color: var(--brand); border-color: transparent; } .st-listed { background: var(--info-bg); color: var(--info-ink); border-color: transparent; }
.st-returned, .st-donated { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }

/* forms */
.form { display: grid; gap: .8rem; }
.grid-f { display: grid; gap: .8rem; grid-template-columns: minmax(0, 1fr); } .grid-f > * { min-width: 0; }
@media (min-width: 560px) { .grid-f { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .grid-f .span2 { grid-column: span 2; } }
.field { display: grid; gap: .25rem; align-content: start; }
.lbl { font-size: .85rem; font-weight: 600; color: var(--muted); }
.hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=search], input[type=date], select, textarea { width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; }
input[disabled] { background: var(--bg); color: var(--muted); }
textarea { resize: vertical; }
input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .3rem 0 .8rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 999px; font-size: .9rem; cursor: pointer; background: var(--card); }
.filters { display: grid; gap: .5rem; grid-template-columns: 1fr 1fr; margin-bottom: .6rem; }
.filters input[type=search] { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; } .filters input[type=search] { grid-column: auto; } }
.sticky-actions { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 6px); z-index: 10; display: flex; gap: .5rem; flex-wrap: wrap; padding: .6rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
@media (min-width: 900px) { .sticky-actions { bottom: 10px; } }

/* lists */
.list { display: grid; }
.row { min-width: 0; display: flex; align-items: center; gap: .6rem; padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
.list > .row:last-child { border-bottom: 0; }
.card-row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .6rem; }
.row-main { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.row-t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-s { font-size: .83rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-r { text-align: right; min-width: 5.5rem; } .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
#inv-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .2rem .8rem; margin-top: .5rem; }
.menu { display: grid; gap: .5rem; } .menu-item { display: flex; justify-content: space-between; padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-weight: 600; }

/* dashboard */
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg-b { white-space: nowrap; flex: 1 1 auto; border: 0; background: transparent; color: var(--ink); padding: .5rem .8rem; font: inherit; font-size: .88rem; cursor: pointer; min-height: 40px; }
.seg-b[aria-pressed=true] { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin-bottom: .9rem; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); }
.kpi-l { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-v { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-s { font-size: .78rem; color: var(--muted); }
.kpi.hero { grid-column: span 2; background: var(--brand-soft); border-color: transparent; }
.kpi.hero .kpi-v { font-size: 2.2rem; } .kpi.hero.pos .kpi-v { color: var(--pos); } .kpi.hero.neg .kpi-v { color: var(--neg); }
@media (min-width: 700px) { .kpis.six { grid-template-columns: repeat(3, 1fr); } }
.kpis.small .kpi-v { font-size: 1.2rem; }
.grid2 { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); } .grid2 > * { min-width: 0; } @media (min-width: 800px) { .grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.chart { width: 100%; height: auto; display: block; }
.bar-pos { fill: var(--brand); } .bar-neg { fill: var(--neg); }
.chart-label, .chart-value { font-size: 12px; fill: var(--ink); } .chart-value { font-weight: 700; } .chart-axis { stroke: var(--line); stroke-width: 1; }
.toplist { margin: 0; padding-left: 1.2rem; } .toplist li { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; }
.how summary { cursor: pointer; font-weight: 600; } .how ul { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.meter { height: 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; margin-top: .35rem; } .meter.big { height: 14px; margin: .6rem 0; }
.meter-f { height: 100%; background: var(--brand); } .meter-f.full { background: var(--pos); }
.thr { display: grid; gap: .8rem; grid-template-columns: 1fr; } @media (min-width: 600px) { .thr { grid-template-columns: 1fr 1fr; } }
.haul-top, .haul-bot { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; flex-wrap: wrap; }

/* sell modal + buy */
.preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 0 0 1rem; position: sticky; top: -.6rem; z-index: 2; }
.pv { background: var(--bg); border-radius: 10px; padding: .5rem .6rem; } .pv-l { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; } .pv-v { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.pv.pos .pv-v { color: var(--pos); } .pv.neg .pv-v { color: var(--neg); }
.verdict { font-size: 2rem; font-weight: 900; letter-spacing: .08em; text-align: center; padding: .8rem; border-radius: var(--radius); margin: .8rem 0; }
.verdict.buy { background: var(--brand-soft); color: var(--pos); } .verdict.pass { background: var(--danger-bg); color: var(--danger-ink); }
.counter { font-size: .85rem; color: var(--muted); align-self: end; padding-bottom: .8rem; } .counter.over { color: var(--neg); font-weight: 700; }
.out-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; } .out-row .field { grid-column: 1 / -1; }
.warns { display: grid; gap: .4rem; margin-top: .6rem; }
.listing-grid { align-items: start; } #out-desc { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88rem; }

/* modal / toast */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(8, 16, 14, .55); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal { background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.25); }
@media (min-width: 700px) { .modal-back { align-items: center; padding: 1rem; } .modal { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .6rem .2rem 1.1rem; } .modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: .6rem 1.1rem 1rem; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .7rem 1.1rem calc(.9rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + 14px + env(safe-area-inset-bottom)); z-index: 200; display: grid; justify-items: center; gap: .4rem; pointer-events: none; padding: 0 1rem; }
@media (min-width: 900px) { .toasts { bottom: 20px; } }
.toast { background: #14201d; color: #fff; padding: .65rem 1rem; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 560px; font-size: .92rem; } .toast.error { background: var(--neg); }
.danger-zone { border-color: var(--neg); }
.legal { font-size: .88rem; color: var(--muted); }
details.preset { border-top: 1px solid var(--line); padding: .5rem 0; } details.preset summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 1.2rem; background: var(--bg); }
.gate-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 1.6rem; max-width: 460px; text-align: center; box-shadow: var(--shadow); }
.gate-card .steps { text-align: left; line-height: 1.7; }
@media print { .topbar, .tabbar, .sidebar, .btn, .banners { display: none !important; } .content { padding: 0; } }

@media (max-width: 600px) {
  #inv-list .row, .card-row { flex-wrap: wrap; row-gap: .3rem; }
  #inv-list .row-main, .card-row .row-main { flex: 1 1 100%; }
  #inv-list .row-r, .card-row .row-r { margin-left: auto; }
  .preview { grid-template-columns: repeat(2, 1fr); }
}

ul.plain { padding-left: 1.1rem; margin: .3rem 0; } ul.plain li { margin: .3rem 0; }

@media (max-width: 600px) {
  .page-head .seg { width: 100%; }
  .page-head .seg .seg-b { flex: 1 1 30%; }
  .sticky-actions { gap: .4rem; padding: .45rem; }
  .sticky-actions .btn { min-height: 40px; padding: .3rem .6rem; font-size: .9rem; flex: 1 1 auto; }
}

.table-wrap { overflow-x: auto; } .tbl { width: 100%; border-collapse: collapse; font-size: .88rem; } .tbl th, .tbl td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; } .tbl .num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; } .tbl tfoot th, .tbl tfoot td { font-weight: 800; border-top: 2px solid var(--line); }

/* ledger look (matches tidylever.com): flat paper, hairlines, mono numbers */
body { font-family: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.kpi-v, .pv-v, .amt, .tbl .num, .chart-value { font-family: var(--mono); letter-spacing: -.01em; font-weight: 600; }
.kpi-l, .pv-l, .tbl th, .lbl, .edition-tag { font-family: var(--mono); font-weight: 500; letter-spacing: .05em; }
.kpi-l, .pv-l { font-size: .72rem; }
.kpi.hero { background: var(--card); border-color: var(--ink); }
.kpi.hero .kpi-v { font-weight: 600; }
.pill, .chip { border-radius: 4px; }
.pill { text-transform: none; font-family: var(--mono); font-weight: 500; font-size: .72rem; }
.btn, .seg, .banner, .pv, .nav-item, input[type=text], input[type=search], input[type=date], select, textarea, .toast { border-radius: 6px; }
.btn.primary:hover { background: #0a4c46; border-color: #0a4c46; }
.nav-item.active { background: transparent; color: var(--ink); box-shadow: inset 3px 0 0 var(--brand); border-radius: 0; font-weight: 700; }
.row { border-bottom-style: dashed; }
.modal, .gate-card { border-radius: 10px; }
@media (max-width: 699px) { .modal { border-radius: 10px 10px 0 0; } }
.verdict { font-family: var(--mono); font-weight: 600; letter-spacing: .12em; }
.tab-add .tab-ic { box-shadow: none; }
