/* ==========================================================================
   5Region Console — base, components, shell
   ========================================================================== */

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  overflow-x: hidden;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-4) 0; }
::selection { background: var(--accent-soft-2); }
:focus { outline: none; }
:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--r-sm); }
[hidden] { display: none !important; }

.num, .tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "cv11"; }
.mono { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: -0.01em; }
.muted { color: var(--text-3); }
.muted-2 { color: var(--text-2); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.up { color: var(--ok); }
.down { color: var(--err); }
.flat { color: var(--text-3); }
.link { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; transition: text-decoration-color var(--t-fast); }
.link:hover { text-decoration-color: currentColor; }
.link-quiet:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s-2); }
.row-3 { display: flex; align-items: center; gap: var(--s-3); }
.stack { display: flex; flex-direction: column; gap: var(--s-2); }
.stack-4 { display: flex; flex-direction: column; gap: var(--s-4); }
.wrap { flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }

/* Icons (inline SVG from sprite) */
.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 14px; height: 14px; }
.i-xs { width: 12px; height: 12px; }
.i-lg { width: 20px; height: 20px; }
.i-fill { fill: currentColor; stroke: none; }

/* ---------- Keyboard hint ---------- */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font: 500 var(--fs-2xs)/1 var(--font-sans);
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 1.5px;
  border-radius: var(--r-xs);
  font-variant-numeric: tabular-nums;
}
.kbd + .kbd { margin-left: 2px; }
.btn-primary .kbd { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.22); color: rgba(255, 255, 255, 0.85); }

/* ---------- Buttons ---------- */
.btn {
  --btn-h: 32px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--btn-h); padding: 0 12px;
  font-size: var(--fs-base); font-weight: 500; line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  user-select: none;
  position: relative;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { background: var(--surface-3); }
.btn:disabled, .btn.is-disabled { opacity: 0.45; pointer-events: none; }
.btn .i { color: var(--text-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 1px 0 rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary .i { color: currentColor; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-press); }
.btn-dark { background: var(--surface-inverse); color: var(--text-inverse); border-color: var(--surface-inverse); }
.btn-dark .i { color: currentColor; }
.btn-dark:hover { background: var(--surface-inverse); opacity: .9; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); border-color: transparent; }
.btn-danger { color: var(--err); }
.btn-danger .i { color: currentColor; }
.btn-danger:hover { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.btn-sm { --btn-h: 28px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 5px; }
.btn-xs { --btn-h: 24px; padding: 0 8px; font-size: var(--fs-xs); border-radius: var(--r-sm); gap: 4px; }
.btn-lg { --btn-h: 40px; padding: 0 16px; font-size: var(--fs-md); }
.btn-icon { width: var(--btn-h); padding: 0; }
.btn-block { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading .i, .btn.is-loading .kbd { opacity: 0; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--on-accent) var(--on-accent) transparent transparent;
  animation: spin .7s linear infinite;
}
.btn:not(.btn-primary).is-loading::after { border-color: var(--text-2) var(--text-2) transparent transparent; }
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; }
.btn-group > .btn:first-child { border-radius: var(--r) 0 0 var(--r); }
.btn-group > .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }
.btn-group > .btn + .btn { margin-left: -1px; }
.btn-group > .btn-primary + .btn-primary { border-left-color: rgba(255,255,255,.25); }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--r-sm);
  color: var(--text-3);
  transition: background var(--t-fast), color var(--t-fast);
  flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.is-on { color: var(--text); background: var(--surface-3); }
.icon-btn-sm { width: 24px; height: 24px; border-radius: var(--r-xs); }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: var(--s-4); }
.row > .field + .field, .row-3 > .field + .field, [class*="grid"] > .field + .field { margin-top: 0; }
.label { display: flex; align-items: baseline; gap: var(--s-2); font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.label .counter { margin-left: auto; }
.hint { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.45; }
.hint .i { display: inline-block; vertical-align: -2px; }
.counter { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.counter.is-warn { color: var(--warn); }
.counter.is-err { color: var(--err); }
.counter.is-ok { color: var(--ok); }

.input, .select, .textarea {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  min-width: 0;
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--line-strong) 60%, var(--text-3)); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); outline: none; border-radius: var(--r); }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.is-invalid, .textarea.is-invalid { border-color: var(--err-dot); }
.input-sm { height: 28px; font-size: var(--fs-sm); padding: 0 8px; border-radius: var(--r-sm); }
.textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2385858e' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  cursor: pointer;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .i { position: absolute; left: 10px; color: var(--text-3); pointer-events: none; }
.input-group > .input { padding-left: 32px; }
.input-group > .input-suffix { position: absolute; right: 8px; display: flex; align-items: center; gap: 4px; color: var(--text-3); }
.input-affix { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); overflow: hidden; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.input-affix:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input-affix .affix { display: flex; align-items: center; padding: 0 10px; color: var(--text-3); background: var(--surface-2); border-right: 1px solid var(--line); font-size: var(--fs-sm); white-space: nowrap; }
.input-affix .input { border: 0; box-shadow: none !important; border-radius: 0; }

