/* The back-office as a phone app.
   Mobile first: one column, bottom tab bar. Past 900px the tab bar becomes a sidebar and
   the ticket rail flows into columns - same templates, no second layout to keep in sync. */

:root {
  color-scheme: light dark;

  --bg: #eef1ef;
  --surface: #ffffff;
  --sunk: #e5eae7;
  --ink: #16201d;
  --muted: #5d6b66;
  --line: #d6ded9;

  --accent: #1f6b53;
  --accent-ink: #ffffff;
  --accent-wash: #1f6b530f;
  --soon: #9d5712;
  --late: #a32a21;

  --tap: 44px;
  --gutter: 16px;
  --r-ticket: 8px;
  --r-sheet: 22px;
  --lift: 0 -1px 0 var(--line), 0 -8px 24px #0000000a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #191f1d;
    --sunk: #141a18;
    --ink: #e6ece9;
    --muted: #8fa09a;
    --line: #2a332f;

    --accent: #49a184;
    --accent-ink: #06120e;
    --accent-wash: #49a1841f;
    --soon: #d18f45;
    --late: #e2796a;
    --lift: 0 -1px 0 var(--line), 0 -8px 24px #00000047;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Archivo, ui-sans-serif, system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15.5px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; }
h3 { font-size: 0.9375rem; }
p { margin: 0; }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* --- shell ------------------------------------------------------------------ */

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-areas: "bar" "main" "nav";
  grid-template-rows: auto 1fr auto;
}

.topbar {
  grid-area: bar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px var(--gutter);
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.1875rem; }
.topbar .venue { margin-left: auto; color: var(--muted); font-size: 0.8125rem; }
.topbar .back {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: -6px; padding: 4px 6px;
  color: var(--accent); text-decoration: none; font-size: 0.9375rem;
}

.main { grid-area: main; width: 100%; padding: var(--gutter) var(--gutter) 28px; }

.tabs {
  grid-area: nav;
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--lift);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px;
  padding: 6px 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.6875rem;
}
.tabs a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.tabs a.on { color: var(--accent); }
.tabs a.on svg { stroke-width: 2.1; }

@media (min-width: 900px) {
  .app {
    grid-template-areas: "nav bar" "nav main";
    grid-template-columns: 236px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }
  .tabs {
    position: sticky; top: 0; height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: 14px 10px;
    border-right: 1px solid var(--line);
    box-shadow: none;
  }
  .tabs a {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    min-height: 42px; padding: 0 12px; border-radius: 9px; font-size: 0.9375rem;
  }
  .tabs a.on { background: var(--accent-wash); }
  .main { padding: 24px 28px 48px; max-width: 1180px; }
  .topbar { padding-inline: 28px; }
}

