:root {
  --bg: #0a0e13;
  --bg-soft: #0e141b;
  --panel: #111820;
  --panel-2: #151e27;
  --panel-3: #1a2530;
  --line: #22303d;
  --line-soft: #1a2530;
  --text: #e8eef4;
  --text-dim: #a6b5c4;
  --muted: #77899a;
  --accent: #5eead4;
  --accent-ink: #062c29;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --red: #f87171;
  --green: #4ade80;
  --radius: 12px;
  --mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(94, 234, 212, 0.28); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 236px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 20px;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 9px; background: #0c2b28; color: var(--accent);
  border: 1px solid #1c4b45;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 15px; letter-spacing: 0.2px; }
.brand-text small { color: var(--muted); font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: 0; color: var(--text-dim);
  padding: 9px 11px; border-radius: 8px; cursor: pointer; text-align: left;
  border-left: 2px solid transparent;
}
.nav-item svg { width: 17px; height: 17px; fill: currentColor; opacity: 0.8; }
.nav-item span { flex: 1; }
.nav-item em { font-style: normal; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: #12231f; color: var(--accent); border-left-color: var(--accent); }
.nav-item.active svg { opacity: 1; }

.sidebar-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--line-soft); }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.tiny { font-size: 11px; }
.muted { color: var(--muted); }

.main { margin-left: 236px; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 18px 30px;
  background: rgba(10, 14, 19, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.2px; }
.topbar p { margin: 2px 0 0; font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.content { padding: 24px 30px 64px; max-width: 1520px; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text-dim); font-size: 12px; font-family: var(--mono);
  white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.12); }
