  :root {
    --bg: #f3f5f7; --surface: #ffffff; --surface-2: #f7f8fa; --fill: #eceff3; --seg-thumb: #ffffff;
    --line: #e3e7ec; --line-strong: #d3d9e0;
    --ink: #0f1419; --ink-2: #414b57; --muted: #6e7986;
    --accent: #1f63e6; --accent-press: #1a54c4; --accent-soft: #eaf1fe; --on-accent: #ffffff;
    --bar: #1f63e6; --bar-dim: #a9c2f2;
    --ring: rgba(31, 99, 230, 0.22);
    --shadow: 0 1px 2px rgba(15, 20, 25, 0.04), 0 1px 1px rgba(15, 20, 25, 0.03);
    --shadow-pop: 0 16px 40px -12px rgba(15, 20, 25, 0.25), 0 2px 6px rgba(15, 20, 25, 0.06);
    --good: #1f9d63; --good-soft: #e5f5ec; --warn: #b86e00; --warn-soft: #fdf1dc; --bad: #d93f45; --bad-soft: #fde8e8;
    --d-today: #e5484d; --d-tomorrow: #e5890a; --d-week: #1f63e6; --d-later: #8e4ec6; --d-none: #c3cad3;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0b0d10; --surface: #15181d; --surface-2: #1b1f25; --fill: #22272e; --seg-thumb: #353b45;
      --line: #262b33; --line-strong: #353c46;
      --ink: #eef1f4; --ink-2: #b8c0ca; --muted: #8791a0;
      --accent: #5b8fff; --accent-press: #7aa4ff; --accent-soft: #1a2640; --on-accent: #ffffff;
      --bar: #5b8fff; --bar-dim: #2d4677;
      --ring: rgba(91, 143, 255, 0.3);
      --shadow: none; --shadow-pop: 0 18px 44px -12px rgba(0, 0, 0, 0.7);
      --good: #3dd68c; --good-soft: #13291e; --warn: #f5a524; --warn-soft: #2e2410; --bad: #f2555a; --bad-soft: #321718;
      --d-today: #f2555a; --d-tomorrow: #f5a524; --d-week: #5b8fff; --d-later: #b07ee8; --d-none: #4a525d;
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #0b0d10; --surface: #15181d; --surface-2: #1b1f25; --fill: #22272e; --seg-thumb: #353b45;
    --line: #262b33; --line-strong: #353c46;
    --ink: #eef1f4; --ink-2: #b8c0ca; --muted: #8791a0;
    --accent: #5b8fff; --accent-press: #7aa4ff; --accent-soft: #1a2640; --on-accent: #ffffff;
    --bar: #5b8fff; --bar-dim: #2d4677;
    --ring: rgba(91, 143, 255, 0.3);
    --shadow: none; --shadow-pop: 0 18px 44px -12px rgba(0, 0, 0, 0.7);
    --good: #3dd68c; --good-soft: #13291e; --warn: #f5a524; --warn-soft: #2e2410; --bad: #f2555a; --bad-soft: #321718;
    --d-today: #f2555a; --d-tomorrow: #f5a524; --d-week: #5b8fff; --d-later: #b07ee8; --d-none: #4a525d;
    color-scheme: dark;
  }

  *, *::before, *::after { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 15px/1.4 var(--font); letter-spacing: -0.005em;
    -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  }
  button, input, select, textarea { font: inherit; color: inherit; }
  .num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
  .muted { color: var(--muted); }
  h1, h2, h3 { margin: 0; letter-spacing: -0.02em; text-wrap: balance; }

  /* ---------- Top bar ---------- */
  .topbar {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .topbar-inner {
    max-width: 1240px; margin: 0 auto; padding: 12px 16px 0;
    display: grid; gap: 10px;
  }
  .brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .brand h1 { font-size: 20px; font-weight: 700; }
  .snapshot { font-size: 12px; color: var(--muted); }
  .snapshot b { font-weight: 600; color: var(--ink-2); }
  .tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { text-decoration: none; display: inline-block;
    flex: 0 0 auto; border: 0; background: none; cursor: pointer;
    padding: 10px 12px 11px; font-size: 14px; font-weight: 500; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
  }
  .tab:hover { color: var(--ink-2); }
  .tab[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
  .tab .count { font-family: var(--mono); font-size: 11px; margin-left: 5px; padding: 1px 6px; border-radius: 99px; background: var(--fill); color: var(--ink-2); }

  main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 80px; }

  /* ---------- Shared bits ---------- */
  .card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
    padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 500; cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s, transform .1s;
  }
  .btn:hover { background: var(--surface-2); color: var(--ink); }
  .btn:active { transform: scale(0.98); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
  .btn.primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
  .btn.danger { color: var(--bad); }
  .btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
  .btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
  .btn.big { padding: 14px 20px; font-size: 16px; border-radius: 12px; }
  .btn:disabled { opacity: .45; cursor: default; transform: none; }
  .icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .chip {
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    font-size: 12px; font-weight: 500; padding: 3px 8px; border-radius: 99px;
    background: var(--fill); color: var(--ink-2);
  }
  .chip.good { background: var(--good-soft); color: var(--good); }
  .chip.warn { background: var(--warn-soft); color: var(--warn); }
  .chip.bad { background: var(--bad-soft); color: var(--bad); }
  .chip.accent { background: var(--accent-soft); color: var(--accent); }
  .chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

  input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], textarea {
    width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
    background: var(--surface); font-size: 16px; -webkit-appearance: none; appearance: none;
  }
  input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
  input[type="number"], input[type="date"] { font-family: var(--mono); font-size: 16px; }
  input[type="search"] {
    padding-left: 36px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808a96' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 11px center / 16px no-repeat;
  }
  .field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
  .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
  .section-title h2 { font-size: 18px; }
  .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .empty { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 14px; }

  /* ---------- Mill ---------- */
  .day-strip {
    display: flex; align-items: center; gap: 10px 24px; flex-wrap: wrap;
    padding: 14px 16px; margin-bottom: 16px;
  }
  .day-stat { display: grid; gap: 2px; }
  .day-stat .v { font-family: var(--mono); font-size: 20px; font-weight: 600; }
  .day-stat .l { font-size: 12px; color: var(--muted); }
  .progress { height: 6px; border-radius: 99px; background: var(--fill); overflow: hidden; flex: 1 1 160px; min-width: 120px; }
  .progress > i { display: block; height: 100%; background: var(--good); border-radius: 99px; }
  .day-strip .spacer { flex: 1 1 0; }

  .mill-grid { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
  .queue { padding: 6px; display: grid; gap: 2px; position: sticky; top: 112px; }
  .q-item {
    display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: center;
    width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 10px;
    padding: 10px; cursor: pointer;
  }
  .q-item:hover { background: var(--surface-2); }
  .q-item[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
  .q-num {
    width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
    font: 600 12px/1 var(--mono); background: var(--fill); color: var(--ink-2);
  }
  .q-item.done .q-num { background: var(--good); color: #fff; }
  .q-item.active .q-num { background: var(--accent); color: #fff; }
  .q-main { min-width: 0; }
  .q-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .q-item.done .q-title { color: var(--muted); }
  .q-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .q-side { display: grid; justify-items: end; gap: 3px; }
  .q-move { display: flex; gap: 2px; }
  .q-move button { width: 22px; height: 22px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-size: 11px; }
  .q-move button:hover { background: var(--fill); color: var(--ink); }

  .mix { padding: 20px; display: grid; gap: 20px; }
  .mix-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
  .mix-head h2 { font-size: 24px; }
  .mix-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
  .batch-dots { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; }
  .batch-dots i { width: 22px; height: 6px; border-radius: 99px; background: var(--fill); }
  .batch-dots i.on { background: var(--good); }
  .batch-dots i.now { background: var(--accent); }

  .bins { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
  .bin {
    border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2);
    display: grid; gap: 8px; align-content: start;
  }
  .bin.active { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
  .bin.idle { opacity: .55; }
  .bin .name { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); }
  .bin .dump { font: 600 26px/1 var(--mono); }
  .bin .dump small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
  .bin .flow { font: 500 12px/1.5 var(--mono); color: var(--muted); display: grid; }
  .bin .flow .after { color: var(--ink-2); }
  .bin .flow .neg { color: var(--bad); }
  .bin .now-btn { justify-self: start; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
  .bin-edit { display: flex; gap: 6px; }
  .bin-edit input { padding: 6px 8px; font-size: 14px; }

  .hand { display: grid; gap: 0; }
  .hand-row {
    display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 12px; align-items: center;
    padding: 10px 4px; border-top: 1px solid var(--line); cursor: pointer;
  }
  .hand-row:first-child { border-top: 0; }
  .hand-row input { width: 20px; height: 20px; accent-color: var(--good); margin: 0; }
  .hand-row .amt { font: 600 15px/1 var(--mono); text-align: right; }
  .hand-row .amt small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 3px; }
  .hand-row.checked .ing, .hand-row.checked .amt { color: var(--muted); text-decoration: line-through; }
  .notes-box { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--ink); font-size: 14px; display: grid; gap: 4px; }
  .notes-box b { color: var(--warn); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
  .mix-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
  .done-box { display: grid; gap: 12px; padding: 16px; border-radius: 12px; background: var(--good-soft); }
  .done-box .row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
  .done-box label { flex: 1 1 180px; }

  .confirm-bar {
    display: grid; gap: 10px; padding: 14px 16px; margin-bottom: 16px;
    border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 12px;
  }
  .confirm-bar ul { margin: 0; padding-left: 18px; font-size: 14px; }
  .confirm-bar .row { display: flex; gap: 8px; flex-wrap: wrap; }

  /* ---------- Schedule ---------- */
  .toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
  .toolbar input[type="search"] { flex: 1 1 240px; width: auto; }
  .day-group { margin-bottom: 18px; }
  .day-head { display: flex; align-items: center; gap: 8px; margin: 0 2px 8px; }
  .day-head .dot { width: 8px; height: 8px; border-radius: 50%; }
  .day-head h3 { font-size: 14px; font-weight: 600; }
  .day-head .sum { font: 500 12px var(--mono); color: var(--muted); margin-left: auto; }
  .orders { overflow: hidden; }
  .order {
    display: grid; grid-template-columns: 28px minmax(0, 1.2fr) minmax(0, 1.6fr) 84px 64px minmax(0, 1.2fr) 190px;
    gap: 12px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line);
  }
  .order:first-child { border-top: 0; }
  .order input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
  .order .cust { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .order .rec { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
  .order .qty, .order .tags { font: 500 13px var(--mono); text-align: right; color: var(--ink-2); }
  .order .note { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .order .end { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
  .order.header { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-block: 9px; background: var(--surface-2); }

  /* ---------- Drawer (order editor) ---------- */
  .scrim { position: fixed; inset: 0; background: rgba(10, 14, 20, 0.35); z-index: 40; }
  .drawer {
    position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(460px, 100%);
    background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop);
    display: grid; grid-template-rows: auto 1fr auto; animation: slide .22s ease-out;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  @keyframes slide { from { transform: translateX(24px); opacity: 0; } }
  .drawer header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
  .drawer header h2 { font-size: 18px; }
  .drawer .body { overflow-y: auto; padding: 18px; display: grid; gap: 14px; align-content: start; }
  .drawer footer { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
  .drawer footer .spacer { flex: 1; }
  .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .suggest { display: flex; gap: 6px; flex-wrap: wrap; }
  .suggest button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 99px; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
  .suggest button:hover { border-color: var(--accent); color: var(--accent); }
  .preview { padding: 12px; border-radius: 10px; background: var(--surface-2); font-size: 13px; display: grid; gap: 6px; }
  .err { color: var(--bad); font-size: 13px; }

  /* ---------- Recipes ---------- */
  .rec-grid { display: grid; grid-template-columns: minmax(240px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
  .rec-list { max-height: calc(100vh - 210px); overflow-y: auto; padding: 6px; }
  .rec-item { display: grid; gap: 2px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
  .rec-item:hover { background: var(--surface-2); }
  .rec-item[aria-current="true"] { background: var(--accent-soft); }
  .rec-item .n { font-weight: 600; font-size: 14px; }
  .rec-item .d { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
  .rec-detail { padding: 20px; display: grid; gap: 18px; }
  .ing-table { width: 100%; border-collapse: collapse; font-size: 14px; }
  .ing-table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 8px 8px; }
  .ing-table td { padding: 8px; border-top: 1px solid var(--line); vertical-align: middle; }
  .ing-table td.r, .ing-table th.r { text-align: right; }
  .ing-table .bar { height: 6px; border-radius: 99px; background: var(--fill); min-width: 60px; }
  .ing-table .bar i { display: block; height: 100%; border-radius: 99px; background: var(--bar); }
  .ing-table tfoot td { font-weight: 600; border-top: 2px solid var(--line-strong); }
  .scale { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
  .scale label { width: 160px; }

  /* ---------- Bins ---------- */
  .bin-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
  .bin-card { padding: 16px; display: grid; gap: 12px; }
  .bin-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .bin-card h3 { font-size: 15px; }
  .bin-card .onhand { font: 600 28px/1 var(--mono); }
  .bin-card .onhand small { font-size: 13px; color: var(--muted); font-weight: 500; }
  .meter { position: relative; height: 10px; border-radius: 99px; background: var(--fill); overflow: hidden; }
  .meter i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--bar); }
  .kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; }
  .kv dt { color: var(--muted); }
  .kv dd { margin: 0; font-family: var(--mono); text-align: right; }
  .log { padding: 4px 0; }
  .log-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 14px; align-items: baseline; }
  .log-row:first-child { border-top: 0; }
  .log-row .t { font: 500 12px var(--mono); color: var(--muted); }
  .log-row .d { font: 500 12px var(--mono); color: var(--ink-2); text-align: right; }

  /* ---------- Tonnage ---------- */
  .kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
  .kpi { padding: 14px 16px; display: grid; gap: 4px; }
  .kpi .l { font-size: 12px; color: var(--muted); }
  .kpi .v { font: 600 26px/1.1 var(--mono); }
  .kpi .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
  .kpi .s { font-size: 12px; color: var(--muted); }
  .chart-card { padding: 16px 16px 10px; margin-bottom: 16px; position: relative; }
  .chart-wrap { overflow-x: auto; }
  .chart-wrap svg { display: block; width: 100%; min-width: 560px; height: auto; }
  .chart-wrap { min-height: 240px; }
  .chart-wrap text { fill: var(--muted); font: 500 11px var(--mono); }
  .chart-wrap .grid line { stroke: var(--line); }
  .chart-wrap .bar { fill: var(--bar); }
  .chart-wrap .bar.partial { fill: var(--bar-dim); }
  .chart-wrap .hit { fill: transparent; cursor: pointer; }
  .chart-wrap .bar { pointer-events: none; }
  .chart-wrap .bar.hover { fill: var(--accent-press); }
  .tip {
    position: absolute; pointer-events: none; z-index: 5; padding: 8px 10px; border-radius: 8px;
    background: var(--ink); color: var(--bg); font-size: 12px; white-space: nowrap; box-shadow: var(--shadow-pop);
    transform: translate(-50%, -100%); margin-top: -8px;
  }
  .tip b { font-family: var(--mono); }
  .two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
  .hbars { display: grid; gap: 10px; padding: 16px; }
  .hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 13px; }
  .hbar .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hbar .v { font: 500 12px var(--mono); color: var(--ink-2); }
  .hbar .track { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--fill); }
  .hbar .track i { display: block; height: 100%; border-radius: 99px; background: var(--bar); }
  .table-wrap { overflow-x: auto; }
  table.plain { width: 100%; border-collapse: collapse; font-size: 13px; }
  table.plain th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 16px; background: var(--surface-2); }
  table.plain td { padding: 9px 16px; border-top: 1px solid var(--line); }
  table.plain .r { text-align: right; }

  .toast {
    position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
    z-index: 60; padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--bg);
    font-size: 14px; font-weight: 500; box-shadow: var(--shadow-pop); display: flex; gap: 12px; align-items: center;
    max-width: calc(100% - 32px);
  }
  .toast button { border: 0; background: none; color: var(--bg); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }

  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

  @media (max-width: 900px) {
    .mill-grid, .rec-grid, .two-col { grid-template-columns: 1fr; }
    .queue { position: static; }
    .rec-list { max-height: 320px; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bins { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  }
  @media (max-width: 720px) {
    .order { grid-template-columns: 28px minmax(0, 1fr) auto; row-gap: 3px; }
    .order .cust { grid-column: 2; }
    .order .rec { grid-column: 2; grid-row: 2; font-size: 13px; }
    .order .qty { grid-column: 3; grid-row: 1; }
    .order .tags { display: none; }
    .order .note { grid-column: 2 / -1; grid-row: 3; }
    .order .note:empty { display: none; }
    .order .end { grid-column: 3; grid-row: 2; }
    .order.header { display: none; }
    .mix { padding: 16px; }
    .mix-head h2 { font-size: 20px; }
    .bin .dump { font-size: 22px; }
  }

  /* ---------- Gate ---------- */
  .gate { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px 16px; }
  .gate-card { width: 100%; max-width: 380px; min-width: 0; padding: 24px; display: grid; gap: 14px; }
  .gate-card > * { min-width: 0; }
  .gate-card h1 { font-size: 22px; }
  .gate-card p { margin: 0; color: var(--muted); font-size: 14px; }
  #pin { width: 100%; min-width: 0; font-family: var(--mono); font-size: 26px; letter-spacing: .3em; text-align: center; }
  .brandmark { display: flex; align-items: center; gap: 10px; }
  .brandmark i { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-style: normal; font-weight: 700; font-size: 14px; }

  /* ---------- Top bar additions ---------- */
  .brand .mode { font-size: 12px; }
  .top-actions { display: flex; gap: 8px; align-items: center; }
  .banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--ink-2); font-size: 13px; margin-bottom: 14px; }
  .banner b { color: var(--ink); }

  /* ---------- Order page (phone-first) ---------- */
  .order-page { max-width: 640px; margin: 0 auto; }
  .order-cta { display: flex; gap: 10px; margin-bottom: 18px; }
  .order-cta .btn { flex: 1; }
  .ocard { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 14px 16px; border-top: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; font: inherit; color: inherit; }
  .ocard:first-child { border-top: 0; }
  .ocard:hover { background: var(--surface-2); }
  .ocard .c { font-weight: 600; font-size: 16px; }
  .ocard .q { font: 600 15px var(--mono); text-align: right; }
  .ocard .r { color: var(--ink-2); font-size: 14px; }
  .ocard .s { justify-self: end; }
  .ocard .n { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

  /* ---------- Combobox ---------- */
  .combo { position: relative; }
  .combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-pop); max-height: 300px; overflow-y: auto; padding: 4px; }
  .combo-list button { display: grid; gap: 1px; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; cursor: pointer; font: inherit; color: inherit; }
  .combo-list button:hover, .combo-list button:focus { background: var(--fill); outline: none; }
  .combo-list .sub { font-size: 12px; color: var(--muted); }
  .combo-list .none { padding: 10px 12px; font-size: 13px; color: var(--muted); }

  @media (max-width: 720px) {
    .drawer { width: 100%; border-left: 0; }
    .drawer .body { padding: 16px; }
    .btn { padding: 11px 14px; }
    .topbar-inner { padding-top: 10px; }
    .brand .snapshot { display: none; }
  }

  /* ---------- Recipe editor ---------- */
  .drawer.wide { width: min(680px, 100%); }
  .ing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; }
  .ing-in { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); padding: 2px 0; }
  .ing-in span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ing-in em { font-style: normal; font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin-left: 4px; }
  .ing-in input { padding: 7px 9px; text-align: right; }
  .ing-in.has { color: var(--ink); font-weight: 500; }
  .ing-in.has input { border-color: var(--accent); }

  /* ---------- Saving ---------- */
  body.busy { cursor: progress; }
  body.busy [data-act="commit"], body.busy [data-act="close-yes"] { opacity: .6; pointer-events: none; }

  /* ---------- Page heading ---------- */
  .page-head { margin: 2px 0 14px; display: grid; gap: 4px; }
  .page-head h2 { font-size: 20px; }
  .page-head p { margin: 0; font-size: 14px; color: var(--muted); }

  /* ---------- Selects ---------- */
  select {
    width: 100%; padding: 10px 34px 10px 12px; border-radius: 10px; border: 1px solid var(--line-strong); font-size: 16px;
    -webkit-appearance: none; appearance: none;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808a96' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 10px center / 16px no-repeat;
  }
  select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

  /* ---------- + New menu ---------- */
  .add-menu { position: relative; }
  .add-menu .menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 170px; padding: 4px; box-shadow: var(--shadow-pop); }
  .add-menu.open .menu { display: grid; }
  .add-menu .menu button { text-align: left; border: 0; background: none; padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
  .add-menu .menu button:hover, .add-menu .menu button:focus-visible { background: var(--fill); }

  /* ---------- Segmented control ---------- */
  .seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--fill); }
  .seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
  .seg button[aria-pressed="true"] { background: var(--seg-thumb); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

  /* ---------- Schedule: picking ---------- */
  label.order { cursor: pointer; }
  .order.picked { background: var(--accent-soft); }
  .order.on-list { cursor: default; }
  .wl-summary { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px; margin-bottom: 14px; text-decoration: none; color: inherit; font-size: 14px; }
  .wl-summary b { margin-right: 6px; }
  .day-head .pick-day { margin-left: 4px; }
  .print-bar { display: none; }

  /* ---------- Bag tags ---------- */
  .tag-list { display: grid; gap: 14px; }
  .tag-item { overflow: hidden; }
  .tag-item.off { opacity: .7; }
  .tag-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 12px 14px; }
  .tag-title { display: grid; gap: 2px; min-width: 0; }
  .tag-title b { font-size: 16px; }
  .tag-title .muted { font-size: 13px; }
  .tag-ctl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  .stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
  .stepper button { width: 42px; height: 40px; border: 0; background: var(--surface); font-size: 20px; cursor: pointer; color: var(--ink); }
  .stepper button:active { background: var(--fill); }
  .stepper span { min-width: 34px; text-align: center; font-size: 16px; font-weight: 600; }
  .lbs-in { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
  .lbs-in input { width: 96px; padding: 9px 10px; text-align: right; }
  .tag-fit { position: relative; overflow: hidden; margin: 0 14px 14px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
  .tag-fit.scroll { overflow-x: auto; }
  .tag-fit .tag-sheet { transform-origin: top left; }
  .tag-add { padding: 14px; margin-top: 14px; display: grid; gap: 10px; }
  .tag-add-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px auto; gap: 8px; }
  .tag-print { display: none; }

  /* The tag itself: a letter-size page, laid out like the Bulk Labels sheet. Always black on white. */
  .tag-sheet {
    width: 816px; height: 1056px; padding: 64px 72px 56px; background: #fff; color: #000;
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; display: flex; flex-direction: column; gap: 26px;
    letter-spacing: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .tag-sheet h4 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
  .tg-name { font-size: 46px; font-weight: 700; line-height: 1.1; text-align: center; text-transform: uppercase; overflow-wrap: anywhere; }
  .tg-wt { display: flex; justify-content: center; gap: 36px; font-size: 24px; font-weight: 700; }
  .tg-ga { width: 460px; margin: 10px auto 0; font-size: 19px; }
  .tg-ga h4 { text-align: center; font-size: 22px; }
  .tg-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; }
  .tg-row i { flex: 1; border-bottom: 2px dotted #000; transform: translateY(-4px); }
  .tg-row b { min-width: 64px; text-align: right; }
  .tg-ing p, .tg-warn p { margin: 0; font-size: 15px; line-height: 1.45; }
  .tg-warn h4 { color: #000; }
  .tg-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; font-size: 16px; }
  .tg-addr { font-weight: 700; font-size: 17px; line-height: 1.35; text-align: right; }

  @media (max-width: 760px) {
    /* Schedule on a phone: bigger tap targets, add button at the bottom */
    .send-top { display: none; }
    .order { padding: 13px 14px; }
    .order input[type="checkbox"] { width: 24px; height: 24px; }
    .day-head { flex-wrap: wrap; }
    .print-bar {
      display: flex; align-items: center; gap: 10px; justify-content: space-between;
      position: sticky; bottom: 0; z-index: 15; margin: 16px -16px -80px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
      background: color-mix(in srgb, var(--bg) 90%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
      border-top: 1px solid var(--line);
    }
    .print-bar[hidden] { display: none; }
    .print-bar .btn { flex: 1; }
    .print-bar .num { font-size: 13px; color: var(--ink-2); }
    .tags-screen .print-btn { display: none; }
    .tags-screen .toolbar .seg { flex: 1 1 100%; }
    .tags-screen .seg button { flex: 1; }
    .tag-fit { margin: 0 10px 10px; }
    .tag-add-row { grid-template-columns: minmax(0, 1fr) 64px auto; }
  }

  /* ---------- Printing bag tags ---------- */
  @page { size: letter portrait; margin: 0; }
  @media print {
    body.route-tags { background: #fff !important; }
    body.route-tags .topbar, body.route-tags .tags-screen, body.route-tags #overlay, body.route-tags #toast-host { display: none !important; }
    body.route-tags main { max-width: none; margin: 0; padding: 0; }
    body.route-tags .tag-print { display: block; }
    /* Shorter than the page, so a phone's own print margins can't push a tag onto a second sheet */
    .tag-page { break-after: page; page-break-after: always; break-inside: avoid; }
    .tag-page:last-child { break-after: auto; page-break-after: auto; }
    .tag-page .tag-sheet { width: 100%; height: 9.8in; padding: 0.5in 0.6in 0.3in; }
  }
  .tags-screen { max-width: 860px; margin: 0 auto; }

  /* ---------- Logo ---------- */
  .brand { align-items: center; }
  .brand-logo { display: inline-flex; color: var(--ink); text-decoration: none; }
  .brand-logo svg { height: 28px; width: auto; display: block; }
  .brand-sub { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--line-strong); }
  .gate-logo { color: var(--ink); display: flex; justify-content: center; padding: 6px 0 2px; }
  .gate-logo svg { height: 46px; width: auto; }
  .gate-card h1 { text-align: center; font-size: 17px; font-weight: 600; color: var(--ink-2); }
  .tg-foot { align-items: flex-end; }
  .tg-logo { display: flex; justify-content: flex-end; color: #000; margin-bottom: 6px; }
  .tg-logo svg { height: 38px; width: auto; }
  @media (max-width: 720px) { .brand-logo svg { height: 24px; } }

  /* ---------- Sheet sync banner ---------- */
  .sync-banner { background: var(--warn-soft); border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink-2); font-size: 13px; }
  .sync-banner.bad { background: var(--bad-soft); }
  .sync-inner { max-width: 1240px; margin: 0 auto; padding: 9px 16px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
  .sync-inner b { color: var(--ink); }
  .sync-meta { color: var(--muted); font-size: 12px; }
  .sync-banner.bad .sync-meta { color: var(--bad); }
  .sync-inner .btn { margin-left: auto; }
  @media print { .sync-banner { display: none !important; } }
