/* Tea Stall Admin.
   Shell: one latte-cream frame (sidebar + top bar) around a white work sheet.
   Coffee brown is the ink. Mustard appears on data, on the one main action, and nowhere else. */

:root {
  --ground: #f3e9d9;
  --surface: #fffdfa;
  --raised: #f8f2e8;
  --active: #eadfcd;
  --border: #e9dfcf;
  --rule: #f1e9dc;
  --control: #d3c4ad;
  --text: #3a2114;
  --muted: #6b5444;
  --faint: #7b5e4b;
  --accent: #bd8710;
  --primary: #e2a62b;
  --primary-ink: #3a2114;
  --positive: #2f6f45;
  --negative: #a8321f;
  --warning: #6a4a00;
  --pill-positive-bg: #e0efe2; --pill-positive-ink: #1f4d2e;
  --pill-negative-bg: #f8e2db; --pill-negative-ink: #7f2616;
  --pill-warning-bg: #f9ebc2; --pill-warning-ink: #6a4a00;
  --pill-neutral-bg: #efe6d6; --pill-neutral-ink: #4a2c1a;
  --chart-1: #bd8710; --chart-2: #4a2c1a; --chart-muted: #dccdb6;
  --chart-mark: var(--text); --chart-span: 0.06;
  --grid: var(--rule); --axis-ink: var(--muted); --ink: var(--text);
  --bar-fill: #f6e6bd;

  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --brand-font: "Baloo 2", var(--font);
  --fs-title: 24px; --fs-section: 16px; --fs-kpi: 24px; --fs-body: 14px; --fs-small: 12px;

  --sidebar-width: 228px;
  --topbar: 48px;
  --pad: 24px;
  --gap: 16px;
  --card-pad: 20px;
  --radius-sheet: 16px;
  --radius-card: 10px;
  --radius-control: 8px;
  --control-height: 34px;
  --row-height: 52px;
  --nav-row: 32px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: var(--fs-body)/20px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, figure, ul, ol, dl, dd { margin: 0; }
ul[class], ol[class] { padding: 0; list-style: none; }
svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table, .kpi-value { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100svh; }
.sidebar { position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; gap: 2px; padding: 12px 12px 16px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 8px; margin-bottom: 8px; }
.brand svg { width: 26px; height: 26px; flex: none; }
.brand b { font: 800 20px/1 var(--brand-font); letter-spacing: 0; }
.brand span { color: var(--muted); font-size: var(--fs-small); margin-left: -4px; }
.group-label { margin: 18px 8px 6px; font-size: var(--fs-small); color: var(--faint); }
.nav-item { display: flex; align-items: center; gap: 10px; height: var(--nav-row); padding: 0 8px; border-radius: 8px; color: var(--muted); border: 0; background: none; width: 100%; text-align: left; cursor: pointer; transition: background-color 150ms ease, color 150ms ease; }
.nav-item svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--text); font-weight: 500; }
.nav-item .count { margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; background: var(--negative); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.nav-item .count.quiet { background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }
.sidebar .bottom { margin-top: auto; padding-top: 12px; }
.whoami { padding: 6px 8px; font-size: var(--fs-small); color: var(--muted); }
.whoami b { display: block; color: var(--text); font-size: var(--fs-body); font-weight: 500; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 16px 0 4px; }
.topbar .search { flex: 1; display: flex; justify-content: center; }
.topbar .search input { width: min(100%, 440px); height: 32px; padding: 0 12px 0 34px; border: 1px solid var(--control); border-radius: 999px; background: var(--surface) no-repeat 12px center / 14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b5444' stroke-width='1.5' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='4.5'/%3E%3Cpath d='m10.5 10.5 3 3'/%3E%3C/svg%3E"); }
.topbar .search input::placeholder { color: var(--faint); }
.topbar .date { color: var(--muted); white-space: nowrap; }
.sheet { flex: 1; min-width: 0; margin: 0 8px 8px 0; padding: var(--pad); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); }

/* ---------- title, tabs, filters ---------- */
.crumb { color: var(--muted); margin-bottom: 4px; display: inline-flex; gap: 6px; align-items: center; }
.crumb:hover { color: var(--text); }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.title-row h1 { font-size: var(--fs-title); line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
.title-row .sub { margin-top: 4px; color: var(--muted); max-width: 72ch; }
.title-row .sub b { color: var(--text); font-weight: 500; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: var(--gap); overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button { position: relative; padding: 10px 0; color: var(--muted); border: 0; background: none; cursor: pointer; white-space: nowrap; transition: color 150ms ease; }
.tabs [aria-selected="true"] { color: var(--text); font-weight: 500; }
.tabs [aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--text); }
.tabs .n { color: var(--faint); margin-left: 6px; font-variant-numeric: tabular-nums; font-weight: 400; }
.filters { display: flex; align-items: center; gap: 8px; margin-bottom: var(--gap); flex-wrap: wrap; }
.filters .spacer { flex: 1; }
.stamp { color: var(--faint); font-size: var(--fs-small); }

/* ---------- panels ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.cols-rail { display: grid; grid-template-columns: minmax(0, 1fr) 372px; gap: var(--gap); align-items: start; }
.stack { display: grid; gap: var(--gap); min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--card-pad); min-width: 0; }
.panel > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel h2 { font-size: var(--fs-section); line-height: 1.3; font-weight: 600; }
.panel .meta { color: var(--muted); font-size: var(--fs-small); }
.panel.flush { padding: 0; }
.panel.flush > header { padding: 16px var(--card-pad) 0; }
.card-link { color: var(--text); font-weight: 500; text-underline-offset: 3px; white-space: nowrap; }
.card-link:hover { text-decoration: underline; }
.note { color: var(--muted); font-size: var(--fs-small); line-height: 18px; margin-top: 10px; }

.kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border: 1px solid var(--border); border-radius: var(--radius-card); }
.kpi { padding: 14px var(--card-pad) 16px; min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { color: var(--muted); }
.kpi-value { margin-top: 4px; font-size: var(--fs-kpi); line-height: 1.2; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; }
.kpi.lead .kpi-value { font-size: 32px; font-weight: 600; }
.kpi-value small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 3px; letter-spacing: 0; }
.delta { margin-top: 2px; font-size: var(--fs-small); color: var(--muted); }
.delta .good { color: var(--positive); } .delta .bad { color: var(--negative); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 36px; padding: 0 12px; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: calc((var(--row-height) - 20px) / 2) 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 0; } th:last-child, td:last-child { padding-right: 0; }
.panel.flush th:first-child, .panel.flush td:first-child { padding-left: var(--card-pad); } .panel.flush th:last-child, .panel.flush td:last-child { padding-right: var(--card-pad); }
th.n, td.n { text-align: right; white-space: nowrap; }
td .sub { display: block; font-size: var(--fs-small); color: var(--muted); }
td.who a { font-weight: 500; }
td.who a:hover { text-decoration: underline; text-underline-offset: 3px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--raised); }
.truncate { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.tight { white-space: nowrap; width: 1%; }

.pill { display: inline-flex; align-items: center; flex: none; height: 22px; padding: 0 9px; border-radius: 999px; font-size: var(--fs-small); font-weight: 500; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; }
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.pill.dark { background: var(--text); color: var(--surface); }

/* The billing-day strip: one cell per day. This is how a shop's health is read at a glance. */
.strip { display: inline-flex; gap: 2px; vertical-align: middle; }
.strip i { width: 9px; height: 18px; border-radius: 2px; background: var(--rule); }
.strip i.t { background: #e9c66a; }
.strip i.p { background: var(--text); }
.strip.big i { width: auto; flex: 1; height: 28px; min-width: 6px; }
.strip.big { display: flex; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: var(--fs-small); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 9px; height: 12px; border-radius: 2px; background: var(--rule); border: 1px solid var(--border); }
.legend i.t { background: #e9c66a; border-color: #e9c66a; } .legend i.p { background: var(--text); border-color: var(--text); }
.strip-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: var(--fs-small); margin-top: 6px; }

/* ---------- lists ---------- */
.rows { display: grid; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 0; }
.row + .row { border-top: 1px solid var(--rule); }
.row .grow { flex: 1; min-width: 0; }
.row .grow b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .grow span { display: block; color: var(--muted); font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.row:hover b { text-decoration: underline; text-underline-offset: 3px; }

.queue { display: grid; }
/* fixed tracks, so the pills, strips and buttons line up from row to row */
.q { display: grid; grid-template-columns: minmax(140px, 1fr) 140px 250px 148px; gap: 16px; align-items: center; padding: 12px var(--card-pad); border-top: 1px solid var(--rule); }
.q > * { min-width: 0; }
.q .who b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q .who a:hover b { text-decoration: underline; text-underline-offset: 3px; }
.q .who span { color: var(--muted); font-size: var(--fs-small); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q .why { color: var(--muted); font-size: var(--fs-small); line-height: 16px; margin-top: 5px; }
.q .why b { color: var(--text); font-weight: 400; }
.q .do { display: flex; gap: 6px; justify-content: flex-end; }
.btn.icon-only { width: 32px; height: 32px; padding: 0; }
.btn.icon-only svg, .q .do .btn svg { width: 16px; height: 16px; }
.q .do .btn { height: 32px; }
.only-phone { display: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 var(--card-pad) 14px; }
.chip { height: 28px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--control); background: var(--surface); color: var(--muted); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.chip .n { margin-left: 6px; font-variant-numeric: tabular-nums; opacity: 0.8; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color 150ms ease, transform 120ms var(--ease-out); }
.btn:hover { background: var(--raised); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { background: #d99c20; }
.btn.danger { color: var(--negative); }
.btn.small { height: 28px; padding: 0 10px; font-size: var(--fs-small); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.field { display: grid; gap: 6px; }
.field > span, .field > label { font-weight: 500; }
.field .hint { color: var(--muted); font-size: var(--fs-small); font-weight: 400; }
.input, select.input, textarea.input { height: 36px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); width: 100%; min-width: 0; }
textarea.input { height: auto; min-height: 88px; padding: 8px 12px; line-height: 20px; resize: vertical; }
.input::placeholder { color: var(--faint); }
.input.short { width: 96px; }
.form { display: grid; gap: 14px; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 140px; }
.form-row .field.fixed { flex: none; min-width: 0; }
.msg { min-height: 20px; font-size: var(--fs-small); color: var(--muted); }
.msg.err { color: var(--negative); } .msg.ok { color: var(--positive); }
.empty { display: grid; place-items: center; min-height: 88px; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-control); color: var(--muted); text-align: center; }
.panel.flush .empty { margin: 0 var(--card-pad) var(--card-pad); }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; }
.facts dt { color: var(--muted); }
.facts dd { min-width: 0; overflow-wrap: anywhere; }

/* settings: a label column and a form column */
.setting { display: grid; grid-template-columns: 260px minmax(0, 560px); gap: 24px; padding: 24px 0; border-top: 1px solid var(--border); }
.setting:first-of-type { border-top: 0; padding-top: 4px; }
.setting h2 { font-size: var(--fs-section); font-weight: 600; }
.setting .about { color: var(--muted); margin-top: 4px; }

/* ---------- support desk ---------- */
.desk { display: grid; grid-template-columns: 320px minmax(0, 1fr) 280px; border: 1px solid var(--border); border-radius: var(--radius-card); min-height: 560px; overflow: hidden; }
.desk > * { min-width: 0; }
.desk .list { border-right: 1px solid var(--border); overflow: auto; max-height: calc(100svh - 230px); }
.desk .side { border-left: 1px solid var(--border); padding: 16px; display: grid; gap: 16px; align-content: start; overflow: auto; max-height: calc(100svh - 230px); }
.ticket { display: block; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.ticket[aria-selected="true"] { background: var(--active); }
.ticket:not([aria-selected="true"]):hover { background: var(--raised); }
.ticket .top { display: flex; justify-content: space-between; gap: 8px; }
.ticket b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket time { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
.ticket time.late { color: var(--negative); font-weight: 500; }
.ticket p { color: var(--muted); font-size: var(--fs-small); line-height: 18px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.thread { display: flex; flex-direction: column; max-height: calc(100svh - 230px); }
.thread > header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.thread > header { flex-wrap: nowrap; align-items: flex-start; }
.thread > header > div { min-width: 0; flex: 1; }
.thread > header h2 { font-size: var(--fs-section); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread > header .btn { flex: none; }
.hide-desktop { display: none; }
.bubbles { flex: 1; overflow: auto; padding: 20px; display: grid; gap: 14px; align-content: start; }
.bubble { max-width: min(560px, 86%); }
.bubble .by { font-size: var(--fs-small); color: var(--muted); margin-bottom: 3px; }
.bubble p { padding: 10px 14px; border-radius: 12px; background: var(--raised); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.admin { justify-self: end; }
.bubble.admin .by { text-align: right; }
.bubble.admin p { background: var(--active); }
.bubble.note { justify-self: end; }
.bubble.note .by { text-align: right; }
.bubble.note p { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.composer { border-top: 1px solid var(--border); padding: 14px 20px 16px; display: grid; gap: 10px; }
.composer .bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer .bar .spacer { flex: 1; }
.side h3 { font-size: var(--fs-body); font-weight: 600; margin-bottom: 8px; }

/* ---------- cohort table ---------- */
.cohort td.c { text-align: right; width: 64px; padding-left: 4px; padding-right: 4px; }
.cohort td.c span { display: block; padding: 4px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }

/* ---------- dialog, toast, login ---------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius-sheet); padding: 24px; width: min(92vw, 460px); color: var(--text); background: var(--surface); box-shadow: 0 16px 48px rgba(58, 33, 20, 0.18); }
dialog::backdrop { background: rgba(58, 33, 20, 0.32); }
dialog h2 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
dialog .about { color: var(--muted); margin-bottom: 16px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 999px; box-shadow: 0 8px 24px rgba(58, 33, 20, 0.2); z-index: 50; transition: opacity 200ms ease, transform 200ms var(--ease-out); }
.toast.hide { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
.login { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(100%, 360px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); padding: 28px; display: grid; gap: 14px; }
.login .brand { padding: 0; margin: 0 0 4px; }
.skeleton { background: var(--raised); border-radius: 6px; min-height: 120px; }

/* ---------- phone ---------- */
.menu-toggle { display: none; }
@media (max-width: 1180px) {
  .cols-rail { grid-template-columns: minmax(0, 1fr); }
  .desk { grid-template-columns: 280px minmax(0, 1fr); }
  .desk .side { display: none; }
  .q { grid-template-columns: minmax(0, 1fr) max-content; row-gap: 8px; }
  .q .signal { grid-column: 1; grid-row: 2; } .q .do { grid-column: 2; grid-row: 2; align-self: end; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 20; background: var(--ground); transform: translateX(-100%); transition: transform 200ms var(--ease-out); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .topbar .date { display: none; }
  .sheet { margin: 0; border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; border-left: 0; border-right: 0; border-bottom: 0; padding: 16px; }
  .grid > * { grid-column: 1 / -1 !important; }
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-left: 1px solid var(--border); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .setting { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .desk { grid-template-columns: minmax(0, 1fr); }
  .desk.reading .list { display: none; }
  .desk:not(.reading) .thread { display: none; }
  .desk .list, .thread { max-height: none; }
  .hide-phone { display: none; }
  .only-phone { display: inline; }
  .q .do .btn, .q .do .btn.icon-only { height: 40px; width: auto; padding: 0 12px; }
  .hide-desktop { display: inline-flex; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; } }
@media print { .sidebar, .topbar { display: none; } .sheet { border: 0; margin: 0; } }