/* Checkbox */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: var(--fs-base); }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 16px; height: 16px; flex: none;
  border: 1.5px solid var(--line-strong); border-radius: 4px;
  background: var(--surface);
  display: grid; place-items: center;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.check:hover .box { border-color: var(--text-3); }
.check input:checked + .box, .check input:indeterminate + .box { background: var(--text); border-color: var(--text); }
.check input:checked + .box::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--surface); border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.check input:indeterminate + .box::after { content: ""; width: 8px; height: 2px; background: var(--surface); border-radius: 1px; }
.check input:focus-visible + .box { box-shadow: var(--focus-ring); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 30px; height: 18px; flex: none; border-radius: 999px; background: var(--line-strong); position: relative; transition: background var(--t); }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform var(--t) var(--ease); }
.switch input:checked + .track { background: var(--text); }
:root[data-theme="dark"] .switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }

/* Segmented */
.segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-3); border-radius: var(--r); }
.segmented button { height: 26px; padding: 0 10px; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.segmented button:hover { color: var(--text); }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .segmented button.is-active { background: var(--line-strong); }

/* ---------- Badges, chips, dots ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px;
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-2); background: var(--surface-3);
  border-radius: var(--r-xs);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge .i { width: 11px; height: 11px; }
.badge-outline { background: transparent; border: 1px solid var(--line-strong); }
.badge-accent { color: var(--accent-text); background: var(--accent-soft); }
.badge-ok { color: var(--ok); background: var(--ok-soft); }
.badge-warn { color: var(--warn); background: var(--warn-soft); }
.badge-err { color: var(--err); background: var(--err-soft); }
.badge-info { color: var(--info); background: var(--info-soft); }
.badge-violet { color: var(--violet); background: var(--violet-soft); }
.badge-dark { color: var(--text-inverse); background: var(--surface-inverse); }

/* Article flags: compact monochrome tokens; meaning carried by label */
.flag {
  display: inline-flex; align-items: center; gap: 3px;
  height: 18px; padding: 0 5px;
  font-size: 10px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase;
  border-radius: 4px; white-space: nowrap;
  color: var(--text-2); border: 1px solid var(--line-strong); background: var(--surface);
}
.flag .i { width: 10px; height: 10px; stroke-width: 2.25; }
.flag-top { color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); background: var(--accent-soft); }
.flag-ex { color: var(--violet); border-color: color-mix(in srgb, var(--violet) 28%, var(--line)); background: var(--violet-soft); }
.flag-video { color: var(--info); border-color: color-mix(in srgb, var(--info) 28%, var(--line)); background: var(--info-soft); }
.flags { display: inline-flex; gap: 4px; flex-wrap: wrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; background: var(--text-4); }
.dot-ok { background: var(--ok-dot); }
.dot-warn { background: var(--warn-dot); }
.dot-err { background: var(--err-dot); }
.dot-info { background: var(--info-dot); }
.dot-accent { background: var(--accent); }
.dot-ring { box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 0%, transparent); }
.dot-pulse { position: relative; }
.dot-pulse::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1.5px solid currentColor; opacity: .0; animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: .5; transform: scale(.6);} 100% { opacity: 0; transform: scale(1.6);} }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }
.status-ok .dot { background: var(--ok-dot); }
.status-warn .dot { background: var(--warn-dot); }
.status-err .dot { background: var(--err-dot); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-2); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip .i { color: var(--text-3); }
.chip.is-set { color: var(--text); background: var(--surface-2); border-style: solid; }
.chip.is-set .chip-val { color: var(--text); font-weight: 600; }
.chip .chip-x { margin-right: -4px; width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; color: var(--text-3); }
.chip .chip-x:hover { background: var(--surface-3); color: var(--text); }
.chip-dashed { border-style: dashed; color: var(--text-3); box-shadow: none; }

.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; font-size: var(--fs-xs); color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-full); white-space: nowrap; }

.delta { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }
.delta.flat { color: var(--text-3); }
.delta .i { width: 11px; height: 11px; stroke-width: 2.5; }

