/* Socialmass component layer (Phase 1.1 design system). Tokens live in tokens.css (load it first); this file holds no
   raw colour. Component API and page recipes: docs/design/COMPONENTS.md. Living gallery: /app/design.
   Page-specific rules go in web/assets/<page>.css owned by the page's phase, never here.

   Sections: 1 base, 2 type, 3 icons, 4 app shell, 5 page layout, 6 buttons, 7 forms, 8 chips, segmented, stepper, tabs,
   9 badges, avatars, channel marks, 10 cards and lists, 11 tables, 12 KPI and figures, 13 states, skeleton, empty,
   14 overlays (menu, dialog, sheet, tooltip, toast, command palette), 15 banners, 16 legacy names, 17 responsive. */

/* ============ 1. base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg-canvas); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font-sans); font-size: var(--text-base); line-height: var(--leading-normal); font-weight: var(--weight-regular);
  color: var(--fg); background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
img, svg, canvas { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
a { color: var(--accent-fg); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
p { margin: 0; }
hr { border: 0; height: 1px; background: var(--border); margin: var(--space-5) 0; }
.skip-link { position: absolute; left: var(--space-2); top: -60px; z-index: var(--z-tooltip); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--ink); color: var(--on-ink); }
.skip-link:focus { top: var(--space-2); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ============ 2. type ============ */
h1, h2, h3, h4 { margin: 0; color: var(--fg); text-wrap: balance; }
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
h2 { font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); line-height: var(--leading-snug); }
h3 { font-size: var(--text-base); font-weight: var(--weight-semibold); line-height: var(--leading-snug); }
.text-xs { font-size: var(--text-xs); }
.text-sm, .meta, .dim { font-size: var(--text-sm); }
.text-muted, .meta, .dim { color: var(--fg-muted); }
.text-subtle { color: var(--fg-subtle); }
.text-strong { font-weight: var(--weight-semibold); color: var(--fg); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.mono, code, kbd, pre { font-family: var(--font-mono); font-size: var(--text-sm); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.na { color: var(--fg-subtle); }
.grow { flex: 1; min-width: 0; }
.kbd, kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--bg-surface); box-shadow: 0 1px 0 var(--border);
  font-family: var(--font-sans); font-size: var(--text-2xs); font-weight: var(--weight-medium); color: var(--fg-muted); line-height: 1;
}

/* ============ 3. icons: <svg class="icon"><use href="/app/assets/vendor/icons.svg#name"/></svg> ============ */
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-xs { width: 12px; height: 12px; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; stroke-width: 1.5; }

/* ============ 4. app shell: sidebar (#shell-rail), main, phone bars ============ */
body:has(> #shell-rail) {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
  height: 100vh; height: 100dvh; overflow: hidden;
}
html[data-sidebar="collapsed"] body:has(> #shell-rail) { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
body:has(> #shell-rail) > .demo-banner { grid-column: 1 / -1; grid-row: 1; }
body:has(> #shell-rail) > #shell-rail { grid-column: 1; grid-row: 2; }
body:has(> #shell-rail) > .app-main { grid-column: 2; grid-row: 2; }

.sidebar {
  display: flex; flex-direction: column; gap: var(--space-1); min-height: 0;
  padding: var(--space-3) var(--space-3) var(--space-3); overflow-y: auto; overflow-x: hidden;
  background: var(--bg-canvas); scrollbar-width: thin;
}
.sidebar-head { display: flex; align-items: center; gap: var(--space-1); margin-bottom: var(--space-2); }
.workspace-btn {
  display: flex; align-items: center; gap: var(--space-2); flex: 1; min-width: 0; height: 40px; padding: 0 var(--space-2);
  border: 0; border-radius: var(--radius-md); background: transparent; cursor: pointer; text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.workspace-btn:hover, .workspace-btn[aria-expanded="true"] { background: var(--bg-muted); }
.workspace-name { flex: 1; min-width: 0; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-btn .icon { color: var(--fg-subtle); }
.search-trigger {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; height: 34px; padding: 0 var(--space-2) 0 var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--bg-surface); color: var(--fg-subtle);
  cursor: pointer; text-align: left; box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.search-trigger:hover { border-color: var(--border-strong); color: var(--fg-muted); }
.search-trigger .search-text { flex: 1; }
.search-trigger .kbd { box-shadow: none; }
.sidebar .new-post { margin: var(--space-2) 0 var(--space-1); }
.nav-group { display: flex; flex-direction: column; gap: 1px; margin-top: var(--space-4); }
.nav-group:first-of-type { margin-top: var(--space-2); }
.nav-label { padding: 0 var(--space-3) var(--space-1); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg-subtle); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--space-3); height: 34px; padding: 0 var(--space-3);
  border-radius: var(--radius-sm); color: var(--fg-muted); font-weight: var(--weight-medium); text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-item:hover { background: var(--bg-muted); color: var(--fg); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--bg-surface); color: var(--fg); box-shadow: var(--shadow-sm); }
.nav-item .icon { color: var(--fg-subtle); transition: color var(--dur-fast) var(--ease-out); }
.nav-item:hover .icon, .nav-item[aria-current="page"] .icon { color: var(--fg); }
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill);
  background: var(--bg-muted); color: var(--fg-muted); font-size: var(--text-2xs); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums;
}
.nav-badge.is-strong { background: var(--ink); color: var(--on-ink); }
.nav-item[aria-current="page"] .nav-badge:not(.is-strong) { background: var(--bg-muted); }
.sidebar-spacer { flex: 1; min-height: var(--space-4); }
.sidebar-foot { display: flex; flex-direction: column; gap: 1px; }
.sidebar-foot .nav-group { margin-top: 0; }
.user-btn {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; height: 48px; margin-top: var(--space-2); padding: 0 var(--space-2);
  border: 0; border-radius: var(--radius-md); background: transparent; cursor: pointer; text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--bg-muted); }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mail { font-size: var(--text-xs); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn > .icon { color: var(--fg-subtle); }

/* collapsed: icons only, labels as tooltips */
html[data-sidebar="collapsed"] .sidebar { padding-left: var(--space-2); padding-right: var(--space-2); align-items: center; }
html[data-sidebar="collapsed"] .sidebar :is(.workspace-name, .workspace-btn > .icon, .search-text, .search-trigger .kbd, .nav-text, .nav-label, .user-meta, .user-btn > .icon, .new-post-text) { display: none; }
html[data-sidebar="collapsed"] .sidebar-head { flex-direction: column; }
html[data-sidebar="collapsed"] :is(.workspace-btn, .user-btn) { flex: none; width: 40px; justify-content: center; padding: 0; }
html[data-sidebar="collapsed"] .search-trigger { width: 40px; height: 36px; padding: 0; justify-content: center; }
html[data-sidebar="collapsed"] .sidebar .new-post { width: 40px; padding: 0; }
html[data-sidebar="collapsed"] .nav-group { width: 100%; align-items: center; }
html[data-sidebar="collapsed"] .nav-item { width: 40px; justify-content: center; padding: 0; }
html[data-sidebar="collapsed"] .nav-badge { position: absolute; top: 1px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; }
html[data-sidebar="collapsed"] .nav-group + .nav-group { margin-top: var(--space-3); padding-top: var(--space-3); box-shadow: inset 0 1px 0 var(--border); }

/* phone bars, hidden on desktop */
.mobile-bar, .tabbar { display: none; }

.app-main { min-width: 0; overflow-y: auto; overflow-x: hidden; padding: var(--space-6) var(--space-7) var(--space-9); outline: none; }

/* ============ 5. page layout ============ */
.page { max-width: var(--page-max); margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-5); }
.page-narrow { max-width: 880px; }
.page-header, .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4) var(--space-5); flex-wrap: wrap; }
.page-header > div:first-child, .page-head > div:first-child { min-width: 0; }
.page-title, .page-head h1 { margin: 0; font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.page-sub, .page-head p { margin: var(--space-1) 0 0; color: var(--fg-muted); font-size: var(--text-base); max-width: 68ch; }
.page-actions, .actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.filter-bar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.filter-bar .spacer, .toolbar-spacer { flex: 1; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-title { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.cluster { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.split { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--space-6); align-items: start; }

/* ============ 6. buttons ============ */
.btn {
  --btn-h: var(--control-md); --btn-bg: var(--bg-muted); --btn-bg-hover: var(--bg-pressed); --btn-fg: var(--fg);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--btn-h); min-height: var(--btn-h); padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-pill); background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--text-base); font-weight: var(--weight-medium); line-height: 1; letter-spacing: -0.005em; white-space: nowrap;
  text-decoration: none; cursor: pointer; user-select: none; touch-action: manipulation;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--btn-bg-hover); text-decoration: none; color: var(--btn-fg); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn .icon { margin: 0 -2px; }
