/* ==========================================================================
   Client demo base styles — SOURCE OF TRUTH.
   Edit here, then run `npm run sync-shared` to copy into clients/_shared/.

   Design direction: "the counter ledger, cleaned up". Owners we pitch run their
   business from a register and WhatsApp. The UI keeps that clarity: paper-white
   panels, ruled rows instead of boxes inside boxes, numbers set large in a
   hyper-legible face, colour reserved for the client's brand and for status.
   One bold element per demo: the Overview "Today" band in the brand colour.
   Type: Public Sans (built for public-service forms: plain zero, tabular figures),
   two weights only, 400 and 700.

   Per demo: set --brand, --brand-accent and --on-brand on :root in index.html.
   The brand must hold 4.5:1 against white text (--on-brand) — darken it if not.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */
:root {
  /* Brand (overridden per demo) */
  --brand: #1f5f8b;
  --brand-accent: #b45309;
  --on-brand: #ffffff;
  /* Brand used as text/lines on the page ground (lighter tone in dark mode) */
  --brand-ink: var(--brand);
  --brand-soft: color-mix(in oklab, var(--brand) 10%, var(--surface));
  --brand-press: color-mix(in oklab, var(--brand) 86%, #000);

  /* Neutrals — light */
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #eef0ed;           /* table heads, segmented control, hover rows */
  --surface-3: #e3e6e2;           /* progress tracks */
  --ink: #1a1d1f;                 /* 16.4:1 on --surface */
  --ink-2: #4a5156;               /* secondary text, 8.0:1 */
  --ink-3: #5f676d;               /* labels, meta, 5.9:1 */
  --line: color-mix(in oklab, var(--ink) 12%, var(--surface));
  --line-strong: color-mix(in oklab, var(--ink) 24%, var(--surface));
  --scrim: rgb(20 22 24 / 0.5);

  /* Status (text on its soft tone holds 4.5:1) */
  --ok: #17703c;
  --warn: #8f4a00;
  --bad: #b42318;
  --info: #1d4f91;
  --ok-soft: color-mix(in oklab, var(--ok) 11%, var(--surface));
  --warn-soft: color-mix(in oklab, var(--warn) 12%, var(--surface));
  --bad-soft: color-mix(in oklab, var(--bad) 10%, var(--surface));
  --info-soft: color-mix(in oklab, var(--info) 10%, var(--surface));

  /* Charts (read by charts.js) */
  --chart-grid: color-mix(in oklab, var(--ink) 8%, var(--surface));
  --chart-text: var(--ink-3);
  --chart-3: #8a9399;             /* neutral series: previous period, "other" */

  /* Type: one family, two weights, scale 12/14/16/20/24/32 */
  --font-sans: "Public Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-12: 0.75rem;   /* bottom-nav labels and chart ticks only */
  --fs-14: 0.875rem;  /* labels, meta, table text on desktop */
  --fs-16: 1rem;      /* body, anything people read */
  --fs-20: 1.25rem;
  --fs-24: 1.5rem;
  --fs-32: 2rem;
  --w-regular: 400;
  --w-bold: 700;
  --lh-tight: 1.2;
  --lh: 1.5;

  /* Spacing: 8px grid with a 4px half step */
  --s-half: 4px;
  --s-1: 8px;
  --s-2: 16px;
  --s-3: 24px;
  --s-4: 32px;
  --s-5: 40px;
  --s-6: 48px;
  --s-8: 64px;

  /* Radius: one family, sized by hierarchy (band > panel > control) */
  --r-sm: 6px;     /* buttons, inputs, pills' inner shapes */
  --r-md: 10px;    /* panels, cards, tiles */
  --r-lg: 16px;    /* the Today band, sheets, modals */
  --r-pill: 999px;

  /* Shadows: only for things that float above the page */
  --shadow-sm: 0 1px 2px rgb(20 22 24 / 0.06);
  --shadow-md: 0 4px 16px rgb(20 22 24 / 0.10);
  --shadow-lg: 0 16px 40px rgb(20 22 24 / 0.18);

  /* Motion tokens (design-taste-frontend motion.md) */
  --t-in: 150ms;
  --t-out: 120ms;
  --t-press: 90ms;
  --t-panel: 200ms;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-enter: cubic-bezier(.22, 1, .36, 1);

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;
  --pad: var(--s-2);               /* panel padding: 16 mobile / 24 desktop */
  --gutter: var(--s-2);
  --content-max: 1240px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* The demo badge sits above the bottom nav on phones */
  --demo-badge-offset: calc(var(--bottomnav-h) + var(--safe-b) + 12px);

  /* z-index scale */
  --z-sticky: 20;
  --z-nav: 40;
  --z-badge: 60;
  --z-toast: 80;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --brand-ink: color-mix(in oklab, var(--brand) 45%, #fff);
  --brand-soft: color-mix(in oklab, var(--brand) 24%, var(--surface));
  --bg: #121416;
  --surface: #1a1d20;
  --surface-2: #22262a;
  --surface-3: #2c3136;
  --ink: #eceeef;
  --ink-2: #c3c8cc;
  --ink-3: #a3aab0;
  --line: color-mix(in oklab, var(--ink) 13%, var(--surface));
  --line-strong: color-mix(in oklab, var(--ink) 24%, var(--surface));
  --scrim: rgb(0 0 0 / 0.62);
  --ok: #6fd39a;
  --warn: #f2b45c;
  --bad: #ff8b7e;
  --info: #93b8f5;
  --ok-soft: color-mix(in oklab, var(--ok) 14%, var(--surface));
  --warn-soft: color-mix(in oklab, var(--warn) 14%, var(--surface));
  --bad-soft: color-mix(in oklab, var(--bad) 14%, var(--surface));
  --info-soft: color-mix(in oklab, var(--info) 14%, var(--surface));
  --chart-grid: color-mix(in oklab, var(--ink) 9%, var(--surface));
  --chart-3: #7d878e;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 16px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.55);
  color-scheme: dark;
}

@media (min-width: 861px) {
  :root { --pad: var(--s-3); --gutter: var(--s-3); --demo-badge-offset: 16px; }
}

/* ---------- 2. Base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: var(--lh);
  font-weight: var(--w-regular);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, [role="button"], label, select { touch-action: manipulation; }
a { color: var(--brand-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: var(--w-bold); line-height: var(--lh-tight); text-wrap: balance; }
h1 { font-size: var(--fs-20); }
h2 { font-size: var(--fs-16); }
h3 { font-size: var(--fs-16); }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.small { font-size: var(--fs-14); }
.bold { font-weight: var(--w-bold); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.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; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

.skip-link {
  position: fixed; z-index: 100; left: var(--s-2); top: var(--s-2);
  padding: var(--s-1) var(--s-2); border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg); font-weight: var(--w-bold);
  transform: translateY(-200%);
}
.skip-link:focus-visible { transform: none; }

/* ---------- 3. Layout: sidebar → bottom nav ------------------------------ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}
.sidebar {
  position: sticky; top: 0;
  height: 100dvh;
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-3) var(--s-2);
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 var(--s-1); min-width: 0; }
.brand-logo {
  width: 40px; height: 40px; flex: none;
  border-radius: var(--r-sm);
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--line);
}
.brand-logo--text {
  display: grid; place-items: center; border: 0;
  background: var(--brand); color: var(--on-brand);
  font-weight: var(--w-bold); font-size: var(--fs-16);
}
.brand-name { font-weight: var(--w-bold); line-height: var(--lh-tight); }
.brand-area { font-size: var(--fs-14); color: var(--ink-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2); text-decoration: none;
  font-size: var(--fs-16);
  transition: background-color var(--t-out) var(--ease), color var(--t-out) var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); transition-duration: var(--t-in); }
.nav-item[aria-current="page"] { background: var(--brand-soft); color: var(--ink); font-weight: var(--w-bold); }
.nav-item[aria-current="page"] .icon { color: var(--brand-ink); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--brand-ink);
}
.nav-count {
  margin-left: auto; min-width: 24px; padding: 0 7px; border-radius: var(--r-pill);
  background: var(--brand); color: var(--on-brand);
  font-size: var(--fs-14); font-weight: var(--w-bold); text-align: center; line-height: 22px;
}
.sidebar-foot { margin-top: auto; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--s-2);
  min-height: var(--topbar-h);
  padding: 0 var(--s-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-brand { display: none; }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title p { font-size: var(--fs-14); color: var(--ink-3); }
.topbar-actions { display: flex; align-items: center; gap: var(--s-1); }

.content {
  width: 100%; max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) calc(var(--s-4) + 56px);  /* room for the demo badge */
}
.view { display: none; flex-direction: column; gap: var(--gutter); }
.view.is-active { display: flex; animation: view-in var(--t-panel) var(--ease-enter); }
@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }
.view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px var(--s-2); }
.view-head p { color: var(--ink-2); max-width: 62ch; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s-1); align-items: center; flex: 1 1 auto; min-width: 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: var(--z-nav);
    inset: auto 0 0 0; height: auto;
    padding: 0 var(--s-half) var(--safe-b);
    flex-direction: row; gap: 0;
    border-right: 0; border-top: 1px solid var(--line);
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; gap: 0; }
  .nav-item {
    flex: 1 1 0; min-width: 0;
    flex-direction: column; justify-content: center; gap: 2px;
    min-height: var(--bottomnav-h); padding: 6px 2px;
    font-size: var(--fs-12); border-radius: 0; text-align: center;
  }
  .nav-item > span:not(.nav-count) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-item[aria-current="page"] { background: transparent; }
  .nav-item[aria-current="page"]::before { left: 28%; right: 28%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .nav-count { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; min-width: 20px; padding: 0 5px; line-height: 18px; font-size: var(--fs-12); }
  .topbar { padding: 0 var(--s-2); gap: 12px; }
  .topbar-brand { display: block; }
  .topbar-brand .brand-logo { width: 36px; height: 36px; }
  .topbar-title h1 { font-size: var(--fs-16); }
  .topbar-title p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: var(--s-2) var(--s-2) calc(var(--bottomnav-h) + var(--safe-b) + var(--s-8)); }
}

