/* Branch orders: kitchen-ticket clarity with a waffle-grid motif (the waffle grid is also the sheet grid).
   The site follows orders.xlsx: one tab per branch. Computer: tab list on the side, form beside the orders.
   Phone: the tab list slides in, one column, big touch targets, a save bar at the bottom. */
:root {
  /* colour */
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #1a1d2e;
  --muted: #5b6075;
  --line: #dcdfea;
  --accent: #3340a6;          /* blueberry: actions, the date column */
  --accent-ink: #ffffff;
  --accent-soft: #e6e8f7;
  --maple: #8f5400;           /* maple syrup: quantities, the product columns */
  --maple-strong: #e39a1c;
  --maple-soft: #fcefd8;
  --leaf: #23704f;            /* supplied, saved */
  --leaf-soft: #e1f2ea;
  --slate: #4a5470;           /* the manager block */
  --slate-soft: #eceef4;
  --danger: #b3261e;
  --danger-ink: #ffffff;
  --danger-soft: #fbe7e5;
  --toast-bg: #1a1d2e;
  --toast-fg: #f3f4f8;
  --toast-action: #ffc266;
  --overlay: rgb(51 64 166 / 0.14);
  --scrim: rgb(17 19 28 / 0.4);
  --shadow: 0 1px 2px rgb(26 29 46 / 0.05), 0 6px 20px rgb(26 29 46 / 0.06);

  /* type */
  --font-display: "Suez One", "Segoe UI", Arial, sans-serif;
  --font-body: "Assistant", "Segoe UI", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --fs-xs: 0.8125rem;
  --fs-s: 0.9375rem;
  --fs-m: 1.0625rem;
  --fs-l: 1.375rem;
  --fs-xl: 1.75rem;

  /* shape */
  --radius: 14px;
  --radius-s: 10px;
  --tap: 44px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c;
    --surface: #1a1d2a;
    --surface-2: #151824;
    --ink: #eceef6;
    --muted: #a2a7bd;
    --line: #2c3043;
    --accent: #8f9bff;
    --accent-ink: #11131c;
    --accent-soft: #252a4a;
    --maple: #f3b54a;
    --maple-strong: #f3b54a;
    --maple-soft: #3a2c12;
    --leaf: #6fd3a2;
    --leaf-soft: #17352a;
    --slate: #b7bdd4;
    --slate-soft: #23273a;
    --danger: #ff8a80;
    --danger-ink: #11131c;
    --danger-soft: #3c1c1a;
    --toast-bg: #eceef6;
    --toast-fg: #11131c;
    --toast-action: #3340a6;
    --overlay: rgb(143 155 255 / 0.16);
    --scrim: rgb(0 0 0 / 0.55);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-m) / 1.55 var(--font-body);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
img { max-width: 100%; }
button, input { font: inherit; color: inherit; }
code { font-family: var(--font-mono); font-size: 0.9em; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }

.skip {
  position: absolute;
  right: 16px;
  top: -60px;
  padding: 10px 14px;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: var(--accent-ink);
  z-index: 50;
}
.skip:focus { top: calc(8px + env(safe-area-inset-top, 0px)); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap {
  width: 100%;
  max-width: 1360px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.eyebrow {
  font-weight: 700;
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  color: var(--muted);
}
.label { font-weight: 600; font-size: var(--fs-s); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  font-weight: 600;
  font-size: var(--fs-s);
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-wide { flex: 1; }
.btn-danger { background: var(--danger); color: var(--danger-ink); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, var(--ink)); }
.btn-ghost.danger:hover, .btn-ghost.danger[aria-expanded="true"] { border-color: var(--danger); color: var(--danger); }
.btn .i { width: 18px; height: 18px; }

#btn-save .i-save { display: none; }
#btn-save[data-mode="server"] .i-save,
#btn-save[data-mode="handle"] .i-save,
#btn-save[data-mode="sheets"] .i-save { display: block; }
#btn-save[data-mode="server"] .i-download,
#btn-save[data-mode="handle"] .i-download,
#btn-save[data-mode="sheets"] .i-download { display: none; }
#btn-open .i-reload { display: none; }
#btn-open[data-mode="sheets"] .i-reload { display: block; }
#btn-open[data-mode="sheets"] .i-folder { display: none; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }
#btn-save { position: relative; }
#btn-save.is-urgent::after {
  content: "";
  position: absolute; top: -4px; left: -4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--maple-strong);
  border: 2px solid var(--bg);
}

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px;
  border: 0; border-radius: var(--radius-s);
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn[aria-disabled="true"] { opacity: 0.3; pointer-events: none; }