.btn-primary { --btn-bg: var(--ink); --btn-bg-hover: var(--ink-hover); --btn-fg: var(--on-ink); }
.btn-secondary { --btn-bg: var(--bg-muted); --btn-bg-hover: var(--bg-pressed); }
.btn-outline { --btn-bg: var(--bg-surface); --btn-bg-hover: var(--bg-muted); border-color: var(--border); box-shadow: var(--shadow-xs); }
.btn-ghost { --btn-bg: transparent; --btn-bg-hover: var(--bg-muted); --btn-fg: var(--fg-muted); }
.btn-ghost:hover { --btn-fg: var(--fg); }
.btn-danger { --btn-bg: var(--danger); --btn-bg-hover: var(--danger-hover); --btn-fg: var(--on-ink); }
.btn-danger-ghost { --btn-bg: transparent; --btn-bg-hover: var(--danger-subtle); --btn-fg: var(--danger); }
.btn-sm, .btn-small { --btn-h: var(--control-sm); padding: 0 var(--space-3); font-size: var(--text-sm); gap: 6px; }
.btn-lg { --btn-h: var(--control-lg); padding: 0 var(--space-5); font-size: 0.9375rem; }
.btn-block { width: 100%; }
.btn-icon { width: var(--btn-h); padding: 0; }
.btn-icon .icon { margin: 0; }
/* loading: withBusy() sets disabled + aria-busy; a spinner replaces the label unless the button carries its own .spin */
.btn[aria-busy="true"] { opacity: 1; cursor: progress; }
.btn[aria-busy="true"]:not(:has(.spin)) { color: transparent; }
.btn[aria-busy="true"]:not(:has(.spin))::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin 700ms linear infinite;
}
.btn[aria-busy="true"]:not(:has(.spin)) .icon { visibility: hidden; }
/* split button: main action + menu chevron */
.split-btn { display: inline-flex; }
.split-btn > .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; padding-right: var(--space-3); }
.split-btn > .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; width: auto; padding: 0 var(--space-3) 0 10px; margin-left: 1px; }
.split-btn > .btn:active:not(:disabled) { transform: none; }

