:root {
  --bg: #f5f4f0; --card: #fff; --ink: #1d1d1b; --muted: #6b6a65; --line: #e4e2dc; --soft: #efede7;
  --accent: #2f5bd3; --accent-ink: #fff;
  --ok: #1f8a4c; --ok-bg: #e3f4ea; --warn: #b06a00; --warn-bg: #fdf0d9; --bad: #c0352b; --bad-bg: #fbe4e1; --info-bg: #e6edfb;
  --fabric: #7a4fd0; --ink-c: #0b8fb3; --paper: #8a6d3b; --other: #666;
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --card: #201f1d; --ink: #ecebe6; --muted: #9c9a92; --line: #34322e; --soft: #2a2926;
    --accent: #6f93ff; --accent-ink: #0d1326;
    --ok: #54c784; --ok-bg: #173323; --warn: #f0b04a; --warn-bg: #3a2c12; --bad: #ff7b6e; --bad-bg: #3d1c19; --info-bg: #1c2540;
    --fabric: #b393ff; --ink-c: #4fd0f0; --paper: #d2b27a; --other: #aaa;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 17px; white-space: nowrap; }
.brand .sub { color: var(--muted); font-size: 13px; margin-left: 4px; }
.topright { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sync { color: var(--muted); font-size: 12px; white-space: nowrap; }
.sync.bad { color: var(--bad); }

.tabs { display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 47px; z-index: 4; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 7px 12px; border-radius: 999px; white-space: nowrap; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--ink); color: var(--bg); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

main { max-width: 1180px; margin: 0 auto; padding: 14px 16px 80px; }
.tab { display: none; }
.tab.on { display: block; }

h2 { font-size: 15px; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
h2 .count { color: var(--muted); font-weight: 400; font-size: 13px; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.err { color: var(--bad); }

.btn { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.chip { border: 1px solid var(--line); background: var(--soft); padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }

/* summary strip */
.alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-bottom: 6px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.stat b { font-size: 22px; display: block; }
.stat.bad { background: var(--bad-bg); border-color: transparent; }
.stat.warn { background: var(--warn-bg); border-color: transparent; }
.stat.ok { background: var(--ok-bg); border-color: transparent; }

/* stock cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 8px; border-left: 4px solid var(--other); }
.card.fabric { border-left-color: var(--fabric); }
.card.ink { border-left-color: var(--ink-c); }
.card.paper { border-left-color: var(--paper); }
.card .head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card .name { font-weight: 600; cursor: pointer; }
.card .name:hover { text-decoration: underline; }
.qtyline { display: flex; align-items: baseline; gap: 6px; }
.qty { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.unit { color: var(--muted); }
.bar { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; position: relative; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.bar.warn i { background: var(--warn); } .bar.bad i { background: var(--bad); }
.need { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 12px; color: var(--muted); }
.need div { background: var(--soft); border-radius: 7px; padding: 4px 6px; }
.need b { display: block; color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }
.need .short b { color: var(--bad); }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
.acts .btn { flex: 1; }
.pill { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--accent); }
.pill.gray { background: var(--soft); color: var(--muted); }
.est { font-size: 11px; color: var(--warn); }
.meta { font-size: 12px; color: var(--muted); }

/* tables */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: 12px; color: var(--muted); background: var(--soft); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tr.group td { background: var(--soft); font-weight: 600; }
tr.dim td { color: var(--muted); }

.fabsum { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.fabsum .stat { cursor: pointer; }
.fabsum .stat .line { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.fabsum .stat .line b { font-size: 13px; display: inline; color: var(--ink); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 10px; }
.toolbar input[type=search] { flex: 1; min-width: 160px; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); }
label.tick { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }

/* dialog */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
#dlgForm { padding: 18px; display: flex; flex-direction: column; gap: 12px; max-height: 85vh; overflow-y: auto; }
#dlgForm h3 { margin: 0; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font-size: 15px; }
.field textarea { min-height: 60px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlgacts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.bigin { font-size: 28px !important; text-align: center; font-weight: 700; }
.preview { text-align: center; font-size: 13px; color: var(--muted); min-height: 18px; }
.rules { display: flex; flex-direction: column; gap: 6px; }
.rules .r { display: grid; grid-template-columns: 1fr 100px 30px; gap: 6px; }
.rules input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.names { display: flex; gap: 6px; flex-wrap: wrap; }
.names button { padding: 10px 14px; }

.gate { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.gatebox { max-width: 380px; text-align: center; }
.gatebox form { display: flex; gap: 8px; }
.gatebox input { flex: 1; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; max-width: calc(100vw - 32px); }
.empty { padding: 26px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--r); }
.note { background: var(--info-bg); border-radius: var(--r); padding: 10px 12px; font-size: 13px; }

/* daily count sheet */
.countsheet td { vertical-align: middle; }
.countsheet .todaycol { background: var(--info-bg); }
.cin { width: 76px; padding: 7px 8px; border: 2px solid var(--line); border-radius: 9px; background: var(--card); text-align: right; font-size: 16px; font-weight: 600; }
.cin:focus { outline: none; border-color: var(--accent); }
.cin.atmin { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
.circ { display: inline-block; min-width: 26px; padding: 1px 6px; border: 2px solid var(--bad); border-radius: 999px; color: var(--bad); text-align: center; }
.show-sm { display: none; }

@media (max-width: 560px) {
  .show-sm { display: table-cell; }
  .sync { display: none; }
  .two { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  th, td { padding: 6px 7px; }
}