/* ---------- 4. Grids ------------------------------------------------------ */
.grid-2 { display: grid; gap: var(--gutter); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { display: grid; gap: var(--gutter); grid-template-columns: minmax(0, 5fr) minmax(0, 3fr); }
.cards { display: grid; gap: var(--gutter); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 1100px) { .grid-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 520px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }

/* ---------- 5. Today band (the one bold element) ------------------------- */
.today {
  display: grid; grid-template-columns: minmax(0, 1fr);
  border-radius: var(--r-lg); overflow: hidden;
  background: var(--brand); color: var(--on-brand);
}
.today--photo { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.today-body { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-4); min-width: 0; }
.today-name { font-size: var(--fs-32); line-height: 1.1; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.today-meta { display: flex; flex-wrap: wrap; gap: 4px var(--s-2); font-size: var(--fs-16); opacity: .88; }
.today-status { font-size: var(--fs-20); line-height: 1.35; max-width: 34ch; }
.today-actions { display: flex; flex-wrap: wrap; gap: var(--s-1); margin-top: auto; padding-top: var(--s-1); }
.today .btn { background: var(--on-brand); color: var(--brand); border-color: var(--on-brand); }
.today .btn:hover { background: color-mix(in oklab, var(--on-brand) 88%, var(--brand)); }
.today .btn-quiet { background: transparent; color: var(--on-brand); border-color: color-mix(in oklab, var(--on-brand) 55%, transparent); }
.today .btn-quiet:hover { background: color-mix(in oklab, var(--on-brand) 12%, transparent); }
.today .btn:focus-visible { outline-color: var(--on-brand); }
.today-photo { position: relative; min-height: 220px; margin: 0; }
.today-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 860px) {
  .today--photo { grid-template-columns: minmax(0, 1fr); }
  .today-photo { order: -1; min-height: 0; aspect-ratio: 16 / 9; }
  .today-body { padding: var(--s-3) var(--s-2); }
  .today-name { font-size: var(--fs-24); }
  .today-status { font-size: var(--fs-16); }
  .today-actions .btn { flex: 1 1 auto; }
}

/* ---------- 6. Panels & cards -------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--pad);
  min-width: 0;
}
.panel--flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px var(--s-2); margin-bottom: var(--s-2); }
.panel--flush > .panel-head { padding: var(--pad) var(--pad) 0; }
.panel-head h2 { font-size: var(--fs-16); }
.panel-head p { font-size: var(--fs-14); color: var(--ink-3); margin-top: 2px; }

/* A card that is itself an item (menu item, trainer, product) */
.card {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden;
}
.card-media { aspect-ratio: 4 / 3; width: 100%; object-fit: cover; background: var(--surface-2); }
/* No photo yet: a short tinted strip with initials, never a big empty square */
.card-media--blank { aspect-ratio: 5 / 2; display: grid; place-items: center; color: var(--brand-ink); background: var(--brand-soft); font-size: var(--fs-24); font-weight: var(--w-bold); }
.card-body { display: flex; flex-direction: column; gap: var(--s-half); padding: 12px var(--s-2) var(--s-2); flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-1); margin-top: auto; padding-top: var(--s-1); }
@media (max-width: 520px) {
  .card-body { padding: 12px; }
  .card-foot { flex-wrap: wrap; }
  .card-foot .btn { flex: 1 1 100%; }
}

