/* Keystone DNS design system.
   Tokens first, then primitives, then components. Every colour used by a
   component comes from a token so themes and dark mode stay consistent.
   State is never conveyed by colour alone: badges carry a glyph and text. */

/* ---------- Tokens ---------- */
:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;

  --fs-xs: 0.75rem;   --fs-sm: 0.8125rem; --fs-md: 0.875rem;
  --fs-lg: 1rem;      --fs-xl: 1.25rem;   --fs-2xl: 1.625rem;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-pill: 999px;
  --control-h: 36px; --control-h-sm: 28px;
  --sidebar-w: 248px; --sidebar-w-collapsed: 60px; --topbar-h: 56px;
  --ease: cubic-bezier(.2, .7, .3, 1);

  /* light surfaces */
  --bg: #f5f6f7; --surface: #ffffff; --surface-2: #f0f2f3; --surface-3: #e8ebed;
  --border: #e0e4e7; --border-strong: #c5ccd2;
  --text: #13181c; --text-2: #46515b; --text-3: #66727d;
  --shadow-sm: 0 1px 2px rgb(16 24 32 / .06);
  --shadow-md: 0 4px 12px rgb(16 24 32 / .08), 0 1px 2px rgb(16 24 32 / .06);
  --shadow-lg: 0 24px 56px rgb(16 24 32 / .22), 0 2px 6px rgb(16 24 32 / .10);
  --scrim: rgb(10 14 17 / .55);

  /* accent: emerald */
  --accent: #047857; --accent-hover: #065f46; --accent-contrast: #ffffff;
  --accent-soft: #e2f4ed; --accent-text: #046349; --focus: #10b981;

  /* status */
  --ok: #046349; --ok-soft: #e2f4ed;
  --warn: #8a5a06; --warn-soft: #fcf1d6;
  --danger: #b42318; --danger-hover: #912018; --danger-soft: #fde7e4;
  --info: #1a5ea6; --info-soft: #e5effa;
  --neutral-soft: #eceff1;

  /* navigation is charcoal in both colour schemes */
  --nav-bg: #111518; --nav-border: #20262b; --nav-text: #b3bcc4; --nav-text-dim: #7b8690;
  --nav-hover: #1b2126; --nav-active: #1f262b; --nav-active-text: #ffffff;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1012; --surface: #14181b; --surface-2: #1a1f23; --surface-3: #222830;
  --border: #252b30; --border-strong: #38414a;
  --text: #e7ebee; --text-2: #a9b2ba; --text-3: #818b95;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-md: 0 4px 14px rgb(0 0 0 / .45);
  --shadow-lg: 0 24px 56px rgb(0 0 0 / .6);
  --scrim: rgb(0 0 0 / .65);
  --accent: #34d399; --accent-hover: #5fe0b0; --accent-contrast: #04140e;
  --accent-soft: #0f2a20; --accent-text: #5fe0b0; --focus: #34d399;
  --ok: #5fe0b0; --ok-soft: #0f2a20;
  --warn: #f2c15a; --warn-soft: #2e2410;
  --danger: #ff8a7a; --danger-hover: #ffa799; --danger-soft: #34150f;
  --info: #7db8f5; --info-soft: #11243a;
  --neutral-soft: #1f252a;
  color-scheme: dark;
}

