/* Sideways House HQ — design system (release sideways-house-hq).
   One semantic token set drives every screen. Two themes:
     SAGE       (default)  pale pastel-green XLumen cards (near-black text) on a very dark sage page (light sage text)
     LIGHT SAGE (optional) the previous cream / forest palette, mapped onto the same tokens
   The theme is chosen in Settings → Display (stored per device) and applied by /theme.js before first paint.
   No blue primary UI. Red is reserved for destructive actions and genuine errors.
   Contrast (WCAG 2.1) is verified by tests/sh/hq.test.js for both themes: primary/secondary/muted text,
   link and status colours ≥ 4.5:1 on surfaces; primary-button text ≥ 4.5:1; control borders ≥ 3:1.
   Type: 18px body / controls, 16px floor for secondary labels, tiered 38 / 26 / 21px headings, 32px figures.
   Sizes are in rem so browser text scaling (Safari "Larger Text", Cmd/Ctrl +) scales the whole UI. */

:root {
  /* ---- SAGE (default): pale pastel-green XLumen ----
     Pale pistachio page → pistachio cards → soft mint nested cards → stronger soft-green elevated cards; very pale
     green-cream inputs and buttons; medium pastel sage for selected items; near-black text throughout; muted-sage
     borders. Flat colour only: the page glow and chart fills resolve to solid colours.
     The page itself is very dark sage; text that sits directly on it (page / section headings, notes, page-level
     links and status text) uses the --page-* tokens below. Text inside cards keeps the near-black tokens. */
  --bg: #1B251E;
  --bg-glow: #1B251E;
  --page-title: #F1F6EA;
  --page-heading: #DCEBCF;
  --page-text: #C9D9BF;
  --page-muted: #A8BBA2;
  --page-accent: #A7D6A5;
  --page-link: #B9E3B2;
  --page-success: #9FDAAB;
  --page-warning: #EDC77F;
  --page-danger: #F3A797;
  --page-focus: #A7D6A5;
  --sidebar: #DCEDC9;
  --sidebar-hover: #CBE4B4;
  --surface: #D3E8BC;
  --surface-raised: #A9D3B5;
  --surface-sunken: #C6E1C0;
  --surface-hover: #C2DEAB;
  --input-bg: #EEF5E8;
  --button-bg: #EEF5E8;
  --border: #A3C496;
  --border-strong: #4F7052;
  --text-primary: #111813;
  --text-secondary: #1E2A21;
  --text-muted: #33433A;
  --text-on-primary: #0E1610;
  --primary: #6FAE7E;
  --primary-hover: #82BD90;
  --primary-soft: #BCDDB4;
  --primary-text: #24502F;
  --nav-active: #91C79B;
  --nav-active-text: #111813;
  --link: #1F5233;
  /* status / accent tints are opaque so badges, chips and notice boxes read the same on a card or on the page */
  --success: #1A5E33;
  --success-bg: #C3E4C4;
  --warning: #6A4204;
  --warning-bg: #F3E3BF;
  --danger: #962A19;
  --danger-bg: #F3D6CC;
  --danger-solid: #9E2F1D;
  --info: #22564A;
  --info-bg: #C7E3D9;
  --neutral-bg: #C3DDB6;
  --focus: #24502F;
  --chart: #6FAE7E;
  --chart-2: #6FAE7E;
  --overlay: rgba(20, 30, 25, .35);
  --shadow: 0 1px 2px rgba(40, 80, 50, .07), 0 6px 18px rgba(40, 80, 50, .07);
  --shadow-lg: 0 18px 48px rgba(40, 80, 50, .16);
  --topbar-bg: #E8F2D8;
  --preview-wrap: #D3E8BC;
  color-scheme: light;

  /* ---- shape, type, touch ---- */
  --radius: 16px;
  --radius-sm: 12px;
  --touch: 44px;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --fs-body: 1.125rem;    /* 18px */
  --fs-ui: 1.125rem;      /* 18px  navigation / controls */
  --fs-table: 1.0625rem;  /* 17px  table cells */
  --fs-label: 1.0625rem;  /* 17px  form labels */
  --fs-btn: 1.125rem;     /* 18px  buttons */
  --fs-meta: 1rem;        /* 16px  metadata / secondary labels */
  --fs-tiny: 1rem;        /* 16px  absolute floor (tags, chart axes) */
  --fs-h1: 2.375rem;      /* 38px */
  --fs-h2: 1.625rem;      /* 26px */
  --fs-h3: 1.3125rem;     /* 21px */
  --fs-metric: 2rem;      /* 32px */
  --sidebar-w: 268px;

  /* ---- legacy aliases (older views reference these names inline) ---- */
  --canvas: var(--bg); --panel: var(--surface); --panel-2: var(--surface-sunken); --pale: var(--surface-sunken);
  --soft: var(--border); --forest: var(--text-primary); --eucalyptus: var(--primary); --sage: var(--primary); --sage-muted: var(--border-strong);
  --text: var(--text-primary); --text-2: var(--text-secondary); --muted: var(--text-muted);
  --good: var(--success); --good-bg: var(--success-bg); --warn: var(--warning); --warn-bg: var(--warning-bg); --bad: var(--danger); --bad-bg: var(--danger-bg);
}

