:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #eef3f8;
  color: #172033;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 1120px; background: #eef3f8; }
h1, h2, p { margin: 0; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; padding: 24px; color: white; background: linear-gradient(180deg, #0f172a 0%, #164e63 100%); box-shadow: 14px 0 32px rgba(15, 23, 42, .16); }
.brand { display: grid; gap: 8px; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.16); }
.brand span { color: #38bdf8; font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.brand strong { font-size: 24px; letter-spacing: -.04em; }
.nav-list { display: grid; gap: 10px; }
.nav-item { width: 100%; justify-content: flex-start; border-color: rgba(255,255,255,.14); background: rgba(255,255,255,.08); color: #e0f2fe; text-align: left; }
.nav-item:hover, .nav-item.active { background: white; color: #0f766e; box-shadow: 0 12px 24px rgba(0,0,0,.16); }
.sidebar-note { margin-top: auto; color: #bae6fd; font-size: 13px; line-height: 1.6; }

.main-content { min-width: 0; padding: 24px; }
.page { display: none; gap: 18px; }
.page.active { display: grid; }
.page-header { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 22px; border: 1px solid #d8e1ec; border-radius: 18px; background: rgba(255,255,255,.92); box-shadow: 0 12px 28px rgba(15, 23, 42, .06); }
.page-header h1 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -.04em; }
.page-actions { display: flex; gap: 10px; flex-shrink: 0; }
.eyebrow { color: #0891b2; font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: #64748b; }

.panel { min-width: 0; padding: 18px; border: 1px solid #d8e1ec; border-radius: 18px; background: rgba(255,255,255,.96); box-shadow: 0 12px 28px rgba(15, 23, 42, .06); }
.panel-title { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.panel-title h2 { font-size: 20px; letter-spacing: -.03em; }
.settings-panel { max-width: 880px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-card { padding: 16px; border-radius: 16px; background: white; border: 1px solid #d8e1ec; box-shadow: 0 10px 24px rgba(15, 23, 42, .05); }
.stat-card span { color: #64748b; font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 30px; line-height: 1; }

form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 800; color: #475569; }
.checkbox { display: flex; align-items: center; gap: 8px; color: #172033; }
.checkbox input { width: auto; height: auto; }

input, select, textarea, button { border: 1px solid #cbd5e1; border-radius: 10px; padding: 0 12px; font-size: 14px; outline: none; }
input, select, button { height: 40px; }
textarea { min-height: 110px; padding: 10px 12px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: #0891b2; box-shadow: 0 0 0 3px rgba(8,145,178,.14); }
button { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; border-color: #0f766e; background: #0f766e; color: white; font-weight: 900; transition: transform .12s ease, box-shadow .12s ease, background .12s ease; }
button:hover { background: #0d9488; box-shadow: 0 8px 18px rgba(13,148,136,.2); }
button:active { transform: translateY(1px); }
button.secondary, button.ghost { background: white; color: #0f766e; }
button.ghost { border-color: #d8e1ec; }
button.danger { background: #b91c1c; border-color: #b91c1c; }
button.small { height: 32px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.icon-button { width: 38px; padding: 0; font-size: 24px; line-height: 1; }

.upstream-groups { display: grid; gap: 14px; }
.group-card { border: 1px solid #d8e1ec; border-radius: 16px; overflow: hidden; background: white; }
.group-header { display: flex; gap: 12px; align-items: flex-start; padding: 16px; background: #f8fafc; }
.group-main { display: grid; gap: 7px; flex: 1; min-width: 0; }
.group-main strong { font-size: 17px; }
.group-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; background: #e0f2fe; color: #075985; font-size: 12px; font-weight: 900; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.badge.neutral { background: #eef2ff; color: #3730a3; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.key-table { padding: 0 16px 16px; }
.key-empty { padding: 0 16px 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 9px; border-bottom: 1px solid #edf2f7; text-align: left; vertical-align: top; }
th { color: #64748b; background: #f8fafc; font-weight: 900; }
.status-text { max-width: 280px; color: #475569; word-break: break-word; }
.model-tags, .fetched-models { display: flex; flex-wrap: wrap; gap: 7px; }
.model-tag { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border-radius: 999px; background: #f1f5f9; color: #334155; font-size: 12px; font-weight: 800; }
.model-editor { display: grid; gap: 10px; font-size: 13px; color: #52606d; }
.model-header, .model-row { display: flex; gap: 8px; align-items: center; }
.model-header { justify-content: space-between; }
.model-actions { display: flex; gap: 8px; }
.model-row input { flex: 1; }
.model-check { display: flex; align-items: center; gap: 6px; width: auto; padding: 7px 9px; border: 1px solid #d8e1ec; border-radius: 999px; color: #172033; background: #f8fafc; font-weight: 700; }
.model-check input { height: auto; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 22px; background: rgba(15, 23, 42, .58); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(760px, 100%); max-height: min(86vh, 920px); overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); border-radius: 18px; background: white; box-shadow: 0 28px 70px rgba(0,0,0,.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid #e2e8f0; }
.modal-header h2 { font-size: 20px; }
.modal-body { overflow-y: auto; padding: 20px; }
.result-grid { display: grid; gap: 10px; }
.result-card { display: grid; gap: 6px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; }
.chat-test-result { display: grid; gap: 10px; margin-top: 14px; }
.chat-test-result.error { color: #991b1b; }
.chat-test-result pre { max-height: 320px; overflow: auto; margin: 0; padding: 12px; border-radius: 10px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; word-break: break-word; }

#toast { position: fixed; right: 20px; bottom: 20px; display: none; max-width: 460px; padding: 13px 15px; border-radius: 12px; color: white; background: #0f172a; box-shadow: 0 14px 34px rgba(0,0,0,.22); z-index: 80; }

@media (max-width: 1180px) {
  body { min-width: 0; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .main-content { padding: 16px; }
  .page-header { align-items: stretch; flex-direction: column; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
}