/* ---------- header ---------- */

.top-inner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 16px;
  padding-block: 20px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { flex: none; border-radius: 12px; }
.brand-text { min-width: 0; }
.top h1 { font-family: var(--font-display); font-weight: 400; font-size: var(--fs-xl); line-height: 1.1; }
.file-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 4px; font-size: var(--fs-xs); color: var(--muted); }
.file-name { font-family: var(--font-mono); }
.status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="saved"], .status[data-state="saved"] .dot { color: var(--leaf); }
.status[data-state="saved"] .dot { background: var(--leaf); }
.status[data-state="dirty"] { color: var(--maple); font-weight: 600; }
.status[data-state="dirty"] .dot { background: var(--maple-strong); }
.status[data-state="saving"] { color: var(--accent); }
.status[data-state="saving"] .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.25; } }
.top-actions { display: flex; gap: 8px; }
.nav-toggle { display: none; color: var(--ink); }

/* ---------- shell: tab list + main ---------- */

.shell { display: grid; gap: 24px; padding-bottom: 48px; align-items: start; }
.main { min-width: 0; }
.view { display: flex; flex-direction: column; gap: 20px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.panel-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.panel h3, .view-head h2, .branch-head h2 { font-family: var(--font-display); font-weight: 400; line-height: 1.2; }
.panel h3 { font-size: var(--fs-l); }
.panel-sub { color: var(--muted); font-size: var(--fs-s); }
.view-head { display: flex; flex-direction: column; gap: 2px; }
.view-head h2, .branch-head h2 { font-size: var(--fs-xl); }

/* the tab list */
.nav {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 10px;
  min-width: 0;
}
.nav-head { display: flex; align-items: center; justify-content: space-between; padding-inline: 6px; }
.nav-title { font-weight: 700; font-size: var(--fs-xs); letter-spacing: 0.04em; color: var(--muted); }
.nav-close { display: none; }
.nav-all {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 0 10px;
  border-radius: var(--radius-s);
  color: var(--ink); text-decoration: none; font-weight: 700;
}
.nav-all:hover { background: var(--surface-2); }
.nav-all[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.search {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 16px; color: var(--ink); }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; overscroll-behavior: contain; }
.nav-item {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) 10px; gap: 8px; align-items: start;
  padding: 8px 8px 9px;
  border-radius: var(--radius-s);
  color: var(--ink); text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="page"] { background: var(--accent-soft); }
.nav-num { font: 500 11px/1 var(--font-mono); color: var(--muted); padding-top: 5px; text-align: center; }
.nav-name { display: block; font-weight: 600; font-size: var(--fs-s); line-height: 1.3; }
.nav-meta { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--muted); }
.nav-meta .ok { color: var(--leaf); font-weight: 600; }
.nav-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--maple-strong); visibility: hidden; }
.nav-item.has-changes .nav-dot { visibility: visible; }
.nav-none { padding: 8px 10px; color: var(--muted); font-size: var(--fs-s); }
.nav-backdrop { position: fixed; inset: 0; z-index: 34; background: var(--scrim); }

/* ---------- all branches ---------- */

.date-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 18px; }
.chips { display: flex; gap: 8px; overflow-x: auto; min-width: 0; max-width: 100%; padding-bottom: 2px; }
.chip {
  flex: none;
  display: inline-flex; align-items: baseline; gap: 8px;
  min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface);
  cursor: pointer;
}
.chip .num { font-weight: 500; }
.chip-meta { font-size: var(--fs-xs); color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .chip-meta { color: inherit; opacity: 0.85; }

.prep-title { font-size: var(--fs-l); margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--maple-soft);
}
.tile-name { font-size: var(--fs-s); line-height: 1.3; }
.tile-num { font: 500 1.75rem/1 var(--font-mono); color: var(--maple); font-variant-numeric: tabular-nums; }
.tile.is-zero { background: var(--surface-2); }
.tile.is-zero .tile-num { color: var(--muted); }