:root[data-theme="light"] {
  /* ---- LIGHT SAGE (optional) ---- */
  --bg: #F2EFE6;
  --bg-glow: #EAF1E6;
  /* the cream page is light, so page-level text keeps the normal text colours */
  --page-title: var(--text-primary);
  --page-heading: var(--text-primary);
  --page-text: var(--text-secondary);
  --page-muted: var(--text-muted);
  --page-accent: var(--primary-text);
  --page-link: var(--link);
  --page-success: var(--success);
  --page-warning: var(--warning);
  --page-danger: var(--danger);
  --page-focus: var(--focus);
  --sidebar: #E3EBDD;
  --sidebar-hover: #D3E0CC;
  --surface: #FFFDF7;
  --surface-raised: #FFFFFF;
  --surface-sunken: #F4F2EA;
  --surface-hover: #EAF1E6;
  --input-bg: #FFFFFF;
  --border: #D6DED0;
  --border-strong: #6E856A;
  --text-primary: #1A211D;
  --text-secondary: #33403A;
  --text-muted: #52615A;
  --text-on-primary: #F7F4EA;
  --primary: #1F3B2D;
  --primary-hover: #2B4E3C;
  --primary-soft: rgba(31, 59, 45, .08);
  --primary-text: #1F3B2D;
  --button-bg: #FFFFFF;
  --nav-active: #1F3B2D;
  --nav-active-text: #F7F4EA;
  --link: #1F5A3C;
  --success: #1C6A3B;
  --success-bg: #E1F0E1;
  --warning: #85540A;
  --warning-bg: #FBF0D9;
  --danger: #9E2F1D;
  --danger-bg: #F9E4DE;
  --danger-solid: #9E2F1D;
  --info: #2F6152;
  --info-bg: #E2EEE8;
  --neutral-bg: #ECEEE6;
  --focus: #2F6B4F;
  --chart: #4F7A69;
  --chart-2: #8FA98F;
  --overlay: rgba(20, 30, 25, .45);
  --shadow: 0 1px 2px rgba(31, 59, 45, .06), 0 10px 26px rgba(31, 59, 45, .08);
  --shadow-lg: 0 18px 48px rgba(31, 59, 45, .18);
  --topbar-bg: rgba(242, 239, 230, .94);
  --preview-wrap: #DDE4D8;
  color-scheme: light;
}

/* ================================================================ base */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
html { background-color: var(--bg); } /* explicit page colour, so Safari never falls back to its own dark-mode canvas */
body {
  background: var(--bg) radial-gradient(1200px 600px at 85% -10%, var(--bg-glow), transparent 70%) no-repeat fixed;
  background-color: var(--bg);
  color: var(--text-primary); font: 400 var(--fs-body)/1.55 var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
a { color: var(--link); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
::selection { background: var(--nav-active); color: var(--nav-active-text); }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ================================================================ app shell */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 20px 14px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain; z-index: 60;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text-primary); padding: 4px 10px 8px; min-height: var(--touch); }
.brand:hover { color: var(--text-primary); }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; }
.brand strong { display: block; font-family: var(--serif); font-size: 1.5rem; line-height: 1; font-weight: 600; }
.brand small { display: block; font-size: var(--fs-tiny); letter-spacing: .22em; text-transform: uppercase; color: var(--primary-text); font-weight: 700; margin-top: 4px; }
.sidebar-cta { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border-radius: var(--radius-sm); background: var(--primary); color: var(--text-on-primary); font-weight: 700; font-size: var(--fs-ui); text-decoration: none; box-shadow: var(--shadow); }
.sidebar-cta:hover { background: var(--primary-hover); color: var(--text-on-primary); }
.nav-group { margin-bottom: 4px; }
.nav-group-label { font-size: var(--fs-tiny); letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; padding: 12px 12px 6px; }
.nav-link {
  display: flex; align-items: center; min-height: var(--touch); padding: 8px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-weight: 600; font-size: var(--fs-ui); line-height: 1.25;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--text-primary); }
