:root {
  color-scheme: light dark;
  --bg:#f5f6f8; --surface:#fff; --fg:#14171c; --muted:#5a6270; --line:#e0e3e9;
  --btn:#2358d6; --btn-hover:#1b47b0; --btn-text:#fff;
  --link:#1d4ed8; --sel:#e6eefc;
  --ok-bg:#e7f6ec; --ok-line:#2f9e55; --err-bg:#fdecec; --err-line:#d33a3a;
  --warn:#9a4a00; --warn-bg:#fff0d9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0e1013; --surface:#171a20; --fg:#f2f3f5; --muted:#aab0bb; --line:#2c313a;
    --btn:#2f66e8; --btn-hover:#4a7bf0; --btn-text:#fff;
    --link:#9bbcff; --sel:#1c2b4a;
    --ok-bg:#12301f; --ok-line:#3fb56a; --err-bg:#3a1717; --err-line:#e85d5d;
    --warn:#fbbf24; --warn-bg:#3a2b0c;
  }
}
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color:var(--link); }
h1 { font-size:1.6rem; line-height:1.2; margin:.5rem 0 .25rem; }
h2 { font-size:1.2rem; margin:2rem 0 .6rem; }
em { color:var(--muted); }
.muted, .count { color:var(--muted); font-weight:400; }
.count { font-size:.9em; margin-left:.4rem; }
.num { text-align:right; font-variant-numeric:tabular-nums; }

/* header */
body > header { display:flex; align-items:center; gap:1.5rem; padding:0 1.25rem; background:var(--surface); border-bottom:1px solid var(--line); flex-wrap:wrap; }
body > header strong { font-size:1.05rem; padding:.9rem 0; }
body > header nav { display:flex; gap:.25rem; flex:1; }
body > header nav a { padding:.95rem .9rem; text-decoration:none; color:var(--muted); font-weight:500; border-bottom:3px solid transparent; }
body > header nav a:hover { color:var(--fg); }
body > header nav a.active { color:var(--fg); border-bottom-color:var(--btn); }
.logout { margin:0; color:var(--muted); }
main { max-width:1080px; margin:0 auto; padding:1.25rem 1.25rem 4rem; }
.back { display:inline-block; margin-bottom:.25rem; text-decoration:none; }

/* controls */
input, button, .btn { font:inherit; min-height:2.6rem; padding:.45rem .9rem; border-radius:8px; border:1px solid var(--line); background:var(--surface); color:var(--fg); }
input:focus-visible, button:focus-visible, .btn:focus-visible, a:focus-visible { outline:3px solid var(--link); outline-offset:2px; }
button, .btn { background:var(--btn); border-color:var(--btn); color:var(--btn-text); font-weight:600; cursor:pointer; text-decoration:none; display:inline-flex; align-items:center; }
button:hover, .btn:hover { background:var(--btn-hover); border-color:var(--btn-hover); }
button.secondary, .btn.secondary { background:var(--surface); color:var(--fg); border-color:var(--line); font-weight:500; }
button.secondary:hover, .btn.secondary:hover { border-color:var(--muted); background:var(--surface); }
button.link { background:none; border:0; color:var(--link); min-height:0; padding:0; font-weight:500; }
input[type=checkbox] { width:1.3rem; height:1.3rem; min-height:0; padding:0; accent-color:var(--btn); cursor:pointer; }
.flash { padding:.75rem 1rem; border-radius:8px; border-left:4px solid; margin:0 0 1rem; }
.flash.ok { background:var(--ok-bg); border-color:var(--ok-line); }
.flash.err { background:var(--err-bg); border-color:var(--err-line); }
.badge { display:inline-block; font-size:.78rem; font-weight:600; padding:.05rem .45rem; border-radius:99px; background:var(--warn-bg); color:var(--warn); vertical-align:middle; }
.note-flag { display:inline-block; margin-top:.15rem; padding:.1rem .5rem; border-radius:6px; background:var(--warn-bg); color:var(--warn); font-size:.9rem; }

/* sticky action bar */
.actions { display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; margin:1rem 0; }
.actions input { flex:1; min-width:12rem; }
.actions .muted { margin-left:auto; }
.sticky { position:sticky; top:0; z-index:5; background:var(--bg); padding:.7rem 0; margin:0; border-bottom:1px solid var(--line); }

