/* cubek components: plain CSS over tokens.css, no framework. Class names
   are the API; /design on cubek.dev shows every one in both themes. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-ui);
  line-height: var(--leading-ui);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; font-variant-ligatures: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: var(--tracking-heading); line-height: 1.2; }
p { margin: 0; }
::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.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; }
.skip-link { position: absolute; left: var(--s-4); top: -48px; z-index: 100; padding: var(--s-2) var(--s-3); background: var(--accent); color: var(--on-accent); border-radius: var(--r-sm); font-weight: 600; }
.skip-link:focus { top: var(--s-3); }
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--s-6); }
@media (max-width: 640px) { .container { padding: 0 var(--s-4); } }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.eyebrow { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.link { color: var(--accent-text); text-decoration: underline; text-decoration-color: var(--accent-border); text-underline-offset: 3px; }
.link:hover { text-decoration-color: currentColor; }
.dot-grid {
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 22px 22px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 34px; padding: 0 var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text);
  font-size: var(--text-ui); font-weight: 500; line-height: 1; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: transparent; }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 28px; padding: 0 var(--s-2); font-size: var(--text-sm); border-radius: var(--r-sm); }
.btn-lg { height: 42px; padding: 0 var(--s-5); font-size: var(--text-md); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

/* ---------- Form controls ---------- */
.field { display: grid; gap: var(--s-2); }
.label { font-size: var(--text-sm); font-weight: 500; color: var(--text-2); }
.hint { font-size: var(--text-xs); color: var(--muted); }
.hint.error { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 var(--s-3);
  background: var(--bg-subtle); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  font-size: var(--text-ui);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: var(--s-2) var(--s-3); resize: vertical; line-height: var(--leading-ui); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
.input-group { display: flex; align-items: center; gap: var(--s-2); }
.check { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--text-ui); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* ---------- Badges, status dots, kbd ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 var(--s-2);
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--neutral-soft); color: var(--text-2);
  font-size: var(--text-xs); font-weight: 500; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); border-color: transparent; color: var(--accent-text); }
.badge-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.badge-info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.badge-mono { font-family: var(--font-mono); border-radius: var(--r-sm); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot-info { background: var(--info); box-shadow: 0 0 0 3px var(--info-soft); }
.dot-live { animation: dot-pulse 1.6s var(--ease) infinite; }
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.status { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--text-sm); color: var(--text-2); }
.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
  background: var(--surface); color: var(--text-2); font-family: var(--font-mono); font-size: 11px;
}

