/* ═══════════════════════════════════════════════════════════════════════════
   Meltbox design system — Autogenic Labs brand (warm cream register).
   Dense, keyboard-first, IDE-grade. See BUILDING-APPS.md for usage.
   Principles: color encodes one comparative variable; band the chrome,
   foreground the content; stable layout (no bounce); 4px grid.
   Palette = brand/DESIGN.md warm cream register: neutrals + gold + semantics
   are CONSTANT across every theme; the ACCENT hue is the one variable a theme
   swaps. Accent = "alive/active/brand"; gold = sparkle / CTA only, never body
   or borders. No gradients, no glows, no halos — ever.
   ═══════════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/lib/fonts/pjs-var.woff2") format("woff2");
  font-weight: 200 800; /* variable font */
  font-style: normal;
  font-display: swap;
}

/* ═══════════════════════════════════════════════════════════════════════════
   THEME SYSTEM — Autogenic Labs brand model (one accent per surface).
   The active workspace owns the theme; the shell sets html[data-theme=<id>].
   Six themes = the brand accent family: green, coral, teal, blue, indigo
   (DEFAULT), violet. A theme swaps ONLY the accent slots — the warm-cream
   neutrals, gold, and semantics are CONSTANT everywhere. Every accent-derived
   role (--ok/"alive", --env-prod, --env-staging, --chart-1, focus rings,
   spinners, links, active nav, selected states, badges) reads from --accent,
   so a single hue swap recolors the whole surface.
   Base :root carries the shared (non-color) tokens + the cream neutrals + the
   DEFAULT indigo accent, so an un-themed document paints correctly (no flash).
   `light` is kept as an alias of the default for standalone briefs (brief.js
   sets data-theme="light" when none is present — do not remove).
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  /* type — brand family for chrome, mono for data */
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
  --fs-data: 12px;
  --fs-ui: 13px;
  --fs-small: 11px;
  --fs-micro: 10px;

  /* density */
  --sp: 4px;
  --row-h: 26px;
  --ctl-h: 24px;
  --radius: 4px;

  /* ── Neutrals — FULL-PAGE THEMING: every neutral is tinted toward --accent,
     so swapping the one accent re-casts the whole page (not just accents).
     Warm base + a wash of the theme hue; text stays dark + readable. ─────── */
  --bg:        color-mix(in srgb, var(--accent) 8%,  #F6F3EC);
  --panel:     color-mix(in srgb, var(--accent) 4%,  #FEFDFB);
  --band:      color-mix(in srgb, var(--accent) 13%, #F1EDE5);
  --raise:     color-mix(in srgb, var(--accent) 16%, #EBE7DF);
  --border:    color-mix(in srgb, var(--accent) 17%, #E3DFD4);
  --border-strong: color-mix(in srgb, var(--accent) 27%, #D1CBBB);
  --text:        color-mix(in srgb, var(--accent) 13%, #1A1611);
  --text-bright: color-mix(in srgb, var(--accent) 9%,  #120F0B);
  --text-dim:    color-mix(in srgb, var(--accent) 18%, #544E3E);
  --text-faint:  color-mix(in srgb, var(--accent) 24%, #948B76);
  --overlay: rgba(31, 28, 22, 0.35);
  --panel-shadow: 0 1px 2px rgba(31,28,22,.05), 0 4px 12px -8px rgba(31,28,22,.14);

  /* ── Gold — sparkle / CTA only, CONSTANT (never body text or borders) ── */
  --gold: #E6C461; --gold-ink: #3A2B0A;

  /* ── Semantics — CONSTANT. success/"alive" is NOT fixed — it's the accent ── */
  --err: #D2492F; --warn: #C9A23E; --info: #3B76D8;

  /* brand mark fill — solid accent (no gradient); kept for shell.css compat */
  --brand-grad: var(--accent);

  /* ── Accent — THE one variable. Default = indigo. A theme swaps only these ── */
  --accent: #6B6BD8; --accent-dim: rgba(107,107,216,.42); --accent-bg: rgba(107,107,216,.1);

  /* ── Accent-derived roles — recolor automatically on a theme swap ─────── */
  --ok: var(--accent);                 /* success / "alive" = the accent */
  --env-prod: var(--accent);           /* PROD env-toggle active = accent (was orange) */
  --env-staging: color-mix(in srgb, var(--accent) 48%, var(--text-faint)); /* muted accent */
  --chart-1: var(--accent);            /* charts lead with the accent */
  --chart-2: #2F8761; --chart-3: #3B76D8; --chart-4: #A553D0; --chart-5: #128680; --chart-6: #D2492F;
  --chart-axis: #857C6A; --chart-grid: #E8DFCC; --chart-tick: #D4C8AE;

  color-scheme: light;
}

/* ── Theme = accent swap only. Each rule repoints ONLY --accent/-dim/-bg; the
   neutrals, gold, semantics, and every accent-derived role stay as the base.
   indigo (+ light alias) = the default; listed explicitly for completeness. ── */
:root[data-theme="indigo"], :root[data-theme="light"] {
  --accent: #6B6BD8; --accent-dim: rgba(107,107,216,.42); --accent-bg: rgba(107,107,216,.1);
}
:root[data-theme="green"] {
  --accent: #2F8761; --accent-dim: rgba(47,135,97,.42); --accent-bg: rgba(47,135,97,.1);
}
:root[data-theme="coral"] {
  --accent: #D2492F; --accent-dim: rgba(210,73,47,.42); --accent-bg: rgba(210,73,47,.1);
}
:root[data-theme="teal"] {
  --accent: #128680; --accent-dim: rgba(18,134,128,.42); --accent-bg: rgba(18,134,128,.1);
}
:root[data-theme="blue"] {
  --accent: #3B76D8; --accent-dim: rgba(59,118,216,.42); --accent-bg: rgba(59,118,216,.1);
}
:root[data-theme="violet"] {
  --accent: #A553D0; --accent-dim: rgba(165,83,208,.42); --accent-bg: rgba(165,83,208,.1);
}

/* ── background-tint intensity ─────────────────────────────────────────────
   The base :root neutrals carry the FULL accent wash. data-tint="soft" (the
   shell's default) roughly halves it toward the cream/white base — a lighter,
   higher-contrast surface for people who find the full tint heavy. Only the
   neutral slots move; accents/gold/semantics are untouched. */
:root[data-tint="soft"] {
  --bg:        color-mix(in srgb, var(--accent) 3.5%, #F8F5EF);
  --panel:     color-mix(in srgb, var(--accent) 1.5%, #FFFFFF);
  --band:      color-mix(in srgb, var(--accent) 6%,  #F4F1EA);
  --raise:     color-mix(in srgb, var(--accent) 8%,  #EDE9E1);
  --border:    color-mix(in srgb, var(--accent) 9%,  #E5E0D5);
  --border-strong: color-mix(in srgb, var(--accent) 15%, #D3CDBE);
  --text:        color-mix(in srgb, var(--accent) 6%,  #191510);
  --text-bright: color-mix(in srgb, var(--accent) 4%,  #110E0A);
  --text-dim:    color-mix(in srgb, var(--accent) 9%,  #4F4939);
  --text-faint:  color-mix(in srgb, var(--accent) 13%, #8E856F);
}

/* ── per-item accent anchors (app/brief dots, accented pages) ──
   Let a single item override --accent for its subtree (categorical dots),
   independent of the workspace theme. Brand accent family + amber for the
   legacy categorical slot. All warm-cream register (no dark variants). */
[data-accent="green"]  { --accent:#2F8761; --accent-dim:rgba(47,135,97,.45);  --accent-bg:rgba(47,135,97,.1); }
[data-accent="coral"]  { --accent:#D2492F; --accent-dim:rgba(210,73,47,.45);  --accent-bg:rgba(210,73,47,.1); }
[data-accent="teal"]   { --accent:#128680; --accent-dim:rgba(18,134,128,.45); --accent-bg:rgba(18,134,128,.1); }
[data-accent="blue"]   { --accent:#3B76D8; --accent-dim:rgba(59,118,216,.45); --accent-bg:rgba(59,118,216,.1); }
[data-accent="indigo"] { --accent:#6B6BD8; --accent-dim:rgba(107,107,216,.45); --accent-bg:rgba(107,107,216,.1); }
[data-accent="violet"] { --accent:#A553D0; --accent-dim:rgba(165,83,208,.45); --accent-bg:rgba(165,83,208,.1); }
/* legacy aliases (rose→coral, cyan→teal, amber categorical) — keep consumers working */
[data-accent="rose"]   { --accent:#D2492F; --accent-dim:rgba(210,73,47,.45);  --accent-bg:rgba(210,73,47,.1); }
[data-accent="cyan"]   { --accent:#128680; --accent-dim:rgba(18,134,128,.45); --accent-bg:rgba(18,134,128,.1); }
[data-accent="amber"]  { --accent:#C9A23E; --accent-dim:rgba(201,162,62,.45); --accent-bg:rgba(201,162,62,.12); }

/* ── base ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-ui);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-dim); color: var(--text-bright); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: 15px; letter-spacing: 0.01em; color: var(--text-bright); }
h2 { font-size: 13px; color: var(--text-bright); }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }

code, pre, .cc-mono { font-family: var(--mono); font-size: var(--fs-data); }
pre {
  background: var(--band);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(var(--sp) * 2);
  overflow: auto;
  margin: 0;
}

/* numerics: always mono, tabular, right-aligned in tables */
.cc-num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.cc-dim { color: var(--text-dim); }
.cc-faint { color: var(--text-faint); }
.cc-small { font-size: var(--fs-small); }

:focus-visible { outline: 1px solid var(--accent-dim); outline-offset: 1px; }

/* ── panels + bands (recessed chrome, raised content) ──────────────────── */
.cc-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--panel-shadow);
}
.cc-band {
  background: var(--band);
  padding: var(--sp) calc(var(--sp) * 2);
  display: flex;
  align-items: center;
  gap: calc(var(--sp) * 2);
  min-height: calc(var(--ctl-h) + var(--sp) * 2);
}
.cc-band-top { border-bottom: 1px solid var(--border); }
.cc-band-bottom { border-top: 1px solid var(--border); }

/* ── controls ──────────────────────────────────────────────────────────── */
.cc-btn {
  font: 500 var(--fs-small) / 1 var(--sans);
  letter-spacing: 0.02em;
  color: var(--text);
  background: var(--raise);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  height: var(--ctl-h);
  padding: 0 calc(var(--sp) * 2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp);
  white-space: nowrap;
}
.cc-btn:hover { border-color: var(--accent-dim); color: var(--text-bright); }
.cc-btn:active { transform: translateY(1px); }
.cc-btn[disabled] { opacity: 0.45; cursor: default; pointer-events: none; }
.cc-btn.primary { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }
/* .cta — the one solid gold call-to-action (flat fill, no gradient/glow) */
.cc-btn.cta { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 600; }
.cc-btn.cta:hover { background: color-mix(in srgb, var(--gold) 92%, #000); border-color: var(--gold); color: var(--gold-ink); }
/* .solid — solid-ink alternative CTA */
.cc-btn.solid { background: var(--text); border-color: var(--text); color: var(--panel); }
.cc-btn.solid:hover { background: var(--text-bright); border-color: var(--text-bright); color: var(--panel); }
.cc-btn.danger { color: var(--err); }
.cc-btn.danger:hover { border-color: var(--err); }
.cc-btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.cc-btn.ghost:hover { color: var(--text); border-color: var(--border-strong); }

.cc-input-el, .cc-select-el, textarea.cc-input-el {
  font: 400 var(--fs-data) / 1.3 var(--mono);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  height: var(--ctl-h);
  padding: 0 calc(var(--sp) * 1.5);
}
textarea.cc-input-el { height: auto; padding: var(--sp) calc(var(--sp) * 1.5); resize: vertical; }
.cc-input-el:focus, .cc-select-el:focus, textarea.cc-input-el:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.cc-input-el::placeholder { color: var(--text-faint); }
label.cc-label {
  display: block;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

/* ── layout helpers ────────────────────────────────────────────────────── */
.stat-row { display: flex; gap: calc(var(--sp) * 2); flex-wrap: wrap; }
.cc-row { display: flex; align-items: center; gap: calc(var(--sp) * 2); }
.cc-col { display: flex; flex-direction: column; gap: calc(var(--sp) * 2); }
.cc-grid { display: grid; gap: calc(var(--sp) * 2); }
.cc-spacer { flex: 1; }
.cc-wrap { padding: calc(var(--sp) * 3); }
.cc-divider { border: 0; border-top: 1px solid var(--border); margin: calc(var(--sp) * 2) 0; }

/* ── component shells (light-DOM custom elements) ──────────────────────── */
cc-toolbar { display: flex; align-items: center; gap: calc(var(--sp) * 2);
  background: var(--band); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp) calc(var(--sp) * 2); min-height: calc(var(--ctl-h) + var(--sp) * 2); }
cc-statusbar { display: flex; align-items: center; gap: calc(var(--sp) * 3);
  background: var(--band); border-top: 1px solid var(--border);
  padding: 0 calc(var(--sp) * 2); height: 24px; font-size: var(--fs-micro);
  color: var(--text-dim); font-family: var(--mono); }

cc-badge { display: inline-flex; align-items: center; height: 16px; padding: 0 6px;
  border-radius: 8px; font: 600 var(--fs-micro) / 1 var(--mono); letter-spacing: 0.04em;
  text-transform: uppercase; border: 1px solid; }
/* ok / "alive" rides the accent so it recolors with the theme; warn/err/info
   are fixed semantics with tints mixed straight from their own token. */
cc-badge[kind="ok"]      { color: var(--ok); border-color: var(--accent-dim); background: var(--accent-bg); }
cc-badge[kind="warn"]    { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, transparent); background: color-mix(in srgb, var(--warn) 9%, transparent); }
cc-badge[kind="err"]     { color: var(--err); border-color: color-mix(in srgb, var(--err) 42%, transparent); background: color-mix(in srgb, var(--err) 9%, transparent); }
cc-badge[kind="info"]    { color: var(--info); border-color: color-mix(in srgb, var(--info) 42%, transparent); background: color-mix(in srgb, var(--info) 9%, transparent); }
cc-badge:not([kind]), cc-badge[kind="neutral"] { color: var(--text-dim); border-color: var(--border-strong); background: var(--raise); }

cc-kbd, kbd.cc-kbd { display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 3px;
  background: var(--raise); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; font: 600 var(--fs-micro) / 1 var(--mono); color: var(--text-dim); }

cc-stat { display: flex; flex-direction: column; gap: 2px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: calc(var(--sp) * 2) calc(var(--sp) * 2.5); min-width: 120px;
  box-shadow: var(--panel-shadow); }
cc-stat .stat-label { font-size: var(--fs-micro); text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dim); }
cc-stat .stat-info { margin-left: 4px; color: var(--text-faint);
  font-size: 10px; text-transform: none; letter-spacing: 0; }
cc-stat .stat-info:hover { color: var(--text-dim); }

/* ── [data-tip] — instant CSS tooltip (native title is slow/unreliable) ── */
[data-tip] { position: relative; cursor: help; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 6px);
  z-index: 700; width: max-content; max-width: 270px;
  background: var(--raise); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 6px 9px; font: 400 11px/1.5 var(--sans);
  letter-spacing: 0; text-transform: none; white-space: normal; text-align: left;
  box-shadow: 0 8px 24px rgba(31, 28, 22, 0.18);
  opacity: 0; visibility: hidden; transition: opacity 90ms ease-out;
  pointer-events: none;
}
[data-tip]:hover::after { opacity: 1; visibility: visible; }
cc-stat .stat-value { font: 600 20px / 1.1 var(--mono); font-variant-numeric: tabular-nums; }
cc-stat .stat-delta { font-size: var(--fs-small); font-family: var(--mono); }
cc-stat .stat-delta.up { color: var(--ok); }
cc-stat .stat-delta.down { color: var(--err); }
cc-stat .stat-spark { margin-top: 2px; }

/* cc-table */
cc-table { display: block; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--panel-shadow); }
cc-table .tbl-scroll { overflow: auto; max-height: var(--table-max-h, 60vh); }
cc-table table { width: 100%; border-collapse: collapse; font-size: var(--fs-data); }
cc-table thead th { position: sticky; top: 0; z-index: 2; background: var(--band);
  border-bottom: 1px solid var(--border-strong); padding: 0 calc(var(--sp) * 2);
  height: var(--row-h); text-align: left; font: 600 var(--fs-micro) / 1 var(--sans);
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim);
  cursor: pointer; user-select: none; white-space: nowrap; }
cc-table thead th .sort { color: var(--accent); margin-left: 3px; }
cc-table tbody td { border-bottom: 1px solid var(--border); padding: 0 calc(var(--sp) * 2);
  height: var(--row-h); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 360px; }
cc-table tbody tr:last-child td { border-bottom: 0; }
cc-table tbody tr:hover { background: var(--raise); }
cc-table tbody tr.focused { background: var(--accent-bg); box-shadow: inset 2px 0 0 var(--accent); }
cc-table tr.tbl-empty td { padding: 18px 12px; text-align: center; color: var(--text-faint);
  font: 400 var(--fs-small)/1.4 var(--sans); border-bottom: 0; height: auto; }
cc-table td.num, cc-table th.num { text-align: right; font-family: var(--mono);
  font-variant-numeric: tabular-nums; }
cc-table tfoot td { background: var(--band); border-top: 1px solid var(--border-strong);
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600;
  height: var(--row-h); padding: 0 calc(var(--sp) * 2); }
cc-table .tbl-filter { background: var(--band); border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: var(--sp) calc(var(--sp) * 2); gap: var(--sp); }
cc-table .tbl-filter input { flex: 1; }
cc-table .tbl-meta { color: var(--text-faint); font: 400 var(--fs-micro) / 1 var(--mono); }

/* cc-tabs */
cc-tabs { display: block; }
cc-tabs .tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  background: var(--band); border-radius: var(--radius) var(--radius) 0 0; padding: 0 var(--sp); }
cc-tabs .tab-bar button { font: 500 var(--fs-small) / 1 var(--sans); color: var(--text-dim);
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: calc(var(--sp) * 2) calc(var(--sp) * 3); cursor: pointer; }
cc-tabs .tab-bar button.active { color: var(--accent); border-bottom-color: var(--accent); }
cc-tabs .tab-bar button:hover { color: var(--text); }
cc-tab { display: none; padding: calc(var(--sp) * 2) 0; }
cc-tab.active { display: block; }

/* cc-json */
cc-json { display: block; font-family: var(--mono); font-size: var(--fs-data);
  background: var(--band); border: 1px solid var(--border); border-radius: var(--radius);
  padding: calc(var(--sp) * 2); overflow: auto; max-height: 50vh; }
cc-json .j-k { color: var(--info); }
cc-json .j-s { color: var(--ok); }
cc-json .j-n { color: var(--warn); }
cc-json .j-b { color: var(--accent); }
cc-json .j-null { color: var(--text-faint); }
cc-json details { padding-left: 14px; }
cc-json summary { cursor: pointer; list-style: none; margin-left: -14px; }
cc-json summary::before { content: "▸ "; color: var(--text-faint); }
cc-json details[open] > summary::before { content: "▾ "; }

/* cc-empty */
cc-empty { display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: calc(var(--sp) * 2); min-height: 120px; color: var(--text-faint);
  font-size: var(--fs-small); text-align: center; }
cc-empty .spin { width: 14px; height: 14px; border: 2px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: cc-spin 0.7s linear infinite; }
@keyframes cc-spin { to { transform: rotate(360deg); } }
cc-empty[kind="error"] { color: var(--err); }

/* cc-toast */
#cc-toasts { position: fixed; bottom: 32px; right: 12px; display: flex;
  flex-direction: column; gap: var(--sp); z-index: 1000; }
.cc-toast { display: flex; align-items: center; gap: calc(var(--sp) * 2);
  background: var(--raise); border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent); border-radius: var(--radius);
  padding: calc(var(--sp) * 1.5) calc(var(--sp) * 2.5); font-size: var(--fs-small);
  font-family: var(--mono); box-shadow: 0 4px 16px rgba(31, 28, 22, 0.14);
  animation: cc-toast-in 0.15s ease-out; }
.cc-toast.err { border-left-color: var(--err); }
.cc-toast.warn { border-left-color: var(--warn); }
.cc-toast-msg { flex: 1; min-width: 0; }
/* action button (e.g. Undo): accent, uppercase, and a real tap target */
.cc-toast-action { flex: none; margin: calc(var(--sp) * -1) calc(var(--sp) * -1) calc(var(--sp) * -1) 0;
  padding: 0 calc(var(--sp) * 1.5); align-self: stretch; min-height: 30px;
  background: transparent; border: 0; border-radius: var(--radius); cursor: pointer;
  font: 700 var(--fs-small)/1 var(--mono); letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); }
.cc-toast-action:hover { background: var(--accent-bg); }
.cc-toast-action:active { opacity: .7; }
@keyframes cc-toast-in { from { opacity: 0; transform: translateY(4px); } }

/* Phones: float the toast bottom-centre, clear of the notch/home-bar inset, and
   give the action a full 44px thumb target so an Undo is easy to hit. */
@media (max-width: 760px) {
  #cc-toasts { left: 10px; right: 10px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); align-items: center; }
  .cc-toast { width: 100%; max-width: 440px; font-size: var(--fs-ui); }
  .cc-toast-action { min-height: 44px; padding: 0 calc(var(--sp) * 2.5); font-size: var(--fs-ui); }
  /* toolbars carry fixed-width inputs on some pages — wrap instead of pushing
     the whole page into a sideways scroll */
  .cc-band, cc-toolbar { flex-wrap: wrap; }
}

/* cc-date-range */
cc-date-range { display: inline-flex; align-items: center; gap: 2px; }
cc-date-range button { font: 500 var(--fs-micro) / 1 var(--mono); color: var(--text-dim);
  background: var(--raise); border: 1px solid var(--border-strong);
  height: var(--ctl-h); padding: 0 calc(var(--sp) * 1.5); cursor: pointer; }
cc-date-range button:first-of-type { border-radius: var(--radius) 0 0 var(--radius); }
cc-date-range button.custom-btn { border-radius: 0 var(--radius) var(--radius) 0; }
cc-date-range button.active { color: var(--accent); background: var(--accent-bg);
  border-color: var(--accent-dim); }
cc-date-range .custom-inputs { display: none; gap: 2px; margin-left: var(--sp); }
cc-date-range .custom-inputs.open { display: inline-flex; }
cc-date-range input[type="date"] { color-scheme: inherit; }

/* cc-chart */
cc-chart { display: block; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: calc(var(--sp) * 2); box-shadow: var(--panel-shadow); }
cc-chart .u-legend { font: 400 var(--fs-micro) / 1.4 var(--mono) !important;
  color: var(--text-dim) !important; }
cc-chart .u-legend .u-marker { border-radius: 2px; }

/* ═══ form controls — cc-checkbox / cc-radio / cc-switch / cc-select /
   cc-slider / cc-segmented / cc-field ═══ */

/* shared: a control row = hidden native input + drawn box + label text */
cc-checkbox, cc-switch, cc-radio { display: inline-flex; }
.ctl-line { display: inline-flex; align-items: center; gap: calc(var(--sp) * 1.5);
  min-height: var(--ctl-h); cursor: pointer; position: relative; user-select: none; }
.ctl-line.disabled { opacity: 0.45; cursor: default; }
.ctl-line input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.ctl-text { font-size: var(--fs-small); color: var(--text); }

.ctl-box { flex: none; width: 14px; height: 14px; border: 1px solid var(--border-strong);
  border-radius: 3px; background: var(--bg); display: inline-flex; align-items: center;
  justify-content: center; font: 700 10px/1 var(--mono); color: var(--panel); }
.ctl-box.round { border-radius: 50%; }
.ctl-line input:checked + .ctl-box:not(.round),
.ctl-line input:indeterminate + .ctl-box { background: var(--accent); border-color: var(--accent); }
.ctl-line input:checked + .ctl-box:not(.round)::after { content: "✓"; }
.ctl-line input:indeterminate + .ctl-box::after { content: "–"; }
.ctl-line input:checked + .ctl-box.round { border-color: var(--accent); }
.ctl-line input:checked + .ctl-box.round::after { content: ""; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent); }
.ctl-line input:focus-visible + .ctl-box,
.ctl-line input:focus-visible + .sw-track { outline: 1px solid var(--accent-dim); outline-offset: 1px; }

cc-radio-group { display: flex; flex-direction: column; gap: var(--sp); }
cc-radio-group[horizontal] { flex-direction: row; flex-wrap: wrap; gap: calc(var(--sp) * 3); }

/* cc-switch */
.sw-track { flex: none; width: 26px; height: 14px; border-radius: 7px; position: relative;
  background: var(--raise); border: 1px solid var(--border-strong);
  transition: background 0.12s, border-color 0.12s; }
.sw-knob { position: absolute; top: 1px; left: 1px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-faint); transition: transform 0.12s, background 0.12s; }
.ctl-line input:checked + .sw-track { background: var(--accent); border-color: var(--accent); }
.ctl-line input:checked + .sw-track .sw-knob { transform: translateX(12px); background: var(--panel); }

/* cc-select */
cc-select { position: relative; display: inline-block; min-width: 140px; }
cc-select .sel-btn { display: flex; width: 100%; align-items: center; justify-content: space-between;
  gap: var(--sp); height: var(--ctl-h); padding: 0 calc(var(--sp) * 1.5);
  font: 400 var(--fs-data) / 1 var(--mono); color: var(--text); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; }
cc-select .sel-btn:focus-visible,
cc-select .sel-btn[aria-expanded="true"] { outline: none; border-color: var(--accent-dim); }
cc-select .sel-cur { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
cc-select .sel-cur.placeholder { color: var(--text-faint); }
.sel-caret { color: var(--text-faint); font-size: 9px; }
cc-select .sel-list { position: absolute; top: calc(100% + 2px); left: 0; min-width: 100%; z-index: 750;
  max-height: 240px; overflow: auto; background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(31, 28, 22, 0.18); padding: 2px; }
cc-select .sel-opt { display: flex; align-items: center; height: var(--ctl-h);
  padding: 0 calc(var(--sp) * 1.5); font: 400 var(--fs-data) / 1 var(--mono);
  border-radius: 3px; cursor: pointer; white-space: nowrap; }
cc-select .sel-opt:hover, cc-select .sel-opt.active { background: var(--raise); }
cc-select .sel-opt.selected { color: var(--accent); background: var(--accent-bg); }

/* cc-slider */
cc-slider { display: inline-flex; align-items: center; gap: calc(var(--sp) * 2); min-width: 160px; }
cc-slider input[type="range"] { flex: 1; appearance: none; -webkit-appearance: none;
  height: var(--ctl-h); background: transparent; margin: 0; cursor: pointer; }
cc-slider input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px;
  background: var(--border-strong); }
cc-slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px;
  height: 12px; margin-top: -4.5px; border-radius: 50%; background: var(--accent); border: none; }
cc-slider input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px;
  background: var(--border-strong); }
cc-slider input[type="range"]::-moz-range-progress { height: 3px; border-radius: 2px;
  background: var(--accent); }
cc-slider input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: none; }
cc-slider .sld-out { font: 400 var(--fs-data) / 1 var(--mono); font-variant-numeric: tabular-nums;
  color: var(--text-dim); min-width: 3ch; text-align: right; }

/* cc-segmented — same register as cc-date-range's preset buttons */
cc-segmented { display: inline-flex; align-items: center; gap: 2px; }
cc-segmented button { font: 500 var(--fs-micro) / 1 var(--mono); color: var(--text-dim);
  background: var(--raise); border: 1px solid var(--border-strong);
  height: var(--ctl-h); padding: 0 calc(var(--sp) * 2); cursor: pointer; }
cc-segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
cc-segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
cc-segmented button.active { color: var(--accent); background: var(--accent-bg);
  border-color: var(--accent-dim); }

/* cc-field */
cc-field { display: block; }
cc-field .field-msg { font-size: var(--fs-micro); color: var(--text-faint); margin-top: 2px; }
cc-field .field-msg.error { color: var(--err); }
cc-field.has-error .cc-input-el,
cc-field.has-error .sel-btn { border-color: var(--err); }

/* ═══ overlays — cc-modal / cc-menu ═══ */

cc-modal { position: fixed; inset: 0; z-index: 800; display: none; background: var(--overlay);
  align-items: center; justify-content: center; padding: calc(var(--sp) * 4); }
cc-modal[open] { display: flex; }
cc-modal .modal-sheet { background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 6px; min-width: 320px; max-width: min(560px, 92vw); max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(31, 28, 22, 0.2); }
cc-modal .modal-sheet header { display: flex; align-items: center; gap: calc(var(--sp) * 2);
  padding: calc(var(--sp) * 2) calc(var(--sp) * 3); border-bottom: 1px solid var(--border);
  background: var(--band); border-radius: 6px 6px 0 0; }
cc-modal .modal-title { flex: 1; font: 600 var(--fs-small) / 1 var(--sans);
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
cc-modal .modal-x { flex: none; width: 20px; height: 20px; display: inline-flex;
  align-items: center; justify-content: center; background: none; border: none;
  border-radius: var(--radius); color: var(--text-faint); font: 600 10px/1 var(--mono);
  cursor: pointer; }
cc-modal .modal-x:hover { color: var(--text); background: var(--raise); }
cc-modal .modal-body { padding: calc(var(--sp) * 3); overflow: auto; }

cc-menu { position: relative; display: inline-block; }
cc-menu .menu-list { position: absolute; top: calc(100% + 2px); left: 0; z-index: 750;
  min-width: 160px; background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(31, 28, 22, 0.18); padding: 2px;
  display: flex; flex-direction: column; }
cc-menu .menu-list[hidden] { display: none; }
cc-menu .menu-item { display: flex; align-items: center; height: var(--ctl-h);
  padding: 0 calc(var(--sp) * 2); font: 400 var(--fs-data) / 1 var(--sans); color: var(--text);
  text-align: left; background: none; border: none; border-radius: 3px; cursor: pointer;
  white-space: nowrap; }
cc-menu .menu-item:hover, cc-menu .menu-item.active { background: var(--raise); }
cc-menu .menu-item.danger { color: var(--err); }
cc-menu .menu-item[disabled] { opacity: 0.45; cursor: default; }

/* ═══ feedback & display — cc-progress / cc-spinner / cc-tag / cc-alert /
   cc-avatar / cc-skeleton ═══ */

cc-progress { display: flex; align-items: center; gap: calc(var(--sp) * 2); min-width: 160px; }
cc-progress .prog-track { flex: 1; height: 4px; border-radius: 2px; background: var(--raise);
  border: 1px solid var(--border); overflow: hidden; position: relative; }
cc-progress .prog-fill { display: block; height: 100%; border-radius: 2px;
  background: var(--accent); transition: width 0.2s ease-out; }
cc-progress .prog-track.ind .prog-fill { position: absolute; width: 36%;
  animation: cc-prog-slide 1.1s ease-in-out infinite; }
@keyframes cc-prog-slide { from { left: -36%; } to { left: 100%; } }
cc-progress .prog-pct { font: 400 var(--fs-micro) / 1 var(--mono);
  font-variant-numeric: tabular-nums; color: var(--text-dim); min-width: 4ch; text-align: right; }

cc-spinner { display: inline-block; width: 14px; height: 14px; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: cc-spin 0.7s linear infinite; }
cc-spinner[size="lg"] { width: 22px; height: 22px; }

cc-tag { display: inline-flex; align-items: center; gap: var(--sp); height: 18px;
  padding: 0 calc(var(--sp) * 1.5); border-radius: 9px; font: 500 var(--fs-micro) / 1 var(--mono);
  color: var(--text-dim); background: var(--raise); border: 1px solid var(--border-strong);
  white-space: nowrap; }
cc-tag[kind="accent"] { color: var(--accent); background: var(--accent-bg);
  border-color: var(--accent-dim); }
cc-tag .tag-x { display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; margin-right: -2px; padding: 0; font: 600 8px/1 var(--mono);
  color: var(--text-faint); background: none; border: none; border-radius: 50%; cursor: pointer; }
cc-tag .tag-x:hover { color: var(--err); background: var(--band); }

cc-alert { display: flex; gap: calc(var(--sp) * 2); padding: calc(var(--sp) * 2) calc(var(--sp) * 2.5);
  background: var(--panel); border: 1px solid var(--border); border-left-width: 2px;
  border-radius: var(--radius); font-size: var(--fs-small); }
cc-alert .alert-icon { flex: none; line-height: 1.5; }
cc-alert .alert-title { display: block; color: var(--text-bright); margin-bottom: 1px; }
cc-alert .alert-msg { color: var(--text-dim); line-height: 1.5; }
cc-alert, cc-alert[kind="info"] { border-left-color: var(--info); }
cc-alert[kind="info"] .alert-icon, cc-alert:not([kind]) .alert-icon { color: var(--info); }
cc-alert[kind="warn"] { border-left-color: var(--warn); }
cc-alert[kind="warn"] .alert-icon { color: var(--warn); }
cc-alert[kind="err"] { border-left-color: var(--err); }
cc-alert[kind="err"] .alert-icon { color: var(--err); }
cc-alert[kind="ok"] { border-left-color: var(--ok); }
cc-alert[kind="ok"] .alert-icon { color: var(--ok); }

cc-avatar { display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%; overflow: hidden;
  background: var(--accent-bg); border: 1px solid var(--accent-dim); color: var(--accent);
  font: 600 9px/1 var(--sans); letter-spacing: 0.02em; }
cc-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* cc-skeleton — subtle opacity pulse, no shimmer gradient */
cc-skeleton { display: block; height: 14px; border-radius: var(--radius);
  background: var(--raise); animation: cc-skel 1.2s ease-in-out infinite; }
@keyframes cc-skel { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ═══ cc-calendar ═══ */

cc-calendar { display: inline-block; width: 240px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: calc(var(--sp) * 2); box-shadow: var(--panel-shadow); }
cc-calendar .cal-head { display: flex; align-items: center; gap: var(--sp);
  margin-bottom: var(--sp); }
cc-calendar .cal-month { flex: 1; text-align: center; font: 600 var(--fs-small) / 1 var(--sans);
  color: var(--text-bright); }
cc-calendar .cal-nav { flex: none; width: 22px; height: 22px; display: inline-flex;
  align-items: center; justify-content: center; background: var(--raise);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  color: var(--text-dim); font: 600 12px/1 var(--mono); cursor: pointer; }
cc-calendar .cal-nav:hover { color: var(--text); border-color: var(--accent-dim); }
cc-calendar .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
cc-calendar .cal-dow { display: flex; align-items: center; justify-content: center; height: 20px;
  font: 600 var(--fs-micro) / 1 var(--mono); text-transform: uppercase; color: var(--text-faint); }
cc-calendar .cal-day { display: flex; align-items: center; justify-content: center; height: 26px;
  font: 400 var(--fs-data) / 1 var(--mono); font-variant-numeric: tabular-nums;
  color: var(--text); background: none; border: none; border-radius: 3px; cursor: pointer; }
cc-calendar .cal-day:hover { background: var(--raise); }
cc-calendar .cal-day.out { color: var(--text-faint); }
cc-calendar .cal-day.today { box-shadow: inset 0 0 0 1px var(--accent-dim); }
cc-calendar .cal-day.selected { background: var(--accent); color: var(--panel); font-weight: 600; }

/* shortcuts overlay */
#cc-shortcuts-overlay { position: fixed; inset: 0; background: var(--overlay);
  display: none; align-items: flex-start; justify-content: center; z-index: 900;
  padding-top: 12vh; }
#cc-shortcuts-overlay.open { display: flex; }
#cc-shortcuts-overlay .sheet { background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 6px; min-width: 360px; max-width: 480px; max-height: 60vh; overflow: auto;
  box-shadow: 0 12px 48px rgba(31, 28, 22, 0.2); }
#cc-shortcuts-overlay .sheet header { padding: calc(var(--sp) * 2) calc(var(--sp) * 3);
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: var(--fs-small);
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
#cc-shortcuts-overlay .sheet ul { list-style: none; margin: 0; padding: var(--sp) 0; }
#cc-shortcuts-overlay .sheet li { display: flex; justify-content: space-between;
  align-items: center; padding: var(--sp) calc(var(--sp) * 3); font-size: var(--fs-small); }
#cc-shortcuts-overlay .sheet li:hover { background: var(--raise); }

/* ── iOS focus-zoom guard ──────────────────────────────────────────────────
   iOS Safari force-zooms the page when a focused text control's computed
   font-size is under 16px, and the zoom sticks after blur (pinching back out
   is fiddly). On touch devices, hold every text-entry control at 16px so the
   zoom never fires; fine-pointer devices keep the dense 12-13px sizing.
   !important is deliberate: control fonts are set by many per-page and
   per-component rules (often via the `font:` shorthand), and this guard must
   beat all of them, including later-loaded page styles. Do NOT solve this
   with user-scalable=no or maximum-scale on the viewport meta instead: that
   disables pinch-zoom, which is an accessibility violation. */
@media (pointer: coarse) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]):not([type=button]):not([type=submit]):not([type=reset]):not([type=image]):not([type=hidden]),
  textarea,
  select,
  .cc-input-el,
  .cc-select-el {
    font-size: 16px !important;
  }
  /* 16px text fits the 24px --ctl-h box but reads cramped; give single-line
     controls touch-friendly room without disturbing the desktop density vars. */
  input.cc-input-el, .cc-select-el, select { min-height: 32px; }
}

/* ── touch tap-target floor ────────────────────────────────────────────────
   Companion to the focus-zoom guard above: on coarse pointers, buttons and
   menu rows get a taller minimum so thumbs can hit them. min-height (never
   height) so the desktop density vars and one-off heights stay untouched on
   fine pointers, and flex centering keeps every label in place. */
@media (pointer: coarse) {
  .cc-btn { min-height: 32px; }
  cc-menu .menu-item, cc-select .sel-opt { min-height: 40px; }
  cc-tabs .tab-bar button { min-height: 40px; }
  .ctl-line { min-height: 32px; }
  cc-date-range button, cc-segmented button { min-height: 30px; }
  /* modal close: slightly larger glyph box + an invisible 44px hit pad */
  cc-modal .modal-x { position: relative; width: 28px; height: 28px; }
  cc-modal .modal-x::after { content: ""; position: absolute; left: 50%; top: 50%;
    width: 44px; height: 44px; transform: translate(-50%, -50%); }
}
