:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #65676b;
  --line: #dadde1;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #d1242f;
  --warn: #b26b00;
  --warn-bg: #fff4e0;
  --ok: #1a7f37;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1c1f24;
    --text: #e6e8eb;
    --muted: #9aa0a6;
    --line: #2f343b;
    --accent: #4c8dff;
    --warn: #f0b45b;
    --warn-bg: #3a2c12;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--accent); color: var(--accent-text);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 650; }
main {
  max-width: 720px; margin: 0 auto;
  padding: 12px 12px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
}

/* bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; height: var(--tabs-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px;
}
.tabs[hidden] { display: none; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); font-weight: 600; }

/* generic building blocks */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; border: 1px solid var(--line);
}
.card h2 { margin: 0 0 10px; font-size: 17px; }
.card h2 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.spacer { height: 8px; }

button, .btn {
  font: inherit; border: 0; border-radius: 12px; cursor: pointer;
  min-height: 48px; padding: 10px 16px; font-weight: 600;
  background: var(--line); color: var(--text);
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.ghost { background: transparent; color: var(--accent); }
button.block { display: block; width: 100%; margin-top: 8px; }
button:disabled { opacity: .4; cursor: default; }
button:active:not(:disabled) { transform: scale(.98); }

input, select, textarea {
  font: inherit; width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
input[type=color] { padding: 4px; width: 64px; flex: none; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; margin: 10px 0 4px; font-size: 14px; color: var(--muted); }

/* spool swatch */
.swatch {
  --c: #888; flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle, var(--card) 0 22%, var(--c) 23% 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18);
}
.swatch.lg { width: 56px; height: 56px; }
.swatch.empty { background: repeating-linear-gradient(45deg, var(--line) 0 4px, transparent 4px 8px); }

/* printers */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.slot {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; min-height: 68px; font-weight: 400; width: 100%;
}
.slot .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.slot .nm { font-weight: 600; font-size: 14px; line-height: 1.2; overflow-wrap: anywhere; }

/* stock list */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 36px; padding: 6px 14px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line); font-weight: 500; font-size: 14px;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.fil {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; font-weight: 400;
}
.fil.warn { border-color: var(--warn); background: var(--warn-bg); }
.fil .nm { font-weight: 600; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.count {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); white-space: nowrap;
}
.count b { font-size: 13px; }
.count.zero { opacity: .45; }
.big-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin: 8px 0; }
.big-counts div { background: var(--bg); border-radius: 12px; padding: 8px 4px; }
.big-counts b { display: block; font-size: 26px; }
.big-counts span { font-size: 12px; color: var(--muted); }

/* stepper */
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 56px; min-height: 52px; font-size: 24px; padding: 0; }
.stepper input { text-align: center; font-size: 22px; font-weight: 600; min-height: 52px; }
.stepper-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.stepper-row .t { flex: 1; }
.stepper-row .t small { display: block; color: var(--muted); }
.stepper-row .stepper { width: 190px; flex: none; }

/* choice buttons in sheets */
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: var(--bg); border: 1px solid var(--line); font-weight: 500; min-height: 58px;
}
.choice .t { flex: 1; }
.choice .t small { display: block; font-weight: 400; color: var(--muted); }
.choice .n { font-size: 20px; font-weight: 700; }

/* bottom sheet */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px;
  max-height: 92vh; border-radius: 18px 18px 0 0; background: var(--card); color: var(--text);
}
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
#sheet-body { padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 8px 0 10px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.sheet-head h3 { margin: 0; flex: 1; font-size: 18px; }
.sheet-head button { min-height: 40px; padding: 6px 10px; }
.sheet-list { max-height: 55vh; overflow-y: auto; margin-top: 8px; }
@media (min-width: 700px) {
  dialog#sheet { margin: auto; border-radius: 18px; }
}

/* log */
.day { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 4px 6px; }
.ev { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.ev .meta { font-size: 12px; color: var(--muted); }
.ev .note { font-size: 14px; font-style: italic; margin-top: 2px; }
.ev .kind { font-size: 11px; text-transform: uppercase; font-weight: 700; letter-spacing: .04em; margin-right: 6px; }
.kind.load { color: var(--accent); }
.kind.unload { color: var(--warn); }
.kind.purchase { color: var(--ok); }
.kind.count { color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); transition: all .2s; z-index: 100; font-size: 15px;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

.login { max-width: 360px; margin: 40px auto; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }
.choice.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.choice.primary .t small { color: inherit; opacity: .85; }