/* tables */
table { width:100%; border-collapse:collapse; }
th, td { text-align:left; padding:.7rem .75rem; border-bottom:1px solid var(--line); vertical-align:middle; }
th { color:var(--muted); font-weight:500; font-size:.85rem; text-transform:uppercase; letter-spacing:.04em; }
th.num { text-align:right; }
tbody tr:last-child td { border-bottom:0; }
.card, .batch-group, .month, table.pile-list, table.rows { background:var(--surface); border:1px solid var(--line); border-radius:10px; }
table.pile-list, table.rows { border-collapse:separate; border-spacing:0; overflow:hidden; }
table.pile-list tr:last-child td, table.rows tbody tr:last-child td { border-bottom:0; }

/* selectable rows */
table.rows td.chk, table.rows th.chk { width:3rem; padding-right:0; }
table.rows tbody tr { cursor:pointer; }
table.rows tbody tr:hover { background:color-mix(in srgb, var(--sel) 50%, transparent); }
table.rows tbody tr:has(input:checked) { background:var(--sel); }
.primary { font-size:1.1rem; font-weight:600; letter-spacing:.01em; }
.sub { color:var(--muted); font-size:.88rem; }
.qty { font-size:1.15rem; font-weight:700; }

/* piles list */
.pile-list { table-layout:fixed; }
.pile-list td { padding:.8rem .9rem; }
.pile-list td:nth-child(2) { width:9.5rem; } .pile-list td:nth-child(3) { width:7rem; } .pile-list td:nth-child(4) { width:11rem; }
.pile-list td:nth-child(5) { width:auto; }
.pile-list .pile-name { font-size:1.1rem; font-weight:600; width:15rem; }
.pile-list .pile-name a { color:var(--fg); text-decoration:none; }
.pile-list .pile-name a:hover { text-decoration:underline; }
.pile-pcs { font-size:1.3rem; font-weight:700; }
.take { display:flex; gap:.5rem; justify-content:flex-end; flex-wrap:wrap; } .take form { margin:0; }

/* batches */
.batch-group { padding:.25rem 1rem .5rem; margin:1.25rem 0; overflow-x:auto; }
.batch-group table { background:none; border:0; }
.batch-head { display:flex; justify-content:space-between; gap:1rem; align-items:center; flex-wrap:wrap; padding:.75rem 0; }
.batch-actions { display:flex; gap:.5rem; }
.batch { display:flex; gap:1rem; align-items:center; flex-wrap:wrap; padding:.9rem 1.1rem; background:var(--surface); border:2px solid var(--btn); border-radius:10px; margin:1rem 0; }
.batch form { margin:0 0 0 auto; }

/* delivered */
.month { padding:.25rem 1.1rem 1.1rem; margin:1.25rem 0; }
.month-head { display:flex; justify-content:space-between; align-items:baseline; gap:1rem; flex-wrap:wrap; }
.month-total { display:flex; gap:1rem; align-items:baseline; flex-wrap:wrap; }
.amount { font-size:1.6rem; font-weight:700; font-variant-numeric:tabular-nums; }
.period-total { display:flex; gap:1rem; align-items:baseline; flex-wrap:wrap; }
.summary { background:none; border:0; } .summary tfoot th { color:var(--fg); font-size:1rem; text-transform:none; border-top:2px solid var(--line); border-bottom:0; }
.month details { margin-top:.75rem; } summary { cursor:pointer; padding:.4rem 0; color:var(--link); font-weight:500; }
.month details table { font-size:.95rem; }

/* item page */
dl { display:grid; grid-template-columns:max-content 1fr; gap:.4rem 1.5rem; background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:1rem 1.25rem; }
dt { color:var(--muted); } dd { margin:0; } .pre { white-space:pre-wrap; }

/* login */
.login { max-width:340px; margin:5rem auto; display:grid; gap:.9rem; background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:1.5rem; }
.login label { display:grid; gap:.3rem; color:var(--muted); font-size:.9rem; } .login h1 { margin:0; }

@media (max-width:640px) {
  main { padding:1rem .75rem 3rem; } body > header { gap:.5rem; padding:0 .75rem; }
  th, td { padding:.6rem .5rem; } .pile-list .pile-name { width:auto; }
}