.avatar {
  --av: 24px;
  width: var(--av); height: var(--av); flex: none;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  font-size: calc(var(--av) * 0.4); font-weight: 600; letter-spacing: -0.02em;
  color: #fff; background: #8a8a93;
  user-select: none;
}
.avatar-sm { --av: 20px; }
.avatar-md { --av: 32px; }
.avatar-lg { --av: 40px; }
.avatar-xl { --av: 64px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; align-items: stretch; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 10px;
  font-size: var(--fs-base); font-weight: 500; color: var(--text-3);
  white-space: nowrap; flex: none;
  transition: color var(--t-fast);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); }
.tab.is-active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--text); }
.tab .tab-count { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; font-weight: 500; }
.tab .dot { width: 6px; height: 6px; }
.tab-panel:not(.is-active) { display: none; }

/* Saved views (pill tabs) */
.views { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
.views::-webkit-scrollbar { display: none; }
.view {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2);
  border-radius: var(--r-sm); white-space: nowrap; flex: none;
  transition: background var(--t-fast), color var(--t-fast);
}
.view:hover { background: var(--surface-3); color: var(--text); }
.view.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .view.is-active { background: var(--surface-3); }
.view .view-count { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; font-size: var(--fs-xs); }
.view .i { width: 14px; height: 14px; color: var(--text-3); }