.nav-link.active { background: var(--nav-active); color: var(--nav-active-text); box-shadow: inset 4px 0 0 var(--primary); }
:root:not([data-theme="light"]) :is(.nav-link.active, .tabs a.active, .preset-row a.active, .kpi.accent) :is(.muted, small) { color: inherit; } /* dark text on the selected sage pill */
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--border); font-size: var(--fs-meta); color: var(--text-muted); }
.sidebar-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.link-btn { background: transparent; border: 1px solid var(--border-strong); color: var(--text-primary); border-radius: 999px; padding: 8px 16px; min-height: var(--touch); cursor: pointer; font: inherit; font-size: var(--fs-meta); }
.link-btn:hover { background: var(--sidebar-hover); }
.nav-backdrop { display: none; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 28px 12px; background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; min-width: var(--touch); min-height: var(--touch); align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 1.25rem; cursor: pointer; color: var(--text-primary); padding: 0 12px; }
.search-wrap { position: relative; flex: 1; max-width: 720px; min-width: 0; }
.search-wrap input { width: 100%; min-height: var(--touch); padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--input-bg); color: var(--text-primary); font: inherit; font-size: var(--fs-ui); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: min(70vh, 520px); overflow: auto; z-index: 50; -webkit-overflow-scrolling: touch; }
.search-results a { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 48px; padding: 10px 16px; color: var(--text-primary); text-decoration: none; border-bottom: 1px solid var(--border); }
.search-results a:hover { background: var(--surface-hover); }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; margin-left: auto; }
.topbar-add { white-space: nowrap; }

main { padding: 28px 32px 72px; width: 100%; max-width: 1600px; }
body.logged-out .sidebar, body.logged-out .topbar { display: none; }
body.logged-out main { max-width: none; }

/* ================================================================ type */
h1 { font-family: var(--serif); font-weight: 600; font-size: var(--fs-h1); line-height: 1.12; margin: 0 0 8px; color: var(--text-primary); letter-spacing: .005em; overflow-wrap: anywhere; }
h2 { font-size: var(--fs-h2); line-height: 1.25; margin: 32px 0 12px; color: var(--text-primary); font-weight: 700; }
h3 { font-size: var(--fs-h3); line-height: 1.3; margin: 16px 0 10px; color: var(--text-primary); font-weight: 650; }
p { margin: 0 0 12px; }
.section-note { color: var(--text-secondary); margin: 0 0 20px; max-width: 920px; font-size: var(--fs-body); }
.eyebrow { font-size: var(--fs-tiny); letter-spacing: .16em; text-transform: uppercase; color: var(--primary-text); font-weight: 700; margin: 0 0 6px; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-meta); }
.ok { color: var(--success); } .warn { color: var(--warning); } .bad { color: var(--danger); }
b, strong { font-weight: 650; }
small { font-size: max(var(--fs-tiny), .85em); }

/* ---- text that sits directly on the page (not inside a card, tile, control or badge) uses the --page-* colours.
   Page titles are brightest, section headings a step softer, notes and muted text quieter still. */
main :is(h1):not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *) { color: var(--page-title); }
main :is(h2, h3, h4, summary):not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *) { color: var(--page-heading); }
main :is(p, li, label, .section-note, .field-legend):not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *) { color: var(--page-text); }
main :is(.muted, .group-note, small, .small):not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *) { color: var(--page-muted); }
main .eyebrow:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .vault-card, .stat, .period, .tile, .warn-box, .bad-box, .good-box) *) { color: var(--page-accent); }
main a:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-stage, .vault-card, .vault-item, .photo, .period, .tile, .ring-card, .chan-chip, .btn, .tag)):not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *) { color: var(--page-link); }
main .warn:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *):not(.card, .tag, .cap, button, .btn, .kpi, .stat, .ql-answer, .vault-card) { color: var(--page-warning); }
main .ok:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *):not(.card, .tag, .cap, button, .btn, .kpi, .stat, .ql-answer, .vault-card) { color: var(--page-success); }
main .bad:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .unit-pick, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table, .tabs, .preset-row, .chip-row, button, .btn, .tag, .cap, pre) *):not(.card, .tag, .cap, button, .btn, .kpi, .stat, .ql-answer, .vault-card) { color: var(--page-danger); }
main:not(:has(> *)) { color: var(--page-text); } /* the brief "Loading…" text */
main :is(a, button, .btn, input, select, textarea, summary):focus-visible:not(:is(.card, .kpi, .coll-card, .chan-card, .hub-card, .ql-answer, .ql-pipeline, .vault-card, .vault-item, .photo, .drop, .stat, .period, .tile, .ring-card, .theme-option, .sec, .match, .item, .preview-frame-wrap, .search-results, .warn-box, .bad-box, .good-box, table) *) { outline-color: var(--page-focus); }

/* ================================================================ controls */
button, .btn {
  min-height: var(--touch); padding: 9px 18px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--button-bg); cursor: pointer; font: inherit; font-size: var(--fs-btn); font-weight: 600; color: var(--text-primary);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.2;
  touch-action: manipulation; transition: background-color .12s, border-color .12s, transform .06s;
}
button:hover, .btn:hover { background: var(--surface-hover); color: var(--text-primary); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--primary); color: var(--text-on-primary); border-color: var(--primary); }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--text-on-primary); }
button.danger, .btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: transparent; }
button.danger:hover { background: var(--danger-bg); }
button.good { color: var(--success); border-color: color-mix(in srgb, var(--success) 55%, transparent); }
button.ghost, .btn.ghost { background: transparent; }
button.small, .btn.small, button.compact, .btn.compact { min-height: 40px; padding: 6px 12px; font-size: var(--fs-meta); }
button:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-lg { min-height: 56px; padding: 12px 22px; font-size: 1.125rem; }