/* optional accents; each defines light values, then dark overrides */
:root[data-accent="amber"]  { --accent: #a15c07; --accent-hover: #854a0e; --accent-soft: #fdf0d9; --accent-text: #8a4f08; --focus: #f59e0b; }
:root[data-accent="purple"] { --accent: #6d3fc4; --accent-hover: #5a32a3; --accent-soft: #efe8fb; --accent-text: #5a32a3; --focus: #8b5cf6; }
:root[data-accent="ocean"]  { --accent: #0b68a8; --accent-hover: #09558a; --accent-soft: #e3f0fa; --accent-text: #09558a; --focus: #0ea5e9; }
:root[data-theme="dark"][data-accent="amber"]  { --accent: #f5b041; --accent-hover: #f8c56f; --accent-contrast: #1b1203; --accent-soft: #2e2410; --accent-text: #f8c56f; }
:root[data-theme="dark"][data-accent="purple"] { --accent: #b497f5; --accent-hover: #c9b3f8; --accent-contrast: #140b28; --accent-soft: #231a3a; --accent-text: #c9b3f8; }
:root[data-theme="dark"][data-accent="ocean"]  { --accent: #5cb8f0; --accent-hover: #86cbf5; --accent-contrast: #04131e; --accent-soft: #10273a; --accent-text: #86cbf5; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs-md)/1.5 var(--font-sans);
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
h2 { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: var(--fs-lg); font-weight: 600; }
a { color: var(--accent-text); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--font-mono); font-size: .94em; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--text-2); } .subtle { color: var(--text-3); font-size: var(--fs-sm); }
.tnum { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* layout helpers */
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--sp-4); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3, .cols-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 720px) { .cols-2, .cols-4 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns .18s var(--ease); }
.shell[data-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--nav-bg); color: var(--nav-text); border-right: 1px solid var(--nav-border); overflow: hidden;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); height: var(--topbar-h); padding: 0 var(--sp-4); color: #fff; flex-shrink: 0; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-contrast); font-weight: 750; flex-shrink: 0; }
.brand-name { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand-name small { display: block; font-size: 10px; font-weight: 500; letter-spacing: .12em; color: var(--nav-text-dim); text-transform: uppercase; }
.console-version { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 3px 8px; padding: 8px var(--sp-4); border-top: 1px solid var(--nav-border); color: var(--nav-text-dim); font-size: 11px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.login-version { margin: 0; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; text-align: center; }
.shell[data-collapsed="true"] .console-version { justify-content: center; padding-inline: 2px; }
.shell[data-collapsed="true"] .console-build { display: none; }
.nav-scroll { flex: 1; overflow-y: auto; padding: var(--sp-2); scrollbar-width: thin; scrollbar-color: var(--nav-border) transparent; }
.nav-group { padding: var(--sp-4) var(--sp-3) var(--sp-1); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--nav-text-dim); white-space: nowrap; }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; height: 34px; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--nav-text);
  text-decoration: none; text-align: left; white-space: nowrap; cursor: pointer; position: relative;
}
.nav-item:hover { background: var(--nav-hover); color: #fff; }
.nav-item[aria-current="page"] { background: var(--nav-active); color: var(--nav-active-text); font-weight: 550; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .9; }
.nav-help-heading { display: flex; gap: 2px; }
.nav-help-heading > a { flex: 1; min-width: 0; }
.nav-help-heading .nav-help-toggle { flex: 0 0 28px; justify-content: center; padding: 0; }
.nav-help-subitem { padding-inline-start: 40px; font-size: var(--fs-sm); }
.sidebar-foot { padding: var(--sp-2); border-top: 1px solid var(--nav-border); }
.shell[data-collapsed="true"] :is(.brand-name, .nav-group, .nav-label) { display: none; }
.shell[data-collapsed="true"] .nav-item { justify-content: center; padding: 0; }
@media (min-width: 861px) {
  .shell[data-collapsed="true"] :is(.nav-help-toggle, .nav-help-submenu) { display: none; }
}

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-6); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-3); font-size: var(--fs-sm); min-width: 0; }
.crumbs strong { color: var(--text); font-weight: 600; }
#tenant-switch { width: auto; max-width: 220px; }
.page { width: 100%; max-width: 1440px; margin: 0 auto; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-head > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.eyebrow { font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--accent-text); margin-bottom: var(--sp-1); }
.page-head p { color: var(--text-2); margin-top: var(--sp-1); max-width: 70ch; }
@media (max-width: 860px) {
  .shell, .shell[data-collapsed="true"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .2s var(--ease); }
  .shell[data-mobile-open="true"] .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .topbar, .page { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}
@media (max-width: 560px) {
  .topbar { height: auto; min-height: var(--topbar-h); flex-wrap: wrap; gap: var(--sp-2); padding-block: var(--sp-2); }
  .topbar .crumbs { flex-basis: calc(100% - var(--control-h) - var(--sp-2)); }
  #tenant-switch { max-width: min(220px, 32vw); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); font-weight: 550; font-size: var(--fs-md); white-space: nowrap;
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, box-shadow .12s; box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.ks-icon { flex: none; vertical-align: middle; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #2a0703; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-link { height: auto; padding: 2px 4px; border: 0; background: none; box-shadow: none; color: var(--accent-text); font-weight: 550; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-sm { height: var(--control-h-sm); padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn[data-loading="true"] { color: transparent; position: relative; pointer-events: none; }
.btn[data-loading="true"]::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-3); border-top-color: transparent; animation: spin .7s linear infinite; }
.btn-primary[data-loading="true"]::after { border-color: var(--accent-contrast); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field-heading { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field-heading > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field-help-wrap { position: relative; display: inline-flex; align-items: center; }
.field-help-button { width: 1.2rem; height: 1.2rem; border-radius: 50%; border: 1px solid currentColor; color: var(--accent-text); background: transparent; font-size: 0.72rem; cursor: help; line-height: 1; padding: 0; }
.field-help-popover { display: grid; gap: 6px; visibility: hidden; position: absolute; z-index: 20; inset-block-start: 100%; inset-inline-start: 0; width: min(17rem, 70vw); padding: 0.65rem; color: var(--text); background: var(--surface, var(--bg)); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px #0004; font-size: var(--fs-sm); font-weight: 400; }
.field-help-wrap:is(:hover, :focus-within) .field-help-popover { visibility: visible; }
.help-topics { columns: 18rem; margin: 0; padding-inline-start: 1.25rem; }
.help-topics li { margin-block: 0.35rem; break-inside: avoid; }
.help-topic { scroll-margin-top: 6rem; }
.help-screenshots { margin-top: 0.9rem; }
.help-screenshots figure { margin: 0; }
.help-screenshots img { max-width: 100%; height: auto; display: block; border: 1px solid var(--border); border-radius: 8px; }
.help-screenshots figcaption { margin-top: 0.35rem; }
.api-guide { width: min(100%, 58rem); min-width: 0; line-height: 1.6; }
.api-guide h2 { scroll-margin-top: 6rem; margin-block: var(--sp-6) var(--sp-3); font-size: var(--fs-lg); color: var(--accent-text); }
.api-guide h3, .api-guide p, .api-guide pre, .api-guide table { margin-block: 0 var(--sp-3); }
.api-guide ul, .api-guide ol { margin-block: 0 var(--sp-3); padding-inline-start: 1.6em; }
.api-guide li + li { margin-top: var(--sp-1); }
.api-guide nav { margin-bottom: var(--sp-5); padding: var(--sp-3); background: var(--accent-soft); border-radius: var(--radius-md); }
.api-guide nav ul { columns: 16rem; margin: 0; }
.api-guide nav li { break-inside: avoid; }
.api-code-example {
  --syntax-keyword: #5932a1; --syntax-string: #15623e; --syntax-number: #884500;
  --syntax-name: #075782; --syntax-variable: #8e2559; --syntax-comment: #536476;
  min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface);
}
:root[data-theme="dark"] .api-code-example {
  --syntax-keyword: #c5a6ff; --syntax-string: #82d5ae; --syntax-number: #f4bf76;
  --syntax-name: #83caff; --syntax-variable: #f1a8ce; --syntax-comment: #97a9ba;
}
.api-guide .api-code-example { margin-bottom: var(--sp-4); }
.api-code-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); color: var(--accent-text); background: var(--accent-soft); font-size: var(--fs-sm); font-weight: 600; }
.api-code-example pre { margin: 0; max-width: 100%; overflow-x: auto; padding: var(--sp-3); color: var(--text); font-size: var(--fs-sm); }
.api-code-example .syntax-keyword { color: var(--syntax-keyword); }
.api-code-example .syntax-string { color: var(--syntax-string); }
.api-code-example .syntax-constant { color: var(--syntax-number); }
.api-code-example :is(.syntax-support, .syntax-entity, .syntax-storage) { color: var(--syntax-name); }
.api-code-example .syntax-variable { color: var(--syntax-variable); }
.api-code-example .syntax-comment { color: var(--syntax-comment); }
.api-guide :not(pre) > code { overflow-wrap: anywhere; }
.api-guide table { width: 100%; table-layout: fixed; border-collapse: collapse; overflow-wrap: anywhere; }
.api-guide th:first-child { width: 28%; }
.api-guide th, .api-guide td { padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); text-align: start; vertical-align: top; }
.api-guide th { color: var(--accent-text); background: var(--accent-soft); }
.rule-match-input { flex: 1 1 22rem; min-width: min(17rem, 100%); }
.field .req { color: var(--danger); margin-left: 2px; }
.help { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.45; }
.field-error { font-size: var(--fs-xs); color: var(--danger); display: flex; gap: 6px; align-items: flex-start; }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: 7px 11px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); transition: border-color .12s, box-shadow .12s;
}
.textarea { resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-group .addon { display: flex; align-items: center; padding: 0 11px; background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 34px; }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.switch { appearance: none; width: 36px; height: 20px; border-radius: var(--radius-pill); background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: translate .15s var(--ease); }
.switch:checked { background: var(--accent); }
.switch:checked::after { translate: 16px 0; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); }
.segmented button { height: 28px; padding: 0 12px; border: 0; border-radius: 5px; background: none; color: var(--text-2); font-weight: 550; cursor: pointer; }
.segmented button[aria-pressed="true"], .segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.repeat-row { display: flex; align-items: flex-start; gap: var(--sp-2); }
.repeat-row .idx { width: 22px; height: var(--control-h); display: grid; place-items: center; color: var(--text-3); font-size: var(--fs-sm); flex-shrink: 0; }
.counter { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.counter[data-over="true"] { color: var(--danger); font-weight: 600; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.card-body { padding: var(--sp-5); }
.card-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.stat { padding: var(--sp-4) var(--sp-5); }
.stat-label { font-size: var(--fs-sm); color: var(--text-2); }
.stat-value { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -.02em; line-height: 1.25; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-note { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.kv { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: 10px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; text-align: right; min-width: 0; }
.activity-entry { overflow-wrap: anywhere; }
.activity-heading { align-items: flex-start; }
.activity-heading .badge { flex: none; }

.callout { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-md); background: var(--surface-2); font-size: var(--fs-sm); line-height: 1.55; }
.callout svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.callout > div { min-width: 0; overflow-wrap: anywhere; }
.callout-info { border-left-color: var(--info); } .callout-info svg { color: var(--info); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); } .callout-warn svg { color: var(--warn); }
.callout-danger { border-left-color: var(--danger); background: var(--danger-soft); } .callout-danger svg { color: var(--danger); }
.callout-ok { border-left-color: var(--ok); background: var(--ok-soft); } .callout-ok svg { color: var(--ok); }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--radius-pill); background: var(--neutral-soft); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; }
.type-tag { display: inline-grid; place-items: center; min-width: 52px; height: 22px; padding: 0 7px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-text); font: 650 11px/1 var(--font-mono); letter-spacing: .02em; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); text-align: left; }
.table th { padding: 9px var(--sp-4); font-weight: 600; border-bottom: 1px solid var(--border); }
.table thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-size: var(--fs-xs); letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.table tbody th { overflow-wrap: anywhere; }
.table th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.table td { padding: 11px var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table tr[aria-selected="true"] { background: var(--accent-soft); }
.table tr[data-disabled="true"] td { color: var(--text-3); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-sm); }
.toolbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); }
.bulkbar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-sm); font-weight: 550; }