/* ---------- Menus / popovers ---------- */
.menu {
  position: fixed; z-index: 400;
  min-width: 200px; max-width: min(340px, calc(100vw - 16px));
  max-height: min(420px, calc(100vh - 24px));
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top left;
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease);
  pointer-events: none;
}
:root[data-theme="dark"] .menu { background: var(--surface-2); }
.menu.is-open { opacity: 1; transform: none; pointer-events: auto; }
.menu-search { padding: 4px 4px 6px; border-bottom: 1px solid var(--line); margin: -4px -4px 4px; }
.menu-search .input { border: 0; box-shadow: none !important; height: 32px; background: transparent; }
.menu-label { padding: 6px 8px 4px; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 30px; padding: 4px 8px;
  font-size: var(--fs-base); color: var(--text); text-align: left;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.menu-item:hover, .menu-item.is-hl { background: var(--surface-3); }
.menu-item .i { color: var(--text-3); }
.menu-item .menu-meta { margin-left: auto; color: var(--text-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; padding-left: 12px; }
.menu-item .menu-check { margin-left: auto; color: var(--text); opacity: 0; }
.menu-item.is-checked .menu-check { opacity: 1; }
.menu-item.is-danger { color: var(--err); }
.menu-item.is-danger .i { color: currentColor; }
.menu-item .menu-desc { display: block; font-size: var(--fs-xs); color: var(--text-3); line-height: 1.35; }
.menu-sep { height: 1px; background: var(--line); margin: 4px -4px; }
.menu-empty { padding: 10px 8px; color: var(--text-3); font-size: var(--fs-sm); }

/* Tooltip */
[data-tip] { position: relative; }
.tooltip {
  position: fixed; z-index: 600; pointer-events: none;
  max-width: 260px; padding: 5px 8px;
  font-size: var(--fs-xs); line-height: 1.4; font-weight: 500;
  color: var(--text-inverse); background: var(--surface-inverse);
  border-radius: var(--r-sm);
  opacity: 0; transition: opacity var(--t-fast);
  font-variant-numeric: tabular-nums;
}
.tooltip.is-on { opacity: 1; }
.tooltip .kbd { background: transparent; color: inherit; opacity: .7; border-color: currentColor; margin-left: 6px; }

/* ---------- Overlay: dialog / drawer / sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 500;
  background: var(--overlay);
  opacity: 0; transition: opacity var(--t);
  backdrop-filter: blur(1.5px);
}
.overlay.is-open { opacity: 1; }

.dialog {
  position: fixed; z-index: 510; left: 50%; top: 14vh;
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100vh - 16vh - 24px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-dialog);
  transform: translate(-50%, 6px) scale(.985); opacity: 0;
  transition: opacity var(--t), transform var(--t) var(--ease);
}
:root[data-theme="dark"] .dialog { background: var(--surface-2); }
.dialog.is-open { opacity: 1; transform: translate(-50%, 0); }
.dialog-lg { width: min(720px, calc(100vw - 24px)); }
.dialog-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: 18px 20px 0; }
.dialog-icon { width: 32px; height: 32px; flex: none; border-radius: var(--r); display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.dialog-icon.is-warn { background: var(--warn-soft); color: var(--warn); }
.dialog-icon.is-err { background: var(--err-soft); color: var(--err); }
.dialog-icon.is-ok { background: var(--ok-soft); color: var(--ok); }
.dialog-title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.dialog-sub { margin-top: 4px; color: var(--text-2); font-size: var(--fs-base); }
.dialog-body { padding: 16px 20px; overflow-y: auto; color: var(--text-2); }
.dialog-body p + p { margin-top: 8px; }
.dialog-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line-soft); }
.dialog-foot .grow { color: var(--text-3); font-size: var(--fs-xs); }

.drawer {
  position: fixed; z-index: 510; top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-dialog);
  transform: translateX(100%);
  transition: transform 240ms var(--ease);
}
.drawer.is-open { transform: none; }
.drawer:not(.is-open) { visibility: hidden; transition: transform 240ms var(--ease), visibility 0s 240ms; }
.drawer-head { display: flex; align-items: center; gap: var(--s-2); min-height: 52px; padding: 0 12px 0 20px; border-bottom: 1px solid var(--line); flex: none; }
.drawer-title { font-size: var(--fs-md); font-weight: 600; flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; overscroll-behavior: contain; }
.drawer-foot { flex: none; display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--line); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 700; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: min(420px, calc(100vw - 32px));
  padding: 10px 10px 10px 14px;
  font-size: var(--fs-base); color: var(--text-inverse);
  background: var(--surface-inverse);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  transform: translateY(8px); opacity: 0;
  transition: opacity var(--t), transform var(--t) var(--ease);
}
.toast.is-on { transform: none; opacity: 1; }
.toast .toast-ic { flex: none; }
.toast .toast-ic.ok { color: #3fbf6e; }
.toast .toast-ic.warn { color: #f0a92a; }
.toast .toast-ic.err { color: #ff6d66; }
.toast .toast-msg { flex: 1; min-width: 0; line-height: 1.4; }
.toast .toast-msg small { display: block; opacity: .65; font-size: var(--fs-xs); }
.toast .toast-act { flex: none; font-weight: 600; font-size: var(--fs-sm); padding: 4px 8px; border-radius: var(--r-sm); color: inherit; }
.toast .toast-act:hover { background: rgba(127,127,127,.2); }

/* ---------- Command palette ---------- */
.cmdk {
  position: fixed; z-index: 520; left: 50%; top: 12vh;
  width: min(620px, calc(100vw - 24px));
  max-height: min(520px, 76vh);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-dialog);
  transform: translate(-50%, 4px) scale(.985); opacity: 0;
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease);
  overflow: hidden;
}
:root[data-theme="dark"] .cmdk { background: var(--surface-2); }
.cmdk.is-open { opacity: 1; transform: translate(-50%, 0); }
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 52px; border-bottom: 1px solid var(--line); flex: none; }
.cmdk-input .i { color: var(--text-3); width: 18px; height: 18px; }
.cmdk-input input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; font-size: var(--fs-md); outline: none; }
.cmdk-input input::placeholder { color: var(--text-4); }
.cmdk-list { flex: 1; overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.cmdk-group { padding: 8px 10px 4px; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.cmdk-item { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 6px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--text); }
.cmdk-item .i { color: var(--text-3); }
.cmdk-item.is-hl { background: var(--surface-3); }
.cmdk-item .cmdk-thumb { width: 36px; height: 24px; border-radius: 4px; object-fit: cover; flex: none; background: var(--surface-3); }
.cmdk-item .cmdk-text { flex: 1; min-width: 0; }
.cmdk-item .cmdk-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item .cmdk-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item .cmdk-meta { flex: none; font-size: var(--fs-xs); color: var(--text-3); }
.cmdk-item mark { background: none; color: var(--text); font-weight: 650; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.cmdk-foot { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--text-3); flex: none; }
.cmdk-foot span { display: inline-flex; align-items: center; gap: 4px; }
.cmdk-empty { padding: 28px 16px; text-align: center; color: var(--text-3); }
.cmdk-hint { margin: 6px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--info-soft); color: var(--info); font-size: var(--fs-sm); display: flex; gap: 8px; align-items: center; }

