/*
 * rein-web styles, following the AchieveGo design language (rein-admin/.claude/skills/achievego-frontend-design).
 *
 * Tokens come in three layers:
 *   1. The public theme tokens  --bg --panel --line --text --muted --accent --ok --bad --warn --code --radius --font
 *      These names are a contract: plugin UIs use them, and a tenant's manifest theme (ui.theme.light / .dark) overrides
 *      them (shell.js sets them on <html>). Their defaults are the AchieveGo palette.
 *   2. The AchieveGo semantic tokens (--surface, --border, --surface-2, --success, --danger-soft, --radius-md, --fs-*,
 *      --space-*, --shadow-*, --z-* …), DERIVED from layer 1 wherever the meaning overlaps, so a tenant theme flows
 *      into every component. Component rules use only these (and never a raw hex).
 *   3. --ag-* primitives: only for values no public token covers (the AI violet, the mono font, the inverse surfaces).
 * Dark mode: tenants' themes have a real dark variant, so the public tokens keep a prefers-color-scheme: dark default
 * (a deliberate deviation from the design system's "no dark mode", decided for rein-web).
 *
 * Bare element styles (button, input, details, pre …) sit in :where() so any class wins over them; plugin UIs rely on
 * them and on the classes marked "plugin contract" below. The rest are the design system's classes (.button, .panel,
 * .tabs, .data-table, .field, .badge, .notice, .empty, .loading, .list-rows …), for 系统管理 and plugins alike.
 */
:root {
  color-scheme: light;

  /* ---- 1. public theme tokens (contract; tenant themes override them) ---- */
  --bg: #ffffff;
  --panel: #ffffff;
  --line: #eaeaea;
  --text: #000000;
  --muted: #666666;
  --accent: #0070f3;
  --ok: #16a34a;
  --bad: #ea580c;
  --warn: #f59e0b;
  --code: #f5f5f5;
  --radius: 8px;
  --font: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* ---- 3. primitives without a public token ---- */
  --ag-white: #ffffff;
  --ag-gray-900: #111111;
  --ag-gray-950: #0a0a0a;
  --ag-violet-500: #7c5cff;
  --ag-violet-700: #5b3fd6;
  --ag-font-mono: "Geist Mono", "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  /* ---- 2. semantic tokens, derived from the public ones ---- */
  /* surfaces */
  --surface: var(--panel);
  --surface-subtle: color-mix(in srgb, var(--text) 2%, var(--panel));
  --surface-2: color-mix(in srgb, var(--text) 4%, var(--panel));
  --surface-3: color-mix(in srgb, var(--text) 7%, var(--panel));
  /* lines */
  --border: var(--line);
  --border-strong: color-mix(in srgb, var(--text) 10%, var(--line));
  /* text: three greys + inverse (--text and --muted are public tokens) */
  --subtle: color-mix(in srgb, var(--muted) 60%, var(--panel));
  --text-inverse: var(--ag-white);
  /* the one accent; -strong leans towards --text (darker on light, lighter on dark) */
  --accent-strong: color-mix(in srgb, var(--accent) 85%, var(--text));
  --accent-wash: color-mix(in srgb, var(--accent) 4%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 28%, transparent);
  /* status colours: real states only */
  --success: var(--ok);
  --success-strong: color-mix(in srgb, var(--success) 85%, var(--text));
  --success-wash: color-mix(in srgb, var(--success) 4%, transparent);
  --success-soft: color-mix(in srgb, var(--success) 10%, transparent);
  --success-line: color-mix(in srgb, var(--success) 28%, transparent);
  --warning: var(--warn);
  --warning-strong: color-mix(in srgb, var(--warning) 65%, var(--text));
  --warning-wash: color-mix(in srgb, var(--warning) 4%, transparent);
  --warning-soft: color-mix(in srgb, var(--warning) 10%, transparent);
  --warning-line: color-mix(in srgb, var(--warning) 28%, transparent);
  --danger: var(--bad);
  --danger-strong: color-mix(in srgb, var(--danger) 85%, var(--text));
  --danger-wash: color-mix(in srgb, var(--danger) 4%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 10%, transparent);
  --danger-line: color-mix(in srgb, var(--danger) 28%, transparent);
  /* AI signal: marks machine output */
  --ai: var(--ag-violet-500);
  --ai-strong: var(--ag-violet-700);
  --ai-wash: color-mix(in srgb, var(--ai) 4%, transparent);
  --ai-soft: color-mix(in srgb, var(--ai) 10%, transparent);
  --ai-line: color-mix(in srgb, var(--ai) 28%, transparent);
  /* fixed inverse surface: sign-in screen only (not a theme) */
  --invert-bg: var(--ag-gray-900);
  --invert-bg-2: var(--ag-gray-950);
  --invert-line: rgba(255, 255, 255, 0.15);
  --invert-grid: rgba(255, 255, 255, 0.06);
  --invert-muted: rgba(255, 255, 255, 0.64);
  --overlay-scrim: rgba(0, 0, 0, 0.48);
  /* fonts (--font is public) */
  --mono: var(--ag-font-mono);
  /* type scale */
  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 20px;
  --fs-3xl: 24px;
  --fs-4xl: 28px;
  --fs-5xl: 32px;
  /* spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  /* radii, from the public --radius (8px → 4 / 6 / 8 / 12) */
  --radius-xs: calc(var(--radius) / 2);
  --radius-sm: calc(var(--radius) - 2px);
  --radius-md: var(--radius);
  --radius-lg: calc(var(--radius) + 4px);
  --radius-pill: 999px;
  /* shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.12);
  --shadow-drawer: -12px 0 32px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.26);
  /* layers */
  --z-sticky: 100;
  --z-popover: 300;
  --z-drawer-backdrop: 1040;
  --z-drawer: 1050;
  --z-modal: 1100;
  --z-modal-top: 1200;
  --z-screen: 1300;
  --z-floating: 1500;
  --z-tooltip: 2000;
}
/* dark defaults of the public tokens; a tenant theme's `dark` overrides them the same way */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0a0a0a; --panel: #111111; --line: #2a2a2a; --text: #ededed; --muted: #a1a1a1;
    --accent: #3291ff; --ok: #3fb950; --bad: #fb923c; --warn: #fbbf24; --code: #1c1c1c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

