:root {
  color-scheme: light;
  --canvas: #f2f4f3;
  --surface: #ffffff;
  --surface-muted: #f7f8f7;
  --rail: #151918;
  --rail-2: #202624;
  --ink: #151a18;
  --ink-2: #4e5954;
  --ink-3: #6d7772;
  --line: #d9dfdc;
  --line-strong: #bdc7c2;
  --green: #087443;
  --green-dark: #075d38;
  --green-soft: #e4f4eb;
  --amber: #925c07;
  --amber-soft: #fff1d2;
  --red: #b4232d;
  --red-soft: #fde8e8;
  --cyan: #176b87;
  --cyan-soft: #e3f2f6;
  --focus: #087443;
  --shadow: 0 12px 28px rgba(17, 27, 22, .09), 0 2px 5px rgba(17, 27, 22, .06);
  --radius: 5px;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--ink); line-height: 1.5; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .58; }
input, select { color: var(--ink); }
input::placeholder { color: #737d78; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
code, .mono { font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace; letter-spacing: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent); outline-offset: 2px; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand-lockup { display: flex; align-items: center; gap: 10px; font-weight: 720; letter-spacing: 0; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border: 1px solid #47514d; border-radius: 4px; background: #232a27; color: #d9f3e4; font-size: 11px; font-weight: 800; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(90deg, var(--rail) 0 12px, var(--canvas) 12px); }
.login-panel { width: min(100%, 400px); padding: 30px; border: 1px solid var(--line); border-top: 3px solid var(--green); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.login-panel .brand-lockup { margin-bottom: 42px; }
.login-panel h1 { margin: 0 0 8px; font-size: 24px; line-height: 1.2; letter-spacing: 0; }
.login-panel > p { margin: 0 0 24px; color: var(--ink-2); }
.login-panel form { display: grid; gap: 10px; }

.app-shell { min-height: 100vh; }
.side-rail { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; width: 228px; flex-direction: column; padding: 20px 14px 16px; background: var(--rail); color: #eff4f1; }
.side-brand { height: 44px; padding: 0 10px; }
.primary-nav { display: grid; gap: 3px; margin-top: 32px; }
.primary-nav a { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; min-height: 42px; padding: 0 11px; border: 1px solid transparent; border-radius: 4px; color: #aeb8b3; text-decoration: none; }
.primary-nav a:hover { background: var(--rail-2); color: #fff; }
.primary-nav a.active { border-color: #3f4a46; background: #29312e; color: #fff; }
.primary-nav a.active svg { color: #7ed6a6; }
.primary-nav b { min-width: 22px; padding: 1px 6px; border-radius: 10px; background: #313a36; color: #cad3cf; font-size: 11px; text-align: center; }
.rail-footer { display: grid; gap: 12px; margin-top: auto; padding-top: 16px; border-top: 1px solid #303936; }
.gateway-state { display: flex; align-items: center; gap: 9px; padding: 4px 10px; }
.gateway-state > span:last-child { display: grid; }
.gateway-state b { font-size: 12px; }
.gateway-state small { color: #8f9c96; font-size: 11px; }
.status-light { width: 8px; height: 8px; border-radius: 50%; background: #3fc67a; box-shadow: 0 0 0 3px rgba(63, 198, 122, .13); }
.button-rail { justify-content: flex-start; border-color: #36403c; background: transparent; color: #b8c2bd; }
.button-rail:hover { background: var(--rail-2); color: #fff; }

.workspace { min-height: 100vh; margin-left: 228px; padding: 30px clamp(24px, 4vw, 58px) 70px; }
.page { width: min(100%, 1420px); margin: 0 auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; min-height: 76px; margin-bottom: 26px; padding-bottom: 18px; border-bottom: 1px solid var(--line-strong); }
.page-header h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: 0; }
.page-header p { margin: 7px 0 0; color: var(--ink-2); }
.mobile-header, .mobile-nav { display: none; }

.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 4px; transition: background-color .16s ease-out, border-color .16s ease-out, color .16s ease-out, box-shadow .16s ease-out; }
.button { min-height: 38px; gap: 8px; padding: 8px 13px; font-weight: 650; }
.button svg { width: 16px; height: 16px; }
.button-primary { border-color: var(--green); background: var(--green); color: #fff; }
.button-primary:hover { border-color: var(--green-dark); background: var(--green-dark); box-shadow: 0 4px 10px rgba(8, 116, 67, .18); }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.button-secondary:hover { border-color: #8f9b95; background: var(--surface-muted); }
.button-danger { border-color: var(--red); background: var(--red); color: #fff; }
.button-danger:hover { background: #941c25; }
.button-block { width: 100%; margin-top: 8px; }
.icon-button { width: 34px; height: 34px; padding: 0; border-color: var(--line); background: var(--surface); color: var(--ink-2); }
.icon-button:hover { border-color: var(--line-strong); background: var(--surface-muted); color: var(--ink); }
.icon-button.danger:hover { border-color: #e4a7ac; background: var(--red-soft); color: var(--red); }

.field-label, .field label, fieldset legend { display: block; margin-bottom: 6px; color: var(--ink); font-size: 12px; font-weight: 700; }
input, select { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); }
input:hover, select:hover { border-color: #929e98; }
input:focus, select:focus { border-color: var(--focus); outline: 3px solid color-mix(in srgb, var(--focus) 16%, transparent); }
input:disabled { background: #eef1ef; color: var(--ink-3); }
.input-action { position: relative; }
.input-action input { padding-right: 44px; }
.input-action .icon-button { position: absolute; top: 2px; right: 2px; border-color: transparent; background: transparent; }
.field-error, .form-error { min-height: 20px; margin: 0; color: var(--red); font-size: 12px; }

.operating-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 26px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.signal { min-width: 0; padding: 16px 18px; border-right: 1px solid var(--line); }
.signal:last-child { border-right: 0; }
.signal dt { color: var(--ink-2); font-size: 12px; font-weight: 650; }
.signal dd { display: flex; align-items: baseline; gap: 7px; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.signal strong { overflow: hidden; font-size: 25px; line-height: 1.1; text-overflow: ellipsis; }
.signal span { color: var(--ink-3); font-size: 12px; }
.signal[data-tone="good"] strong { color: var(--green); }
.signal[data-tone="warn"] strong { color: var(--amber); }
.signal[data-tone="danger"] strong { color: var(--red); }

.data-section { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.section-heading h2, .settings-band h2, .reference-band h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.section-heading p { margin: 3px 0 0; color: var(--ink-3); font-size: 12px; }
.timestamp { color: var(--ink-3); font-size: 12px; }
.table-frame { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 9px 16px; background: #f4f6f5; color: var(--ink-2); font-size: 11px; font-weight: 720; text-align: left; white-space: nowrap; }
td { height: 62px; padding: 11px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
tbody tr:hover { background: #fafbfa; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.actions-heading { text-align: right; }
.cell-main { display: flex; align-items: center; gap: 9px; font-weight: 680; }
.cell-sub { display: block; max-width: 34ch; margin-top: 3px; overflow: hidden; color: var(--ink-3); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.provider-code { display: grid; place-items: center; width: 27px; height: 27px; flex: none; border: 1px solid var(--line-strong); border-radius: 3px; background: var(--surface-muted); color: var(--ink-2); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; min-width: 155px; }
.empty-row td { height: 150px; color: var(--ink-3); text-align: center; }
.empty-state { display: grid; justify-items: center; gap: 5px; }
.empty-state svg { width: 24px; height: 24px; color: #8d9792; }
.empty-state b { color: var(--ink-2); }

.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface-muted); color: var(--ink-2); font-size: 11px; font-weight: 680; white-space: nowrap; }
.badge::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.badge.good { border-color: #add7c0; background: var(--green-soft); color: var(--green-dark); }
.badge.warn { border-color: #e8cd91; background: var(--amber-soft); color: var(--amber); }
.badge.danger { border-color: #e8b1b5; background: var(--red-soft); color: var(--red); }
.badge.info { border-color: #b5d7e1; background: var(--cyan-soft); color: var(--cyan); }
.badge.neutral::before { display: none; }
.quota-cell { min-width: 150px; }
.quota-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.quota-line b { font-size: 13px; }
.quota-line small { color: var(--ink-3); }
.quota-track { display: block; width: 100%; height: 3px; margin-top: 8px; overflow: hidden; border: 0; appearance: none; background: #e4e8e6; }
.quota-track::-webkit-progress-bar { background: #e4e8e6; }
.quota-track::-webkit-progress-value { background: var(--green); }
.quota-track::-moz-progress-bar { background: var(--green); }
.quota-track.warn::-webkit-progress-value { background: var(--amber); }
.quota-track.warn::-moz-progress-bar { background: var(--amber); }
.quota-track.danger::-webkit-progress-value { background: var(--red); }
.quota-track.danger::-moz-progress-bar { background: var(--red); }

.action-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.action-group { display: flex; align-items: center; gap: 8px; }
.action-group select { width: auto; min-width: 130px; }
.segmented { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 5px; background: #e8ecea; }
.segment { min-height: 31px; padding: 4px 10px; border: 0; border-radius: 3px; background: transparent; color: var(--ink-2); font-size: 12px; font-weight: 650; }
.segment:hover { color: var(--ink); }
.segment.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(18, 30, 24, .12); }
.provider-note { display: grid; grid-template-columns: minmax(140px, .7fr) minmax(280px, 2fr) auto; align-items: center; gap: 18px; min-height: 58px; margin-bottom: 14px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-muted); }
.provider-note h2 { margin: 0; font-size: 13px; }
.provider-note p { margin: 0; color: var(--ink-2); font-size: 12px; }
.text-link { display: inline-flex; align-items: center; gap: 5px; color: var(--cyan); font-size: 12px; font-weight: 680; text-decoration: none; white-space: nowrap; }
.text-link:hover { text-decoration: underline; }
.text-link svg { width: 13px; height: 13px; }

.settings-band, .reference-band { display: grid; grid-template-columns: minmax(220px, .8fr) minmax(320px, 1.2fr); gap: 44px; padding: 24px 0; border-top: 1px solid var(--line-strong); }
.settings-band p { max-width: 46ch; margin: 7px 0 0; color: var(--ink-2); }
.settings-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 9px; }
.settings-form label { grid-column: 1 / -1; }
.reference-band dl { margin: 0; }
.reference-band dl div { display: grid; grid-template-columns: 70px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.reference-band dt { color: var(--ink-3); font-size: 12px; font-weight: 700; }
.reference-band dd { margin: 0; }
.reference-band code { display: inline-block; margin: 0 5px 5px 0; padding: 2px 5px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); font-size: 12px; }
.mobile-session-band { display: none; }

dialog { width: min(720px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 13, 11, .58); }
dialog[open] { animation: dialog-in .18s cubic-bezier(.2, .8, .2, 1); }
@keyframes dialog-in { from { transform: translateY(8px); opacity: .72; } to { transform: translateY(0); opacity: 1; } }
.compact-dialog { width: min(500px, calc(100vw - 28px)); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 19px 22px 15px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 17px; }
.dialog-header p { margin: 4px 0 0; color: var(--ink-3); font-size: 12px; }
.dialog-body { display: grid; gap: 18px; padding: 20px 22px; }
.dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 22px; border-top: 1px solid var(--line); background: var(--surface-muted); }
.dialog-footer > div { display: flex; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { min-width: 0; }
.field small, fieldset small { display: block; margin-top: 5px; color: var(--ink-3); font-size: 11px; }
fieldset.field { padding: 0; border: 0; }
.quota-editor { padding: 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-muted); }
.quota-editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.quota-editor h3 { margin: 0; font-size: 13px; }
.quota-editor p { margin: 3px 0 0; color: var(--ink-2); font-size: 11px; }
.unit-chip { padding: 2px 7px; border: 1px solid var(--line-strong); border-radius: 3px; background: var(--surface); color: var(--ink-2); font-size: 11px; font-weight: 700; }
.billing-facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 4px; background: var(--line); }
.billing-fact { min-height: 56px; padding: 9px 11px; background: var(--surface); }
.billing-fact b { display: block; font-size: 11px; }
.billing-fact span { color: var(--ink-2); font-size: 11px; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.check-option { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.check-option:hover { border-color: var(--line-strong); }
.check-option input { width: 16px; min-height: 16px; accent-color: var(--green); }
.secret-value { display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 4px; background: #f4f6f5; }
.secret-value code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: var(--ink); font-size: 12px; }
.clipboard-fallback { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; width: min(390px, calc(100vw - 32px)); gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 11px 13px; border: 1px solid #3d4843; border-radius: 4px; background: #202624; color: #f7faf8; box-shadow: var(--shadow); animation: toast-in .2s cubic-bezier(.2, .8, .2, 1); }
.toast.error { border-color: #9f343c; background: #4b2024; }
.toast svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: #78d5a1; }
.toast.error svg { color: #ffafb5; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 980px) {
  .side-rail { width: 196px; }
  .workspace { margin-left: 196px; padding-inline: 22px; }
  .provider-note { grid-template-columns: 1fr auto; }
  .provider-note p { grid-column: 1 / -1; grid-row: 2; }
  .operating-strip { grid-template-columns: repeat(2, 1fr); }
  .signal:nth-child(2) { border-right: 0; }
  .signal:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  body { padding-bottom: 68px; }
  .side-rail { display: none; }
  .mobile-header { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; height: 58px; padding: 0 16px; border-bottom: 1px solid #303936; background: var(--rail); color: #fff; }
  .mobile-header .icon-button { border-color: #3d4843; background: var(--rail-2); color: #e8eeeb; }
  .mobile-nav { position: fixed; inset: auto 0 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); height: 64px; padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid #303936; background: var(--rail); }
  .mobile-nav a { display: grid; place-items: center; align-content: center; gap: 3px; color: #9aa69f; font-size: 10px; text-decoration: none; }
  .mobile-nav a.active { color: #8ae0b1; }
  .mobile-nav svg { width: 19px; height: 19px; }
  .workspace { margin-left: 0; padding: 20px 14px 32px; }
  .page-header { align-items: center; min-height: 64px; margin-bottom: 18px; padding-bottom: 14px; }
  .page-header h1 { font-size: 22px; }
  .page-header p { font-size: 12px; }
  .page-header .button-secondary { display: none; }
  .operating-strip { margin-bottom: 18px; }
  .signal { padding: 13px; }
  .signal strong { font-size: 21px; }
  .action-bar { align-items: stretch; flex-direction: column; }
  .segmented { flex-wrap: nowrap; overflow-x: auto; }
  .segment { flex: 0 0 auto; }
  .action-group .button { flex: 1; }
  .provider-note { grid-template-columns: 1fr auto; }
  .account-section .section-heading { display: none; }
  .account-table thead { display: none; }
  .account-table, .account-table tbody, .account-table tr, .account-table td { display: block; width: 100%; }
  .account-table tr { position: relative; padding: 15px; border-top: 1px solid var(--line); }
  .account-table tr:first-child { border-top: 0; }
  .account-table td { height: auto; padding: 5px 0; border: 0; }
  .account-table td:last-child { padding-top: 10px; }
  .account-table .row-actions { justify-content: flex-start; }
  .account-table .cell-sub, .key-table .cell-sub { max-width: none; overflow: visible; text-overflow: clip; white-space: normal; }
  .key-table thead { display: none; }
  .key-table, .key-table tbody, .key-table tr, .key-table td { display: block; width: 100%; }
  .key-table tr { padding: 15px; border-top: 1px solid var(--line); }
  .key-table tr:first-child { border-top: 0; }
  .key-table td { height: auto; padding: 5px 0; border: 0; text-align: left; }
  .key-table td:last-child { padding-top: 10px; }
  .key-table .row-actions { justify-content: flex-start; }
  .account-table td[data-label]::before, .key-table td[data-label]::before { display: block; margin-bottom: 3px; color: var(--ink-3); content: attr(data-label); font-size: 10px; font-weight: 720; text-transform: uppercase; }
  .row-actions .icon-button { width: 44px; height: 44px; }
  .page-header .button-primary { min-width: 44px; min-height: 44px; }
  .mobile-header .icon-button { width: 44px; height: 44px; }
  .settings-band, .reference-band { grid-template-columns: 1fr; gap: 20px; }
  .mobile-session-band { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0; border-top: 1px solid var(--line-strong); }
  .mobile-session-band h2 { margin: 0; font-size: 15px; }
  .mobile-session-band p { margin: 5px 0 0; color: var(--ink-2); font-size: 12px; }
  .settings-form { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .billing-facts { grid-template-columns: 1fr; }
  .dialog-header, .dialog-body, .dialog-footer { padding-inline: 16px; }
  .dialog-footer { align-items: stretch; flex-direction: column; }
  .dialog-footer > div { justify-content: flex-end; }
  .toast-region { right: 16px; bottom: 80px; }
}

@media (max-width: 420px) {
  .login-panel { padding: 24px 20px; }
  .page-header { align-items: flex-start; }
  .page-header .button-primary { width: 38px; padding: 0; }
  .page-header .button-primary span { display: none; }
  .operating-strip { grid-template-columns: 1fr 1fr; }
  .signal { min-height: 78px; }
  .signal dd { display: grid; gap: 2px; }
  .action-group { display: grid; grid-template-columns: 1fr 1fr; }
  .button { padding-inline: 10px; }
  .check-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