input, select, textarea {
  min-height: var(--touch); padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: max(16px, var(--fs-ui)); /* ≥16px stops iOS Safari zooming on focus */
  background: var(--input-bg); min-width: 0; color: var(--text-primary); max-width: 100%; font-weight: 400;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }
select { appearance: none; -webkit-appearance: none; padding-right: 38px; background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; }
input[type="checkbox"], input[type="radio"] { min-height: 0; width: 24px; height: 24px; padding: 0; accent-color: var(--primary); flex-shrink: 0; margin: 0; }
input[type="color"] { padding: 4px; width: 100%; min-width: 64px; }
input[type="range"] { min-height: 32px; padding: 0; accent-color: var(--primary); background: transparent; border: 0; }
input[type="file"] { font-size: var(--fs-meta); }
textarea { width: 100%; min-height: 120px; line-height: 1.5; }
textarea.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-label); color: var(--text-secondary); font-weight: 600; }
label.inline { flex-direction: row; align-items: center; gap: 10px; min-height: var(--touch); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; align-items: end; }
.form-grid.one { grid-template-columns: minmax(0, 1fr); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 12px 0; }
.toolbar > input, .toolbar > select { flex: 1 1 180px; }
.tabs { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.tabs a { display: inline-flex; align-items: center; min-height: var(--touch); padding: 8px 18px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text-secondary); font-size: var(--fs-ui); font-weight: 600; }
.tabs a:hover { border-color: var(--border-strong); color: var(--text-primary); }
.tabs a.active { background: var(--nav-active); color: var(--nav-active-text); border-color: var(--nav-active); }
.tabs .count { margin-left: 8px; font-size: var(--fs-tiny); background: var(--neutral-bg); padding: 1px 8px; border-radius: 999px; }
.tabs a.active .count { background: rgba(255, 255, 255, .18); }
details > summary { cursor: pointer; font-weight: 650; padding: 6px 0; color: var(--text-primary); min-height: var(--touch); display: flex; align-items: center; gap: 8px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--primary-text); transition: transform .15s; display: inline-block; }
details[open] > summary::before { transform: rotate(90deg); }

/* ================================================================ surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0; }
/* larger type: long unbroken words (uppercase labels, env-var names, IDs) wrap inside their card instead of widening the page */
.card, .chan-card, .kpi, .stat, .metric-label { overflow-wrap: break-word; }
.card.link { cursor: pointer; transition: transform .12s, border-color .12s; }
.card.link:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.card.empty { color: var(--text-muted); box-shadow: none; background: var(--surface-sunken); border-style: dashed; }
.card.raised { background: var(--surface-raised); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid + *, .stat-strip + * { margin-top: 14px; }
.metric-label { font-size: var(--fs-tiny); color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.big { font-size: var(--fs-metric); font-weight: 700; margin-top: 6px; color: var(--text-primary); font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.big.ok { color: var(--success); } .big.bad { color: var(--danger); } .big.warn { color: var(--warning); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; }
.kv > div:nth-child(odd) { color: var(--text-muted); }
.kv > div { overflow-wrap: anywhere; }
pre, code { white-space: pre-wrap; word-break: break-word; font-size: var(--fs-tiny); }
pre { background: var(--surface-sunken); padding: 12px; border-radius: var(--radius-sm); max-height: 380px; overflow: auto; border: 1px solid var(--border); color: var(--text-secondary); }
.warn-box, .card.warn-card { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.bad-box, .card.bad-card { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.good-box { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); right: 20px; padding: 14px 20px; border-radius: var(--radius-sm); background: var(--nav-active); color: var(--nav-active-text); z-index: 100; max-width: min(560px, calc(100vw - 40px)); box-shadow: var(--shadow-lg); font-size: var(--fs-ui); white-space: pre-line; }
.toast.error { background: var(--danger-solid); color: #fff; }
.login { max-width: 460px; margin: 10vh auto; padding: 32px; }
.login h1 { font-size: 2.75rem; }

/* ================================================================ tables */
.table-wrap { overflow-x: auto; padding: 0; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-table); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
td { color: var(--text-primary); }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: var(--fs-tiny); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; background: var(--surface-sunken); position: sticky; top: 0; font-weight: 700; white-space: nowrap; z-index: 1; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td, tr.clickable:active td { background: var(--surface-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .muted, td .small { font-size: var(--fs-meta); }
td button, td .btn { min-height: 40px; padding: 6px 12px; font-size: var(--fs-meta); }

/* ================================================================ tags / status */
.tag { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--neutral-bg); font-size: var(--fs-tiny); margin: 2px 4px 2px 0; white-space: nowrap; color: var(--text-secondary); font-weight: 650; line-height: 1.35; }
.tag.good { background: var(--success-bg); color: var(--success); }
.tag.warn { background: var(--warning-bg); color: var(--warning); }
.tag.bad { background: var(--danger-bg); color: var(--danger); }
.tag.info { background: var(--info-bg); color: var(--info); }
.tag.solid { background: var(--primary); color: var(--text-on-primary); }
.own-yes { color: var(--success); font-weight: 700; font-size: 1.25rem; } .own-no { color: var(--text-muted); font-size: 1.25rem; }
.progress { height: 10px; background: var(--surface-sunken); border-radius: 999px; overflow: hidden; margin: 10px 0; border: 1px solid var(--border); }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--chart-2), var(--primary)); border-radius: 999px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); display: inline-block; flex-shrink: 0; }
.dot.good { background: var(--success); } .dot.warn { background: var(--warning); } .dot.bad { background: var(--danger); } .dot.info { background: var(--info); }
.layer { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-tiny); font-weight: 750; letter-spacing: .08em; text-transform: uppercase; padding: 3px 10px; border-radius: 6px; white-space: nowrap; }
.layer.canonical { background: var(--primary-soft); color: var(--primary-text); border: 1px solid color-mix(in srgb, var(--primary) 50%, transparent); }
.layer.override { background: var(--warning-bg); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 50%, transparent); }