/* ---- baseline ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-width: 320px;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
:where(a) { color: var(--accent); text-decoration: none; }
:where(a:hover) { color: var(--accent-strong); }
:is(button, a, summary, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* the shell's own chrome and built-in pages get the design system's heading scale; plugin areas keep browser defaults */
:where(.topnav, .sidebar, .main-body > .builtin, .empty-view, .auth-screen) :is(h1, h2, h3, p) { margin: 0; }
:where(.topnav, .sidebar, .main-body > .builtin, .empty-view, .auth-screen) h1 { font-size: var(--fs-5xl); line-height: 1.15; font-weight: 600; letter-spacing: -0.02em; }
:where(.main-body > .builtin) h2 { font-size: var(--fs-md); line-height: 1.25; font-weight: 600; }
:where(.main-body > .builtin) h3 { font-size: var(--fs-base); line-height: 1.35; font-weight: 600; }

/* ---- bare elements (plugin contract): button like .button, button.primary like .button.primary ---- */
:where(button) {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 32px; padding: 0 var(--space-3); margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-base); font-weight: 500; line-height: 1.2; white-space: nowrap; cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
:where(button:hover) { border-color: var(--border-strong); background: var(--surface-2); }
:where(button.primary) { border-color: var(--accent); background: var(--accent); color: var(--text-inverse); }
:where(button.primary:hover) { border-color: var(--accent-strong); background: var(--accent-strong); }
:where(button:disabled) { cursor: not-allowed; opacity: .48; color: var(--subtle); border-color: var(--border); background: var(--surface-2); }
:where(input, select, textarea) {
  max-width: 100%; margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-base); outline: none;
}
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"]), select) { min-height: 32px; padding: 0 var(--space-3); }
:where(input[type="checkbox"], input[type="radio"]) { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
:where(select) {
  appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
:where(textarea) { min-height: 82px; padding: 10px; line-height: 1.45; resize: vertical; }
:where(input, select, textarea):focus { border-color: var(--accent); box-shadow: none; }
:where(input, textarea)::placeholder { color: var(--subtle); }
:where(details) { margin: 6px 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
:where(details > summary) { cursor: pointer; }
:where(pre) {
  margin: 6px 0 0; padding: var(--space-2) 10px; border-radius: var(--radius-sm); background: var(--code);
  font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.55; white-space: pre-wrap; word-break: break-all;
}
:where(code) { font-family: var(--mono); font-size: 0.92em; }
:where(label) { color: var(--muted); font-size: var(--fs-sm); }

/* ---- small classes (plugin contract) ---- */
.muted { color: var(--muted); font-size: var(--fs-sm); }
.ok { color: var(--success); }
.bad, .err { color: var(--danger); }
.warnline { color: var(--warning-strong); }
.pill {
  display: inline-flex; align-items: center; min-height: 20px; padding: 0 var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--muted); font-size: var(--fs-sm); font-weight: 500; line-height: 1.4; white-space: nowrap;
}
.pill.pending { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning-strong); }
.pill.approved { border-color: var(--success-line); background: var(--success-soft); color: var(--success-strong); }
.pill.rejected { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-strong); }
.amount { font-size: var(--fs-2xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: var(--space-3) 0; }
.kv { padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.kv b { display: block; color: var(--muted); font-size: var(--fs-sm); font-weight: 500; }
.kv span { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }
/* approve / reject: the status button tones */
.approve { border-color: var(--success-line); background: var(--success-soft); color: var(--success-strong); }
.approve:hover { border-color: var(--success); background: var(--success-soft); }
.reject { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-strong); }
.reject:hover { border-color: var(--danger); background: var(--danger-soft); }
/* counters: sidebar items, plugin UIs */
.count {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 18px; height: 18px; padding: 0 5px;
  border: 1px solid var(--warning-line); border-radius: var(--radius-pill);
  background: var(--warning-soft); color: var(--warning-strong);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums;
}
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--mono); }
.mono-muted { font-family: var(--mono); font-size: var(--fs-sm); color: var(--muted); }
.dot-sep { color: var(--subtle); }
.warning-text { color: var(--warning-strong); }
.danger-text { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- sign-in (outside the app shell; fixed inverse surface) ---- */
.auth-screen {
  position: fixed; inset: 0; z-index: var(--z-screen); overflow: auto;
  display: grid; place-items: center; padding: var(--space-6) var(--space-4);
  background-color: var(--invert-bg-2);
  background-image: linear-gradient(var(--invert-grid) 1px, transparent 1px), linear-gradient(90deg, var(--invert-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--text-inverse);
}
.auth-form {
  width: min(380px, 100%); display: grid; gap: var(--space-4);
  padding: 28px; border: 1px solid var(--invert-line); border-radius: var(--radius-md);
  background: var(--invert-bg); box-shadow: var(--shadow-popover);
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: var(--fs-base); font-weight: 600; }
.auth-brand .brand-mark { background: var(--text-inverse); color: var(--invert-bg); }
.auth-form h1 { font-size: var(--fs-3xl); margin-top: var(--space-2); }
.auth-hint { color: var(--invert-muted); font-size: var(--fs-sm); line-height: 1.5; margin-top: calc(-1 * var(--space-2)); }
.auth-field { display: grid; gap: 6px; }
.auth-field label { color: var(--invert-muted); }
.auth-field :is(input, select) { width: 100%; min-height: 32px; background-color: var(--invert-bg-2); border-color: var(--invert-line); color: var(--text-inverse); }
.auth-field :is(input, select):focus { border-color: var(--accent); }
.auth-field select { background-image: linear-gradient(45deg, transparent 50%, var(--invert-muted) 50%), linear-gradient(135deg, var(--invert-muted) 50%, transparent 50%); }
.auth-error { color: var(--danger); font-size: var(--fs-sm); line-height: 1.45; }
.auth-error:empty { display: none; }
/* the sign-in page's language buttons (each in its own language), right of the brand */
.auth-lang { display: flex; gap: 2px; margin-left: auto; }
.auth-lang button { min-height: 24px; padding: 0 var(--space-2); border: 1px solid transparent; border-radius: var(--radius-xs); background: transparent; color: var(--invert-muted); font-size: var(--fs-sm); font-weight: 500; }
.auth-lang button:hover { border-color: var(--invert-line); background: transparent; color: var(--text-inverse); }
.auth-lang button[aria-pressed="true"] { border-color: var(--invert-line); background: var(--invert-bg-2); color: var(--text-inverse); }

/* ---- top bar ---- */
.topnav {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  height: 56px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
/* an open menu must cover the sticky mobile nav below the bar */
.topnav:has(.menu:not([hidden])) { z-index: var(--z-popover); }
.topnav-left, .topnav-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topnav-left { flex: 1 1 auto; }
.topnav-right { flex: none; }
.topnav-logo { display: inline-flex; align-items: center; flex: none; color: var(--text); }
.topnav-logo img { display: block; height: 24px; max-width: 120px; object-fit: contain; }
.brand-mark {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px;
  border-radius: var(--radius-xs); background: var(--text); color: var(--surface);
  font-size: var(--fs-sm); font-weight: 700; line-height: 1;
}
.topnav-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-base); font-weight: 600; }
.topnav-slash { flex: none; color: var(--border-strong); font-size: var(--fs-2xl); font-weight: 400; }
.menu-anchor { position: relative; display: flex; min-width: 0; }
.topnav-crumb {
  display: flex; align-items: center; gap: var(--space-2); min-width: 0; max-width: 280px;
  font-size: var(--fs-base); font-weight: 500; white-space: nowrap;
}
.topnav-crumb > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
button.topnav-crumb, .topnav-user, .topnav-lang {
  min-height: 32px; padding: 0 var(--space-2); border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font-size: var(--fs-base); font-weight: 500; cursor: pointer;
}
button.topnav-crumb:hover, .topnav-user:hover, .topnav-lang:hover,
button.topnav-crumb[aria-expanded="true"], .topnav-user[aria-expanded="true"], .topnav-lang[aria-expanded="true"] {
  border-color: transparent; background: var(--surface-2); color: var(--text);
}
.topnav-user { display: flex; align-items: center; gap: var(--space-2); min-width: 0; max-width: 260px; padding-left: var(--space-1); }
/* the language, beside the user: globe + current language */
.topnav-lang { display: flex; align-items: center; gap: 6px; flex: none; }
.topnav-lang-name { white-space: nowrap; }
.topnav-globe { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.topnav-user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topnav-avatar {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px;
  border: 1px solid var(--border); border-radius: 50%; background: var(--surface-2);
  color: var(--muted); font-size: var(--fs-sm); font-weight: 600;
}
.topnav-chevron { flex: none; width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- popover menus (lib/menu.js) ---- */
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-popover);
  display: grid; gap: 2px; min-width: 200px; max-width: min(320px, calc(100vw - 24px)); max-height: min(420px, calc(100vh - 80px)); overflow: auto;
  padding: var(--space-1); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); box-shadow: var(--shadow-popover);
}
.menu.start { right: auto; left: 0; }
.menu-head { display: grid; gap: 2px; padding: var(--space-2) 10px; min-width: 0; }
.menu-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-base); font-weight: 600; }
.menu-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-label { padding: 6px 10px 2px; color: var(--subtle); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; }
.menu-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; min-height: 32px; padding: 0 10px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
  font-size: var(--fs-base); font-weight: 400; text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus, .menu-item:focus-visible { outline: none; border: 0; background: var(--surface-2); color: var(--text); }