/* ---------- Cards (Railway-style service cards) ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); }
.card-hover { transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card-hover:hover { border-color: var(--border-strong); background: var(--surface-2); }
.card-title { font-size: var(--text-md); font-weight: 600; letter-spacing: var(--tracking-heading); }
.card-text { margin-top: var(--s-2); color: var(--text-2); line-height: 1.6; }
.service {
  display: grid; gap: var(--s-3);
  width: 100%; padding: var(--s-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
a.service:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.service-head { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.service-icon {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2);
}
.service-icon svg { width: 18px; height: 18px; }
.service-name { font-weight: 600; font-size: var(--text-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-url { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding-top: var(--s-3); border-top: 1px solid var(--border); font-size: var(--text-xs); color: var(--muted); }
.service.is-active { border-color: var(--accent-border); box-shadow: 0 0 0 1px var(--accent-border), 0 0 32px -8px var(--accent-soft); }

/* ---------- Tables and list rows ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-ui); }
.table th { text-align: left; font-weight: 500; font-size: var(--text-xs); color: var(--muted); padding: var(--s-2) var(--s-4); border-bottom: 1px solid var(--border); background: var(--bg-subtle); white-space: nowrap; }
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.list { display: grid; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-3); color: var(--muted); font-weight: 500; white-space: nowrap;
  background: none; border: 0; cursor: pointer; transition: color var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--text); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { content: ""; position: absolute; left: var(--s-2); right: var(--s-2); bottom: -1px; height: 2px; border-radius: 2px; background: var(--text); }
.segmented { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-subtle); }
.segmented .tab { height: 28px; border-radius: var(--r-sm); }
.segmented .tab[aria-selected="true"] { background: var(--surface-2); box-shadow: 0 0 0 1px var(--border-strong); }
.segmented .tab[aria-selected="true"]::after { display: none; }

/* ---------- Dialog ---------- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--s-4); background: var(--overlay); backdrop-filter: blur(2px); animation: fade-in var(--dur) var(--ease); }
.dialog {
  width: min(460px, 100%); padding: 0; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); animation: pop-in var(--dur) var(--ease);
}
.dialog::backdrop { background: var(--overlay); }
.dialog-head { padding: var(--s-5) var(--s-5) 0; }
.dialog-title { font-size: var(--text-md); font-weight: 600; }
.dialog-body { padding: var(--s-3) var(--s-5) var(--s-5); color: var(--text-2); line-height: 1.6; display: grid; gap: var(--s-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); background: var(--bg-subtle); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 60; display: grid; gap: var(--s-2); width: min(360px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); font-size: var(--text-ui); animation: pop-in var(--dur) var(--ease);
}
.toast .dot { margin-top: 6px; }
.toast-title { font-weight: 600; }
.toast-text { color: var(--text-2); font-size: var(--text-sm); margin-top: 2px; }

/* ---------- Agent prompt ("For your agent": a prompt to copy, the manual steps collapsed) ---------- */
.agent { overflow: hidden; text-align: left; background: var(--code-bg); border: 1px solid var(--accent-border); border-radius: var(--r-lg); color: var(--code-text); }
.agent-head { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); border-bottom: 1px solid var(--border); background: var(--accent-soft); }
.agent-label { display: inline-flex; align-items: center; gap: 6px; flex: none; color: var(--accent-text); font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.agent-note { flex: 1; min-width: 0; color: var(--text-2); font-size: var(--text-sm); }
.agent-head .copy-btn { flex: none; margin-left: auto; }
.agent-prompt { margin: 0; padding: var(--s-4); font-family: var(--font-mono); font-size: 13px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: break-word; }
.agent-manual { border-top: 1px solid var(--border); }
.agent-manual > summary { cursor: pointer; padding: var(--s-2) var(--s-4); color: var(--muted); font-size: var(--text-sm); list-style: none; }
.agent-manual > summary::-webkit-details-marker { display: none; }
.agent-manual > summary::before { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 8px 2px 1px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur) var(--ease); }
.agent-manual[open] > summary::before { transform: rotate(45deg); }
.agent-manual > summary:hover { color: var(--text); }
.agent-manual pre { margin: 0; padding: 0 var(--s-4) var(--s-4); font-family: var(--font-mono); font-size: 13px; line-height: 1.7; overflow-x: auto; }
@media (max-width: 560px) { .agent-head { flex-wrap: wrap; } .agent-note { order: 3; flex-basis: 100%; padding-bottom: var(--s-1); } }

/* ---------- Code block with copy ---------- */
.code {
  position: relative; overflow: hidden;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--r-lg);
  color: var(--code-text);
}
.code-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); height: 38px; padding: 0 var(--s-2) 0 var(--s-4); border-bottom: 1px solid var(--border); color: var(--muted); font-family: var(--font-mono); font-size: var(--text-xs); }
.code-head .lights { display: flex; gap: 6px; }
.code-head .lights i { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); }
.code pre { margin: 0; padding: var(--s-4); overflow-x: auto; font-size: 13px; line-height: 1.7; tab-size: 2; }
.code pre code { font-size: inherit; }
.code .copy-float { position: absolute; top: var(--s-2); right: var(--s-2); background: var(--code-bg); }
.code .copy-float:hover { background: var(--surface-2); }
.code:has(> .copy-float) pre { padding-right: var(--s-12); }
.code:not(:hover) .copy-float:not(:focus-visible):not(.is-done) { opacity: 0.55; }
.code .c-prompt { color: var(--code-prompt); user-select: none; }
.code .c-comment { color: var(--code-comment); }
.code .c-ok { color: var(--accent-text); }
.code .c-url { color: var(--text); text-decoration: underline; text-decoration-color: var(--accent-border); text-underline-offset: 3px; }
.copy-btn { color: var(--muted); }
.copy-btn.is-done { color: var(--accent-text); }
:not(pre) > code { padding: 0.1em 0.35em; border-radius: 4px; background: var(--neutral-soft); color: var(--text); font-size: 0.86em; }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  background: var(--header-bg); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { height: 100%; display: flex; align-items: center; gap: var(--s-6); }
.brand { display: inline-flex; align-items: center; color: var(--text); flex: none; border-radius: var(--r-sm); }
.brand svg { height: 26px; width: auto; }
.brand .mark { color: var(--accent); }
.nav { display: flex; align-items: center; gap: var(--s-1); }
.nav a { padding: 6px var(--s-3); border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; transition: color var(--dur) var(--ease), background var(--dur) var(--ease); }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.menu { position: relative; display: none; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 8px); display: grid; gap: 2px; min-width: 220px; padding: var(--s-2); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); }
.menu-panel a { padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); color: var(--text-2); }
.menu-panel a:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 760px) {
  .site-header .nav, .header-actions .hide-sm { display: none; }
  .menu { display: block; }
}