.link-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.link-chips a {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); text-decoration: none; font-size: var(--fs-s);
}
.link-chips a:hover { border-color: var(--accent); color: var(--accent); }
.link-chips .num { font-size: 11px; color: var(--muted); }

.order-n { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }

/* ---------- categories ---------- */

.cat-add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-add-row input {
  flex: 1 1 240px; min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 16px;
}
.cat-add-row input:focus { border-color: var(--accent); outline: none; }
#cat-form .form-error { margin: 12px 0 0; }

.cat-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.cat {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px 16px;
  padding-block: 14px;
  border-bottom: 1px solid var(--line);
}
.cat-name { font-weight: 700; font-size: var(--fs-m); }
.cat-meta { font-size: var(--fs-s); color: var(--muted); }
.cat-meta .partial { color: var(--maple); font-weight: 600; }
.cat-missing { margin-top: 4px; font-size: var(--fs-s); }
.cat-missing summary { cursor: pointer; color: var(--accent); width: fit-content; }
.cat-missing p { margin-top: 4px; color: var(--muted); font-size: var(--fs-xs); }
.cat-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.cat-confirm {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  background: var(--danger-soft);
}
.cat-confirm p { font-size: var(--fs-s); }
.cat-confirm-buttons { display: flex; gap: 8px; }
.cat.is-renaming { display: block; }
.cat-rename { display: flex; flex-direction: column; gap: 8px; }
.cat-rename-label { font-size: var(--fs-s); }
.cat-rename .form-error { margin: 0; }
#cat-rename-input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- one branch ---------- */

.branch-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }
.branch-name { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pager { display: flex; gap: 4px; }
.pager .icon-btn { border: 1px solid var(--line); background: var(--surface); }

.mgr {
  flex-basis: 100%;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--slate-soft);
}
.mgr-title { font-weight: 700; font-size: var(--fs-xs); letter-spacing: 0.04em; color: var(--slate); }
.mgr-name { font-weight: 700; }
.mgr-missing { color: var(--muted); font-size: var(--fs-s); }
.mgr-phone { display: inline-flex; align-items: center; gap: 2px; }
.call {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border-radius: 999px;
  background: var(--leaf-soft); color: var(--leaf);
  font-family: var(--font-mono); font-weight: 500; font-size: var(--fs-s);
  text-decoration: none;
}
.call:hover { background: color-mix(in srgb, var(--leaf-soft) 70%, var(--leaf)); }
.call .i { width: 18px; height: 18px; }

/* form on top, the branch's orders under it at full width, so every column fits */
.layout { display: grid; gap: 20px; align-items: start; }

/* order form */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend { font-weight: 600; font-size: var(--fs-s); padding: 0; margin-bottom: 6px; }
input[type="date"] {
  min-height: var(--tap);
  width: 100%;
  max-width: 320px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 16px;
}
input[aria-invalid="true"] { border-color: var(--danger); }

.prod-list { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--line); }
@media (min-width: 640px) {
  .prod-list { grid-template-columns: 1fr 1fr; column-gap: 32px; }
  .form-foot { flex-direction: row; align-items: center; justify-content: space-between; }
  .form-buttons .btn-wide { flex: none; min-width: 200px; }
}
.prod {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding-block: 10px;
  border-bottom: 1px solid var(--line);
}
.prod-name { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: var(--fs-m); line-height: 1.3; cursor: pointer; }
.prod.has-qty .prod-name { font-weight: 700; }

.col-chip {
  display: inline-grid; place-items: center; flex: none;
  min-width: 22px; height: 22px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 6px;
  font: 500 11px/1 var(--font-mono);
  color: var(--muted);
}
.prod.has-qty .col-chip { border-color: var(--maple-strong); color: var(--maple); background: var(--maple-soft); }