/* ---------- 7. KPI strip: one ruled panel, four cells --------------------- */
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.kpi { display: flex; flex-direction: column; gap: var(--s-1); padding: var(--pad); min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--line); }
.kpi-label { font-size: var(--fs-14); color: var(--ink-3); }
.kpi-value { font-size: var(--fs-32); font-weight: var(--w-bold); line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--s-1); font-size: var(--fs-14); color: var(--ink-3); }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: var(--w-bold); }
.delta.good { color: var(--ok); }
.delta.bad { color: var(--bad); }
.kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(even) { border-left: 1px solid var(--line); }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis--3 .kpi:nth-child(n) { border-top: 0; border-left: 1px solid var(--line); }
  .kpis--3 .kpi:first-child { border-left: 0; }
}
@media (max-width: 860px) { .kpi-value { font-size: var(--fs-24); } }
@media (max-width: 520px) {
  .kpis--3 { grid-template-columns: minmax(0, 1fr); }
  .kpis--3 .kpi:nth-child(n) { border-left: 0; }
  .kpis--3 .kpi + .kpi { border-top: 1px solid var(--line); }
}

/* ---------- 8. Rows, pills, avatars, progress ---------------------------- */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; padding-top: 0; }
.row:last-child { padding-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row-sub { font-size: var(--fs-14); color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 0 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-14); font-weight: var(--w-bold); white-space: nowrap; line-height: 1.5;
  background: var(--surface-2); color: var(--ink-2);
}
.pill .icon { width: 14px; height: 14px; stroke-width: 2.2; }
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--bad { background: var(--bad-soft); color: var(--bad); }
.pill--info { background: var(--info-soft); color: var(--info); }
.pill--brand { background: var(--brand-soft); color: var(--brand-ink); }