/* ---------- Table ---------- */
.table-wrap { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: clip; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th {
  position: sticky; top: 0; z-index: 2;
  height: 34px; padding: 0 10px;
  font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); text-align: left; white-space: nowrap;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.table td { height: 44px; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: color-mix(in srgb, var(--focus) 6%, var(--surface)); }
.table tbody tr.is-selected:hover { background: color-mix(in srgb, var(--focus) 9%, var(--surface)); }
.table tbody tr.is-kbd { box-shadow: inset 2px 0 0 var(--text); }
.table .col-num, .table th.col-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .col-check { width: 36px; padding-right: 0; }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table tr.is-clickable { cursor: pointer; }
.th-sort { display: inline-flex; align-items: center; gap: 3px; color: inherit; font-weight: 500; font-size: inherit; border-radius: 4px; }
.th-sort:hover { color: var(--text); }
.th-sort .i { width: 12px; height: 12px; opacity: 0; }
.th-sort.is-sorted { color: var(--text); }
.th-sort.is-sorted .i { opacity: 1; }
.th-sort:hover .i { opacity: .6; }
.table-foot { display: flex; align-items: center; gap: var(--s-3); padding: 10px 12px; border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--text-3); background: var(--surface); }
.table-compact td { height: 38px; }

.pager { display: inline-flex; align-items: center; gap: 2px; }
.pager button { min-width: 28px; height: 28px; padding: 0 6px; border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; display: inline-grid; place-items: center; }
.pager button:hover { background: var(--surface-3); color: var(--text); }
.pager button.is-active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.pager button:disabled { opacity: .35; pointer-events: none; }

/* Bulk action bar */
.bulkbar {
  position: fixed; z-index: 300; left: 50%; bottom: 20px;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 6px 6px 14px;
  max-width: calc(100vw - 24px);
  color: var(--text-inverse); background: var(--surface-inverse);
  border-radius: 10px;
  box-shadow: var(--shadow-dialog);
  transform: translate(-50%, 140%); opacity: 0;
  transition: transform 220ms var(--ease), opacity 220ms;
}
.bulkbar.is-on { transform: translate(-50%, 0); opacity: 1; }
.bulkbar .bulk-count { font-weight: 600; font-size: var(--fs-base); white-space: nowrap; margin-right: 8px; font-variant-numeric: tabular-nums; }
.bulkbar .bulk-sep { width: 1px; height: 20px; background: rgba(127,127,127,.35); margin: 0 4px; }
.bulkbar .btn { background: transparent; border-color: transparent; color: inherit; box-shadow: none; }
.bulkbar .btn .i { color: inherit; opacity: .75; }
.bulkbar .btn:hover { background: rgba(127,127,127,.22); }
.bulkbar .bulk-actions { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }

/* ---------- Panels & sections ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.panel-head { display: flex; align-items: center; gap: var(--s-2); min-height: 46px; padding: 0 16px; border-bottom: 1px solid var(--line-soft); }
.panel-title { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.005em; display: flex; align-items: center; gap: 8px; min-width: 0; }
.panel-title .muted { font-weight: 400; }
.panel-head .panel-link { margin-left: auto; font-size: var(--fs-sm); color: var(--text-3); display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.panel-head .panel-link:hover { color: var(--text); }
.panel-body { padding: 16px; }
.panel-body-flush { padding: 0; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--line-soft); font-size: var(--fs-sm); color: var(--text-3); }

.section-title { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.005em; }
.section-sub { color: var(--text-3); font-size: var(--fs-sm); margin-top: 2px; }
.eyebrow { font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }

/* List rows inside panels */
.list > li, .list > a, .list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; min-height: 44px;
  border-bottom: 1px solid var(--line-soft);
}
.list > li:last-child, .list > a:last-child { border-bottom: 0; }
a.list-row, .list > a { transition: background var(--t-fast); }
a.list-row:hover, .list > a:hover { background: var(--surface-2); }

/* Key/value */
.kv { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 8px 16px; font-size: var(--fs-sm); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }

/* Callouts */
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r); font-size: var(--fs-sm); line-height: 1.5; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); }
.callout > .i { margin-top: 2px; }
.callout strong { color: var(--text); font-weight: 600; }
.callout-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn-dot) 30%, transparent); }
.callout-warn > .i { color: var(--warn); }
.callout-err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err-dot) 25%, transparent); }
.callout-err > .i { color: var(--err); }
.callout-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info-dot) 25%, transparent); }
.callout-info > .i { color: var(--info); }
.callout-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok-dot) 25%, transparent); }
.callout-ok > .i { color: var(--ok); }

/* Meter */
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; display: flex; gap: 2px; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--text-3); }

/* Empty state */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; color: var(--text-3); }
.empty-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-3); margin-bottom: 6px; }
.empty-title { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.empty-text { max-width: 380px; font-size: var(--fs-sm); line-height: 1.5; }
.empty .btn { margin-top: 8px; }

/* Skeleton */
.skel { display: block; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 40%, var(--surface-3) 80%); background-size: 300% 100%; animation: shimmer 1.3s ease-in-out infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Thumbnails */
.thumb { width: 48px; height: 32px; flex: none; border-radius: 4px; object-fit: cover; background: var(--surface-3); border: 1px solid var(--line-soft); }
.thumb-empty { display: grid; place-items: center; color: var(--text-4); background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, var(--surface-3) 4px 5px); }
.thumb-empty .i { width: 13px; height: 13px; }