.spin { display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 7. forms ============ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field > label, .label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg); }
.btn .label { font-size: inherit; font-weight: inherit; color: inherit; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.label-row a, .label-row .link { font-size: var(--text-sm); }
.req { color: var(--fg-subtle); font-weight: var(--weight-regular); }
.hint { margin: 0; font-size: var(--text-sm); color: var(--fg-muted); }
.err { display: flex; align-items: flex-start; gap: 6px; margin: 0; font-size: var(--text-sm); color: var(--danger); }
.err:empty { display: none; }
.input, .select, .textarea,
.field input:where(:not([type="checkbox"], [type="radio"], [type="range"])), .field select, .field textarea {
  width: 100%; height: var(--control-md); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--fg);
  font-size: var(--text-base); line-height: 1.2; outline: none; box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
:is(.input, .select, .textarea, .field input, .field select, .field textarea):hover { border-color: var(--fg-disabled); }
:is(.input, .select, .textarea, .field input, .field select, .field textarea):focus-visible,
:is(.input, .select, .textarea, .field input, .field select, .field textarea):focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}
:is(.input, .select, .textarea, .field input, .field select, .field textarea)[aria-invalid="true"] { border-color: var(--danger); }
:is(.input, .select, .textarea, .field input, .field select, .field textarea)[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-subtle); }
:is(.input, .select, .textarea, .field input, .field select, .field textarea):disabled { background: var(--bg-muted); color: var(--fg-disabled); border-color: var(--border); box-shadow: none; cursor: not-allowed; }
:is(.input, .field input)[readonly] { background: var(--bg-canvas); color: var(--fg-muted); box-shadow: none; }
:is(.input, .textarea, .field input, .field textarea)::placeholder { color: var(--fg-subtle); }
.select, .field select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-subtle) 50%), linear-gradient(135deg, var(--fg-subtle) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px); background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
}
.textarea, .field textarea { height: auto; min-height: 96px; padding: 10px var(--space-3); line-height: var(--leading-normal); resize: vertical; }
.input-sm { height: var(--control-sm); font-size: var(--text-sm); }
/* input with a leading icon or trailing control */
.input-group { position: relative; display: flex; align-items: center; min-width: 0; }
.input-group > .icon { position: absolute; left: 12px; color: var(--fg-subtle); pointer-events: none; }
.input-group > .icon ~ .input { padding-left: 36px; }
.input-group > .input-addon { position: absolute; right: 4px; }
.input-group .input:has(~ .input-addon) { padding-right: 76px; }
.search { position: relative; display: flex; align-items: center; width: 280px; max-width: 100%; }
.search > .input { width: 100%; }
.search > .icon { position: absolute; left: 12px; color: var(--fg-subtle); pointer-events: none; }
.search > .input, .search > input { height: 32px; padding-left: 34px; border-radius: var(--radius-pill); }
/* checkbox (native input, restyled) */
input[type="checkbox"]:not(.switch), .checkbox {
  appearance: none; flex: none; display: inline-grid; place-content: center; width: 16px; height: 16px; margin: 0;
  border: 1px solid var(--fg-disabled); border-radius: 5px; background: var(--bg-surface); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
input[type="checkbox"]:not(.switch)::before {
  content: ""; width: 8px; height: 4px; margin-top: -2px; border: solid var(--on-ink); border-width: 0 0 2px 2px;
  transform: rotate(-45deg) scale(0); transition: transform var(--dur-fast) var(--ease-out);
}
input[type="checkbox"]:not(.switch):hover { border-color: var(--fg-muted); }
input[type="checkbox"]:not(.switch):checked, input[type="checkbox"]:not(.switch):indeterminate { background: var(--ink); border-color: var(--ink); }
input[type="checkbox"]:not(.switch):checked::before { transform: rotate(-45deg) scale(1); }
input[type="checkbox"]:not(.switch):indeterminate::before { width: 8px; height: 0; margin: 0; border-width: 0 0 2px 0; transform: none; }
input[type="checkbox"]:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="checkbox"][aria-invalid="true"] { border-color: var(--danger); }
.check-row, .field label:has(input[type="checkbox"]) { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 32px; font-size: var(--text-base); font-weight: var(--weight-regular); cursor: pointer; }
/* switch: <input type="checkbox" class="switch" role="switch"> */
input.switch {
  appearance: none; flex: none; position: relative; width: 34px; height: 20px; margin: 0; border-radius: var(--radius-pill);
  background: var(--border-strong); cursor: pointer; transition: background-color var(--dur) var(--ease-out);
}
input.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--bg-surface); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease-out);
}
input.switch:hover { background: var(--fg-disabled); }
input.switch:checked { background: var(--accent); }
input.switch:checked::before { transform: translateX(14px); }
input.switch:disabled { opacity: 0.45; cursor: not-allowed; }
.switch-row { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg); cursor: pointer; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ============ 8. chips, segmented control, period stepper, tabs ============ */
.chips { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--bg-surface); color: var(--fg);
  font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; text-decoration: none; line-height: 1;
}
button.chip, a.chip { cursor: pointer; transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
button.chip:hover, a.chip:hover { background: var(--bg-muted); text-decoration: none; }
button.chip:disabled { opacity: 0.45; cursor: not-allowed; }
.chip[aria-pressed="true"], .chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.chip[aria-pressed="true"]:hover, .chip.is-active:hover { background: var(--ink-hover); }
.chip .icon { width: 14px; height: 14px; color: currentColor; }
.chip .chip-label { color: var(--fg-muted); font-weight: var(--weight-regular); }
.chip .chip-value { color: var(--fg); }
.chip .chip-value:empty { display: none; }
.chip-add { border-style: dashed; color: var(--fg-muted); }
.chip.has-value { background: var(--accent-subtle); border-color: var(--accent-soft); }
.chip.has-value .chip-value { color: var(--accent-fg); }
.chip.has-value:hover { background: var(--accent-soft); }
.chip-clear { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: -6px; border: 0; border-radius: 50%; background: transparent; color: var(--fg-subtle); cursor: pointer; }
.chip-clear:hover { background: var(--bg-muted); color: var(--fg); }

.segmented { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: var(--radius-pill); background: var(--bg-muted); }
.segmented > button, .segmented > a {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--fg-muted);
  font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.segmented > :hover { color: var(--fg); text-decoration: none; }
.segmented > [aria-pressed="true"], .segmented > [aria-checked="true"], .segmented > [aria-selected="true"], .segmented > [aria-current="page"] { background: var(--bg-surface); color: var(--fg); box-shadow: var(--shadow-sm); }
.segmented > :disabled { opacity: 0.45; cursor: not-allowed; }
.segmented-sm > button { height: 24px; padding: 0 10px; font-size: var(--text-xs); }

.stepper { display: inline-flex; align-items: center; height: 34px; padding: 0 2px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--bg-surface); box-shadow: var(--shadow-xs); }
.stepper > button { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--fg-muted); cursor: pointer; transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.stepper > button:hover:not(:disabled) { background: var(--bg-muted); color: var(--fg); }
.stepper > button:disabled { opacity: 0.35; cursor: not-allowed; }
.stepper-label { min-width: 132px; padding: 0 var(--space-2); text-align: center; font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; font-variant-numeric: tabular-nums; }