.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: grid; place-items: center; object-fit: cover;
  background: var(--surface-2); color: var(--ink-2);
  font-size: var(--fs-14); font-weight: var(--w-bold);
}
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person > div { min-width: 0; }

.progress { height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; min-width: 64px; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--brand-ink); }
.progress--warn > span { background: var(--warn); }
.progress--bad > span { background: var(--bad); }

/* ---------- 9. Tables (stack into cards on phones) ------------------------ */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-14); }
.table th {
  text-align: left; font-weight: var(--w-bold); color: var(--ink-3);
  padding: 10px var(--s-2); border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface-2);
}
.table th button {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px;
  padding: 0; border: 0; background: none; color: inherit; font-weight: inherit; cursor: pointer;
}
.table th button .icon { width: 14px; height: 14px; opacity: .35; }
.table th[aria-sort] button .icon { opacity: 1; }
.table th[aria-sort="descending"] button .icon { transform: rotate(180deg); }
.table td { padding: 12px var(--s-2); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .right { text-align: right; }
.table th.right button { margin-left: auto; }
.table-empty { padding: var(--s-4) var(--s-2) !important; text-align: center !important; color: var(--ink-3); }
@media (hover: hover) and (pointer: fine) { .table tbody tr:hover td { background: color-mix(in oklab, var(--surface-2) 60%, var(--surface)); } }

@media (max-width: 860px) {
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr { padding: 12px var(--pad); border-top: 1px solid var(--line); }
  .table--stack tbody tr:first-child { border-top: 0; }
  .table--stack td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s-2);
    padding: 4px 0; border: 0; text-align: right; min-height: 32px; font-size: var(--fs-16);
  }
  .table--stack td::before { content: attr(data-label); font-size: var(--fs-14); color: var(--ink-3); text-align: left; flex: none; }
  .table--stack td[data-primary] { justify-content: flex-start; text-align: left; padding-bottom: 8px; }
  .table--stack td[data-primary]::before { display: none; }
  .table--stack td.table-empty { display: block; }
  .table--stack td.table-empty::before { display: none; }
}