.dot.warn { background: var(--amber); }
.dot.off { background: #435364; }
.dot.err { background: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer;
  font-size: 13px; line-height: 1.2; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.btn:hover { border-color: #33475a; background: var(--panel-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #4a2630; background: #1d1216; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 16px 17px; position: relative; overflow: hidden;
}
.stat .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.9px; }
.stat .value { font-size: 27px; font-weight: 600; margin-top: 7px; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.stat .corner { position: absolute; right: 14px; top: 14px; color: var(--muted); opacity: 0.55; }
.stat .corner svg { width: 17px; height: 17px; fill: currentColor; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.1px; }
.section-head .hint { color: var(--muted); font-size: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.panel-pad { padding: 16px 17px; }
.split { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; align-items: start; }

.provider-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.provider-card {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 15px 15px 12px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color 120ms ease;
}
.provider-card:hover { border-color: #2b3d4d; }
.provider-card.disabled { opacity: 0.62; }
.provider-card.needs-key { border-left: 2px solid #4b3a17; }
.provider-card.cooling { border-left: 2px solid #4b2630; }
.pc-head { display: flex; align-items: flex-start; gap: 9px; }
.pc-head .name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
.pc-head .name small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; font-family: var(--mono); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10px; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line);
  color: var(--text-dim); background: var(--panel-2); white-space: nowrap;
}
.badge.none { color: var(--green); border-color: #1f4a35; background: #10231a; }
.badge.email { color: var(--blue); border-color: #1e3a5c; background: #101d2d; }
.badge.phone { color: var(--amber); border-color: #4a3b16; background: #221c0e; }
.badge.card { color: #f0a5a5; border-color: #4a2630; background: #221316; }
.badge.ok { color: var(--green); border-color: #1f4a35; background: #10231a; }
.badge.warn { color: var(--amber); border-color: #4a3b16; background: #221c0e; }
.badge.bad { color: var(--red); border-color: #4a2630; background: #221316; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-dim);
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: 5px; padding: 2px 6px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.accent { color: var(--accent); border-color: #1f4a45; }

.metrics { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.metrics b { color: var(--text-dim); font-weight: 600; font-family: var(--mono); font-size: 11px; }
.pc-foot { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.pc-foot .spacer { flex: 1; }

.switch { position: relative; display: inline-block; width: 34px; height: 19px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #2a3947; border-radius: 999px; cursor: pointer; transition: 140ms; }
.switch span::after { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; background: #9fb0c0; border-radius: 50%; transition: 140ms; }
.switch input:checked + span { background: #1f6b5e; }
.switch input:checked + span::after { transform: translateX(15px); background: var(--accent); }

.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 10.5px;
  letter-spacing: 0.8px; text-transform: uppercase; padding: 9px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #0f161d; }
.table .mono { font-family: var(--mono); font-size: 11px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11.5px; }
.table-wrap { overflow-x: auto; }

.empty { padding: 34px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty strong { display: block; color: var(--text-dim); margin-bottom: 4px; font-weight: 600; }

.callout {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid #4a3b16; background: #1c180c; border-radius: var(--radius);
  padding: 13px 15px; color: #e8d9a8; font-size: 12.5px;
}
.callout .icon { color: var(--amber); flex: none; margin-top: 1px; }
.callout strong { color: #fbe7ac; }
.callout a { color: var(--amber); text-decoration: underline; text-underline-offset: 2px; }
.callout.good { border-color: #1f4a35; background: #0e1c15; color: #b8e6cb; }
.callout.good .icon { color: var(--green); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 340px; }

.input, .select, .textarea {
  width: 100%; background: #0c1218; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; color: var(--text); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: #2f6d64; box-shadow: 0 0 0 2px rgba(94, 234, 212, 0.08); }
.textarea { resize: vertical; min-height: 84px; font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.help { font-size: 11px; color: var(--muted); margin-top: 4px; }
.mono { font-family: var(--mono); }
.code {
  background: #080d12; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 13px; font-family: var(--mono); font-size: 11.5px; line-height: 1.6;
  overflow-x: auto; white-space: pre; color: #cfe0ee;
}
.code .k { color: var(--accent); }
.code .c { color: #6b7f90; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(4, 7, 10, 0.72);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 30px; z-index: 100; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 640px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 17px 19px 13px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 17px 19px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 19px 17px; border-top: 1px solid var(--line-soft); }
.icon-btn {
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.icon-btn svg { width: 14px; height: 14px; fill: currentColor; }

.key-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.key-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 8px;
  font-size: 12px;
}
.key-row .mask { font-family: var(--mono); color: var(--text-dim); }
.key-row .label { margin: 0; color: var(--text); font-size: 12px; }
.key-row .err { color: var(--red); font-size: 11px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-row .spacer { flex: 1; }

.route-list { display: flex; flex-direction: column; gap: 6px; }
.route-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 7px;
  font-size: 12px;
}
.route-row .idx { font-family: var(--mono); color: var(--muted); width: 20px; text-align: right; }
.route-row .pname { color: var(--text); min-width: 110px; }
.route-row .mname { font-family: var(--mono); color: var(--text-dim); font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-row .off { color: var(--red); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.route-row.dragging { opacity: 0.5; }

.alias-card { margin-bottom: 12px; }
.alias-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.alias-head h3 { margin: 0; font-size: 13.5px; font-family: var(--mono); color: var(--accent); font-weight: 500; }
.alias-head p { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; }
.alias-head .spacer { flex: 1; }
.alias-body { padding: 12px 14px; }

.playground-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.output {
  min-height: 260px; background: #080d12; border: 1px solid var(--line);
  border-radius: 10px; padding: 13px; font-family: var(--mono); font-size: 12px;
  line-height: 1.65; white-space: pre-wrap; word-break: break-word; color: #d5e5f2;
}
.output .placeholder { color: var(--muted); font-family: var(--sans); }
.meta-line { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.meta-line b { color: var(--text-dim); font-weight: 500; font-family: var(--mono); }

.toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--panel-3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; font-size: 12.5px; max-width: 380px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); animation: toast-in 160ms ease-out;
}
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin-bottom: 16px; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 12px; cursor: pointer; font-size: 12.5px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.snippet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); color: var(--text-dim); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }

.checklist { display: flex; flex-direction: column; gap: 7px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--panel-2); font-size: 12.5px; }
.check-row .name { min-width: 190px; font-weight: 500; }
.check-row .note { flex: 1; color: var(--muted); font-size: 11.5px; }
.check-row a { color: var(--blue); font-size: 11.5px; }
.check-row.done { border-color: #1f4a35; }
.check-row.done .name::after { content: " ✓"; color: var(--green); }

.loading { display: flex; align-items: center; gap: 9px; color: var(--muted); padding: 40px; justify-content: center; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------- auth ---------------------------------- */
body.auth-mode .sidebar, body.auth-mode .main { display: none; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 24px 22px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 19px; font-weight: 600; letter-spacing: -0.2px; }
.auth-card > p { margin: 0 0 16px; font-size: 12.5px; }
.auth-error { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 10px; }

body[data-role="viewer"] .admin-only { display: none !important; }

.user-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.user-line .badge { margin-left: 4px; }

.pill-ok { color: var(--green); border-color: #1f4a35; }
.pill-warn { color: var(--amber); border-color: #4a3b16; }

.check-grid { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
.secret-box { display: flex; gap: 8px; }
.secret-box .input { flex: 1; color: var(--accent); }
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; }

/* capability models (embedding / rerank / decision) */
.chip.cap { cursor: pointer; font-family: var(--mono); }
.chip.cap b { font-weight: 600; text-transform: uppercase; font-size: 9px; letter-spacing: 0.5px; margin-right: 3px; }
.chip.cap:hover { border-color: #33475a; color: var(--text); }
.chip.cap.embedding b, .badge.kind-embedding { color: var(--blue); }
.chip.cap.rerank b, .badge.kind-rerank { color: var(--amber); }
.chip.cap.decision b, .badge.kind-decision { color: var(--accent); }

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .playground-grid, .snippet-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: static; width: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .brand { padding: 0 8px 0 0; flex: none; }
  .brand-text { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-item { padding: 7px 9px; white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; }
  .nav-item.active { border-left: 0; border-bottom-color: var(--accent); }
  .nav-item em { display: none; }
  .sidebar-foot { display: none; }
  .main { margin-left: 0; }
  .topbar { padding: 14px 16px; }
  .content { padding: 16px; }
  .provider-grid { grid-template-columns: 1fr; }
  .topbar-actions .pill { display: none; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
}