.tabs { display: flex; align-items: stretch; gap: var(--space-5); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0; flex: none;
  border: 0; background: none; color: var(--fg-muted); font-size: var(--text-base); font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab:hover { color: var(--fg); text-decoration: none; }
.tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ink); transform: scaleX(0); transition: transform var(--dur) var(--ease-out); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--fg); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { transform: scaleX(1); }
.tab:focus-visible { outline-offset: -2px; border-radius: var(--radius-xs); }
.tab .tab-count { min-width: 18px; height: 18px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--bg-muted); color: var(--fg-muted); font-size: var(--text-2xs); font-weight: var(--weight-semibold); display: inline-grid; place-items: center; }
.tabs-sm { gap: var(--space-4); }
.tabs-sm .tab { height: 36px; font-size: var(--text-sm); }

/* ============ 9. badges, avatars, channel marks ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-pill); background: var(--bg-muted); color: var(--fg-muted);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap; vertical-align: middle;
}
.badge .icon { width: 12px; height: 12px; stroke-width: 2; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-success { background: var(--success-subtle); color: var(--success); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); }
.badge-danger { background: var(--danger-subtle); color: var(--danger); }
.badge-accent, .badge-info { background: var(--accent-subtle); color: var(--accent-fg); }
.badge-ink { background: var(--ink); color: var(--on-ink); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }

.avatar {
  --size: 32px; position: relative; display: inline-grid; place-items: center; flex: none; width: var(--size); height: var(--size);
  border-radius: 50%; background: var(--bg-muted); color: var(--fg-muted);
  font-size: calc(var(--size) * 0.4); font-weight: var(--weight-semibold); line-height: 1; letter-spacing: 0; user-select: none;
}
.avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.avatar-xs { --size: 20px; } .avatar-sm { --size: 24px; } .avatar-md { --size: 32px; } .avatar-lg { --size: 40px; } .avatar-xl { --size: 56px; }
.avatar-square { border-radius: 7px; }
.avatar-lg.avatar-square, .avatar-xl.avatar-square { border-radius: var(--radius-md); }
.avatar-ink { background: var(--ink); color: var(--on-ink); }
.avatar-outline { background: var(--bg-surface); box-shadow: inset 0 0 0 1px var(--border); }
.avatar > .channel-mark { position: absolute; right: -3px; bottom: -3px; width: 45%; height: 45%; min-width: 14px; min-height: 14px; box-shadow: 0 0 0 2px var(--bg-surface); }
.avatar-stack { display: inline-flex; }
.avatar-stack > .avatar { box-shadow: 0 0 0 2px var(--bg-surface); }
.avatar-stack > .avatar + .avatar { margin-left: -8px; }

.channel-mark { display: inline-grid; place-items: center; flex: none; width: 16px; height: 16px; border-radius: 50%; overflow: hidden; }
.channel-mark svg { width: 100%; height: 100%; }
.channel-mark.ig { background: radial-gradient(circle at 30% 107%, var(--brand-ig-1) 0%, var(--brand-ig-1) 8%, var(--brand-ig-2) 45%, var(--brand-ig-3) 62%, var(--brand-ig-4) 95%); color: var(--on-ink); }
.channel-mark.ig svg { width: 62%; height: 62%; }
.channel-mark.fb { background: var(--on-ink); color: var(--brand-facebook); }
.channel-mark.th { background: var(--ink); color: var(--on-ink); }
.channel-mark.th svg { width: 66%; height: 66%; }

/* ============ 10. cards and grouped lists ============ */
.card, .panel { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-width: 0; }
.panel { padding: var(--space-5); }
.panel + .panel { margin-top: var(--space-4); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5) 0; min-height: 52px; }
.card-header:has(+ .tabs) { padding-bottom: 0; }
.card-title { margin: 0; font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: -0.006em; }
.card-sub { margin: 2px 0 0; font-size: var(--text-sm); color: var(--fg-muted); }
.card-body { padding: var(--space-5); }
.card-header + .card-body { padding-top: var(--space-4); }
.card > .tabs { margin: 0 var(--space-5); }
.card-footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); }
.card-footer .hint { margin-right: auto; }

.list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; }
.list-row {
  position: relative; isolation: isolate; display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--row-h); padding: var(--space-2) 10px; border-radius: 12px; color: inherit; text-decoration: none;
}
a.list-row, button.list-row, .list-row.is-interactive { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; transition: background-color var(--dur-fast) var(--ease-out); }
a.list-row:hover, button.list-row:hover, .list-row.is-interactive:hover { background: var(--bg-canvas); text-decoration: none; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.list-title { font-weight: var(--weight-medium); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-meta { font-size: var(--text-sm); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-value { flex: none; text-align: right; font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-value .list-meta { font-weight: var(--weight-regular); }
.list-rank { flex: none; width: 20px; text-align: right; color: var(--fg-subtle); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.list-thumb { flex: none; width: 36px; height: 36px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg-muted); }
/* proportional bar behind a row (Plausible style). JS sets --bar to "0%".."100%" with el.style.setProperty. */
.bar-row::before { content: ""; position: absolute; z-index: -1; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) * var(--bar-scale, 0)); border-radius: var(--radius-sm); background: var(--bg-muted); }
.bar-row.is-top::before { background: var(--accent-subtle); }
.list-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--fg-muted); font-size: var(--text-sm); }

