:root {
  --bg: #f4f2ee; --card: #fff; --ink: #16181b; --muted: #6b6f76; --line: #dedad3;
  --accent: #1f5eff; --accent-ink: #fff; --ok: #1a7f4b; --warn: #a15c00; --error: #b3261e;
  --soft: #eceae4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --card: #1a1e24; --ink: #eceae6; --muted: #979ba3; --line: #2c3139; --soft: #232830;
          --accent: #6d95ff; --accent-ink: #0b1020; --ok: #4cc38a; --warn: #f0a541; --error: #ff7b72; color-scheme: dark; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: .8rem; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }

.wrap { max-width: 520px; margin: 0 auto; display: grid; gap: 14px; }
.wrap.wide { max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .who { color: var(--muted); font-size: .9rem; }
.topbar button { width: auto; min-height: 40px; padding: 0 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 12px; }
label, .lbl { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-height: 46px;
}
input[type=range] { width: 100%; }
button {
  font: inherit; min-height: 46px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-weight: 600; cursor: pointer; width: 100%;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--error); }
button.small { min-height: 36px; padding: 0 12px; width: auto; font-size: .9rem; }
button:disabled { opacity: .45; cursor: not-allowed; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.error-text { color: var(--error); font-size: .9rem; min-height: 1.2em; }
.note { background: color-mix(in srgb, var(--error) 12%, var(--card)); border-color: var(--error); font-size: .9rem; }

/* printer panel */
.printer summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.printer summary::-webkit-details-marker { display: none; }
.printer > .body { display: grid; gap: 12px; margin-top: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot[data-kind=ok] { background: var(--ok); }
.dot[data-kind=busy] { background: var(--accent); animation: pulse 1s infinite; }
.dot[data-kind=warn] { background: var(--warn); }
.dot[data-kind=error] { background: var(--error); }
@keyframes pulse { 50% { opacity: .3; } }
.log { margin: 0; font: 12px/1.5 ui-monospace, monospace; color: var(--muted); white-space: pre-wrap; max-height: 160px; overflow: auto; }
.preview-wrap { background: repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 16px 16px; border-radius: 10px; padding: 12px; display: grid; place-items: center; }
.preview-wrap canvas { max-width: 100%; height: auto; image-rendering: pixelated; box-shadow: 0 1px 6px rgb(0 0 0 / .2); border-radius: 4px; background: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login .card { width: min(380px, 100%); }

/* label lists */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip { flex: none; width: auto; min-height: 38px; padding: 0 14px; border-radius: 999px; font-size: .9rem; }
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.labels { display: grid; gap: 10px; }
.label-card {
  display: grid; gap: 2px; text-align: left; width: 100%; min-height: 0; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; font-weight: 400;
}
.label-card .name { font-weight: 700; font-size: 1.05rem; }
.label-card .meta { color: var(--muted); font-size: .88rem; }
.empty { text-align: center; padding: 28px 8px; color: var(--muted); }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); padding: 18px; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog form, dialog .stack { display: grid; gap: 12px; }
.stepper { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; align-items: center; }
.stepper input { text-align: center; }
.stepper button { padding: 0; font-size: 1.3rem; }
.allergens { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.allergens label { text-transform: none; letter-spacing: 0; font-size: .92rem; font-weight: 500; color: var(--ink); display: flex; gap: 8px; align-items: center; margin: 0; min-height: 32px; }
.allergens input { width: 18px; height: 18px; }

/* admin */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tab { width: auto; min-height: 42px; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tab[aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); }
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.side { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: grid; gap: 4px; position: sticky; top: 12px; }
.side h3 { padding: 6px 10px 2px; }
.side button { display: flex; justify-content: space-between; text-align: left; border: 0; background: none; min-height: 40px; font-weight: 500; }
.side button[aria-current=true] { background: var(--soft); font-weight: 700; }
.side .count { color: var(--muted); font-weight: 500; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1 1 200px; width: auto; }
.toolbar button { width: auto; }
.table { display: grid; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.item .name { font-weight: 700; }
.item .meta { color: var(--muted); font-size: .88rem; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--soft); font-size: .78rem; font-weight: 600; margin-left: 6px; vertical-align: 1px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile .big { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.bars { display: grid; gap: 5px; }
.bar { display: grid; grid-template-columns: 84px 1fr 36px; gap: 8px; align-items: center; font-size: .85rem; }
.bar .track { background: var(--soft); border-radius: 6px; height: 16px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 0; }
.bar .num { text-align: right; font-variant-numeric: tabular-nums; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; gap: 4px; }
.seg button { width: auto; min-height: 32px; padding: 0 10px; font-size: .85rem; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.alert { border-left: 4px solid var(--warn); }
.alert.urgent { border-left-color: var(--error); }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 10; max-width: calc(100vw - 32px); }
.toast[data-kind=error] { background: var(--error); color: #fff; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; }
  .side h3 { display: none; }
  .side button { gap: 8px; }
}
.stack { display: grid; gap: 12px; }
.stack.top { margin-top: 10px; }

.typed { display: grid; gap: 6px; margin-bottom: 8px; }
.typed > label { text-transform: none; letter-spacing: 0; font-size: .92rem; font-weight: 600; color: var(--ink); display: flex; gap: 8px; align-items: center; margin: 0; }
.typed input[type=checkbox] { width: 18px; height: 18px; }