/* ---------- 10. Buttons --------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-1);
  min-height: 44px; padding: 0 var(--s-2);
  border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-16); font-weight: var(--w-bold); white-space: nowrap; text-decoration: none;
  cursor: pointer; user-select: none;
  transition: background-color var(--t-out) var(--ease), border-color var(--t-out) var(--ease), transform var(--t-out) var(--ease);
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: var(--fs-14); }
.btn-icon { width: 44px; padding: 0; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: color-mix(in oklab, var(--surface) 86%, var(--ink)); transform: translateY(-1px); transition-duration: var(--t-in); }
  .btn-primary:hover { background: var(--brand-press); border-color: var(--brand-press); }
  .btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
}
.btn:active { transform: translateY(1px) scale(.985); transition-duration: var(--t-press); }
@media (max-width: 860px) {
  .btn-sm { min-height: 44px; font-size: var(--fs-16); }
  .view-head > .btn { width: 100%; }
}

/* Segmented filter */
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r-sm); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  min-height: 38px; padding: 0 14px; border-radius: 4px; font-size: var(--fs-14); white-space: nowrap;
  transition: background-color var(--t-out) var(--ease), color var(--t-out) var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: var(--w-bold); box-shadow: var(--shadow-sm); }
@media (max-width: 860px) { .segmented button { min-height: 40px; } }

/* ---------- 11. Forms ----------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: var(--s-2); }
.form-row { display: grid; gap: var(--s-2); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 520px) { .form-row { grid-template-columns: minmax(0, 1fr); } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--fs-14); font-weight: var(--w-bold); }
.field .req { color: var(--bad); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background-color: var(--surface); color: var(--ink);
  font-size: var(--fs-16);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.textarea { padding: 12px; min-height: 96px; resize: vertical; line-height: var(--lh); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); opacity: 1; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--brand-ink); box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand-ink) 25%, transparent); }
.field[data-invalid] .input, .field[data-invalid] .select, .field[data-invalid] .textarea { border-color: var(--bad); }
.field-error { font-size: var(--fs-14); color: var(--bad); }
.field-error:empty { display: none; }
.search { position: relative; flex: 1 1 240px; min-width: 0; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 42px; min-height: 44px; }

/* Modal / bottom sheet (<dialog>) */
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
.modal::backdrop { background: var(--scrim); }
.modal[open] { animation: modal-in var(--t-panel) var(--ease-enter); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding: 12px 12px 12px var(--s-3); border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: var(--fs-20); }
.modal-body { padding: var(--s-3); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-1); padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line); }
@media (max-width: 520px) {
  .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; padding-bottom: var(--safe-b); }
  .modal-body { padding: var(--s-2); }
  .modal-head { padding-left: var(--s-2); }
  .modal-foot { padding: 12px var(--s-2); }
  .modal-foot .btn { flex: 1; }
}