/* ============ 11. data table ============ */
.table-card { overflow: hidden; }
.table-toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.table-wrap { overflow-x: auto; min-width: 0; }
table.table, table.rows { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
:is(table.table, table.rows) th {
  height: 40px; padding: 0 var(--space-3); text-align: left; vertical-align: middle; white-space: nowrap;
  font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg-muted); border-bottom: 1px solid var(--border); background: var(--bg-surface);
}
:is(table.table, table.rows) td { height: 56px; padding: var(--space-2) var(--space-3); vertical-align: middle; border-bottom: 1px solid var(--border); }
:is(table.table, table.rows) :is(th, td):first-child { padding-left: var(--space-5); }
:is(table.table, table.rows) :is(th, td):last-child { padding-right: var(--space-5); }
:is(table.table, table.rows) tbody tr:last-child td { border-bottom: 0; }
:is(table.table, table.rows) tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
:is(table.table, table.rows) tbody tr:hover { background: var(--bg-canvas); }
:is(table.table, table.rows) tbody tr[aria-selected="true"] { background: var(--bg-selected); }
:is(table.table, table.rows) :is(td, th).num { text-align: right; }
:is(table.table, table.rows) td.num { font-weight: var(--weight-medium); }
:is(table.table, table.rows) :is(td, th).shrink { width: 1%; white-space: nowrap; }
:is(table.table, table.rows) tr.group td { height: 36px; background: var(--bg-canvas); font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--fg-muted); }
.table-sticky thead th { position: sticky; top: 0; z-index: 1; }
.th-sort { display: inline-flex; align-items: center; gap: 4px; height: 28px; margin: 0 -6px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.th-sort:hover { background: var(--bg-muted); color: var(--fg); }
.th-sort .icon { width: 12px; height: 12px; color: var(--fg-subtle); }
th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--fg); }
th[aria-sort] .th-sort .icon { color: var(--fg); }
.num .th-sort { flex-direction: row-reverse; }
.cell-primary { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.cell-text { display: flex; flex-direction: column; min-width: 0; }
.cell-title { font-weight: var(--weight-medium); color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-meta { font-size: var(--text-sm); color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-menu { color: var(--fg-subtle); }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) var(--space-3) var(--space-2) var(--space-5); border-top: 1px solid var(--border); font-size: var(--text-sm); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.pagination { display: flex; align-items: center; gap: var(--space-2); }
.pagination .select { width: auto; height: var(--control-sm); font-size: var(--text-sm); }
.thumb { display: block; flex: none; width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg-muted); }

/* ============ 12. KPI tiles and figures ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px; padding: 6px; }
.kpi {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0;
  padding: 14px var(--space-4) var(--space-4); border: 0; border-radius: 12px; background: transparent; color: inherit; text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out);
}
button.kpi { cursor: pointer; }
button.kpi:hover { background: var(--bg-canvas); }
.kpi[aria-selected="true"], .kpi[aria-pressed="true"] { background: var(--bg-muted); }
.kpi:focus-visible { outline-offset: -2px; }
.kpis .kpi { container-type: inline-size; }
.kpis .kpi-value { font-size: min(var(--text-3xl), 15.5cqi); }
.kpi-label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg-muted); white-space: nowrap; }
.kpi[aria-selected="true"] .kpi-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--chart-line); }
.kpi-value, .figure { font-size: var(--text-3xl); font-weight: var(--weight-bold); letter-spacing: -0.035em; line-height: 1.05; color: var(--fg); font-variant-numeric: tabular-nums; white-space: nowrap; }
.figure-sm { font-size: var(--text-xl); letter-spacing: -0.025em; }
.figure-lg { font-size: var(--text-4xl); }
.figure-minor { font-size: 0.62em; font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.figure-unit { margin-left: 0.18em; font-size: 0.5em; font-weight: var(--weight-semibold); color: var(--fg-muted); letter-spacing: 0; }
.figure.is-na, .kpi-value.is-na { color: var(--fg-subtle); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta .icon { width: 14px; height: 14px; stroke-width: 2; }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--fg-muted); }
.delta-note { margin-left: 4px; color: var(--fg-subtle); font-weight: var(--weight-regular); }

/* chart area */
.chart-card .chart-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) var(--space-5) 0; }
.chart-box { position: relative; height: 300px; }
.chart-card .chart-box { margin: var(--space-2) var(--space-4) var(--space-4) var(--space-3); }
.legend { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; font-size: var(--text-xs); color: var(--fg-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 0; border-top: 2px solid var(--chart-line); }
.legend-swatch.is-compare { border-top-color: var(--chart-compare); }
.legend-swatch.is-provisional { border-top-style: dashed; }
.legend-note { font-size: var(--text-xs); color: var(--fg-muted); }

/* ============ 13. states (states.js), skeleton, empty ============ */
.state, .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: var(--space-8) var(--space-4); text-align: center; color: var(--fg-muted); }
.state > .icon, .state > svg, .empty > .icon { width: 22px; height: 22px; margin-bottom: var(--space-1); color: var(--fg-subtle); }
.state .state-title, .empty-title { margin: 0; font-size: 0.9375rem; font-weight: var(--weight-semibold); color: var(--fg); }
.state .state-body, .empty-body { margin: 0; max-width: 46ch; font-size: var(--text-sm); }
.state .btn, .empty-actions { margin-top: var(--space-3); }
.empty-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center; }
.state-error > .icon, .state-error > svg { color: var(--danger); }
.state-offline > .icon, .state-offline > svg { color: var(--warning); }
.state-loading { align-items: stretch; padding: var(--space-4) 0; }
.state-loading .state-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.empty-art {
  display: flex; flex-direction: column; gap: 8px; width: 184px; margin-bottom: var(--space-3); padding: 12px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-surface); box-shadow: var(--shadow-sm);
}
.empty-art-row { display: flex; align-items: center; gap: 8px; }
.empty-art-dot { width: 18px; height: 18px; flex: none; border-radius: 50%; background: var(--bg-muted); }
.empty-art-line { height: 7px; flex: 1; border-radius: 4px; background: var(--bg-muted); }
.empty-art-row:nth-child(2) .empty-art-line { flex: 0.7; }
.empty-art-row:nth-child(3) .empty-art-line { flex: 0.45; }
.empty-art-row:first-child .empty-art-dot { background: var(--accent-soft); }
.skeleton { display: block; position: relative; overflow: hidden; height: 12px; border-radius: 6px; background: var(--bg-muted); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in oklch, var(--bg-surface) 65%, transparent), transparent); animation: shimmer 1.6s var(--ease-out) infinite; }
.skeleton-text { height: 12px; }
.skeleton-title { height: 20px; width: 40%; }
.skeleton-figure { height: 32px; width: 60%; }
.skeleton-circle { border-radius: 50%; width: 32px; height: 32px; flex: none; }
.skeleton-block { height: 220px; border-radius: 12px; }
.skeleton-rows { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-2) var(--space-5); }
.skeleton-row { display: flex; align-items: center; gap: var(--space-3); }
.skeleton-row .skeleton-text:nth-child(2) { flex: 1; }
.skeleton-row .skeleton-text:nth-child(3) { width: 72px; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ============ 14. overlays ============ */
/* dropdown menu (shell.js openMenu / showPop) */
.menu, .pop {
  position: fixed; z-index: var(--z-dropdown); min-width: 220px; max-width: min(320px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto;
  padding: 6px; border-radius: 14px; background: var(--bg-surface); box-shadow: var(--shadow-md);
  animation: pop-in var(--dur-fast) var(--ease-out);
}
.menu-item, .pop-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 6px 10px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--fg); font-size: var(--text-base); text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible, .pop-item:hover, .pop-item:focus-visible { background: var(--bg-muted); outline: none; text-decoration: none; color: var(--fg); }
.menu-item .icon, .pop-item .icon, .pop-item svg { color: var(--fg-muted); }
.menu-item > .grow, .pop-item > .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item .menu-check, .pop-item .menu-check { margin-left: auto; color: var(--fg); }
.menu-item[aria-checked="true"], .pop-item[aria-current] { font-weight: var(--weight-medium); }
.menu-item.is-danger, .menu-item.is-danger .icon { color: var(--danger); }
.menu-item:disabled { opacity: 0.45; cursor: not-allowed; }
.menu-item kbd { margin-left: auto; }
.menu-label, .pop-title { padding: 8px 10px 4px; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg-subtle); }
.menu-sep, .pop-sep { height: 1px; margin: 6px -6px; background: var(--border); }
.menu-who, .pop-who { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; }
.menu-who strong, .pop-who strong { display: block; font-weight: var(--weight-semibold); }
.menu-who .dim, .pop-who .dim { font-size: var(--text-xs); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }

/* dialog and phone bottom sheet (native <dialog>, showModal) */
dialog {
  width: min(480px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 48px); padding: 0; margin: auto;
  border: 0; border-radius: var(--radius-xl); background: var(--bg-surface); color: var(--fg); box-shadow: var(--shadow-lg); overflow: auto;
}
dialog[open] { animation: dialog-in var(--dur) var(--ease-out); }
dialog::backdrop { background: var(--scrim); animation: fade-in var(--dur) var(--ease-out); }
dialog > form, .dialog-body { padding: var(--space-5); }
dialog h2 { margin: 0 0 6px; padding-right: var(--space-6); font-size: var(--text-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
dialog h2 + .meta, dialog h2 + p { margin-bottom: var(--space-5); color: var(--fg-muted); font-size: var(--text-base); }
dialog p { margin: 0 0 var(--space-3); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.dialog-close { position: absolute; top: 14px; right: 14px; }
dialog.dialog-lg { width: min(640px, calc(100vw - 32px)); }
.sheet-handle { display: none; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(100%); } }

/* tooltip (shell.js: any element with data-tooltip) */
.tooltip {
  position: fixed; z-index: var(--z-tooltip); max-width: 260px; padding: 5px 8px; border-radius: var(--radius-sm);
  background: var(--ink); color: var(--on-ink); font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.35;
  pointer-events: none; opacity: 0; transform: translateY(2px); box-shadow: var(--shadow-sm);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.tooltip.is-visible { opacity: 1; transform: none; }
.tooltip .kbd { margin-left: 6px; background: transparent; border-color: color-mix(in oklch, var(--on-ink) 25%, transparent); box-shadow: none; color: var(--on-ink); }

/* toasts */
.toasts { position: fixed; z-index: var(--z-toast); right: var(--space-5); bottom: var(--space-5); display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-2); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-height: 44px; max-width: 400px; padding: 10px var(--space-4) 10px 14px;
  border-radius: 14px; background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-md); font-size: var(--text-base); font-weight: var(--weight-medium);
  animation: toast-in var(--dur) var(--ease-out);
}
.toast > .icon { color: var(--success-on-ink); }
.toast.bad > .icon { color: var(--danger-on-ink); }
.toast-action { margin-left: var(--space-2); padding: 0; border: 0; background: none; color: var(--on-ink); font-weight: var(--weight-semibold); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--dur-fast) var(--ease-in), transform var(--dur-fast) var(--ease-in); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* command palette */
dialog.cmdk { width: min(580px, calc(100vw - 32px)); margin-top: 14vh; overflow: hidden; }
.cmdk-input-row { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 var(--space-4); border-bottom: 1px solid var(--border); color: var(--fg-subtle); }
.cmdk-input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; font-size: var(--text-md); color: var(--fg); }
.cmdk-input::placeholder { color: var(--fg-subtle); }
.cmdk-list { max-height: min(380px, 50dvh); overflow: auto; padding: 6px; }
.cmdk-item[aria-selected="true"] { background: var(--bg-muted); }
.cmdk-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--fg-muted); font-size: var(--text-sm); }
.cmdk-foot { display: flex; align-items: center; gap: var(--space-4); padding: 10px var(--space-4); border-top: 1px solid var(--border); font-size: var(--text-xs); color: var(--fg-muted); }
.cmdk-foot span { display: inline-flex; align-items: center; gap: 6px; }

