:root {
  --bg: #f4f6f9;
  --panel: #fff;
  --panel-soft: #f7f9fc;
  --panel-strong: #eef2f7;
  --line: #e3e7ee;
  --line-strong: #cfd6e2;
  --fg: #101828;
  --dim: #667085;
  --dim-light: #98a2b3;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --green: #12b76a;
  --green-soft: rgba(18, 183, 106, 0.1);
  --amber: #f79009;
  --amber-soft: rgba(247, 144, 9, 0.12);
  --red: #f04438;
  --red-soft: rgba(240, 68, 56, 0.1);
  --ink: #18201c;
  --lime: #c8f169;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 14px;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --sans: "Aptos", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-soft: #1d212a;
  --panel-strong: #242a35;
  --line: #2a303b;
  --line-strong: #3a4250;
  --fg: #f2f4f7;
  --dim: #98a2b3;
  --dim-light: #667085;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, 0.12);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--fg);
  background:
    radial-gradient(circle at 90% 4%, rgba(200, 241, 105, 0.18), transparent 26rem),
    var(--bg);
  font: 13px/1.5 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.6; }
code, pre { font-family: var(--mono); }
h1, h2, h3, p { margin-top: 0; }
a { color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.eyebrow {
  display: block;
  color: var(--accent);
  font: 700 9.5px/1.2 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.muted { color: var(--dim); }
.small { font-size: 11px; }
.mobile-only { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.72fr);
  align-items: center;
  gap: clamp(36px, 8vw, 130px);
  max-width: 1260px;
  margin: 0 auto;
  padding: 40px 28px;
}
.login-story h1 {
  margin: 18px 0 22px;
  font-size: clamp(40px, 5.6vw, 76px);
  line-height: 0.98;
  letter-spacing: -0.06em;
}
.login-story h1 em { color: var(--accent); font-style: normal; }
.login-story > p { max-width: 560px; color: var(--dim); font-size: 15px; line-height: 1.8; }
.story-grid { display: flex; gap: 36px; margin-top: 38px; }
.story-grid div { display: grid; gap: 3px; }
.story-grid b { font-size: 27px; letter-spacing: -0.04em; }
.story-grid span { color: var(--dim); font: 10px/1.2 var(--mono); }
.login-card {
  display: grid;
  gap: 17px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0; font-size: 27px; letter-spacing: -0.04em; }
.login-card > p { margin: 0; color: var(--dim); font-size: 12px; line-height: 1.7; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px;
  flex: 0 0 236px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 24px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: 800 13px/1 var(--mono);
  box-shadow: 0 5px 12px rgba(79, 70, 229, 0.24);
}
.brand-copy { display: flex; flex-direction: column; }
.brand-copy b { font-size: 14px; letter-spacing: -0.02em; }
.brand-copy span { margin-top: 2px; color: var(--dim-light); font: 9px/1.2 var(--mono); }
.nav-label {
  padding: 0 10px 8px;
  color: var(--dim-light);
  font: 700 9px/1.2 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  text-align: left;
  font-size: 12.5px;
  font-weight: 550;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 17px; height: 17px; opacity: 0.78; }
.nav-item:hover { background: var(--panel-soft); color: var(--fg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.sidebar-foot a, .sidebar-foot button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 7px;
  border-radius: 7px;
  text-align: left;
  text-decoration: none;
  font-size: 10.5px;
}
.sidebar-foot a:hover, .sidebar-foot button:hover { background: var(--panel-soft); color: var(--fg); }
.runtime-line { display: flex; align-items: center; gap: 7px; padding: 9px 7px 1px; color: var(--dim-light); font-size: 9.5px; }
.status-dot { width: 6px; height: 6px; flex: 0 0 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 68px;
  flex: 0 0 68px;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 18px; letter-spacing: -0.03em; line-height: 1.2; }
.topbar-title p { margin: 2px 0 0; color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.version-pill, .connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--dim);
  font: 600 10px/1 var(--mono);
  white-space: nowrap;
}
.connection-pill.offline { color: var(--red); }
.connection-pill.offline .status-dot { background: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.icon-button {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--dim);
}
.icon-button:hover { background: var(--panel-soft); color: var(--fg); }
.icon-button svg { width: 16px; height: 16px; }

#main { width: 100%; max-width: 1600px; margin: 0 auto; padding: 24px; }
.page { display: none; }
.page.active { display: block; animation: reveal 0.24s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.page-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-intro h2 { margin: 6px 0 4px; font-size: 22px; letter-spacing: -0.035em; }
.page-intro p { margin: 0; color: var(--dim); font-size: 12px; }
.page-intro > .button-row { align-items: center; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card {
  min-height: 126px;
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.metric-card span, .metric-card small { color: var(--dim); font: 10px/1.3 var(--mono); }
.metric-card strong { margin: 20px 0 7px; font-size: 31px; line-height: 1; letter-spacing: -0.055em; }
.metric-card small { margin-top: auto; }
.metric-card.dark { background: #18201c; border-color: #18201c; color: #fff; }
.metric-card.dark span, .metric-card.dark small { color: #aebbb2; }
.metric-card.lime { background: var(--lime); border-color: var(--lime); color: #18201c; }
.metric-card.lime span, .metric-card.lime small { color: #4b5a40; }
.compact-grid .metric-card { min-height: 105px; }
.compact-grid .metric-card strong { margin: 14px 0 5px; font-size: 26px; }

.panel { padding: 18px 20px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading.compact { margin-bottom: 14px; }
.panel-heading h2 { margin: 5px 0 0; font-size: 15px; letter-spacing: -0.01em; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.75fr); gap: 14px; align-items: start; }
.overview-grid > .panel { margin-bottom: 0; }
.stack { display: grid; gap: 14px; }
.stack .panel { margin: 0; }
.test-panel form { display: grid; gap: 12px; }
.field { display: grid; gap: 7px; }
.field > span { color: var(--dim); font: 700 9.5px/1.2 var(--mono); letter-spacing: 0.06em; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--fg);
  padding: 8px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.55; }
.file-field input { padding: 7px; color: var(--dim); font-size: 11px; }
.file-field input::file-selector-button { margin-right: 8px; border: 0; border-radius: 7px; background: var(--panel-strong); color: var(--fg); padding: 7px 9px; font: 700 10px/1 var(--mono); cursor: pointer; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 11.5px; }
.switch-row small { margin-top: 2px; color: var(--dim); font-size: 10px; }
.switch-row input { width: 35px; height: 19px; accent-color: var(--accent); }

.chat-image-picker { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 7px 10px; padding: 10px; border: 1px dashed var(--line-strong); border-radius: 10px; background: var(--panel-soft); cursor: pointer; }
.chat-image-picker:hover { border-color: var(--accent); background: var(--accent-soft); }
.chat-image-picker input { grid-column: 1 / -1; width: 100%; min-height: 0; padding: 0; border: 0; background: transparent; font-size: 10.5px; }
.chat-image-picker input::file-selector-button { margin-right: 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--fg); padding: 6px 9px; font: 650 10px/1.2 var(--mono); cursor: pointer; }
.chat-image-picker-label { color: var(--accent); font: 700 10px/1.2 var(--mono); }
.chat-image-picker small { color: var(--dim); font-size: 10px; line-height: 1.45; }
.chat-image-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--dim); font: 10px/1.3 var(--mono); }
.chat-image-toolbar .text-button:disabled { color: var(--dim-light); cursor: not-allowed; }
.chat-image-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chat-image-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) 30px; align-items: center; gap: 8px; min-height: 44px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.chat-image-item.pending { border-style: dashed; }
.chat-image-item img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; background: var(--panel-strong); }
.chat-image-copy { min-width: 0; display: grid; gap: 2px; }
.chat-image-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.chat-image-copy span { color: var(--dim); font: 9.5px/1.3 var(--mono); }
.chat-image-remove { width: 30px; height: 30px; flex-basis: 30px; border: 0; background: transparent; color: var(--dim); font-size: 18px; line-height: 1; }
.chat-image-remove:hover { background: var(--red-soft); color: var(--red); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--fg);
  padding: 7px 11px;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.button:hover { background: var(--panel-soft); border-color: var(--line-strong); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 10px rgba(79, 70, 229, 0.18); }
.button.primary:hover { filter: brightness(0.95); }
.button.ghost { background: transparent; color: var(--dim); box-shadow: none; }
.button.wide { width: 100%; }
.button.small { padding: 5px 8px; font-size: 10px; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.text-button { appearance: none; border: 0; background: transparent; color: var(--accent); padding: 0; font-size: 11px; font-weight: 600; }

.detail-list, .settings-list { display: grid; gap: 11px; margin: 0; }
.detail-list div, .settings-list div { display: grid; grid-template-columns: 95px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.detail-list dt, .settings-list dt { color: var(--dim); font-size: 10.5px; }
.detail-list dd, .settings-list dd { margin: 0; overflow-wrap: anywhere; font-size: 11.5px; }
.detail-list code, .settings-list code { color: var(--accent); font-size: 10.5px; }

.chat-output { margin-top: 13px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.chat-output-head { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--dim); font: 10px/1.2 var(--mono); }
.chat-output pre { margin: 0; max-height: 250px; overflow: auto; padding: 11px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; line-height: 1.55; }

.mini-log-list { display: grid; }
.mini-log { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 11px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.mini-log:last-child { border-bottom: 0; }
.mini-log b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 11px/1.35 var(--mono); }
.mini-log small { display: block; margin-top: 2px; color: var(--dim); font-size: 9.5px; }
.mini-log-time { color: var(--dim); text-align: right; font: 10px/1.35 var(--mono); }
.log-status { font: 700 9.5px/1.2 var(--mono); }
.log-status.success { color: var(--green); }
.log-status.error { color: var(--red); }
.log-status.running { color: var(--amber); }

#modelCatalog { margin-top: 24px; }
.catalog-summary { display: grid; grid-template-columns: 1.3fr 1.3fr 1fr 1fr; margin-bottom: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.catalog-summary div { display: flex; flex-direction: column; gap: 5px; padding: 15px 18px; }
.catalog-summary div + div { border-left: 1px solid var(--line); }
.catalog-summary b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; letter-spacing: -0.03em; }
.catalog-summary span { color: var(--dim); font: 9.5px/1.2 var(--mono); }
.rate-pill, .badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 7px;
  font: 650 9.5px/1.2 var(--mono);
  white-space: nowrap;
}
.badge { border: 1px solid var(--line); background: var(--panel-soft); color: var(--dim); }
.badge.ok { border-color: rgba(18, 183, 106, 0.2); background: var(--green-soft); color: var(--green); }
.rate-pill { background: var(--accent-soft); color: var(--accent); }

.account-list { display: grid; gap: 9px; }
.account-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.account-identity { min-width: 0; }
.account-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.account-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.account-state { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 7px; font: 650 9px/1.2 var(--mono); }
.account-state::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.account-state.ready { color: var(--green); background: var(--green-soft); }
.account-state.cooling { color: var(--amber); background: var(--amber-soft); }
.account-state.disabled { color: var(--red); background: var(--red-soft); }
.account-state.busy { color: var(--accent); background: var(--accent-soft); }
.account-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 7px; color: var(--dim); font: 9.5px/1.4 var(--mono); }
.account-error { margin-top: 7px; color: var(--red); font-size: 10.5px; overflow-wrap: anywhere; }
.account-actions { display: flex; gap: 6px; }

.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.analytics-grid .panel { margin-bottom: 18px; }
.distribution { display: grid; gap: 12px; }
.distribution-row > div:first-child { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.distribution-row code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.distribution-row span { color: var(--dim); font: 10px/1 var(--mono); }
.bar-track { height: 6px; overflow: hidden; border-radius: 3px; background: var(--panel-strong); }
.bar-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.latency-chart { height: 160px; display: flex; align-items: flex-end; gap: 3px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.latency-bar { flex: 1; min-width: 2px; border-radius: 3px 3px 0 0; background: var(--accent); opacity: 0.8; }
.latency-bar.success { background: var(--green); }
.latency-bar.error { background: var(--red); }
.segmented { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft); }
.segmented button { appearance: none; border: 0; background: transparent; color: var(--dim); padding: 5px 10px; border-radius: 6px; font-size: 10.5px; font-weight: 600; }
.segmented button.active { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06); }

.settings-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.security-note { padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.security-note strong { font-size: 11.5px; }
.security-note p { margin: 7px 0 0; color: var(--dim); font-size: 11px; line-height: 1.7; }
.security-note code { color: var(--accent); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.env-grid { display: grid; grid-template-columns: minmax(240px, 0.7fr) 1fr; gap: 0; }
.env-grid > * { padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 11px; }
.env-grid > *:nth-last-child(-n + 2) { border-bottom: 0; }
.env-grid code { color: var(--accent); }
.env-grid span { color: var(--dim); }

.search-input { width: 220px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: var(--panel-soft); color: var(--dim); font: 700 9.5px/1.2 var(--mono); letter-spacing: 0.04em; white-space: nowrap; }
td { max-width: 310px; overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-soft); }
td code { font-size: 10.5px; }
.table-empty { padding: 24px; color: var(--dim); text-align: center; }
.empty-state { display: grid; justify-items: center; gap: 7px; padding: 38px 18px; color: var(--dim); text-align: center; }
.empty-state strong { color: var(--fg); font-size: 13px; }
.empty-state p { margin: 0; font-size: 11px; }
.empty-state.compact { padding: 22px; }

.dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--fg); box-shadow: 0 30px 90px rgba(16, 24, 40, 0.25); }
.dialog::backdrop { background: rgba(16, 24, 40, 0.45); backdrop-filter: blur(3px); }
.dialog form { display: grid; gap: 15px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.dialog-heading h2 { margin: 5px 0 0; font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; }
.form-error { margin: 0; color: var(--red); font-size: 11px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(420px, calc(100vw - 44px)); padding: 11px 14px; border-radius: 10px; background: #18201c; color: #fff; font-size: 11.5px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease; }
.toast.show { opacity: 1; transform: none; }

.sidebar-backdrop { display: none; }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .sidebar { width: 210px; flex-basis: 210px; }
  #main { padding: 20px; }
  .overview-grid { grid-template-columns: 1fr; }
  .topbar-actions .version-pill { display: none; }
}

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; flex-basis: 260px; transform: translateX(-104%); transition: transform 0.22s ease; box-shadow: 0 20px 50px rgba(16, 24, 40, 0.2); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(16, 24, 40, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .mobile-only { display: inline-grid !important; }
  .topbar { height: 60px; flex-basis: 60px; padding: 0 14px; }
  .topbar-title h1 { font-size: 16px; }
  .topbar-title p { display: none; }
  .topbar-actions .connection-pill, .topbar-actions .button.ghost { display: none; }
  #main { padding: 16px 14px 88px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 112px; }
  .metric-card strong { font-size: 27px; }
  .analytics-grid, .settings-layout { grid-template-columns: 1fr; }
  .catalog-summary { grid-template-columns: 1fr 1fr; }
  .catalog-summary div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .catalog-summary div:nth-child(4) { border-top: 1px solid var(--line); }
  .mobile-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; height: calc(60px + env(safe-area-inset-bottom, 0px)); padding: 4px 6px env(safe-area-inset-bottom, 0px); align-items: center; justify-content: space-around; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(14px); }
  .mobile-nav-item { appearance: none; border: 0; background: transparent; color: var(--dim-light); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 54px; height: 50px; border-radius: 9px; font-size: 9px; font-weight: 600; }
  .mobile-nav-item.active { color: var(--accent); background: var(--accent-soft); }
}

@media (max-width: 620px) {
  .login-shell { grid-template-columns: 1fr; gap: 26px; padding: 28px 16px; }
  .login-story h1 { font-size: 40px; }
  .login-story > p { font-size: 13px; }
  .story-grid { gap: 22px; }
  .login-card { padding: 23px; }
  .page-intro { gap: 10px; }
  .page-intro h2 { font-size: 20px; }
  .metric-grid { gap: 8px; }
  .metric-card { min-height: 102px; padding: 12px; }
  .metric-card strong { margin: 12px 0 5px; font-size: 24px; }
  .panel { padding: 14px 13px; }
  .account-card { grid-template-columns: 1fr; }
  .account-actions { justify-content: flex-end; }
  .mini-log { grid-template-columns: 50px minmax(0, 1fr); }
  .mini-log-time { display: none; }
  .search-input { width: 100%; }
  .button-row:has(.search-input) { width: 100%; }
  .env-grid { grid-template-columns: 1fr; }
  .env-grid > * { border-bottom: 0; }
  .env-grid span { padding-top: 0; }
  .detail-list div, .settings-list div { grid-template-columns: 80px minmax(0, 1fr); }
}

/* Management forms follow the existing panel, color and spacing system. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.form-stack { display: grid; gap: 14px; margin-top: 18px; }
.form-stack > .button { justify-self: start; }
.field > span { font-size: 12px; letter-spacing: 0.01em; line-height: 1.5; }
.field input, .field select { min-height: 44px; }
.field textarea { font-size: 14px; }
.form-feedback { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--panel-soft); color: var(--fg); font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; }
.form-feedback.is-error { color: var(--red); border: 1px solid currentColor; }
.filter-grid { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(3, minmax(120px, 1fr)); gap: 12px; align-items: end; }
.selection-toolbar { display: grid; gap: 12px; margin: 16px 0; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.selection-toolbar p { margin: 0; font-size: 12px; }
.selection-toolbar .button, .pagination .button, .dialog .button, .settings-panel .button, .account-actions .button { min-height: 44px; font-size: 12px; }
.button.danger { background: var(--red-soft); color: var(--red); border-color: currentColor; }
.button.danger:hover { background: var(--red-soft); filter: brightness(0.94); }
.button.primary.danger { box-shadow: none; }
.button:disabled { cursor: not-allowed; }
.button[aria-busy="true"] { cursor: progress; }
.account-actions { flex-wrap: wrap; justify-content: flex-end; }
.account-card { align-items: start; }
.account-remark { margin: 8px 0 0; color: var(--dim); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.check-label { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 13px; overflow-wrap: anywhere; }
.check-label input { width: 20px; height: 20px; flex: 0 0 20px; padding: 0; accent-color: var(--accent); }
.account-title .check-label { min-width: 0; }
.selector-field { border: 1px solid var(--line); border-radius: 10px; min-width: 0; padding: 12px; }
.selector-field legend { font-weight: 600; padding: 0 5px; }
.check-options { display: grid; gap: 4px; max-height: 230px; overflow: auto; }
.check-options .check-label { padding: 3px 6px; border-radius: 6px; }
.check-options .check-label:hover { background: var(--panel-soft); }
.key-list { display: grid; gap: 12px; }
.key-list .account-meta { font-size: 11px; }
.pagination { justify-content: flex-end; margin-top: 16px; font-size: 12px; }
#newKeySecret { font-family: var(--mono); font-size: 14px; }
.dialog .icon-button { width: 44px; height: 44px; flex-basis: 44px; }
.dialog form > .muted, .dialog .form-stack > p { font-size: 13px; }
.dialog { overscroll-behavior: contain; }
@media (max-width: 1100px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .filter-grid { grid-template-columns: 1fr; }
  .selection-toolbar .button-row { gap: 8px; }
  .selection-toolbar .button { flex: 1 1 130px; }
  .account-actions { justify-content: flex-start; gap: 8px; }
  .key-list .account-card { grid-template-columns: 1fr; }
  .field input, .field select, .field textarea { font-size: 16px; }
  .panel-heading { flex-wrap: wrap; }
  .dialog { padding: 18px; max-height: calc(100dvh - 24px); }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