.stepper {
  direction: ltr;
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  overflow: hidden;
}
.prod.has-qty .stepper { border-color: var(--maple-strong); }
.step {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--accent);
  cursor: pointer;
}
.step:hover { background: var(--accent-soft); }
.step .i { width: 18px; height: 18px; stroke-width: 2.2; }
.qty-input {
  width: 3.5rem;
  border: 0;
  border-inline: 1px solid var(--line);
  background: var(--surface);
  text-align: center;
  font: 500 17px var(--font-mono);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.prod.has-qty .qty-input { color: var(--maple); background: var(--maple-soft); }
.qty-input::-webkit-inner-spin-button, .qty-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  font-size: var(--fs-s);
}
.form-foot { display: flex; flex-direction: column; gap: 12px; }
.form-total { color: var(--muted); font-size: var(--fs-s); }
.form-total strong { color: var(--ink); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.form-buttons { display: flex; gap: 8px; }

/* ---------- order tables (a branch, and all branches) ---------- */

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 28px 12px 32px; color: var(--muted); }
.empty-mark { width: 64px; height: 64px; margin-bottom: 8px; fill: var(--maple-soft); stroke: var(--maple-strong); stroke-width: 2; }
.empty-title { color: var(--ink); font-weight: 700; font-size: var(--fs-m); }
.empty p:last-child { max-width: 36ch; font-size: var(--fs-s); }

.table-wrap { overflow-x: auto; min-width: 0; }
.orders-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.orders-table th, .orders-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: center; vertical-align: middle; }
.orders-table thead th {
  font-size: var(--fs-xs); font-weight: 600; color: var(--muted);
  line-height: 1.3; vertical-align: bottom;
  min-width: 4.25rem;
}
.orders-table thead th .col-chip { display: grid; margin: 0 auto 6px; width: fit-content; }
.orders-table thead th:first-child { text-align: start; }
.orders-table .c-date, .orders-table .c-branch { text-align: start; font-weight: 600; }
.orders-table .c-date { white-space: nowrap; }
.orders-table .c-date .day { color: var(--muted); font-weight: 400; font-size: var(--fs-s); margin-inline-end: 6px; }
.orders-table .c-branch a { color: var(--ink); text-decoration: none; }
.orders-table .c-branch a:hover { color: var(--accent); text-decoration: underline; }
.orders-table .c-total { font-family: var(--font-mono); font-weight: 500; }
.qty {
  display: inline-block; min-width: 2.2em; padding: 2px 8px;
  border-radius: 999px;
  background: var(--maple-soft); color: var(--maple);
  font: 500 var(--fs-s) var(--font-mono);
}
.zero, .na { color: var(--muted); opacity: 0.6; }
.orders-table .c-actions { white-space: nowrap; width: 1%; padding-inline: 0; }
.orders-table tbody tr:hover { background: var(--surface-2); }
.orders-table tr.is-editing { background: var(--accent-soft) !important; }
.orders-table tfoot th, .orders-table tfoot td { border-bottom: 0; font-family: var(--font-mono); font-weight: 500; color: var(--ink); }
.orders-table tfoot th { font-family: var(--font-body); font-weight: 700; text-align: start; }
.orders-table tfoot tr { background: var(--surface-2); }

@keyframes arrive { from { background: var(--maple-soft); } to { background: transparent; } }
.orders-table tr.is-new { animation: arrive 1.6s ease-out; }

.supply {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 12px;
  border: 1px dashed var(--muted); border-radius: 999px;
  background: transparent; color: var(--muted);
  font-weight: 600; font-size: var(--fs-xs);
  white-space: nowrap;
  cursor: pointer;
}
.supply .i { width: 16px; height: 16px; stroke-width: 2.4; display: none; }
.supply[aria-pressed="true"] { border: 1px solid transparent; background: var(--leaf-soft); color: var(--leaf); }
.supply[aria-pressed="true"] .i { display: block; }

/* ---------- the sheet map ---------- */