/* ============ 15. banners ============ */
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-surface); color: var(--fg); font-size: var(--text-base); }
.banner > .icon, .banner > svg { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--fg-muted); }
.banner p { margin: 0; }
.banner-body { flex: 1; min-width: 0; }
.banner-title { font-weight: var(--weight-semibold); }
.banner-actions { display: flex; gap: var(--space-2); margin-left: auto; align-self: center; }
.banner-info { background: var(--accent-subtle); border-color: var(--accent-soft); }
.banner-info > .icon { color: var(--accent-fg); }
.banner-warning { background: var(--notice-bg); border-color: var(--notice-border); color: var(--notice-fg); }
.banner-warning > .icon { color: var(--warning); }
.banner-danger { background: var(--danger-subtle); border-color: color-mix(in oklch, var(--danger) 22%, var(--bg-surface)); }
.banner-danger > .icon, .banner-danger > svg { color: var(--danger); }
.banner-success { background: var(--success-subtle); border-color: color-mix(in oklch, var(--success) 22%, var(--bg-surface)); }
.banner-success > .icon { color: var(--success); }

/* demo banner: first child of <body>, in flow (never fixed or sticky), no close control. Calm amber strip, always visible. */
.demo-banner {
  position: relative; z-index: var(--z-sticky); display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 40px; padding: var(--space-2) var(--space-4);
  background: var(--notice-bg); color: var(--notice-fg); border-bottom: 1px solid var(--notice-border);
  font-size: var(--text-sm); line-height: 1.35;
}
.demo-banner > .icon { flex: none; width: 16px; height: 16px; color: var(--warning); }
.demo-banner p { margin: 0; }
.demo-banner strong { font-weight: var(--weight-semibold); }

/* ============ 16. legacy names (pre-1.1 markup still used by phase branches) ============ */
.toolbar { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar .field { margin: 0; min-width: 160px; }
.chip-ok { color: var(--success); }
.chip-warn { color: var(--warning); }
.chip-bad { color: var(--danger); }
span.chip:is(.chip-ok, .chip-warn, .chip-bad) { height: 22px; padding: 0 var(--space-2); border: 0; font-size: var(--text-xs); }
span.chip.chip-ok { background: var(--success-subtle); }
span.chip.chip-warn { background: var(--warning-subtle); }
span.chip.chip-bad { background: var(--danger-subtle); }
.ribbon { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius-pill); background: var(--accent-subtle); color: var(--accent-fg); font-size: var(--text-xs); font-weight: var(--weight-semibold); }
.wide { max-width: 880px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 4px; padding: 6px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 14px var(--space-4) var(--space-4); border-radius: 12px; }
.stat .stat-label { margin: 0; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--fg-muted); }
.stat .stat-value { margin: 0; font-size: var(--text-xl); font-weight: var(--weight-bold); letter-spacing: -0.025em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .stat-hint { margin: 0; font-size: var(--text-xs); color: var(--fg-subtle); }
.save-bar { position: sticky; bottom: var(--space-3); z-index: var(--z-sticky); display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-surface); box-shadow: var(--shadow-md); }
.secret { display: flex; align-items: center; gap: var(--space-2); padding: 6px 6px 6px var(--space-3); border-radius: var(--radius-md); background: var(--bg-canvas); border: 1px solid var(--border); }
.secret code { flex: 1; min-width: 0; word-break: break-all; font-size: var(--text-sm); }
.feed { list-style: none; padding: 0; margin: 0; }
.dialog-actions .btn, .form-actions .btn { min-width: 88px; }