/* ---------- Accordion ---------- */
.accordion { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.accordion + .accordion { margin-top: var(--sp-2); }
.record-table-wrap { max-height: min(34rem, 65vh); overflow: auto; }
.record-table-wrap thead th { position: sticky; top: 0; z-index: 1; }
.record-pages { flex-wrap: wrap; }
.record-pages .toolbar { padding: 0; }
.acc-head { display: flex; align-items: center; }
.acc-trigger { flex: 1; display: flex; align-items: center; gap: var(--sp-3); min-width: 0; min-height: 48px; padding: 0 var(--sp-4); border: 0; background: none; cursor: pointer; text-align: left; font-weight: 600; }
.acc-trigger:hover { background: var(--surface-2); }
.acc-trigger .chev { flex: none; width: 16px; height: 16px; color: var(--text-3); transition: rotate .15s var(--ease); }
.acc-trigger[aria-expanded="true"] .chev { rotate: 90deg; }
.acc-desc { color: var(--text-3); font-weight: 400; font-size: var(--fs-sm); }
.acc-actions { padding-right: var(--sp-3); }
.acc-panel { border-top: 1px solid var(--border); }

/* ---------- Dialog ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--sp-5); background: var(--scrim); animation: fade .14s ease-out; }
.dialog { width: min(760px, 100%); max-height: min(92dvh, 900px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); animation: rise .18s var(--ease); }
.dialog-sm { width: min(460px, 100%); } .dialog-lg { width: min(980px, 100%); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6) var(--sp-4); border-bottom: 1px solid var(--border); }
.dialog-head p { color: var(--text-2); font-size: var(--fs-sm); margin-top: 2px; }
.dialog-body { padding: var(--sp-5) var(--sp-6); overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-4); }
.dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.dialog-foot .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); margin: 0; }
.fieldset > legend { padding: 0 var(--sp-2); font-weight: 600; font-size: var(--fs-sm); }
.error-summary { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--danger); border-radius: var(--radius-md); background: var(--danger-soft); color: var(--danger); font-size: var(--fs-sm); }
.error-summary ul { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .dialog-head, .dialog-body, .dialog-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); } .acc-desc { display: none; } .segmented { flex-wrap: wrap; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.985); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 80; display: flex; flex-direction: column; gap: var(--sp-2); width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--text-3); border-radius: var(--radius-md); box-shadow: var(--shadow-md); font-size: var(--fs-sm); animation: rise .18s var(--ease); }
.toast-ok { border-left-color: var(--ok); } .toast-danger { border-left-color: var(--danger); } .toast-warn { border-left-color: var(--warn); }
.toast strong { display: block; }

/* ---------- Menus, tabs, misc ---------- */
.menu { position: absolute; z-index: 50; min-width: 200px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.menu-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: 5px; background: none; text-align: left; cursor: pointer; white-space: nowrap; }
.menu-item:hover, .menu-item[data-active="true"] { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--border); }
.tabs { display: flex; gap: var(--sp-5); border-bottom: 1px solid var(--border); }
.tab { height: 40px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--text-2); font-weight: 550; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-xs); font-weight: 700; flex-shrink: 0; }
.kbd { padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); font: 500 11px/1.6 var(--font-mono); color: var(--text-2); }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-10) var(--sp-5); text-align: center; color: var(--text-2); }
.empty svg { width: 28px; height: 28px; color: var(--text-3); }
.skeleton { border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.progress { height: 6px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.codeblock { padding: var(--sp-4); border-radius: var(--radius-md); background: #0f1316; color: #d7e0e6; font: 400 var(--fs-sm)/1.6 var(--font-mono); overflow-x: auto; white-space: pre; border: 1px solid var(--nav-border); }
.steps { display: flex; flex-direction: column; gap: var(--sp-2); list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-md); }
.step-num { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); font-weight: 700; flex-shrink: 0; }
.step[data-state="done"] .step-num { background: var(--ok-soft); color: var(--ok); }
.step[data-state="current"] { border-color: var(--accent); } .step[data-state="current"] .step-num { background: var(--accent); color: var(--accent-contrast); }
.diff-add { background: var(--ok-soft); color: var(--ok); } .diff-del { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.draftbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); flex-wrap: wrap; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.draftbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
@media (max-width: 360px) {
  .draftbar { padding-inline: var(--sp-2); }
  .draftbar-actions { gap: var(--sp-1); }
  .draftbar-actions .btn { padding-inline: 7px; }
}

/* command palette */
.palette { width: min(620px, 100%); align-self: start; margin-top: 12vh; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.palette input { width: 100%; height: 52px; padding: 0 var(--sp-5); border: 0; border-bottom: 1px solid var(--border); background: none; font-size: var(--fs-lg); outline: none; }
.palette-list { max-height: 50vh; overflow-y: auto; padding: 6px; }

/* charts (inline SVG) */
.chart { width: 100%; height: 200px; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart .bar { fill: var(--accent); }
.chart text { fill: var(--text-3); font: 11px var(--font-sans); }

/* auth pages */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-aside { background: var(--nav-bg); color: var(--nav-text); padding: var(--sp-10); display: flex; flex-direction: column; justify-content: space-between; }
.auth-aside h2 { color: #fff; font-size: 2rem; line-height: 1.15; letter-spacing: -.025em; max-width: 16ch; }
.auth-main { display: grid; place-items: center; padding: var(--sp-6); }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: var(--sp-5); }
.login-password { position: relative; }
.login-password .input { padding-inline-end: 48px; }
.login-password .input::-ms-reveal { display: none; }
.login-password .login-password-toggle { position: absolute; inset-block: 2px; inset-inline-end: 2px; width: 40px; min-height: 0; padding: 0; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth-aside { display: none; } }