.menu-item > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.menu-item .menu-check { margin-left: auto; color: var(--accent); visibility: hidden; }
.menu-item[aria-checked="true"] { font-weight: 600; }
.menu-item[aria-checked="true"] .menu-check { visibility: visible; }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }

/* ---- app shell: 232px sidebar + main ---- */
.app-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.sidebar {
  display: flex; flex-direction: column; gap: var(--space-4); min-height: 0; overflow-y: auto;
  padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface);
}
.nav-list { flex: 1; display: grid; align-content: start; gap: 2px; }
.nav-group {
  display: flex; align-items: center; gap: var(--space-2); min-width: 0;
  padding: 6px 10px; color: var(--text); font-size: var(--fs-base); font-weight: 600;
}
/* groups after the first: a hairline above, so each plugin reads as its own block */
.nav-item + .nav-group { margin-top: 10px; padding-top: var(--space-4); border-top: 1px solid var(--border); }
.nav-group-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the items carry their own counts; the group total only shows in the collapsed mobile nav */
.nav-group .count { display: none; margin-left: auto; letter-spacing: 0; }
/* items hang off a rail under their group title; the active one gets a solid marker on the rail */
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 34px; margin-left: 17px; padding: 0 10px;
  border-radius: var(--radius-sm); color: var(--muted); font-size: var(--fs-base); text-decoration: none;
}
.nav-item::before { content: ""; position: absolute; left: -7px; top: -1px; bottom: -1px; width: 1px; background: var(--border-strong); }
.nav-item.active::before { left: -8px; top: 8px; bottom: 8px; width: 3px; border-radius: var(--radius-pill); background: var(--text); }
.nav-item:hover, .nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active { font-weight: 500; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { margin-left: auto; }
.nav-empty { padding: 0 10px; color: var(--subtle); font-size: var(--fs-sm); line-height: 1.5; }
.sidebar-footer { display: grid; gap: 2px; padding: var(--space-3) 10px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--muted); }
.sidebar-footer strong { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }

/* main: the problems strip, then one scrolling body (plugin areas, built-in pages, the empty state) */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-body { flex: 1; min-height: 0; overflow: auto; }
.shell-errors { flex: none; margin: var(--space-3) 28px 0; }
.shell-errors details { margin: 0; padding: 0; border: 0; background: none; }
.shell-errors summary { display: flex; align-items: center; gap: var(--space-2); color: var(--danger-strong); font-weight: 500; list-style: none; }
.shell-errors summary::-webkit-details-marker { display: none; }
.shell-errors summary::before {
  content: ""; flex: none; width: 6px; height: 6px; margin: 0 2px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s ease;
}
.shell-errors details[open] > summary::before { transform: rotate(45deg); }
.shell-errors ul { margin: var(--space-2) 0 0; }

/* plugin slots: full height, the plugin renders its own heading (no shell padding or title) */
.plugin-host, .plugin-area { height: 100%; }
.plugin-area { display: flex; flex-direction: column; }
.plugin-area > .slot { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.plugin-area > .slot > .page { flex: 1; min-height: 0; }
.plugin-status, .slot-err { flex: none; margin: 0; padding: var(--space-3) 28px; }

/* built-in pages (系统管理): the topbar holds the one page title and the page-level actions */
.builtin { padding: 0 28px 34px; }
.builtin > .page { display: grid; gap: var(--space-4); align-content: start; min-width: 0; }
.builtin > .page > * { min-width: 0; }
.topbar { display: flex; flex-direction: column; gap: 6px; margin: 22px 0 20px; }
.topbar-top { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.topbar-heading { display: grid; gap: var(--space-1); min-width: 0; }
.topbar-heading h1 { overflow-wrap: anywhere; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.topbar-actions input[type="search"] { width: 220px; }
.topbar-actions select { width: auto; min-width: 120px; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }
.page-subtitle { max-width: 860px; color: var(--muted); font-size: var(--fs-base); line-height: 1.55; }

/* the empty state: no plugin page for this user */
.empty-view { padding: 28px; }
.empty.empty-page { min-height: min(420px, calc(100vh - 160px)); gap: var(--space-3); padding: var(--space-8) var(--space-6); }
.empty-title { color: var(--text); font-size: var(--fs-4xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.empty-reason { max-width: 560px; color: var(--muted); font-size: var(--fs-base); line-height: 1.6; }
.empty-page .notice { max-width: 640px; text-align: left; }

/* ---- panels ---- */
.panel { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-body { padding: 14px; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  min-height: 58px; padding: var(--space-4) 18px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-wrap: wrap;
}
.panel-header > div:first-child:not(.panel-title):has(> h2, > .panel-title) { display: grid; gap: var(--space-1); min-width: 0; }
.panel-header > div:first-child > .button { justify-self: start; margin-bottom: var(--space-1); }
.panel-header h2 { margin: 0; font-size: var(--fs-md); font-weight: 600; }
.panel-header p, .section-subtitle { margin: 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.45; }
.panel-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.panel-actions select { width: auto; min-width: 120px; }
.panel-actions input[type="search"] { width: 200px; }
.panel-title { display: flex; align-items: center; gap: var(--space-2); }
.danger-zone { border-color: var(--danger-line); background: var(--danger-wash); }
.panel :is(.loading, .empty) { border: 0; border-radius: 0; }

/* ---- divider lists: the one list form ---- */
.list-rows { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: 12px 20px; min-height: 60px; border-bottom: 1px solid var(--border);
}
.list-rows > .list-row:last-child { border-bottom: none; }
.list-row[role="button"] { cursor: pointer; }
.list-row[role="button"]:hover { background: var(--surface-subtle); }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { display: flex; align-items: center; gap: var(--space-2); min-width: 0; font-size: var(--fs-md); font-weight: 400; margin-bottom: var(--space-1); }
.list-row-title > strong { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 500; }
.list-row-title > :is(.badge, .mono-muted) { flex-shrink: 0; }
.list-row-meta { display: flex; align-items: center; gap: 6px; min-width: 0; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; font-size: var(--fs-sm); color: var(--muted); }
.list-row-meta > span { flex-shrink: 0; }
.list-row-meta > span:last-child { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-row-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.list-row-actions .button.ghost { color: var(--muted); font-weight: 500; border-color: transparent; padding: 4px 10px; }
.list-row-actions .button.ghost:hover { color: var(--text); background: var(--surface-2); }
.account-group { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; padding: 0; margin: 0; }
.account-group > .account-group-head { padding: 10px 14px; }
.account-group > .list-rows { border-top: 1px solid var(--border); }
.account-group + .account-group { margin-top: var(--space-3); }
.account-group-head { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; list-style: none; user-select: none; padding: 4px 0; }
.account-group-head::-webkit-details-marker { display: none; }
.account-group-head::before { content: "▸"; font-size: var(--fs-xs); color: var(--muted); transition: transform .15s ease; }
.account-group[open] > .account-group-head::before { transform: rotate(90deg); }
.account-group-head h3 { margin: 0; font-size: var(--fs-base); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.list-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 12px 20px; border-top: 1px solid var(--border); font-size: var(--fs-base); color: var(--muted); }
.list-pagination-info { font-variant-numeric: tabular-nums; }
.list-pagination-buttons { display: flex; gap: var(--space-2); }

/* ---- tables: real multi-column data only ---- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: auto; }
.panel .table-wrap { border: 0; border-radius: 0; }
.data-table { width: 100%; border-collapse: collapse; min-width: 880px; font-size: var(--fs-base); }
.data-table.compact { min-width: 0; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 10px; text-align: left; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table th { color: var(--muted); background: var(--bg); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { padding-left: 20px; }
.data-table th:last-child, .data-table td:last-child { padding-right: 20px; }
.data-table tr.selected td { background: var(--surface-2); }
.data-table tbody tr:hover td { background: var(--surface-subtle); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .nowrap { white-space: nowrap; }
.data-table td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 160px; }
.data-table .row-actions { display: flex; justify-content: flex-end; gap: var(--space-1); flex-wrap: wrap; }

/* ---- buttons: .button + modifiers ---- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  flex: 0 0 auto; max-width: 100%; min-height: 32px; padding: 0 var(--space-4); margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-base); font-weight: 500; line-height: 1.2;
  cursor: pointer; text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.button:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--text-inverse); }
.button.primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); color: var(--text-inverse); }
.button.secondary { background: var(--surface); }
.button.success { border-color: var(--success-line); background: var(--success-soft); color: var(--success-strong); }
.button.warning { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning-strong); }
.button.danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-strong); }
.button:is(.success, .warning, .danger):hover { border-color: currentColor; }
.button.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.button.ghost:hover { background: var(--surface-2); color: var(--text); }
.button.subtle { background: transparent; border-color: transparent; color: var(--muted); }
.button.subtle:hover { background: var(--surface-2); color: var(--text); }
.button.small { min-height: 0; padding: 4px 10px; font-size: var(--fs-sm); }
.button.full { width: 100%; }
.button:disabled, .button[aria-disabled="true"] { cursor: not-allowed; opacity: .48; color: var(--subtle); border-color: var(--border); background: var(--surface-2); }
.button.is-loading::before {
  content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite;
}
.icon-button {
  display: inline-grid; place-items: center; width: 32px; height: 32px; min-height: 0; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent;
  color: var(--muted); font-size: var(--fs-md); cursor: pointer;
}
.icon-button:hover { border-color: transparent; background: var(--surface-2); color: var(--text); }

/* ---- badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--muted); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge.accent { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-strong); }
.badge.success { border-color: var(--success-line); background: var(--success-soft); color: var(--success-strong); }
.badge.warning { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning-strong); }
.badge.danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-strong); }
.badge.ai { border-color: var(--ai-line); background: var(--ai-soft); color: var(--ai-strong); }

/* ---- forms ---- */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > :is(input:not([type="checkbox"], [type="radio"]), select, textarea) { width: 100%; }
.field.inline { grid-template-columns: auto minmax(160px, 220px); align-items: center; gap: 10px; }
.field-hint { margin: 0; color: var(--subtle); font-size: var(--fs-xs); line-height: 1.45; }
.field-hint strong { color: var(--muted); font-weight: 600; }
.form-grid { display: grid; gap: 10px; }
.form-narrow { max-width: 640px; }
.form-stack { display: grid; gap: var(--space-3); align-content: start; }
.form-row { display: grid; gap: var(--space-3); }
.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row.compact { gap: var(--space-2); }
.form-actions { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.check-field { display: flex; align-items: center; gap: var(--space-2); min-height: 36px; color: var(--text); font-size: var(--fs-base); cursor: pointer; }
.checkbox-list { display: grid; gap: 2px; max-height: 240px; overflow: auto; padding: var(--space-1); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.checkbox-item { display: flex; align-items: center; gap: var(--space-2); min-height: 32px; padding: 0 var(--space-2); border-radius: var(--radius-xs); color: var(--text); font-size: var(--fs-base); cursor: pointer; }
.checkbox-item:hover { background: var(--surface-2); }

/* ---- tabs (share the button base) ---- */
.tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 0 12px; margin: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent;
  color: var(--muted); font: inherit; font-size: var(--fs-base); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.tab:hover { border-color: transparent; background: var(--surface-2); color: var(--text); }
.tab.active, .tab[aria-selected="true"], .tab[aria-current="page"] { border-color: var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tabs.small .tab { min-height: 0; padding: 4px 10px; font-size: var(--fs-sm); }

/* ---- metrics, key / value, progress ---- */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.metric { min-height: 80px; min-width: 0; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); padding: var(--space-4) var(--space-5); }
.metric span { font-size: var(--fs-sm); font-weight: 500; color: var(--muted); }
.metric strong { font-size: var(--fs-4xl); font-weight: 600; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
/* the design system's .kv (span label, strong value) inside .kv-grid; a bare .kv is the plugin contract above */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-4) 10px; }
.kv-grid > .kv { display: grid; gap: var(--space-1); align-content: start; min-width: 0; padding: 0; border: 0; border-radius: 0; background: none; }
.kv-grid > .kv > span { font-size: var(--fs-sm); color: var(--muted); }
.kv-grid > .kv > strong { font-size: var(--fs-base); font-weight: 500; overflow-wrap: anywhere; }
.progress-track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.progress-fill { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--accent); }
.progress-fill.success { background: var(--success); }
.progress-fill.auto { background: var(--ai); }

/* ---- feedback: notice, empty, loading ---- */
.notice {
  display: grid; gap: 6px; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-subtle);
  color: var(--text); font-size: var(--fs-base); line-height: 1.5; min-width: 0; overflow-wrap: anywhere;
}
.notice.accent { border-color: var(--accent-line); background: var(--accent-wash); }
.notice.success { border-color: var(--success-line); background: var(--success-wash); }
.notice.warning { border-color: var(--warning-line); background: var(--warning-wash); }
.notice.danger { border-color: var(--danger-line); background: var(--danger-wash); }
.notice.danger > p:first-of-type, .notice.danger > strong { color: var(--danger-strong); }
.notice p { margin: 0; }
.notice ul { margin: 0; padding-left: 18px; }
.notice .hint { margin: var(--space-2) 0 0; color: var(--muted); font-size: var(--fs-sm); }
.empty {
  min-height: 96px; display: grid; place-items: center; align-content: center; gap: var(--space-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  color: var(--subtle); font-size: var(--fs-base); text-align: center; padding: 12px;
}
.loading {
  min-height: 96px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2);
  color: var(--muted); font-size: var(--fs-base); padding: 12px;
}
.loading-spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy { opacity: .48; transition: opacity 140ms ease; }
.text-block { padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-subtle); line-height: 1.55; overflow-wrap: anywhere; }
.json-preview { max-height: 420px; overflow: auto; white-space: pre; word-break: normal; }

/* ---- responsive: 820px sidebar → horizontal nav under the top bar, 640px narrower top bar ---- */
@media (max-width: 820px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: auto; min-height: calc(100vh - 56px); }
  .sidebar {
    position: sticky; top: 56px; z-index: var(--z-sticky); overflow-x: auto; overflow-y: hidden;
    flex-direction: row; gap: 0; padding: var(--space-2) var(--space-3); border-right: 0; border-bottom: 1px solid var(--border);
  }
  .nav-list { display: flex; align-items: center; gap: var(--space-1); }
  .sidebar-footer, .nav-empty { display: none; }
  .sidebar:not(:has(.nav-item)) { display: none; }
  /* one plugin: its items say enough; several: each group's title stays as a small label before its items */
  .nav-group { display: none; }
  .nav-list.multi > .nav-group {
    display: flex; flex: none; margin: 0; padding: 0 var(--space-1) 0 10px; border: 0;
    color: var(--subtle); font-size: var(--fs-xs); letter-spacing: .04em; text-transform: uppercase;
  }
  .nav-list.multi > .nav-group:first-child { padding-left: var(--space-1); }
  .nav-list.multi > .nav-group .count { display: inline-flex; }
  .nav-item { flex: none; min-height: 32px; margin-left: 0; }
  .nav-item::before { display: none; }
  .main-body { overflow: visible; }
  .plugin-host, .plugin-area { height: auto; }
  .shell-errors { margin: var(--space-3) var(--space-4) 0; }
  .plugin-status, .slot-err { padding: var(--space-3) var(--space-4); }
  .builtin { padding: 0 var(--space-4) var(--space-6); }
  .empty-view { padding: var(--space-4); }
  .list-row { flex-direction: column; align-items: stretch; gap: var(--space-2); }
  .list-row-actions { justify-content: flex-end; flex-wrap: wrap; }
  .form-row.two, .form-row.three { grid-template-columns: minmax(0, 1fr); }
  .topbar-actions { width: 100%; }
  .topbar-actions input[type="search"] { flex: 1 1 100%; width: 100%; }
}
@media (max-width: 640px) {
  .topnav { padding: 0 var(--space-3); gap: var(--space-2); }
  .topnav-left { gap: var(--space-2); }
  .topnav-title, .topnav-user-name, .topnav-lang-name { display: none; }
  .topnav-user { padding-right: var(--space-1); }
  .topnav-crumb { max-width: 46vw; }
  .builtin h1, .empty-title { font-size: var(--fs-3xl); }
  .topbar-actions > :is(select, .button) { flex: 1 1 auto; }
  .form-actions .button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  button, .button, .tab, .loading-spinner, .button.is-loading::before { transition: none; animation-duration: 2.4s; }
  .shell-errors summary::before, .account-group-head::before { transition: none; }
}