/* ============ 17. responsive ============ */
@media (max-width: 1100px) {
  .app-main { padding: var(--space-5) var(--space-5) var(--space-8); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
}
@media (max-width: 767px) {
  /* Phones: no sidebar. A top bar (workspace, search, New post) and a bottom tab bar with four tabs plus More. */
  body:has(> #shell-rail) { display: block; height: auto; overflow: visible; }
  body:has(> #shell-rail) > #shell-rail { display: none; }
  .mobile-bar {
    position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--space-1);
    height: 56px; padding: 0 var(--space-2) 0 var(--space-3); background: var(--bg-canvas); border-bottom: 1px solid transparent;
    transition: border-color var(--dur) var(--ease-out);
  }
  .mobile-bar.is-scrolled { border-bottom-color: var(--border); }
  .mobile-bar .workspace-btn { flex: 1; height: 44px; padding: 0 var(--space-1); }
  .mobile-bar .btn-icon { --btn-h: 40px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky); display: flex; align-items: stretch;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); padding: 0 var(--space-1) env(safe-area-inset-bottom, 0px);
    background: var(--bg-surface); border-top: 1px solid var(--border);
  }
  .tab-item {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: transparent; color: var(--fg-subtle); font-size: var(--text-2xs); font-weight: var(--weight-medium); text-decoration: none; cursor: pointer;
  }
  .tab-item .icon { width: 22px; height: 22px; stroke-width: 1.6; }
  .tab-item:hover { text-decoration: none; color: var(--fg-muted); }
  .tab-item[aria-current="page"], .tab-item[aria-expanded="true"] { color: var(--fg); }
  .tab-item[aria-current="page"] .icon { stroke-width: 2.1; }
  .tab-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab-item:focus-visible { outline-offset: -4px; border-radius: var(--radius-md); }
  .app-main { overflow: visible; padding: var(--space-2) var(--space-4) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-6)); }
  .page { gap: var(--space-4); }
  .page-title, .page-head h1 { font-size: var(--text-xl); }
  .page-header .page-actions .btn-label-optional { display: none; }
  .demo-banner { justify-content: flex-start; padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
  .card-header { padding: var(--space-4) var(--space-4) 0; }
  .card-body { padding: var(--space-4); }
  .card > .tabs { margin: 0 var(--space-4); }
  :is(table.table, table.rows) :is(th, td):first-child { padding-left: var(--space-4); }
  :is(table.table, table.rows) :is(th, td):last-child { padding-right: var(--space-4); }
  .table-toolbar { padding: var(--space-3); }
  .table-toolbar .search { flex: 1 1 100%; width: auto; }
  .search { min-width: 0; flex: 1; }
  /* tables scroll sideways instead of wrapping; .hide-sm drops low-priority columns */
  :is(table.table, table.rows) :is(th, td) { white-space: nowrap; }
  :is(table.table, table.rows) .cell-title, :is(table.table, table.rows) .cell-meta { max-width: 62vw; }
  .hide-sm { display: none; }
  :is(table.table, table.rows) .select { height: var(--control-md); font-size: var(--text-base); }
  .kpis .kpi-value { font-size: min(var(--text-xl), 15cqi); }
  .kpi-value, .figure { font-size: var(--text-xl); }
  .chart-box { height: 220px; }
  .toasts { left: var(--space-3); right: var(--space-3); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--space-3)); align-items: stretch; }
  .toast { max-width: none; }
  /* dialogs become bottom sheets */
  dialog:not(.cmdk) { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  dialog:not(.cmdk)[open] { animation: sheet-in var(--dur-slow) var(--ease-out); }
  dialog:not(.cmdk) .sheet-handle { display: block; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--border-strong); }
  dialog.cmdk { margin-top: var(--space-4); }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; --btn-h: var(--control-lg); }
  .menu, .pop { left: var(--space-2) !important; right: var(--space-2); max-width: none; }
  .sheet .menu-item, .sheet .pop-item { min-height: 48px; font-size: var(--text-md); }
  .field input:not([type="checkbox"]), .field select, .field textarea, .input, .select { font-size: var(--text-md); height: var(--control-lg); }
  .field textarea, .textarea { height: auto; }
}
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-sm, .btn-small { min-height: 36px; }
  .nav-item, .menu-item, .pop-item { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .spin, .btn[aria-busy="true"]::after { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
  .skeleton::after { display: none; }
}

/* ============ 18. small compositions shared by several pages ============ */
.cell-title .badge { margin-left: 6px; height: 18px; padding: 0 6px; font-size: var(--text-2xs); }
.banner + .secret, .banner + .field { margin-top: var(--space-3); }
.role-select { width: auto; min-width: 112px; }
.table-toolbar .select { width: auto; height: 32px; border-radius: var(--radius-pill); font-size: var(--text-sm); }
.table-toolbar .switch-row { margin-left: var(--space-1); }
.subnav { display: flex; flex-direction: column; gap: 1px; position: sticky; top: 0; }
.subnav a { display: flex; align-items: center; gap: var(--space-2); height: 34px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--fg-muted); font-weight: var(--weight-medium); text-decoration: none; transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.subnav a:hover { background: var(--bg-muted); color: var(--fg); text-decoration: none; }
.subnav a[aria-current="true"], .subnav a[aria-current="page"] { background: var(--bg-surface); color: var(--fg); box-shadow: var(--shadow-sm); }
.subnav .badge { margin-left: auto; }
.settings-main { max-width: 760px; }
.settings-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); padding: var(--space-3) 0; }
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row .label { display: block; }
.settings-row .hint { margin-top: 2px; }
.settings-row-block + .settings-row-block { border-top: 1px solid var(--border); padding-top: var(--space-3); margin-top: var(--space-3); }
.settings-row-block .settings-row { padding-top: 0; }
.settings-row-block .cluster > .input { flex: 1 1 240px; min-width: 0; }
@media (max-width: 960px) {
  .subnav { position: static; flex-direction: row; overflow-x: auto; gap: var(--space-1); scrollbar-width: none; }
  .subnav a { flex: none; }
}
.chip-select { width: auto; height: 32px; border-radius: var(--radius-pill); font-size: var(--text-sm); box-shadow: none; }
.filter-bar .input.chip-select { padding: 0 var(--space-3); }
.feed { list-style: none; margin: 0; padding: 6px; }
.feed-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px var(--space-3); align-items: start; padding: var(--space-3) 10px; border-radius: 12px; }
.feed-item + .feed-item { margin-top: 1px; }
.feed-item .avatar { grid-row: span 2; margin-top: 1px; }
.feed-what { color: var(--fg); }
.feed-what strong { font-weight: var(--weight-semibold); }
.feed-meta { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: var(--text-sm); color: var(--fg-muted); }
.feed-when { color: var(--fg-subtle); font-size: var(--text-sm); white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-item details { grid-column: 2 / -1; margin-top: 4px; }
.feed-item summary { width: max-content; color: var(--accent-fg); font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer; list-style: none; }
.feed-item summary::-webkit-details-marker { display: none; }
.feed-item pre { margin: var(--space-2) 0 0; padding: var(--space-3); border-radius: var(--radius-md); background: var(--bg-canvas); border: 1px solid var(--border); overflow-x: auto; font-size: var(--text-xs); line-height: 1.5; }
.feed-more { justify-content: center; }
.feed-more:has(> [hidden]:only-child) { display: none; }
