:root {
  --bg: #07090d;
  --panel: #10141b;
  --panel-2: #151a22;
  --line: #252c37;
  --text: #f4f6f8;
  --muted: #8f99a8;
  --orange: #ff6a1a;
  --orange-2: #ff8f45;
  --green: #37d395;
  --red: #ff5d67;
  --yellow: #ffc857;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, "Microsoft YaHei", system-ui, sans-serif; }
body { background-image: radial-gradient(circle at 85% 8%, rgba(255,106,26,.1), transparent 28%), radial-gradient(circle at 30% 95%, rgba(55,211,149,.05), transparent 24%); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--orange-2); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: 31px; }
h2 { margin-bottom: 0; font-size: 25px; }
h3 { margin-bottom: 7px; font-size: 19px; }
h4 { margin-bottom: 4px; }
p { color: var(--muted); line-height: 1.65; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 44px; border: 1px solid var(--line); border-radius: 26px; background: rgba(16,20,27,.94); box-shadow: 0 28px 90px rgba(0,0,0,.48); }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; margin-bottom: 24px; border-radius: 17px; color: white; background: linear-gradient(145deg, var(--orange), #c83a00); font-size: 28px; font-weight: 900; box-shadow: 0 12px 36px rgba(255,106,26,.24); }
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 13px; font-size: 20px; }
.stack { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 8px; color: #cbd1d9; font-size: 13px; font-weight: 650; }
input, select { width: 100%; min-height: 43px; padding: 0 13px; border: 1px solid var(--line); border-radius: 11px; outline: none; color: var(--text); background: #0b0e13; transition: .18s ease; }
input:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,106,26,.1); }
.compact { width: 210px; min-height: 39px; }
.check { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 43px; }
.check input { width: 17px; min-height: auto; accent-color: var(--orange); }
.form-error { min-height: 20px; margin: 14px 0 0; color: var(--red); font-size: 13px; }

