/* ==========================================================================
   AI Proxy design system — Scala-first UI refresh
   Loaded after the legacy tokens/portal/console styles; it owns the visual
   language and overrides legacy components without changing template markup.
   ========================================================================== */

:root,
html.light {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f6f8fb;
  --bg-muted: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --text-4: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 24px;
  --text-2xl: 32px;
  --text-3xl: 44px;
  --text-hero: 56px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --container: 1200px;
  --sidebar-width: 236px;
  --sidebar-collapsed: 68px;
  --topbar-height: 64px;
}

html.dark {
  color-scheme: dark;
  --bg: #0b1120;
  --bg-soft: #0f172a;
  --bg-muted: #1a2a42;
  --surface: #121e33;
  --surface-2: #182742;
  --surface-3: #1f2f4c;
  --text: #e8eef8;
  --text-2: #b6c2d4;
  --text-3: #95a6bd;
  --text-4: #7f90a8;
  --border: #2a3b57;
  --border-strong: #3b5075;
  --primary: #6ea8ff;
  --primary-hover: #8bbaff;
  --primary-soft: rgba(110, 168, 255, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.42);
}

html.dark .btn-primary,
html.dark .btn-primary:hover,
html.dark .btn-primary:focus { --btn-fg: #0b1220; color: #0b1220; }

/* Legacy token bridge: old portal/console rules consume --ae-* and --c-* */
:root {
  --ae-bg: var(--bg);
  --ae-fg: var(--text);
  --ae-border: var(--border);
  --ae-muted: var(--text-3);
  --ae-primary: var(--primary);
  --ae-primary-dark: var(--primary-hover);
  --ae-panel: var(--surface);
  --ae-surface-1: var(--surface-2);
  --ae-surface-2: var(--surface-3);
  --ae-surface-3: var(--bg-muted);
  --ae-text: var(--text);
  --ae-text-secondary: var(--text-2);
  --ae-text-tertiary: var(--text-3);
  --ae-shadow: var(--shadow-sm);
  --ae-shadow-lg: var(--shadow);
  --c-ink: var(--text);
  --c-ink-soft: var(--text-2);
  --c-line: var(--border);
  --c-surface: var(--surface);
  --c-canvas: var(--bg-soft);
  --c-radius: var(--radius-md);
  --c-radius-sm: var(--radius);
  --c-topbar-height: var(--topbar-height);
  --c-sidebar-width: var(--sidebar-width);
  --c-sidebar-collapsed: var(--sidebar-collapsed);
  --c-sidebar-bg: var(--surface);
  --c-focus: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

html.dark {
  --c-focus: 0 0 0 3px rgba(110, 168, 255, 0.24);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body::before { content: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img, svg { max-width: 100%; }
code, pre, kbd { font-family: var(--font-mono); }
::selection { background: var(--primary-soft); color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.hidden { display: none !important; }
.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;
}
.container { width: min(var(--container), calc(100% - 40px)); margin-inline: auto; }
.btn {
  --btn-bg: var(--primary); --btn-fg: #fff; --btn-border: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 8px 16px; border: 1px solid var(--btn-border);
  border-radius: var(--radius); background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--text-sm); font-weight: 600; line-height: 1.2; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--btn-fg); }
.btn:active { transform: translateY(1px); }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: var(--text-xs); }
.btn-lg { min-height: 46px; padding: 11px 22px; font-size: var(--text-base); }
.btn-primary { --btn-bg: var(--primary); --btn-border: var(--primary); --btn-fg: #fff; }
.btn-light { --btn-bg: #fff; --btn-border: rgba(255,255,255,.3); --btn-fg: #0f172a; }
.btn-light:hover { background: #f1f5f9; border-color: #f1f5f9; color: #0f172a; }
.btn-outline-light { --btn-bg: transparent; --btn-border: rgba(255,255,255,.42); --btn-fg: #fff; }
.btn-outline-light:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.7); color: #fff; }
.btn-outline-primary { --btn-bg: transparent; --btn-border: var(--border-strong); --btn-fg: var(--text); }
.btn-outline-primary:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.btn-secondary { --btn-bg: var(--surface-2); --btn-border: var(--border); --btn-fg: var(--text-2); }
.btn-secondary:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
.form-control {
  width: 100%; min-height: 40px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  font-size: var(--text-sm); transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.alert { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: var(--text-sm); }
.alert-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--info); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.d-block { display: block; }
.text-muted { color: var(--text-3) !important; }
.w-100 { width: 100%; }
.me-2 { margin-right: .5rem; }
.m-auto { margin: auto; }
.d-flex { display: flex; }