/* ================================================================ media */
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-sunken); display: inline-block; vertical-align: middle; }
.thumb.empty { font-size: var(--fs-tiny); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; text-align: center; line-height: 1.1; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin: 10px 0 16px; }
.photo { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit; min-width: 0; position: relative; }
.photo.primary { border: 2px solid var(--primary); }
.photo img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 10px; background: var(--surface-sunken); display: block; }
.photo .noimg { aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; background: var(--surface-sunken); border-radius: 10px; color: var(--text-muted); }
.photo input:not([type="checkbox"]):not([type="radio"]) { width: 100%; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.photo-actions button { min-height: 40px; padding: 6px 10px; font-size: var(--fs-meta); flex: 1 1 auto; }
.photo .badge { position: absolute; top: 16px; left: 16px; }
.photo.dragging { opacity: .5; } .photo.drop-target { outline: 3px dashed var(--primary); outline-offset: 2px; }
.crop { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; } .crop input { width: 100%; }
.drop { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--text-secondary); background: var(--surface-sunken); margin: 10px 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop p { margin: 0; }
.big-img { max-width: 100%; max-height: 70vh; border-radius: var(--radius); border: 1px solid var(--border); }
.unit-pick { flex-direction: row; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface); color: inherit; font-weight: 500; min-height: var(--touch); }
.cand-filter { margin: 8px 0; min-width: min(320px, 100%); }