.primary, .ghost, .danger { min-height: 39px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px; color: white; font-weight: 750; }
.primary { background: var(--orange); box-shadow: 0 8px 24px rgba(255,106,26,.18); }
.primary:hover { background: var(--orange-2); }
.ghost { border-color: var(--line); background: #141922; }
.ghost:hover { border-color: #3c4655; background: #1a202a; }
.danger { color: #ff9299; border-color: rgba(255,93,103,.25); background: rgba(255,93,103,.08); }
.wide { width: 100%; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--panel-2); font-size: 23px; }
.mini-button { min-height: 31px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: #d9dee5; background: #151a22; font-size: 12px; }
.mini-button:hover { border-color: var(--orange); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 25px 18px; border-right: 1px solid var(--line); background: rgba(9,12,17,.94); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 27px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; }
.brand span { margin-top: 4px; color: var(--muted); font-size: 11px; }
nav { display: grid; gap: 7px; }
.nav-item { display: flex; gap: 12px; align-items: center; min-height: 46px; padding: 0 14px; border: 0; border-radius: 11px; color: #99a3b2; background: transparent; text-align: left; font-weight: 650; }
.nav-item span { width: 20px; color: #687382; font-size: 18px; }
.nav-item:hover { color: white; background: #121720; }
.nav-item.active { color: white; background: linear-gradient(90deg, rgba(255,106,26,.18), rgba(255,106,26,.04)); box-shadow: inset 3px 0 var(--orange); }
.nav-item.active span { color: var(--orange); }
.sidebar-foot { margin-top: auto; padding: 16px 7px 0; border-top: 1px solid var(--line); }
.identity { margin-bottom: 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }

.content { min-width: 0; padding: 34px 40px 60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; }
.server-state { display: flex; align-items: center; gap: 9px; padding: 9px 13px; border: 1px solid rgba(55,211,149,.18); border-radius: 999px; color: #a9b6b0; background: rgba(55,211,149,.06); font-size: 12px; }
.server-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 13px var(--green); }
.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.metric { padding: 21px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, #121720, #0e1218); }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 12px 0 5px; font-size: 29px; letter-spacing: -.03em; }
.metric small { color: #6f7a89; }
.panel { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(16,20,27,.88); }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; }
.panel-head p { margin-bottom: 0; font-size: 13px; }
.panel-head.standalone { margin-bottom: 18px; }
.actions { display: flex; gap: 9px; align-items: center; }
.intro-panel { display: grid; grid-template-columns: 1fr 1.35fr; align-items: center; gap: 28px; margin-bottom: 18px; overflow: hidden; background: linear-gradient(120deg, rgba(255,106,26,.14), rgba(16,20,27,.9) 40%); }
.intro-panel p { margin-bottom: 0; }
.flow-line { display: flex; align-items: center; justify-content: flex-end; gap: 10px; white-space: nowrap; }
.flow-line span { padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: rgba(7,9,13,.72); font-size: 12px; }
.flow-line b { color: var(--orange); }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-column .panel + .panel { margin-top: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 12px; border-bottom: 1px solid #202631; text-align: left; vertical-align: middle; font-size: 13px; }
th { color: #7e8998; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.table-wrap { overflow-x: auto; }
.money { font-variant-numeric: tabular-nums; font-weight: 800; }
.task-money span { display: block; line-height: 1.65; }
.task-money .positive { color: var(--green); }
.task-money .negative { color: var(--red); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.online, .status.active, .status.completed { color: var(--green); background: rgba(55,211,149,.09); }
.status.offline, .status.disabled, .status.failed { color: var(--red); background: rgba(255,93,103,.09); }
.status.degraded, .status.running, .status.queued { color: var(--yellow); background: rgba(255,200,87,.09); }

.provider-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.provider-card { padding: 19px; border: 1px solid var(--line); border-radius: 15px; background: #0d1117; }
.provider-top, .route-top, .list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.provider-top h4, .route-top h3 { margin: 0; }
.provider-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 17px 0; }
.provider-meta div { padding: 11px; border-radius: 10px; background: #141922; }
.provider-meta span, .provider-meta strong { display: block; }
.provider-meta span { margin-bottom: 5px; color: #717c8b; font-size: 10px; }
.provider-meta strong { overflow: hidden; color: #cbd2da; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.card-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.provider-error { margin: 12px 0 0; padding: 10px; border-radius: 9px; color: #ff9ca2; background: rgba(255,93,103,.07); font-size: 11px; word-break: break-all; }

.route-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.route-card { min-height: 280px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(155deg, #151a22, #0d1117); }
.route-card:nth-child(1) { box-shadow: inset 0 3px var(--orange); }
.route-card:nth-child(2) { box-shadow: inset 0 3px #7667ff; }
.route-card:nth-child(3) { box-shadow: inset 0 3px #24b9c7; }
.route-card:nth-child(4n) { box-shadow: inset 0 3px #e45fc7; }
.route-card:nth-child(4n + 1) { box-shadow: inset 0 3px var(--orange); }
.route-card:nth-child(4n + 2) { box-shadow: inset 0 3px #7667ff; }
.route-card:nth-child(4n + 3) { box-shadow: inset 0 3px #24b9c7; }
.route-card > p { min-height: 42px; font-size: 12px; }
.route-stats { display: flex; gap: 12px; margin: 18px 0; }
.route-stats div { flex: 1; padding: 12px; border-radius: 11px; background: rgba(0,0,0,.22); }
.route-stats span, .route-stats strong { display: block; }
.route-stats span { color: #707b89; font-size: 10px; }
.route-stats strong { margin-top: 5px; font-size: 20px; }
.model-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 44px; margin-bottom: 18px; }
.chip { padding: 6px 8px; border: 1px solid #2a323e; border-radius: 8px; color: #9ca7b5; background: #11161e; font-size: 10px; }
.route-card-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.route-card-actions .primary, .route-card-actions .danger { min-height: 39px; }
.route-empty { grid-column: 1 / -1; border: 1px dashed var(--line); border-radius: var(--radius); }

.list-row { padding: 12px 0; border-bottom: 1px solid #202631; }
.list-row:last-child { border-bottom: 0; }
.list-row small { display: block; margin-top: 4px; color: var(--muted); }
.empty { padding: 30px 10px; color: #687382; text-align: center; }

dialog { width: min(680px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 20px; color: var(--text); background: var(--panel); box-shadow: 0 30px 100px #000; }
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
dialog .large { width: 100%; }
dialog:has(.large) { width: min(760px, calc(100% - 28px)); }
dialog:has(.xlarge) { width: min(1180px, calc(100% - 28px)); }
.dialog-card { padding: 24px; }
.dialog-head, .dialog-actions, .subhead { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.dialog-head { margin-bottom: 23px; }
.dialog-head h3 { margin: 0; }
.dialog-actions { justify-content: flex-end; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-input-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-input-action .ghost { min-height: 43px; white-space: nowrap; }
.credential-card { padding: 18px; border: 1px solid rgba(55,211,149,.3); border-radius: 13px; background: rgba(55,211,149,.06); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 2; word-break: break-all; }
.credential-card strong { display: inline-block; min-width: 58px; color: #8f99a8; }
.codes-textarea { width: 100%; min-height: 360px; resize: vertical; padding: 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; color: #dfe4ea; background: #0b0e13; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.65; }
.provider-endpoint-preview, .provider-verify-result { padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px; background: #0c1016; color: var(--muted); font-size: 11px; line-height: 1.7; word-break: break-all; }
.provider-endpoint-preview strong, .provider-verify-result strong { color: #dfe4ea; }
.provider-verify-result.ok { border-color: rgba(75,193,134,.42); color: #8fd8b5; background: rgba(75,193,134,.07); }
.provider-verify-result.error { border-color: rgba(255,93,103,.45); color: #ff9ca2; background: rgba(255,93,103,.07); }
.import-snippet { width: 100%; min-height: 220px; resize: vertical; padding: 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; color: #dfe4ea; background: #0b0e13; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.65; }
.import-snippet:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,106,26,.1); }
.provider-import-result { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #0c1016; color: var(--muted); font-size: 12px; line-height: 1.7; word-break: break-word; }
.provider-import-result strong { color: #dfe4ea; }
.provider-import-result.ok { border-color: rgba(75,193,134,.42); color: #8fd8b5; background: rgba(75,193,134,.07); }
.provider-import-result.warn { border-color: rgba(255,200,87,.42); color: #ffd77e; background: rgba(255,200,87,.07); }
.provider-import-result.error { border-color: rgba(255,93,103,.45); color: #ff9ca2; background: rgba(255,93,103,.07); }
.route-info { grid-template-columns: 1fr 1.4fr auto; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.subhead { margin: 20px 0 13px; }
.subhead p { margin: 0; font-size: 12px; }
.bindings-editor { display: grid; gap: 10px; max-height: 440px; overflow: auto; }
.binding-row { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 8px; align-items: end; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: #0c1016; }
.binding-row label { font-size: 10px; }
.binding-row input, .binding-row select { min-height: 37px; padding: 0 9px; font-size: 12px; }
.binding-row .icon-button { margin-bottom: 0; }
.binding-row .billing-wide { grid-column: span 2; }
.binding-row [hidden] { display: none; }

.model-picker-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto; gap: 9px; align-items: center; }
.model-picker-summary { display: flex; justify-content: space-between; gap: 16px; margin: 15px 0 10px; color: var(--muted); font-size: 12px; }
.model-picker-list { display: grid; gap: 8px; max-height: 440px; padding-right: 4px; overflow-y: auto; }
.model-option { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; background: #0c1016; cursor: pointer; }
.model-option:hover { border-color: #3c4655; background: #111720; }
.model-option.is-selected { border-color: rgba(255,106,26,.58); background: rgba(255,106,26,.08); }
.model-option input { width: 17px; min-height: auto; margin: 0; accent-color: var(--orange); }
.model-option-copy { min-width: 0; }
.model-option-copy strong, .model-option-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-option-copy strong { color: #e6e9ed; font-size: 13px; }
.model-option-copy small { margin-top: 4px; color: #778290; font-size: 11px; }
.model-kind { display: inline-flex; margin-left: 7px; padding: 2px 6px; border-radius: 999px; color: #9aa6b5; background: #1b222c; font-size: 9px; font-weight: 800; text-transform: uppercase; vertical-align: 1px; }
.model-picker-empty { padding: 34px 14px; border: 1px dashed var(--line); border-radius: 12px; color: #687382; text-align: center; }

.provider-ledger-hint { margin: -8px 0 16px; padding: 12px 14px; border: 1px solid rgba(255,106,26,.22); border-radius: 12px; color: #c9d0d8; background: rgba(255,106,26,.07); font-size: 12px; line-height: 1.7; }
.provider-model-ledger { display: grid; gap: 12px; max-height: 64vh; padding-right: 5px; overflow: auto; }
.provider-model-ledger-row { padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(145deg, #0c1016, #111720); }
.model-ledger-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.model-ledger-head strong, .model-ledger-head small { display: block; }
.model-ledger-head strong { color: #e8ecf0; font-size: 14px; }
.model-ledger-head small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.ledger-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.ledger-stats div { padding: 10px; border-radius: 10px; background: rgba(255,255,255,.035); }
.ledger-stats span, .ledger-stats strong { display: block; }
.ledger-stats span { margin-bottom: 5px; color: #748092; font-size: 10px; }
.ledger-stats strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.ledger-stats .positive { color: var(--green); }
.ledger-stats .negative { color: var(--red); }
.model-cost-grid { display: grid; grid-template-columns: repeat(4, minmax(145px, 1fr)); gap: 9px; align-items: end; }
.model-cost-grid label { font-size: 10px; }
.model-cost-grid input, .model-cost-grid select { min-height: 37px; padding: 0 9px; font-size: 12px; }
.model-cost-grid .wide { grid-column: span 2; }
.model-cost-field[hidden] { display: none; }
.model-cost-actions { display: flex; justify-content: flex-end; }
.model-cost-actions .primary { min-height: 37px; width: 100%; }

.toast { position: fixed; z-index: 100; top: 20px; right: 20px; max-width: 360px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 11px; opacity: 0; pointer-events: none; color: white; background: #1a2029; box-shadow: 0 16px 50px rgba(0,0,0,.4); transform: translateY(-8px); transition: .2s ease; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255,93,103,.45); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .route-grid { grid-template-columns: 1fr; }
  .provider-grid { grid-template-columns: 1fr; }
  .intro-panel { grid-template-columns: 1fr; }
  .flow-line { justify-content: flex-start; overflow-x: auto; }
  .binding-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; }
  nav { grid-template-columns: repeat(2, 1fr); }
  .sidebar-foot { margin-top: 18px; }
  .content { padding: 24px 16px 50px; }
  .topbar, .panel-head { align-items: flex-start; flex-direction: column; }
  .metric-grid, .two-column { grid-template-columns: 1fr; }
  .form-grid, .route-info { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .model-picker-toolbar { grid-template-columns: 1fr; }
  .ledger-stats, .model-cost-grid { grid-template-columns: 1fr; }
  .model-cost-grid .wide { grid-column: auto; }
  .actions { width: 100%; }
  .compact { width: 100%; }
}