/* --- controls --------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
}
.btn:active { translate: 0 1px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--danger { color: var(--late); border-color: color-mix(in srgb, var(--late) 35%, var(--line)); }
.btn--warn { color: var(--soon); border-color: color-mix(in srgb, var(--soon) 40%, var(--line)); }
.btn--quiet { background: none; border-color: transparent; color: var(--muted); }
.btn--wide { width: 100%; }
.btn--small { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }

input, select, textarea {
  font: inherit; color: var(--ink);
  min-height: var(--tap);
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  width: 100%;
}
input[type=checkbox] { width: auto; min-height: 0; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.field { display: block; }
.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.8125rem; }
.fields { display: grid; gap: 12px; }
.fields--pair { grid-template-columns: 1fr 1fr; }

.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--sunk); border-radius: 12px;
}
.seg button {
  flex: 1; min-height: 36px; padding: 0 8px;
  border: 0; border-radius: 9px; background: none;
  color: var(--muted); font: inherit; font-size: 0.875rem; font-weight: 500; cursor: pointer;
}
[data-show="open"] .seg button[value="open"],
[data-show="done"] .seg button[value="done"],
[data-show="all"]  .seg button[value="all"] {
  background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #00000014;
}

.pill {
  display: inline-block; padding: 2px 9px;
  border-radius: 999px; background: var(--sunk); color: var(--muted);
  font-size: 0.75rem; font-weight: 500; white-space: nowrap;
}
.pill--live { background: var(--accent-wash); color: var(--accent); }
.pill--late { background: color-mix(in srgb, var(--late) 14%, transparent); color: var(--late); }
.pill--warn { background: color-mix(in srgb, var(--soon) 16%, transparent); color: var(--soon); }

.chip {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.8125rem;
}
.chip button {
  border: 0; background: none; color: var(--muted);
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer; font-size: 1rem; line-height: 1;
}

/* --- surfaces --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.list > * + * { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 9px 14px;
  background: none; border: 0; color: inherit; font: inherit; text-align: left;
}
button.row, a.row { cursor: pointer; text-decoration: none; }
button.row:hover, a.row:hover { background: var(--accent-wash); }
.row__main { flex: 1 1 auto; min-width: 0; }
.row input, .row select { flex: 1 1 7em; width: auto; min-width: 0; }
.row__sub { color: var(--muted); font-size: 0.8125rem; }
.row__value { color: var(--muted); font-variant-numeric: tabular-nums; }
.row__main > .row__sub { display: block; }
.row__chevron { color: var(--muted); flex: 0 0 auto; }
.row--bare { padding: 0; min-height: 0; }
.row--wrap { flex-wrap: wrap; }

/* A menu row is two targets: the name opens the editor, the switch flips sold out in place. */
.itemtap {
  flex: 1; min-width: 0; padding: 0;
  background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.itemtap > span { display: block; }
.itemtap:hover { color: var(--accent); }

details.fold { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
details.fold > summary {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 9px 14px;
  font-weight: 500; cursor: pointer; list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "＋"; margin-left: auto; color: var(--muted); }
details.fold[open] > summary::after { content: "－"; }
details.fold[open] > summary { border-bottom: 1px solid var(--line); }
.fold__body { padding: 14px; display: grid; gap: 12px; }

/* Three controls will not fit one phone line, and an unlabelled wrapped time field is a
   coin flip between opening and closing. So: day on its own line, then the pair. */
.hours { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px 14px; }
.hours > select { grid-column: 1 / -1; }
@media (min-width: 620px) {
  .hours { grid-template-columns: 1fr 1fr 1fr; align-items: end; }
  .hours > select { grid-column: auto; }
}

.group { margin: 22px 0; }
.group:first-child { margin-top: 0; }
.group > h2 { margin-bottom: 8px; }
.group > p { margin-bottom: 10px; color: var(--muted); font-size: 0.8125rem; max-width: 62ch; }

.notice { padding: 10px 12px; border-radius: 10px; font-size: 0.875rem; margin-bottom: 12px; }
.notice--bad { background: color-mix(in srgb, var(--late) 12%, transparent); color: var(--late); }
.notice--ok { background: var(--accent-wash); color: var(--accent); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 0.9375rem; }

.signin { max-width: 340px; margin: 8vh auto 0; display: grid; gap: 18px; justify-items: start; }
.signin img { border-radius: 12px; }
.signin h1 { font-size: 1.5rem; }
.signin form { width: 100%; }

/* --- the ticket rail -------------------------------------------------------- */

.tickets { display: grid; gap: 12px; }
@media (min-width: 720px) {
  .tickets { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
}

.ticket {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--r-ticket);
  padding: 12px 14px 14px;
}
.ticket[data-due="ok"]   { border-left-color: var(--accent); }
.ticket[data-due="soon"] { border-left-color: var(--soon); }
.ticket[data-due="late"] { border-left-color: var(--late); }
.ticket[data-state="cancelled"], .ticket[data-state="completed"] {
  border-left-color: var(--line); background: var(--sunk);
}
.ticket[data-state="cancelled"] .ticket__lines { text-decoration: line-through; opacity: 0.6; }

.ticket__head { display: flex; align-items: baseline; gap: 10px; }
.ticket__clock {
  font-size: 1.75rem; font-weight: 600; font-stretch: 92%;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1;
}
.ticket__clock-label {
  font-size: 0.8125rem; font-weight: 500; font-stretch: 100%;
  letter-spacing: 0; color: var(--muted);
}
.ticket__due { color: var(--muted); font-size: 0.8125rem; }
.ticket__due[data-due="soon"] { color: var(--soon); }
.ticket__due[data-due="late"] { color: var(--late); }
.ticket__code {
  margin-left: auto; text-align: right; line-height: 1.35;
  color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums;
}
.railnote { margin: 10px 0 12px; color: var(--muted); font-size: 0.8125rem; }
.ticket__meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 8px 0 10px;
}
.ticket__lines { display: grid; gap: 3px; padding: 10px 0; border-top: 1px solid var(--line); }
.ticket__line { display: flex; gap: 8px; }
.ticket__qty {
  flex: 0 0 auto; min-width: 2.1em; color: var(--muted); font-variant-numeric: tabular-nums;
}
.ticket__mods, .ticket__note { display: block; color: var(--muted); font-size: 0.8125rem; }
.ticket__foot {
  display: flex; align-items: center; gap: 10px;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.ticket__total { font-size: 1.125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.ticket__actions { margin-left: auto; display: flex; gap: 8px; }
.ticket__actions .btn { min-height: 38px; }

[data-show="open"] .ticket:not([data-state="confirmed"]),
[data-show="done"] .ticket[data-state="confirmed"],
[data-show="open"] .empty[data-for="done"], [data-show="open"] .empty[data-for="all"],
[data-show="done"] .empty[data-for="open"], [data-show="done"] .empty[data-for="all"],
[data-show="all"]  .empty[data-for="open"], [data-show="all"] .empty[data-for="done"] {
  display: none;
}

/* --- bottom sheet ----------------------------------------------------------- */

dialog.sheet {
  width: 100%; max-width: 520px;
  margin: auto auto 0;
  padding: 0;
  border: 0; border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px #00000038;
}
dialog.sheet::backdrop { background: #0006; }
dialog.sheet[open] { animation: rise 0.2s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes rise { from { translate: 0 18px; opacity: 0; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }
@media (min-width: 620px) {
  dialog.sheet { margin: auto; border-radius: 18px; }
}

.sheet__grip {
  width: 38px; height: 4px; margin: 10px auto 0;
  border-radius: 2px; background: var(--line);
}
.sheet__head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 10px; }
.sheet__head h2 { flex: 1; min-width: 0; }
.sheet__body {
  padding: 0 16px 16px;
  max-height: min(70dvh, 620px); overflow-y: auto;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.sheet__body > * + * { margin-top: 14px; }

/* --- toast ------------------------------------------------------------------ */

.toast {
  position: fixed; left: 50%; translate: -50% 0; z-index: 40;
  bottom: calc(68px + env(safe-area-inset-bottom));
  display: none; align-items: center; gap: 10px;
  padding: 10px 16px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 24px #00000038;
  font: inherit; font-weight: 500; cursor: pointer;
}
.toast[data-visible] { display: flex; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* --- console ---------------------------------------------------------------- */

.thread { display: grid; gap: 8px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 16px; background: var(--sunk); }
.bubble--caller { justify-self: end; border-bottom-right-radius: 5px; }
.bubble--ai {
  justify-self: start; border-bottom-left-radius: 5px;
  background: var(--accent-wash);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.bubble--bad {
  justify-self: start; color: var(--late);
  background: color-mix(in srgb, var(--late) 12%, transparent);
}
.bubble--tool { justify-self: stretch; max-width: none; background: none; padding: 2px 0; }
.bubble--tool summary { color: var(--muted); font-size: 0.8125rem; cursor: pointer; }
.bubble pre {
  margin: 6px 0 0; padding: 9px; border-radius: 8px;
  background: var(--sunk); overflow-x: auto;
  font-size: 0.75rem; line-height: 1.45;
}
.composer { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.composer input, .composer select { flex: 1; min-width: 0; }
.composer .btn { flex: 0 0 auto; }