/* ---------- 12. Toast ----------------------------------------------------- */
.toast-region {
  position: fixed; z-index: var(--z-toast);
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--demo-badge-offset) + 60px);
  display: flex; flex-direction: column; align-items: center; gap: var(--s-1);
  width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
@media (min-width: 861px) { .toast-region { bottom: var(--s-4); } }
.toast {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 8px 8px 8px var(--s-2); border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-md);
  font-size: var(--fs-16);
  pointer-events: auto;
  animation: toast-in var(--t-panel) var(--ease-enter);
}
.toast:not(:has(button)) { padding-right: var(--s-2); }
.toast button { min-height: 36px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: inherit; font-weight: var(--w-bold); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.toast.is-leaving { animation: toast-out var(--t-out) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; } }

/* ---------- 13. Boards, schedules, charts -------------------------------- */
.board { display: grid; gap: var(--gutter); grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); align-items: start; }
.board-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.board-col-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 8px; border-bottom: 2px solid var(--line-strong); font-weight: var(--w-bold); }
.board-col[data-tone="new"] .board-col-head { border-bottom-color: var(--brand-ink); }
.ticket { display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.ticket.is-fresh { animation: view-in var(--t-panel) var(--ease-enter); }
.ticket-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-1); }
.ticket-items { color: var(--ink-2); }
.ticket-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-1); flex-wrap: wrap; }
.board-empty { color: var(--ink-3); padding: var(--s-1) 0; }
@media (max-width: 860px) { .board { grid-template-columns: minmax(0, 1fr); } .ticket-foot .btn { flex: 1 1 auto; } }

.schedule { display: flex; flex-direction: column; }
.slot { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.slot:first-child { border-top: 0; }
.slot-time { font-size: var(--fs-14); color: var(--ink-3); padding-top: 10px; }
.slot-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.slot-item { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; border-left: 3px solid var(--brand-ink); background: var(--brand-soft); border-radius: 0 var(--r-sm) var(--r-sm) 0; min-width: 0; }
.slot-item.is-alt { border-left-color: var(--chart-3); background: var(--surface-2); }
.slot-free { font-size: var(--fs-14); color: var(--ink-3); padding-top: 10px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--s-1); }
.day { display: flex; flex-direction: column; gap: 2px; padding: var(--s-1); border: 1px solid var(--line); border-radius: var(--r-sm); min-width: 0; }
.day.is-today { border-color: var(--brand-ink); box-shadow: inset 0 0 0 1px var(--brand-ink); }
.day-name { font-size: var(--fs-14); color: var(--ink-3); }
.day-value { font-size: var(--fs-20); font-weight: var(--w-bold); }
@media (max-width: 520px) { .week { gap: 4px; } .day { padding: 6px 4px; text-align: center; } .day-value { font-size: var(--fs-16); } }

.chart-box { position: relative; height: 260px; }
.chart-box--sm { height: 220px; }
@media (max-width: 860px) { .chart-box { height: 220px; } .chart-box--sm { height: 200px; } }
.legend { display: flex; flex-wrap: wrap; gap: 4px var(--s-2); font-size: var(--fs-14); color: var(--ink-2); }
.legend-key { display: inline-block; width: 14px; height: 0; margin-right: 6px; vertical-align: middle; border-top: 3px solid; }
.legend-key--dash { border-top-style: dashed; }
.legend-key--box { height: 10px; border: 0; border-radius: 2px; }
.legend--chart { margin-top: var(--s-2); }
.legend--chart b { color: var(--ink); margin-left: 4px; }

/* ---------- 14. Motion preferences --------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .btn:hover, .btn:active { transform: none; }
}
