:root {
  color-scheme: dark;
  --bg: #101214;
  --bg-raised: #17191c;
  --panel: #191c20;
  --panel-hover: #20242a;
  --panel-soft: #151719;
  --line: #2b2f35;
  --line-soft: #23272c;
  --text: #f1f3f5;
  --muted: #9299a2;
  --subtle: #69717b;
  --accent: #e5e7eb;
  --accent-dark: #111315;
  --positive: #60c391;
  --positive-bg: rgba(75, 182, 133, .12);
  --negative: #ee737b;
  --negative-bg: rgba(220, 80, 92, .12);
  --warning: #e0ae65;
  --warning-bg: rgba(211, 157, 72, .12);
  --shadow: 0 24px 80px rgba(0, 0, 0, .25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 13px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
a { color: inherit; text-decoration: none; }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% -20%, #262b31 0, transparent 52%), var(--bg); }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--line); background: rgba(25, 28, 32, .94); box-shadow: var(--shadow); border-radius: 10px; }
.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-logo { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; }
.brand-name { display: block; font-size: 14px; font-weight: 760; letter-spacing: .01em; }
.brand-caption { display: block; margin-top: 2px; color: var(--subtle); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.login-card .brand-lockup { margin-bottom: 56px; }
.login-card h1 { margin: 0 0 8px; font-size: 27px; letter-spacing: -.025em; }
.login-card .muted { max-width: 330px; line-height: 1.55; }
.stack { display: grid; gap: 9px; margin-top: 28px; }
.stack label, .form-grid label { color: #cbd0d6; font-size: 12px; font-weight: 650; }
.stack input { margin-top: 4px; }

.eyebrow { margin: 0 0 7px; color: var(--subtle); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.muted { color: var(--muted); }
.tiny { font-size: 11px; }
.hint, .form-note { color: var(--subtle); font-size: 11px; font-weight: 450; }
.form-note { grid-column: 1 / -1; margin: -3px 0 0; line-height: 1.45; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 13px 16px; border-right: 1px solid var(--line); background: #151719; }
.sidebar-brand { padding: 0 9px 27px; }
.main-nav { display: grid; gap: 2px; }
.nav-label { padding: 0 11px 7px; color: var(--subtle); font-size: 9px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.nav-label-spaced { margin-top: 18px; }
.nav-item { display: flex; align-items: center; width: 100%; gap: 10px; padding: 9px 11px; border: 1px solid transparent; border-radius: 6px; color: #9ba1aa; background: transparent; text-align: left; transition: background .15s, color .15s, border-color .15s; }
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active { border-color: #363b43; background: #24282d; color: var(--text); }
.nav-icon { width: 17px; color: var(--subtle); font-size: 15px; text-align: center; }
.nav-item.active .nav-icon { color: var(--text); }
.sidebar-footer { display: grid; gap: 12px; margin-top: auto; }
.gateway-state { display: flex; align-items: center; gap: 8px; padding: 0 10px; color: var(--muted); font-size: 11px; }
.state-indicator { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--subtle); }
.state-indicator.online { background: var(--positive); box-shadow: 0 0 0 3px rgba(96, 195, 145, .1); }
.state-indicator.offline { background: var(--negative); }

.content { min-width: 0; padding: 29px clamp(18px, 3vw, 45px) 60px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 32px; }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 720; letter-spacing: -.035em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.endpoint-chip { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 11px; }
.endpoint-chip code { color: var(--text); }
.btn, .icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--panel); font-weight: 650; transition: border-color .15s, background .15s, transform .15s; }
.btn:hover, .icon-btn:hover { border-color: #555b64; background: var(--panel-hover); }
.btn:active, .icon-btn:active { transform: translateY(1px); }
.btn.primary { border-color: #dfe2e5; color: #111315; background: #e5e7eb; }
.btn.primary:hover { background: #fff; }
.btn.subtle { background: var(--panel-soft); color: var(--muted); }
.btn.ghost { color: var(--muted); background: transparent; }
.btn.danger { border-color: rgba(238, 115, 123, .3); color: var(--negative); background: var(--negative-bg); }
.btn.full { width: 100%; }
.btn.mini { min-height: 29px; padding: 5px 8px; font-size: 11px; }
.icon-btn { width: 36px; padding: 0; font-size: 17px; }
.text-btn { border: 0; color: var(--muted); background: transparent; font-size: 11px; }
.text-btn:hover { color: var(--text); }

.page { min-width: 0; }
.endpoint-banner { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 8px; background: linear-gradient(105deg, #1d2024, #181a1d); }
.endpoint-url { display: block; font-size: 15px; color: var(--text); }
.endpoint-actions { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.metric { min-width: 0; padding: 15px 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.metric-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.metric-icon { color: var(--subtle); font-size: 14px; }
.metric strong { display: block; margin-top: 11px; overflow: hidden; font-size: 22px; font-weight: 710; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.metric small { display: block; margin-top: 5px; color: var(--subtle); font-size: 10px; }
.dashboard-grid, .routing-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 14px; }
.panel { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 680; }
.compact-list { padding: 5px 10px; }
.compact-row { display: flex; align-items: center; justify-content: space-between; gap: 13px; padding: 12px 8px; border-bottom: 1px solid var(--line-soft); }
.compact-row:last-child { border-bottom: 0; }
.compact-main { min-width: 0; display: grid; gap: 4px; }
.compact-main strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.compact-main span { overflow: hidden; color: var(--subtle); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.compact-meta { flex: 0 0 auto; }

.page-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 14px; }
.section-lead { margin: 0; color: var(--muted); line-height: 1.45; }
.table-panel { overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
th { color: var(--subtle); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
td { color: var(--text); font-size: 12px; }
td > strong, td > code { display: block; font-weight: 650; }
td > small { display: block; margin-top: 5px; color: var(--subtle); font-size: 10px; line-height: 1.35; }
td code { color: #d4d9de; font-size: 11px; }
.url-value { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-wrap { max-width: 180px; }
.table-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; width: max-content; padding: 4px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: var(--panel-soft); font-size: 10px; font-weight: 680; white-space: nowrap; }
.status-pill > span { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-pill.positive { border-color: rgba(96, 195, 145, .27); color: var(--positive); background: var(--positive-bg); }
.status-pill.negative { border-color: rgba(238, 115, 123, .28); color: var(--negative); background: var(--negative-bg); }
.status-pill.warning { border-color: rgba(224, 174, 101, .28); color: var(--warning); background: var(--warning-bg); }
.status-pill.neutral { color: var(--muted); }

.state-panel { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.state-panel strong { font-size: 12px; }
.state-panel > span:not(.spinner) { color: var(--muted); font-size: 11px; }
.state-panel .btn { margin-left: auto; }
.error-state { border-color: rgba(238, 115, 123, .28); }
.error-state > span { color: var(--negative) !important; }
.spinner { width: 14px; height: 14px; flex: 0 0 14px; border: 2px solid #3d4248; border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { display: grid; justify-items: center; gap: 5px; min-height: 112px; padding: 26px 12px; color: var(--subtle); text-align: center; }
.empty-state strong { color: var(--muted); font-size: 12px; }
.empty-state span:not(.empty-symbol) { max-width: 440px; font-size: 11px; line-height: 1.45; }
.empty-symbol { font-size: 20px; color: #59616a; }
.inline-note { margin-bottom: 14px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--panel-soft); font-size: 11px; line-height: 1.5; }

.usage-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.summary-item { padding: 15px 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.summary-item span { display: block; color: var(--muted); font-size: 11px; }
.summary-item strong { display: block; margin-top: 8px; font-size: 20px; }
.request-panel { overflow: hidden; }
.request-header, .request-row { display: grid; grid-template-columns: 75px minmax(145px, 1.1fr) minmax(100px, .8fr) minmax(140px, 1.2fr) 53px 105px 73px 58px; align-items: center; gap: 10px; min-width: 920px; padding: 10px 15px; }
.request-header { color: var(--subtle); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; border-bottom: 1px solid var(--line); }
.request-row { border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: 10px; }
.request-row:last-child { border-bottom: 0; }
.request-row time { color: var(--subtle); }
.request-client { min-width: 0; display: grid; gap: 3px; }
.request-client strong { overflow: hidden; color: var(--text); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.request-client span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.request-model, .request-endpoint { overflow: hidden; color: #cbd1d6; text-overflow: ellipsis; white-space: nowrap; }
.request-endpoint { color: var(--muted); }
.request-status { font-weight: 750; }
.request-status.good { color: var(--positive); }
.request-status.bad { color: var(--negative); }
.routing-options { display: grid; gap: 7px; padding: 16px 18px; }
.routing-option { display: flex; align-items: flex-start; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--panel-soft); text-align: left; }
.routing-option:hover, .routing-option.selected { border-color: #68717b; background: var(--panel-hover); }
.routing-option.selected { box-shadow: inset 2px 0 0 #e5e7eb; }
.routing-option strong, .routing-option small { display: block; }
.routing-option strong { font-size: 12px; }
.routing-option small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.radio-dot { width: 13px; height: 13px; flex: 0 0 13px; margin-top: 1px; border: 1px solid var(--subtle); border-radius: 50%; }
.selected .radio-dot { border: 4px solid var(--text); }
.panel-foot { padding: 0 18px 17px; color: var(--subtle); font-size: 10px; line-height: 1.45; }
.service-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; padding: 15px; }
.service-card { display: grid; gap: 7px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-soft); }
.service-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.service-card > span, .service-card > small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.settings-panel { margin-top: 14px; }
.settings-list { padding: 5px 17px; }
.setting-row { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: 11px; }
.setting-row:last-child { border-bottom: 0; }
.setting-row strong { color: var(--text); font-weight: 580; text-align: right; overflow-wrap: anywhere; }

input, select { width: 100%; min-height: 38px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; outline: 0; color: var(--text); background: #111315; }
input { margin-top: 6px; }
input:focus, select:focus { border-color: #747d87; box-shadow: 0 0 0 2px rgba(229, 231, 235, .08); }
select[multiple] { height: auto; min-height: 100px; margin-top: 6px; }
select option { padding: 5px; }
.dialog { width: min(620px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(3px); }
.dialog > form, .secret-dialog, .dialog:not(form) { padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.secret-box { display: flex; align-items: center; gap: 8px; margin-top: 17px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #111315; }
.secret-box code { flex: 1; overflow: auto; color: #dce1e6; white-space: nowrap; }
.detail-content { max-height: 55vh; margin: 0; padding: 13px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; color: #cbd2d8; background: #111315; font-size: 11px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 20; max-width: min(420px, calc(100vw - 36px)); padding: 11px 13px; border: 1px solid #454b53; border-radius: 6px; color: var(--text); background: #262a2f; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast[data-kind="error"] { border-color: rgba(238, 115, 123, .5); color: #ffdadd; background: #321d20; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric strong { font-size: 19px; }
  .dashboard-grid, .routing-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: relative; height: auto; padding: 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand { padding-bottom: 15px; }
  .main-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .nav-label { grid-column: 1 / -1; padding-top: 8px; }
  .nav-label-spaced { margin-top: 0; }
  .sidebar-footer { grid-template-columns: 1fr auto; align-items: center; margin-top: 15px; }
  .sidebar-footer .btn { width: auto; }
  .content { padding: 22px 16px 44px; }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; margin-bottom: 23px; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .endpoint-chip { flex: 1; }
  .top-actions .btn.primary { margin-left: auto; }
  .endpoint-banner { align-items: flex-start; flex-direction: column; }
  .endpoint-actions { justify-content: flex-start; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 13px; }
  .metric strong { font-size: 18px; }
  .page-toolbar { align-items: stretch; flex-direction: column; }
  .page-toolbar .btn { width: max-content; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .usage-summary { grid-template-columns: 1fr; }
  .service-grid { grid-template-columns: 1fr; }
  .login-card { padding: 25px; }
  .login-card .brand-lockup { margin-bottom: 38px; }
}
@media (max-width: 430px) {
  .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .metric strong { font-size: 16px; }
  .top-actions .icon-btn { order: 3; }
}