/* ---------- Shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; z-index: 100; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  transition: width var(--t) var(--ease);
}
.sb-head { display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 10px 0 14px; flex: none; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 4px; margin: -4px; border-radius: var(--r-sm); }
.brand-mark {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font: 800 14px/1 var(--font-sans); letter-spacing: -0.04em;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.18);
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-name { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-name b { font-size: var(--fs-md); font-weight: 700; letter-spacing: -0.02em; }
.brand-name span { font-size: var(--fs-2xs); color: var(--text-3); font-weight: 500; letter-spacing: .02em; }
.sb-collapse { margin-left: auto; }
.sb-nav { flex: 1; overflow-y: auto; padding: 6px 8px 12px; scrollbar-width: thin; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 32px; padding: 0 8px;
  font-size: var(--fs-base); font-weight: 500; color: var(--text-2);
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item .i { color: var(--text-3); transition: color var(--t-fast); }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item:hover .i { color: var(--text-2); }
.nav-item.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .nav-item.is-active { background: var(--surface-3); }
.nav-item.is-active .i { color: var(--accent); }
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.nav-count { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; font-weight: 500; }
.nav-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 10.5px; font-weight: 650; display: inline-grid; place-items: center; color: var(--warn); background: var(--warn-soft); font-variant-numeric: tabular-nums; }
.nav-caret { color: var(--text-4); transition: transform var(--t); }
.nav-group.is-open .nav-caret { transform: rotate(90deg); }
.nav-sub { display: none; position: relative; margin: 2px 0 4px; padding-left: 17px; }
.nav-sub::before { content: ""; position: absolute; left: 15px; top: 2px; bottom: 2px; width: 1px; background: var(--line-strong); }
.nav-group.is-open .nav-sub { display: block; }
.nav-subitem { position: relative; display: flex; align-items: center; gap: 8px; height: 29px; padding: 0 8px 0 14px; margin-left: 2px; font-size: var(--fs-base); color: var(--text-2); border-radius: var(--r-sm); white-space: nowrap; }
.nav-subitem:hover { background: var(--surface-3); color: var(--text); }
.nav-subitem.is-active { color: var(--text); font-weight: 600; background: var(--surface); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .nav-subitem.is-active { background: var(--surface-3); }
.nav-subitem.is-active::before { content: ""; position: absolute; left: -3px; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--accent); }
.nav-subitem .nav-badge { margin-left: auto; }
.nav-section { margin: 16px 8px 4px; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-4); white-space: nowrap; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.sb-foot { flex: none; padding: 8px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.sb-user { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border-radius: var(--r-sm); text-align: left; }
.sb-user:hover { background: var(--surface-3); }
.sb-user .who { flex: 1; min-width: 0; line-height: 1.25; }
.sb-user .who b { display: block; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user .who span { display: block; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }

.main { margin-left: var(--sidebar-w); min-width: 0; min-height: 100vh; display: flex; flex-direction: column; transition: margin-left var(--t) var(--ease); }

.topbar {
  position: sticky; top: 0; z-index: 90;
  display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 16px 0 var(--gutter);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t);
}
.topbar.is-stuck { border-bottom-color: var(--line); }
.topbar .tb-mobile { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-base); color: var(--text-3); }
.crumbs a { color: var(--text-3); white-space: nowrap; border-radius: 4px; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--text-4); flex: none; }
.crumbs .sep .i { width: 13px; height: 13px; }
.crumbs .current { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.search-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 30px; width: 240px; padding: 0 6px 0 10px;
  font-size: var(--fs-sm); color: var(--text-3);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.search-pill:hover { border-color: var(--line-strong); color: var(--text-2); }
.search-pill .grow { text-align: left; }

.page { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 8px var(--gutter) 64px; flex: 1; min-width: 0; }
.page-wide { max-width: none; }
.page-narrow { max-width: 920px; }
.page-head { display: flex; align-items: flex-end; gap: var(--s-4); flex-wrap: wrap; padding: 14px 0 20px; }
.page-head-main { flex: 1 1 320px; min-width: 0; }
.page-title { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -0.022em; line-height: 1.2; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.page-title .page-count { font-size: var(--fs-lg); font-weight: 500; color: var(--text-3); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.page-sub { margin-top: 4px; color: var(--text-3); font-size: var(--fs-base); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fresh { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); white-space: nowrap; }

/* Toolbar (filters row) */
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .search { width: 300px; max-width: 100%; }
.toolbar .search .input { height: 30px; font-size: var(--fs-sm); }
.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* Mobile tab bar + nav sheet */
.tabbar { display: none; }
.navsheet { display: none; }