/* Theme toggle: both icons rendered, CSS shows the one for the other theme. */
.theme-toggle .i-sun { display: none; }
:root[data-theme="light"] .theme-toggle .i-sun { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: var(--s-12) 0 var(--s-10); color: var(--muted); font-size: var(--text-sm); }
.footer-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: var(--s-8); }
.footer-grid h2 { font-size: var(--text-xs); font-weight: 500; color: var(--text); letter-spacing: 0; margin-bottom: var(--s-3); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.footer-grid a:hover { color: var(--text); }
.footer-base { display: flex; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-10); padding-top: var(--s-6); border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } .footer-grid > :first-child { grid-column: 1 / -1; } }

/* ---------- Empty states, skeletons ---------- */
.empty { display: grid; place-items: center; gap: var(--s-2); padding: var(--s-12) var(--s-6); text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--muted); }
.empty-title { color: var(--text); font-weight: 600; font-size: var(--text-md); }
.skeleton { display: block; height: 12px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-hover) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Prose (docs) ---------- */
.prose { font-size: 15px; line-height: var(--leading-prose); color: var(--text-2); max-width: 760px; }
.prose > * + * { margin-top: var(--s-4); }
.prose h1 { font-size: var(--text-2xl); color: var(--text); letter-spacing: var(--tracking-display); line-height: 1.15; }
.prose h2 { font-size: var(--text-xl); color: var(--text); margin-top: var(--s-10); padding-top: var(--s-2); }
.prose h3 { font-size: var(--text-lg); color: var(--text); margin-top: var(--s-8); }
.prose strong { color: var(--text); font-weight: 600; }
.prose a { color: var(--accent-text); text-decoration: underline; text-decoration-color: var(--accent-border); text-underline-offset: 3px; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: var(--s-1); }
.prose li::marker { color: var(--muted); }
.prose table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; font-size: var(--text-ui); }
.prose th, .prose td { text-align: left; padding: var(--s-2) var(--s-3); border: 1px solid var(--border); vertical-align: top; }
.prose th { background: var(--bg-subtle); color: var(--text); font-weight: 500; }
.prose pre { margin: 0; }
.prose .code { margin-top: var(--s-4); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-8) 0; }
.prose blockquote { margin-left: 0; padding-left: var(--s-4); border-left: 2px solid var(--accent); }

/* ---------- App shell (console): left rail + top bar + main ---------- */
.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s-4);
  padding: var(--s-3); background: var(--bg-subtle); border-right: 1px solid var(--border);
}
.rail-head { display: flex; align-items: center; gap: var(--s-2); height: 36px; padding: 0 var(--s-1); }
.rail-section { display: grid; gap: 2px; }
.rail-label { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--s-2); height: 24px; font-size: var(--text-xs); font-weight: 500; color: var(--muted); }
.rail-item {
  display: flex; align-items: center; gap: var(--s-2); min-height: 32px; padding: 0 var(--s-2);
  border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; font-size: var(--text-sm);
  background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail-item:hover { background: var(--surface-2); color: var(--text); }
.rail-item[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.rail-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item svg { width: 16px; height: 16px; flex: none; }
.rail-foot { margin-top: auto; display: grid; gap: 2px; padding-top: var(--s-3); border-top: 1px solid var(--border); }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--s-3);
  height: 52px; padding: 0 var(--s-6); background: var(--header-bg);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: var(--s-2); min-width: 0; font-size: var(--text-sm); color: var(--muted); }