.legend { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.legend li { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-s); }
.legend bdi { font-family: var(--font-mono); font-weight: 500; font-size: var(--fs-xs); color: var(--muted); }
.swatch { flex: none; width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid; }
.z-date.swatch { background: var(--accent-soft); border-color: var(--accent); }
.z-qty.swatch { background: var(--maple-soft); border-color: var(--maple-strong); }
.z-status.swatch { background: var(--leaf-soft); border-color: var(--leaf); }
.z-mgr.swatch { background: var(--slate-soft); border-color: var(--slate); }

.sheet-frame { border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.sheet-wrap { overflow-x: auto; }
.sheet { border-collapse: collapse; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { height: 30px; padding: 0 8px; border: 1px solid var(--line); white-space: nowrap; }
.sheet tr:first-child > * { border-top: 0; }
.sheet tr > :first-child { border-right: 0; }
.sheet tr > :last-child { border-left: 0; }
.sheet thead th, .sheet tbody th {
  background: var(--surface-2); color: var(--muted);
  font: 500 11px var(--font-mono); text-align: center; min-width: 32px;
}
.sheet td { min-width: 56px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.sheet td.z-empty { min-width: 28px; }
.sheet .z-date-head, .sheet .z-date { background: var(--accent-soft); }
.sheet .z-date-head { color: var(--accent); font-weight: 700; }
.sheet .z-date { font-family: var(--font-mono); text-align: center; }
.sheet .z-prod-head, .sheet .z-qty { background: var(--maple-soft); }
.sheet .z-prod-head { color: var(--maple); font-weight: 700; }
.sheet .z-qty { text-align: center; font-family: var(--font-mono); color: var(--maple); }
.sheet .z-status-head, .sheet .z-status { background: var(--leaf-soft); color: var(--leaf); }
.sheet .z-status-head { font-weight: 700; }
.sheet .z-status { text-align: center; font-weight: 600; }
.sheet .z-mgr-head, .sheet .z-mgr { background: var(--slate-soft); }
.sheet .z-mgr-head { color: var(--slate); font-weight: 700; font-size: 0.95rem; }
.sheet .z-other { background: var(--surface-2); }

/* the sheet tab, as in the spreadsheet's tab bar */
.sheet-tabs { display: flex; padding: 0 10px; border-top: 1px solid var(--line); background: var(--surface-2); }
.sheet-tab {
  margin-top: -1px;
  max-width: 100%;
  padding: 6px 14px;
  border: 1px solid var(--line); border-top-color: var(--surface);
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  color: var(--leaf);
  font-weight: 700; font-size: var(--fs-xs);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-more, .save-note { margin-top: 10px; font-size: var(--fs-s); color: var(--muted); }

/* ---------- no file, connect, loading ---------- */

.nofile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding-block: 40px; margin-bottom: 40px; }
.nofile img { border-radius: 14px; }
.nofile p { max-width: 44ch; color: var(--muted); }
.nofile .hint { font-size: var(--fs-s); }
.nofile .form-error { margin: 0; max-width: 44ch; color: var(--danger); }
.connect-form { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; max-width: 440px; }
.connect-form input {
  flex: 1 1 240px; min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-2);
  font: 500 16px var(--font-mono);
  letter-spacing: 0.04em;
  text-align: center;
}
.connect-form input:focus { border-color: var(--accent); outline: none; }
.connect-form input[aria-invalid="true"] { border-color: var(--danger); }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sheet-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.sheet-link:hover { text-decoration: underline; }

.nav-disconnect {
  margin-top: auto;
  align-self: flex-start;
  min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: var(--fs-xs); cursor: pointer;
}
.nav-disconnect:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- save bar (phone), toast, drop zone ---------- */

.dock {
  position: fixed; inset: auto 0 0;
  z-index: 20;
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgb(0 0 0 / 0.08);
}
.dock p { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; font-size: var(--fs-s); color: var(--maple); }
.dock .dot { background: var(--maple-strong); }
.dock-buttons { display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
/* a save that needs the user shows on every screen size */
.dock.is-alert:not([hidden]) { display: flex; flex-wrap: wrap; }
.dock.is-alert { background: var(--danger-soft); border-top-color: var(--danger); }
.dock.is-alert p { color: var(--danger); }
.dock.is-alert .dot { background: var(--danger); }
body.has-dock .shell { padding-bottom: 110px; }
body.has-dock .toast { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }

/* "are you sure?" for an order */
.orders-table tr.is-confirming { background: var(--danger-soft) !important; }
.orders-table tr.row-confirm td { text-align: start; padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.orders-table tr.row-confirm:hover { background: transparent; }
.form-confirm { flex-direction: column; align-items: stretch; margin-bottom: 4px; background: var(--accent-soft); }
.form-confirm .cat-confirm-buttons { flex-wrap: wrap; }
.change-list { margin: 0; padding-inline-start: 20px; font-size: var(--fs-s); }
.change-list li { margin-block: 2px; }

.toast {
  position: fixed;
  left: max(16px, env(safe-area-inset-left, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  max-width: 460px; margin-inline: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--toast-bg); color: var(--toast-fg);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.2);
  font-size: var(--fs-s);
}
.toast-action {
  flex: none; min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--toast-action); font-weight: 700; cursor: pointer;
}

.drop {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(2px);
}
.drop p {
  padding: 40px 48px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: var(--fs-l);
  text-align: center;
}

/* ---------- computer: the tab list stays beside the content ---------- */

@media (min-width: 1000px) {
  .shell { grid-template-columns: 290px minmax(0, 1fr); }
  .nav { position: sticky; top: 16px; max-height: calc(100vh - 32px); }
  .panel { padding: 24px; }
}

/* ---------- phone and tablet: the tab list slides in from the right ---------- */

@media (max-width: 999px) {
  .nav-toggle:not([hidden]) { display: inline-grid; margin-inline-start: -8px; }
  .nav-close { display: inline-grid; }
  .nav {
    position: fixed; top: 0; bottom: 0; right: 0;
    z-index: 35;
    width: min(88vw, 360px);
    border-radius: 0;
    border-width: 0 0 0 1px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }
  body.nav-open .nav { transform: none; visibility: visible; transition: transform 0.25s ease; }
  body.nav-open { overflow: hidden; }
  .dock:not([hidden]) { display: flex; }
}

@media (max-width: 599px) {
  .top h1 { font-size: var(--fs-l); }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
  .panel { padding: 16px; }
  .view-head h2, .branch-head h2 { font-size: var(--fs-l); }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .cat { grid-template-columns: 1fr; }
  .cat-actions { justify-content: flex-start; }
  .cat-add-row .btn { flex: 1 1 100%; }
  .tile-num { font-size: 1.5rem; }
  .supply { min-height: 40px; }
}

/* order tables become cards on a phone; products with 0 are left out of the card */
@media (max-width: 699px) {
  .orders-table tr.row-confirm { display: block; padding: 0; border: 0; margin-top: -4px; }
  .orders-table tr.row-confirm td { display: block; padding: 0; border: 0; }
  .table-wrap { overflow: visible; }
  .orders-table, .orders-table tbody, .orders-table tfoot { display: block; }
  .orders-table thead { display: none; }
  .orders-table tbody { display: grid; gap: 10px; }
  .orders-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
    padding: 6px 14px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  .orders-table th, .orders-table td { border: 0; padding: 6px 0; }
  .orders-table .c-date, .orders-table .c-branch { grid-column: 1; grid-row: 1; font-size: var(--fs-m); padding-block: 8px; }
  .orders-table .c-actions { grid-column: 2; grid-row: 1; width: auto; }
  .orders-table td[data-label] {
    grid-column: 1 / -1;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    text-align: start;
  }
  .orders-table td[data-label]::before { content: attr(data-label); color: var(--ink); font-family: var(--font-body); }
  .orders-table td.is-zero, .orders-table td.is-na { display: none; }
  .orders-table .c-total { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--line); font-weight: 700; }
  .orders-table .c-total::before { font-weight: 700; }
  .orders-table .c-supply { grid-column: 1 / -1; text-align: start; padding-top: 10px; }
  .orders-table tfoot { margin-top: 14px; }
  .orders-table tfoot th { grid-column: 1 / -1; padding-block: 10px 4px; }
  .orders-table tfoot td:empty { display: none; }
  .orders-table tr.is-editing { border-color: var(--accent); }
}

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