/* Rail mode (tablet / collapsed) */
html.rail .sidebar, .sidebar.is-rail { width: var(--rail-w); }
html.rail .main { margin-left: var(--rail-w); }
html.rail .sb-head { padding: 0; justify-content: center; }
html.rail .brand-name, html.rail .sb-collapse-wide, html.rail .nav-item .nav-label, html.rail .nav-count, html.rail .nav-caret,
html.rail .nav-section, html.rail .sb-user .who, html.rail .nav-sub, html.rail .nav-item .nav-badge { display: none !important; }
html.rail .sb-nav { padding: 6px 10px; }
html.rail .nav-item { justify-content: center; padding: 0; height: 36px; }
html.rail .nav-item .i { width: 18px; height: 18px; }
html.rail .nav-item.has-badge::after { content: ""; position: absolute; top: 7px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn-dot); }
html.rail .sb-foot { align-items: center; padding: 8px 6px; }
html.rail .sb-user { justify-content: center; padding: 6px 0; }
html.rail .nav-sep { margin: 8px 6px; }
html.rail .sb-rail-expand { display: inline-flex !important; }
.sb-rail-expand { display: none !important; }

@media (max-width: 1199px) {
  :root { --gutter: 22px; }
  .search-pill { width: 200px; }
}

/* Mobile */
@media (max-width: 767px) {
  :root { --gutter: 16px; --topbar-h: 52px; }
  .sidebar { display: none; }
  .main, html.rail .main { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 8px 0 12px; gap: 4px; background: color-mix(in srgb, var(--bg) 92%, transparent); border-bottom-color: var(--line); }
  .topbar .tb-mobile { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
  .topbar .crumbs { display: none; }
  .tb-mobile .brand-mark { width: 24px; height: 24px; font-size: 13px; }
  .tb-mobile .tb-title { font-weight: 600; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .search-pill { width: 34px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
  .search-pill .grow, .search-pill .kbd { display: none; }
  .tb-hide-m, .hide-m, .btn .kbd, .quick-a .kbd { display: none !important; }
  .page { padding: 4px var(--gutter) 32px; }
  .page-head { padding: 12px 0 16px; gap: 12px; align-items: flex-start; }
  .page-head-main { flex-basis: 100%; }
  .page-title { font-size: var(--fs-xl); }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .page-actions .btn.btn-icon { flex: none; }

  .tabbar {
    display: flex; position: fixed; z-index: 150; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 500; color: var(--text-3); min-width: 0; position: relative; }
  .tabbar .i { width: 21px; height: 21px; stroke-width: 1.6; }
  .tabbar .is-active { color: var(--text); }
  .tabbar .is-active .i { color: var(--accent); stroke-width: 2; }
  .tabbar .tab-new { flex: 0 0 64px; }
  .tabbar .tab-new span.fab { width: 44px; height: 36px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--accent) 50%, transparent); }
  .tabbar .tab-new .i { color: #fff; width: 20px; height: 20px; stroke-width: 2.2; }
  .tabbar .tb-dot { position: absolute; top: 9px; left: calc(50% + 8px); width: 7px; height: 7px; border-radius: 50%; background: var(--warn-dot); box-shadow: 0 0 0 2px var(--surface); }

  .navsheet { display: block; position: fixed; z-index: 520; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-dialog); transform: translateY(100%); transition: transform 260ms var(--ease); padding: 6px 12px calc(16px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .navsheet:not(.is-open) { visibility: hidden; transition: transform 260ms var(--ease), visibility 0s 260ms; }
  .navsheet.is-open { transform: none; }
  .sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 4px auto 10px; }
  .navsheet .ns-user { display: flex; align-items: center; gap: 12px; padding: 8px 6px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
  .navsheet .ns-user .who { flex: 1; min-width: 0; line-height: 1.3; }
  .navsheet .ns-user b { display: block; font-weight: 600; }
  .navsheet .ns-user span { font-size: var(--fs-sm); color: var(--text-3); }
  .navsheet .ns-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .navsheet .ns-tile { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-soft); font-weight: 500; font-size: var(--fs-base); min-width: 0; }
  .navsheet .ns-tile .i { width: 18px; height: 18px; color: var(--text-3); }
  .navsheet .ns-tile.is-active { border-color: var(--line-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
  .navsheet .ns-tile.is-active .i { color: var(--accent); }
  .navsheet .ns-tile span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .navsheet .ns-label { font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 14px 4px 8px; }
  .navsheet .ns-row { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 8px; border-radius: var(--r); font-weight: 500; }
  .navsheet .ns-row .i { color: var(--text-3); width: 18px; height: 18px; }
  .navsheet .ns-row.is-active { background: var(--surface-2); }
  .navsheet .ns-row.is-active .i { color: var(--accent); }
  .navsheet .ns-row .nav-badge { margin-left: auto; }
  .navsheet .ns-foot { display: flex; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
  .navsheet .ns-foot .btn { flex: 1; }

  /* Overlays become bottom sheets on phones */
  .dialog { top: auto; bottom: 0; left: 0; width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; transform: translateY(100%); }
  .dialog.is-open { transform: none; }
  .dialog-lg { width: 100%; }
  .dialog-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .dialog-foot .btn { flex: 1 1 auto; }
  .dialog-foot .grow { flex-basis: 100%; }
  .drawer { top: auto; width: 100%; max-height: 92vh; height: 92vh; border-left: 0; border-radius: 16px 16px 0 0; transform: translateY(100%); }
  .drawer.is-open { transform: none; }
  .cmdk { top: 8px; max-height: calc(100vh - 16px); }
  .cmdk-foot { display: none; }
  .toasts { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
  .bulkbar { bottom: calc(var(--tabbar-h) + 10px + env(safe-area-inset-bottom)); left: 12px; right: 12px; transform: translateY(160%); max-width: none; }
  .bulkbar.is-on { transform: none; }
  .menu.as-sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; max-width: none; width: 100%; max-height: 70vh; border-radius: 16px 16px 0 0; padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); transform: translateY(100%); }
  .menu.as-sheet.is-open { transform: none; }
  .menu.as-sheet .menu-item { min-height: 42px; font-size: var(--fs-md); }
  .toolbar .search { width: 100%; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* Utility: scroll lock */
html.is-locked, html.is-locked body { overflow: hidden; }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; min-width: 0; }
.chart svg { display: block; overflow: visible; }
.chart-axis { font: 500 10.5px var(--font-sans); fill: var(--viz-axis); font-variant-numeric: tabular-nums; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 150px; padding: 8px 10px;
  font-size: var(--fs-xs); color: var(--text);
  background: var(--surface); border-radius: var(--r-sm);
  box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity var(--t-fast);
}
:root[data-theme="dark"] .chart-tip { background: var(--surface-3); }
.chart-tip.is-on { opacity: 1; }
.ct-date { color: var(--text-3); margin-bottom: 4px; font-weight: 500; }
.ct-row { display: flex; align-items: center; gap: 6px; line-height: 1.7; }
.ct-row b { margin-left: auto; padding-left: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ct-key { width: 10px; height: 2px; border-radius: 1px; background: var(--c); flex: none; }
.ct-key[style*="--dash"] { background: repeating-linear-gradient(90deg, var(--c) 0 3px, transparent 3px 5px); }
.ct-name { color: var(--text-2); }
.spark { display: block; overflow: visible; }
.dist-bar { display: flex; gap: 2px; height: 10px; border-radius: 3px; overflow: hidden; }
.dist-bar span { display: block; min-width: 3px; height: 100%; transition: opacity var(--t-fast); }
.dist-bar span:first-child { border-radius: 3px 0 0 3px; }
.dist-bar span:last-child { border-radius: 0 3px 3px 0; }
.dist-bar:hover span { opacity: .55; }
.dist-bar span:hover { opacity: 1; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; }
.dl-item { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.dl-item b { color: var(--text); font-weight: 600; }
.dl-key { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: var(--fs-xs); color: var(--text-3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i.k { width: 14px; height: 2px; border-radius: 1px; display: inline-block; background: var(--viz-1); }
.legend i.k.dash { background: repeating-linear-gradient(90deg, var(--viz-muted) 0 3px, transparent 3px 6px); height: 2px; }
.show-m { display: none !important; }
@media (max-width: 767px) { .show-m { display: revert !important; } .btn.show-m, .chip.show-m { display: inline-flex !important; } }
@media (min-width: 768px) and (max-width: 1199px) { .hide-t { display: none !important; } }
.search-pill .grow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.rail .sb-user > .i { display: none; }
.cmdk-input input:focus-visible, .ed-title:focus-visible, .ed-subtitle:focus-visible, .ed-body:focus-visible { box-shadow: none; }
.cmdk-foot span { white-space: nowrap; }