.crumbs a { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: var(--r-sm); }
.crumbs a:hover { color: var(--text); }
.crumbs [aria-current="page"] { color: var(--text); font-weight: 500; }
.crumbs .sep { color: var(--border-strong); }
.rail-toggle { display: none; }
.rail-scrim { display: none; }
@media (max-width: 860px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 45; left: 0; top: 0; width: min(280px, 86vw); transform: translateX(-100%); transition: transform var(--dur) var(--ease); box-shadow: var(--shadow-pop); }
  .rail.is-open { transform: none; }
  .rail-scrim.is-open { display: block; position: fixed; inset: 0; z-index: 44; background: var(--overlay); }
  .rail-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--s-3); }
}

/* ---------- Command palette ---------- */
.palette-backdrop { position: fixed; inset: 0; z-index: 70; display: flex; justify-content: center; align-items: flex-start; padding: 12vh var(--s-4) var(--s-4); background: var(--overlay); animation: fade-in var(--dur) var(--ease); }
.palette { width: min(620px, 100%); max-height: 70vh; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); animation: pop-in var(--dur) var(--ease); }
.palette-input { width: 100%; height: 48px; padding: 0 var(--s-4); background: transparent; border: 0; border-bottom: 1px solid var(--border); color: var(--text); font-size: var(--text-md); }
.palette-input:focus { outline: none; }
.palette-list { overflow-y: auto; padding: var(--s-2); margin: 0; list-style: none; }
.palette-group { padding: var(--s-2) var(--s-2) var(--s-1); font-size: var(--text-xs); color: var(--muted); font-weight: 500; }
.palette-item { display: flex; align-items: center; gap: var(--s-3); height: 38px; padding: 0 var(--s-3); border-radius: var(--r-sm); color: var(--text-2); cursor: pointer; }
.palette-item[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.palette-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item mark { background: none; color: var(--accent-text); font-weight: 600; }
.palette-foot { display: flex; gap: var(--s-4); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--border); background: var(--bg-subtle); font-size: var(--text-xs); color: var(--muted); }

/* ---------- Meter (usage vs a limit) ---------- */
.meter { display: grid; gap: 6px; }
.meter-head { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--text-sm); }
.meter-head .value { font-variant-numeric: tabular-nums; color: var(--text-2); }
.meter-bar { height: 6px; border-radius: var(--r-full); background: var(--neutral-soft); overflow: hidden; }
.meter-fill { height: 100%; min-width: 2px; border-radius: var(--r-full); background: var(--accent); transition: width var(--dur) var(--ease); }
.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-danger { background: var(--danger); }

/* ---------- Chart (own SVG: area/line, one y-axis, crosshair) ---------- */
.chart { position: relative; display: grid; gap: var(--s-2); }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); }
.chart-title { font-size: var(--text-sm); font-weight: 500; color: var(--text-2); }
.chart-value { font-size: var(--text-lg); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.chart svg { width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 10px; font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: var(--accent-soft); stroke: none; }
.chart .series-2 { stroke-opacity: 0.7; stroke-dasharray: 5 3; }
.chart .series-3 { stroke-opacity: 0.45; stroke-dasharray: 2 3; }
.chart .ref-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .ref-text { fill: var(--muted); font-size: 10px; font-family: var(--font-sans); }
.chart .cross { stroke: var(--border-strong); stroke-width: 1; }
.chart .cross-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-tip { position: absolute; top: 28px; z-index: 5; pointer-events: none; min-width: 120px; padding: var(--s-2) var(--s-3); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-size: var(--text-xs); color: var(--text-2); font-variant-numeric: tabular-nums; }
.chart-tip strong { color: var(--text); font-weight: 600; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--s-3); font-size: var(--text-xs); color: var(--muted); }
.chart-legend i { display: inline-block; width: 14px; height: 0; margin-right: 6px; vertical-align: middle; border-top: 2px solid var(--accent); }
.chart-legend i.series-2 { border-top-style: dashed; opacity: 0.7; }
.chart-legend i.series-3 { border-top-style: dotted; opacity: 0.6; }
.chart-legend i.ref { border-top: 1px dashed var(--muted); }
.chart .series-dot { fill: var(--accent); stroke: none; }
.chart .series-dot.series-2 { fill-opacity: 0.7; }
.chart .series-dot.series-3 { fill-opacity: 0.45; }
.sparkline { width: 100%; height: 44px; display: block; overflow: visible; }
.sparkline .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.sparkline .spark-area { fill: var(--accent-soft); }
@media (min-width: 861px) {
  .app-shell { background: linear-gradient(to right, var(--bg-subtle) 247px, var(--border) 247px, var(--border) 248px, var(--bg) 248px); }
}
