[hidden] { display: none !important; }
:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #17211d;
  --muted: #5d6b65;
  --line: #dde3e0;
  --brand: #0d5c46;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ec;
  --ok: #157a4f;
  --ok-soft: #e1f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513; --card: #18201d; --ink: #e8eeeb; --muted: #9aa8a2; --line: #2a3531;
    --brand: #2fa37c; --brand-ink: #06140f; --brand-soft: #173229;
    --ok: #4cc58c; --ok-soft: #14301f; --warn: #f0b04c; --warn-soft: #33270f; --bad: #ff8a80; --bad-soft: #3a1714;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .25rem;
  padding: calc(env(safe-area-inset-top) + .5rem) 1rem .5rem;
  background: var(--brand); color: var(--brand-ink);
}
#brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; }
#brand img { width: 28px; height: 28px; border-radius: 7px; }
.spacer { flex: 1; }
.icon-btn { background: none; border: 0; color: inherit; padding: .4rem; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.loading { color: var(--muted); text-align: center; padding: 3rem 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.tight { padding: .25rem 0; }
.row { display: flex; gap: .75rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: .75rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; cursor: pointer;
  padding: .75rem 1rem; background: var(--brand); color: var(--brand-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none;
  min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: var(--brand-soft); color: var(--brand); }
.btn-plain { background: none; color: var(--brand); padding: .5rem; min-height: 0; }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn-block { width: 100%; }
.btn-big { width: 100%; padding: 1rem; font-size: 1.05rem; border-radius: var(--radius); }
.btn-small { padding: .35rem .7rem; min-height: 32px; font-size: .9rem; border-radius: 9px; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input.num { text-align: right; }

.pills { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; }
.pill {
  flex: 0 0 auto; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: .5rem 1rem; font-weight: 600; min-height: 40px;
}
.pill[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.notice { border-radius: 12px; padding: .75rem .9rem; margin-bottom: .75rem; font-size: .95rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice ul { margin: .25rem 0 0; padding-left: 1.1rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a, .list .item { display: flex; gap: .75rem; align-items: center; padding: .75rem 1rem; color: inherit; text-decoration: none; }
.list .main { flex: 1; min-width: 0; }
.list .main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .main small { display: block; }

.sup { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; font-size: .75rem; font-weight: 800; flex: 0 0 auto; background: var(--brand-soft); color: var(--brand); }
.sup.TRI { background: #e6eefc; color: #2550a8; }
.sup.ENT { background: #f3e8fb; color: #7a3aa3; }
.sup.ALL { background: #fdeee2; color: #a8541b; }
.sup.SIG { background: #e3f3f8; color: #1d6f8a; }
@media (prefers-color-scheme: dark) {
  .sup.TRI { background: #1b2740; color: #9bb8f2; }
  .sup.ENT { background: #2b1d36; color: #d1a6ee; }
  .sup.ALL { background: #3a2617; color: #f2b48a; }
  .sup.SIG { background: #15303a; color: #8fd0e6; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.stat small { display: block; font-weight: 600; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

/* capture */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; margin: .75rem 0; }
.page { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--brand-soft); display: grid; place-items: center; font-weight: 700; color: var(--brand); }
.page img { width: 100%; height: 100%; object-fit: cover; }
.page button { position: absolute; top: 4px; right: 4px; min-height: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 1rem; }
.page span { position: absolute; left: 6px; bottom: 4px; font-size: .75rem; color: #fff; text-shadow: 0 1px 2px #000; }
.file-btn input { display: none; }

.progress { text-align: center; padding: 2rem 1rem; }
.spinner { width: 40px; height: 40px; margin: 0 auto 1rem; border: 4px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* review */
.inv-head { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .75rem; margin-bottom: .75rem; }
.lines { width: 100%; border-collapse: collapse; font-size: .9rem; }
.lines th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 700; padding: .25rem .25rem .4rem; border-bottom: 1px solid var(--line); }
.lines td { padding: .4rem .25rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines td.desc { width: 100%; }
.lines td.desc small { display: block; }
.lines input, .lines select { min-height: 36px; padding: .3rem .4rem; font-size: .9rem; }
.lines input.net { width: 5.5rem; }
.lines select.rate { width: 4.6rem; }
.lines select.flag { width: 100%; margin-top: .3rem; }
.lines tr.flagged td { background: var(--warn-soft); }
.src { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 2px; vertical-align: middle; }
.src.printed, .src.remembered, .src.solved, .src.manual { background: var(--ok); }
.src.guessed { background: var(--warn); }
.src.standard { background: var(--line); }
.totals { margin-top: .75rem; display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 800; font-size: 1.1rem; }
.check { margin-top: .75rem; padding-top: .75rem; border-top: 1px dashed var(--line); }

.sticky-actions { position: sticky; bottom: 0; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; }
.thumbs a { display: block; border-radius: 10px; overflow: hidden; background: var(--brand-soft); aspect-ratio: 3/4; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }

#toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: 12px; font-weight: 600;
  transition: transform .25s; z-index: 30; max-width: calc(100% - 2rem);
}
#toast.show { transform: translate(-50%, 0); }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: grid; align-items: end; justify-items: center; }
#modal[hidden] { display: none; }
#modal .sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { #modal { align-items: center; } #modal .sheet { border-radius: 18px; } }

.auth { max-width: 420px; margin: 2rem auto; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 1rem; }