/* ================================================================ collection checklist / vault */
.vault-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin: 10px 0 20px; }
.vault-card { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; text-decoration: none; color: inherit; text-align: left; padding: 0; font: inherit; cursor: pointer; min-width: 0; position: relative; min-height: 0; justify-content: flex-start; font-weight: 400; }
.vault-card > a { color: inherit; text-decoration: none; display: flex; flex-direction: column; flex: 1; }
.vault-card img, .vault-card .noimg { width: 100%; aspect-ratio: 1/1; object-fit: cover; background: var(--surface-sunken); display: block; }
.vault-card .noimg { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: var(--fs-meta); color: var(--text-muted); border-bottom: 1px dashed var(--border-strong); }
.vault-card .noimg .glyph { font-size: 2.25rem; color: var(--border-strong); line-height: 1; }
.vault-card.needed img { filter: grayscale(.7) brightness(.82); }
.vault-card.owned { border-color: color-mix(in srgb, var(--success) 55%, transparent); }
.vault-card.dup { border-color: color-mix(in srgb, var(--info) 55%, transparent); }
.vault-card .vc-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.vault-card .vc-title { font-weight: 700; font-size: 1.125rem; line-height: 1.25; color: var(--text-primary); }
.vault-card:hover { border-color: var(--border-strong); }
.vault-item { display: inline-flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 4px; min-width: 200px; background: var(--surface); }
.state-ribbon { position: absolute; top: 10px; left: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 20px); pointer-events: none; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-tiny); font-weight: 800; letter-spacing: .06em; padding: 4px 10px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); line-height: 1.3; }
.state.OWNED { background: #2B6F45; color: #FFFFFF; }
.state.NEEDED { background: #FBF0D9; color: #6D4408; border: 1px solid #D9B46B; }
.state.DUPLICATE { background: #1E594C; color: #E6FFF7; }
.state.CHASE { background: #82540A; color: #FFF6E4; }
.state.JACKPOT { background: #8F2C1E; color: #FFEFEB; }
:root[data-theme="light"] .state.NEEDED { background: #FBF0D9; color: #6D4408; border-color: #D9B46B; }
.vc-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 10px; font-size: var(--fs-meta); }
.vc-facts span { color: var(--text-muted); } .vc-facts b { font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.vc-notes { font-size: var(--fs-meta); color: var(--text-secondary); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.vc-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; padding: 0 14px 14px; }
.vc-controls .btn { grid-column: 1 / -1; }
.toggle { min-height: 40px; padding: 6px 8px; font-size: var(--fs-tiny); font-weight: 750; letter-spacing: .02em; border-radius: 999px; background: transparent; white-space: nowrap; }
.toggle[aria-pressed="true"].chase { background: #82540A; color: #FFF6E4; border-color: #82540A; }
.toggle[aria-pressed="true"].jackpot { background: #8F2C1E; color: #FFEFEB; border-color: #8F2C1E; }
.toggle[aria-pressed="true"].keep { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.toggle[aria-pressed="true"].prio { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; min-width: 0; }
.stat .metric-label { display: block; }
.stat b { display: block; font-size: 1.75rem; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.15; overflow-wrap: anywhere; }
.stat small { display: block; color: var(--text-muted); font-size: var(--fs-meta); }
.stat.good b { color: var(--success); } .stat.warn b { color: var(--warning); } .stat.bad b { color: var(--danger); }

/* ================================================================ dashboard / quick look */
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.dash-head h1 { margin: 0; }
.dash-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); min-width: 0; min-height: 112px; }
a.kpi:hover { background: var(--surface-hover); color: inherit; }
.kpi .k { font-size: var(--fs-tiny); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.kpi .v { font-size: var(--fs-metric); font-weight: 750; font-variant-numeric: tabular-nums; color: var(--text-primary); line-height: 1.15; overflow-wrap: anywhere; }
.kpi .s { font-size: var(--fs-meta); color: var(--text-secondary); }
.kpi.accent { background: var(--nav-active); border-color: transparent; }
.kpi.accent .k, .kpi.accent .s, .kpi.accent .v { color: var(--nav-active-text); }
.kpi.warn { border-left: 5px solid var(--warning); } .kpi.bad { border-left: 5px solid var(--danger); } .kpi.good { border-left: 5px solid var(--success); }
.period-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.period { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; text-decoration: none; color: inherit; display: block; }
a.period:hover { background: var(--surface-hover); color: inherit; }
.period .k { font-size: var(--fs-tiny); letter-spacing: .08em; text-transform: uppercase; color: var(--primary-text); font-weight: 750; }
.period .line { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; margin-top: 4px; align-items: baseline; }
.period .line span { color: var(--text-muted); font-size: var(--fs-meta); }
.period .line b { font-size: 1.125rem; }
.period .profit b { font-size: 1.625rem; }
.coll-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.coll-card { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: inherit; box-shadow: var(--shadow); min-width: 0; }
.coll-card:hover { border-color: var(--border-strong); color: inherit; }
.coll-card .top { display: flex; gap: 14px; align-items: center; }
.coll-card h3 { margin: 0; font-size: var(--fs-h3); }
.coll-card .facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.coll-card .facts div { background: var(--surface-sunken); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.coll-card .facts span { display: block; font-size: var(--fs-tiny); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.coll-card .facts b { font-size: 1.125rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ring { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.ring span { width: 56px; height: 56px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 750; font-size: var(--fs-meta); color: var(--text-primary); }
.ring-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.ring-card { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.dash-cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; }
.ql-pipeline { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 14px; }
.ql-stage { padding: 14px 10px; text-align: center; border-right: 1px solid var(--border); text-decoration: none; color: inherit; min-height: 88px; display: flex; flex-direction: column; justify-content: center; }
.ql-stage:last-child { border-right: 0; } .ql-stage:hover { background: var(--surface-hover); color: inherit; }
.ql-stage b { display: block; font-size: 2rem; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ql-stage span { font-size: var(--fs-tiny); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.ql-stage.hot b { color: var(--warning); }
.ql-answers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 18px 0; } /* six answers: 3 × 2, no orphan row */
.ql-answer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 3px; border-top: 4px solid var(--primary); }
.ql-answer:hover { color: inherit; border-color: var(--border-strong); }
.ql-answer .q { font-size: var(--fs-tiny); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.ql-answer .a { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ql-answer .s { font-size: var(--fs-meta); color: var(--text-muted); }
.ql-answer.warn { border-top-color: var(--warning); } .ql-answer.bad { border-top-color: var(--danger); } .ql-answer.good { border-top-color: var(--success); }
.tile-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
.tile { border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: inherit; min-width: 0; }
.tile:hover { border-color: var(--border-strong); color: inherit; }
.tile img, .tile .noimg { width: 100%; aspect-ratio: 1/1; object-fit: cover; background: var(--surface-sunken); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 1.75rem; }
.tile div { padding: 8px 10px; font-size: var(--fs-meta); overflow-wrap: anywhere; } .tile b { display: block; font-size: var(--fs-tiny); color: var(--primary-text); }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding: 10px 4px 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: flex-end; }
.bars .bar i { width: 100%; max-width: 44px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, var(--primary), var(--chart-2)); display: block; min-height: 2px; }
.bars .bar small { font-size: var(--fs-tiny); color: var(--text-muted); white-space: nowrap; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chan-chip { display: inline-flex; align-items: center; gap: 8px; min-height: var(--touch); padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: var(--fs-meta); font-weight: 600; text-decoration: none; color: var(--text-secondary); }
.chan-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }

/* ================================================================ add inventory hub */
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin: 16px 0 8px; }
@media (min-width: 1025px) { .hub-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } } /* six methods: 3 × 2 beside the sidebar */
.hub-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-decoration: none; color: inherit; box-shadow: var(--shadow); min-height: 170px; text-align: left; font: inherit; cursor: pointer; justify-content: flex-start; font-weight: 400; }
.hub-card:hover { border-color: var(--primary); color: inherit; background: var(--surface-raised); }
.hub-card .letter { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); font-weight: 800; font-size: 1.25rem; border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent); }
.hub-card h3 { margin: 4px 0 0; }
.hub-card p { color: var(--text-secondary); margin: 0; }
.match-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 10px 0; }
.match { display: flex; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-sunken); text-align: left; min-height: 72px; font-weight: 500; justify-content: flex-start; }
.match.selected { border: 2px solid var(--primary); background: var(--primary-soft); }
.match .thumb { width: 52px; height: 52px; }
.match span { display: flex; flex-direction: column; min-width: 0; }
.match small { color: var(--text-muted); font-size: var(--fs-tiny); }
.steps { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 16px; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: var(--fs-meta); }
.steps li::before { content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-raised); border: 1px solid var(--border-strong); font-weight: 700; color: var(--text-primary); }

/* ================================================================ channels */
.cap { font-size: var(--fs-tiny); font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; display: inline-block; }
.cap.SUPPORTED { background: var(--success-bg); color: var(--success); }
.cap.SUPPORTED_AFTER_AUTH { background: var(--info-bg); color: var(--info); }
.cap.MANUAL_IMPORT, .cap.FILE_IMPORT { background: var(--neutral-bg); color: var(--text-secondary); }
.cap.PARTNER_ACCESS_REQUIRED { background: var(--warning-bg); color: var(--warning); }
.cap.NOT_SUPPORTED { background: transparent; color: var(--text-muted); border: 1px dashed var(--border-strong); }
.chan-group { margin: 28px 0 8px; }
.chan-group h2 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chan-group .group-note { color: var(--text-muted); margin: 0 0 12px; font-size: var(--fs-meta); }
.chan-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.chan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); min-width: 0; }
.chan-card.g-CONNECTED { border-left: 5px solid var(--success); }
.chan-card.g-READY_TO_CONFIGURE, .chan-card.g-WAITING_FOR_CREDENTIALS, .chan-card.g-PARTNER_ACCESS_REQUIRED { border-left: 5px solid var(--warning); }
.chan-card.has-error { border-left: 5px solid var(--danger); }
.chan-card h3 { margin: 0; font-size: var(--fs-h3); }
.chan-card .meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: var(--fs-meta); }
.chan-card .meta > div:nth-child(odd) { color: var(--text-muted); }
.chan-card .caps { display: flex; flex-wrap: wrap; gap: 4px; }
.chan-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chan-actions button, .chan-actions .btn { min-height: 40px; padding: 6px 14px; font-size: var(--fs-meta); }
.chan-row { display: grid; grid-template-columns: minmax(150px, 1.1fr) minmax(110px, .8fr) minmax(90px, .6fr) minmax(0, 1.4fr); gap: 10px 14px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.chan-row > .chan-actions { grid-column: 1 / -1; }
.chan-row:last-child { border-bottom: 0; }
.chan-row.head { background: var(--surface-sunken); font-size: var(--fs-tiny); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

/* ================================================================ listing workspace */
.ws-grid { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 20px; align-items: start; }
.field-legend { display: flex; gap: 10px 24px; flex-wrap: wrap; align-items: center; margin: 6px 0 14px; font-size: var(--fs-meta); color: var(--text-secondary); }
.field-legend > span { display: inline-flex; gap: 10px; align-items: center; }
.overridden { border-color: var(--warning) !important; box-shadow: 0 0 0 1px var(--warning) inset; }

/* ================================================================ P&L */
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.preset-row a { display: inline-flex; align-items: center; min-height: var(--touch); padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text-secondary); font-weight: 600; }
.preset-row a:hover { border-color: var(--border-strong); color: var(--text-primary); }
.preset-row a.active { background: var(--nav-active); color: var(--nav-active-text); border-color: var(--nav-active); }
.pnl-waterfall { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.pnl-waterfall > div { padding: 10px 4px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.pnl-waterfall > div:nth-child(even) { text-align: right; font-weight: 650; }
.pnl-waterfall .total { font-weight: 800; font-size: 1.375rem; border-bottom: 0; border-top: 2px solid var(--border-strong); }

/* ================================================================ web builder / editor */
.builder-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.page-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.editor-grid { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 20px; align-items: start; }
.sec { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 8px; cursor: pointer; flex-wrap: wrap; }
.sec.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); } .sec.is-hidden { opacity: .55; }
.sec .t { flex: 1 1 140px; font-weight: 600; font-size: var(--fs-meta); min-width: 0; }
.sec button { min-height: 40px; min-width: 40px; padding: 4px 10px; font-size: var(--fs-meta); }
.preview-frame-wrap { background: var(--preview-wrap); border-radius: var(--radius); padding: 14px; overflow: auto; border: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
.preview-frame-wrap iframe { display: block; margin: 0 auto; background: #fff; border: 0; border-radius: 10px; box-shadow: var(--shadow-lg); height: 780px; max-width: 100%; transition: width .2s; }
.device-toggle { display: flex; gap: 6px; flex-wrap: wrap; } .device-toggle button.active { background: var(--nav-active); color: var(--nav-active-text); border-color: var(--nav-active); }
.img-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; max-height: 260px; overflow: auto; }
.img-picker button { padding: 0; border-radius: 10px; overflow: hidden; min-height: 0; } .img-picker img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }
.item-list .item, .item { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 10px; margin: 8px 0; }

/* ================================================================ settings: theme picker */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.theme-option { display: flex; gap: 14px; align-items: center; padding: 14px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); text-align: left; min-height: 88px; justify-content: flex-start; font-weight: 600; }
.theme-option[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.theme-option small { display: block; font-weight: 400; color: var(--text-muted); }
.swatch { width: 64px; height: 48px; border-radius: 10px; display: grid; grid-template-columns: 1fr 2fr; overflow: hidden; border: 1px solid var(--border-strong); flex-shrink: 0; }
.swatch.dark i:first-child { background: #1B251E; } .swatch.dark i:last-child { background: #D3E8BC; box-shadow: inset 0 -12px 0 #91C79B; }
.swatch.light i:first-child { background: #E3EBDD; } .swatch.light i:last-child { background: #FFFDF7; box-shadow: inset 0 -12px 0 #1F3B2D; }

/* ================================================================ responsive: iPad landscape (1024–1366) */
@media (max-width: 1366px) {
  main { padding: 24px 26px 64px; }
}
@media (max-width: 1240px) {
  :root { --sidebar-w: 244px; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .period-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ql-cols, .dash-cols, .ws-grid, .editor-grid, .builder-grid { grid-template-columns: minmax(0, 1fr); }
}
/* ---- iPad portrait (768–1024) and below: off-canvas sidebar with backdrop */
@media (max-width: 1024px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow-lg); width: min(320px, 86vw); visibility: hidden; }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 55; }
  body.nav-open { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  main { padding: 20px 20px 64px; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; } /* "All time" spans the row instead of leaving a gap */
  .chan-cards { grid-template-columns: minmax(0, 1fr); }
  .vault-grid, .photo-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
/* ---- phones */
@media (max-width: 640px) {
  :root { --fs-h1: 2rem; --fs-metric: 1.75rem; }
  main { padding: 16px 14px 56px; }
  .topbar-add .lbl { display: none; }
  .card { padding: 14px; }
  .kpi-grid, .period-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .coll-grid, .hub-grid, .ql-answers { grid-template-columns: minmax(0, 1fr); }
  .vault-grid, .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ql-pipeline { grid-template-columns: repeat(5, minmax(64px, 1fr)); overflow-x: auto; }
  .page-row, .chan-row { grid-template-columns: minmax(0, 1fr); }
  .coll-card .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* data tables become stacked cards (each cell carries its column label) */
  .table-wrap.stackable table, .table-wrap.stackable tbody, .table-wrap.stackable tr, .table-wrap.stackable td { display: block; width: 100%; }
  .table-wrap.stackable thead { display: none; }
  .table-wrap.stackable tr { border-bottom: 1px solid var(--border-strong); padding: 6px 0; }
  .table-wrap.stackable td { border: 0; padding: 6px 14px; text-align: left; display: flex; gap: 12px; justify-content: space-between; align-items: baseline; white-space: normal; }
  .table-wrap.stackable td[data-label]:not([data-label=""])::before { content: attr(data-label); color: var(--text-muted); font-size: var(--fs-tiny); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; flex-shrink: 0; }
  .table-wrap.stackable td:empty { display: none; }
}

/* ================================================================ motion & preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .card.link:hover, a.kpi:hover, button:active, .btn:active { transform: none; }
}
@media (hover: none) {
  .card.link:hover { transform: none; }
}
