:root {
  color-scheme: dark;
  --canvas: #090a0c;
  --sidebar: #14161a;
  --surface: #17191d;
  --surface-hover: #1c1f24;
  --surface-strong: #202329;
  --line: #292d33;
  --line-strong: #383d45;
  --ink: #f2f3f5;
  --muted: #9298a3;
  --subtle: #656b75;
  --accent: #2f6fed;
  --accent-soft: rgba(47, 111, 237, .14);
  --success: #18b98a;
  --success-soft: rgba(24, 185, 138, .12);
  --warning: #d89c44;
  --warning-soft: rgba(216, 156, 68, .13);
  --danger: #e15c64;
  --danger-soft: rgba(225, 92, 100, .12);
  --radius: 12px;
  --radius-small: 8px;
  --sidebar-width: 228px;
  --number-font: "Helvetica Neue", "SF Pro Display", Arial, sans-serif;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--canvas); }
body { margin: 0; min-height: 100dvh; background: var(--canvas); color: var(--ink); font-size: 15px; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }
section, header { scroll-margin-top: 24px; }

.skip-link { position: fixed; top: 10px; left: 10px; z-index: 40; padding: 9px 12px; border-radius: 7px; background: var(--accent); color: white; text-decoration: none; transform: translateY(-160%); transition: transform .2s ease; }
.skip-link:focus { transform: translateY(0); }

.app-shell { min-width: 0; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100dvh; padding: 20px 12px 14px; display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid var(--line); }
.sidebar-brand { min-height: 58px; padding: 3px 8px 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 7px; border-bottom: 1px solid var(--line); }
.sidebar-brand img { width: 160px; max-height: 34px; object-fit: contain; object-position: left center; }
.sidebar-brand span { color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; padding-top: 18px; }
.sidebar-nav a { min-height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 11px; border-radius: 8px; color: #aeb3bc; font-size: 14px; font-weight: 550; text-decoration: none; transition: color .18s ease, background .18s ease, transform .18s ease; }
.sidebar-nav a:hover { color: var(--ink); background: var(--surface-hover); }
.sidebar-nav a:active { transform: translateY(1px); }
.sidebar-nav a.active { color: white; background: #25282d; }
.sidebar-nav a.active svg { color: var(--accent); }
.sidebar-nav svg, .sidebar-profile svg, .header-actions svg, .metric-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.sidebar-nav rect { fill: none; }
.sidebar-profile { margin-top: auto; min-height: 58px; padding: 12px 8px 0; display: grid; grid-template-columns: 34px 1fr 30px; align-items: center; gap: 9px; border-top: 1px solid var(--line); }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-strong); color: var(--muted); font-size: 12px; font-weight: 700; }
.sidebar-profile strong, .sidebar-profile span { display: block; }
.sidebar-profile strong { font-size: 12px; font-weight: 650; }
.sidebar-profile span { margin-top: 2px; color: var(--subtle); font-size: 11px; }
.sidebar-profile button { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--subtle); cursor: pointer; transition: color .18s, background .18s; }
.sidebar-profile button:hover { color: var(--ink); background: var(--surface-strong); }

main { min-width: 0; width: 100%; max-width: none; margin: 0; padding: 38px clamp(28px, 2.5vw, 52px) 64px; }
.page-header { min-height: 64px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-header h1 { margin: 0; font-size: clamp(29px, 2vw, 35px); line-height: 1.08; letter-spacing: -.035em; font-weight: 650; }
.page-header p { margin: 9px 0 0; max-width: 620px; color: var(--muted); font-size: 15px; line-height: 1.45; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.system-status { min-height: 42px; padding: 0 12px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.system-status strong, .system-status div > span { display: block; }
.system-status strong { font-size: 12px; font-weight: 650; }
.system-status div > span { margin-top: 2px; color: var(--subtle); font-size: 10px; font-variant-numeric: tabular-nums; }
.lamp { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px var(--warning-soft); }
.lamp.online { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.lamp.offline { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.secondary-button { min-height: 42px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; transition: border-color .18s, background .18s, transform .18s; }
.secondary-button:hover { border-color: var(--line-strong); background: var(--surface-hover); }
.secondary-button:active { transform: translateY(1px); }
.icon-only { width: 42px; display: grid; place-items: center; }
.icon-only.loading svg { animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric-card { min-height: 156px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); transition: border-color .2s ease, transform .2s ease, background .2s ease; }
.metric-card:hover { border-color: var(--line-strong); background: var(--surface-hover); transform: translateY(-1px); }
.metric-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #c4c8ce; font-size: 13px; font-weight: 600; }
.metric-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); background: #202329; }
.metric-icon svg { width: 15px; height: 15px; }
.metric-card > strong { display: block; margin-top: 28px; font-family: var(--number-font); font-size: 31px; line-height: 1; letter-spacing: -.025em; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric-card > p { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

.view-page { min-height: calc(100dvh - 168px); animation: view-in .2s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
.overview-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.overview-panel { min-height: 276px; }
.detail-list { padding: 4px 20px 14px; }
.detail-list > div { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid #24272c; }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list span { color: var(--muted); font-size: 12px; }
.detail-list strong { color: var(--ink); font-family: var(--number-font); font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.detail-list .state-text.success { color: var(--success); }
.detail-list .state-text.warning { color: var(--warning); }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 650; cursor: pointer; transition: color .18s, transform .18s; }
.text-button:hover { color: #72a0ff; }
.text-button:active { transform: translateY(1px); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .75fr); gap: 14px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.panel-heading { min-height: 78px; padding: 18px 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.section-tag, .count-label { color: var(--accent); font-size: 10px; line-height: 1; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.section-tag { padding: 7px 9px; border-radius: 6px; background: var(--accent-soft); }

.finance-panel { min-height: 330px; }
.budget-meter { padding: 24px 20px 20px; }
.budget-labels, .meter-caption { display: flex; justify-content: space-between; gap: 20px; }
.budget-labels { align-items: baseline; color: var(--muted); font-size: 12px; }
.budget-labels strong { color: var(--ink); font-family: var(--number-font); font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.meter { height: 7px; margin-top: 15px; overflow: hidden; border-radius: 99px; background: #25282d; }
.meter-fill { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .45s cubic-bezier(.2,.7,.2,1), background .25s; }
.meter-fill.warning { background: var(--warning); }
.meter-fill.critical { background: var(--danger); }
.meter-caption { margin-top: 9px; color: var(--subtle); font-size: 10px; }
.meter-caption span:last-child { color: var(--warning); font-weight: 650; }
.finance-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 20px 20px; border: 1px solid var(--line); border-radius: 9px; background: #131518; }
.finance-stats div { min-height: 86px; padding: 16px; border-right: 1px solid var(--line); }
.finance-stats div:last-child { border-right: 0; }
.finance-stats span, .finance-stats strong { display: block; }
.finance-stats span { color: var(--muted); font-size: 11px; }
.finance-stats strong { margin-top: 13px; font-family: var(--number-font); font-size: 21px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.settings-panel { min-height: 330px; padding-bottom: 16px; }
.field-label { display: block; margin: 20px 18px 8px; color: #c1c5cb; font-size: 12px; font-weight: 600; }
.input-combo { height: 42px; margin: 0 18px; display: grid; grid-template-columns: 34px 1fr auto; border: 1px solid var(--line); border-radius: 8px; background: #111316; overflow: hidden; }
.input-combo > span { display: grid; place-items: center; color: var(--muted); border-right: 1px solid var(--line); }
.input-combo input { min-width: 0; padding: 0 11px; border: 0; outline: 0; background: transparent; color: var(--ink); font-family: var(--number-font); font-weight: 650; font-variant-numeric: tabular-nums; }
.input-combo input:focus { box-shadow: inset 0 0 0 1px var(--accent); }
.input-combo button { padding: 0 15px; border: 0; background: var(--accent); color: white; font-size: 12px; font-weight: 650; cursor: pointer; transition: filter .18s, transform .18s; }
.input-combo button:hover { filter: brightness(1.1); }
.input-combo button:active { transform: translateY(1px); }
.gateway-switch { min-height: 58px; margin: 15px 18px 0; padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-radius: 8px; background: #131518; cursor: pointer; }
.gateway-switch b, .gateway-switch small { display: block; }
.gateway-switch b { font-size: 12px; font-weight: 650; }
.gateway-switch small { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.3; }
.gateway-switch input { position: absolute; opacity: 0; pointer-events: none; }
.gateway-switch i { width: 38px; height: 21px; position: relative; flex: 0 0 auto; border-radius: 20px; background: #353941; transition: background .2s; }
.gateway-switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #d5d8dd; transition: transform .2s cubic-bezier(.2,.8,.2,1); }
.gateway-switch input:checked + i { background: var(--success); }
.gateway-switch input:checked + i::after { transform: translateX(17px); background: white; }
.gateway-switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 3px; }
.settings-meta { min-height: 36px; margin: 12px 18px 0; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.settings-meta strong { color: var(--ink); font-family: var(--number-font); font-size: 14px; font-weight: 650; }
.settings-note { margin: 16px 18px 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #131518; }
.settings-note strong, .settings-note p { display: block; }
.settings-note strong { font-size: 12px; font-weight: 650; }
.settings-note p { margin: 6px 0 0; max-width: 58ch; color: var(--muted); font-size: 11px; line-height: 1.5; }
.gateway-panel .gateway-switch { margin-top: 20px; }
.system-panel { min-height: 330px; }
.system-detail-list { padding-top: 8px; }
.wide-panel { min-height: 0; }

.usage-panel, .throughput-panel { min-height: 266px; margin-top: 0; }
.panel-total { font-family: var(--number-font); font-size: 27px; line-height: 1; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.plan-list { padding: 5px 20px 14px; }
.plan-list > div { min-height: 40px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #24272c; }
.plan-list > div:last-child { border-bottom: 0; }
.plan-list span { display: flex; align-items: center; color: #c5c8ce; font-size: 12px; }
.plan-list strong { font-family: var(--number-font); font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.plan-dot { width: 6px; height: 6px; margin-right: 10px; border-radius: 50%; background: #5c626d; }
.plan-dot.creator { background: var(--accent); }
.plan-dot.internal { background: var(--success); }
.throughput-stats { display: grid; grid-template-columns: repeat(2, 1fr); }
.throughput-stats > div { min-height: 118px; padding: 20px; border-right: 1px solid var(--line); }
.throughput-stats > div:last-child { border-right: 0; }
.throughput-stats span, .throughput-stats strong { display: block; }
.throughput-stats span { color: var(--muted); font-size: 11px; }
.throughput-stats strong { margin-top: 20px; font-family: var(--number-font); font-size: 31px; font-weight: 650; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.activity-line { height: 6px; margin: 0 20px 20px; overflow: hidden; border-radius: 99px; background: #25282d; }
.activity-line span { display: block; width: 42%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--success), var(--accent)); opacity: .72; }

.jobs-panel { margin-top: 14px; min-height: 260px; }
.view-page > .jobs-panel { margin-top: 0; }
.count-label { align-self: center; padding: 7px 9px; border-radius: 6px; background: var(--accent-soft); }
.table-scroll { max-width: 100%; overflow: auto; }
table { width: 100%; min-width: 860px; border-collapse: collapse; font-size: 12px; }
th { padding: 13px 20px; color: var(--muted); background: #131518; text-align: left; font-size: 10px; font-weight: 700; letter-spacing: .055em; text-transform: uppercase; }
td { padding: 13px 20px; border-top: 1px solid #24272c; color: #aeb3bc; }
tbody tr { transition: background .16s; }
tbody tr:hover { background: var(--surface-hover); }
td.mono { color: #d6d9dd; font-family: var(--number-font); font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 6px; font-size: 10px; font-weight: 700; }
.status.succeeded { color: var(--success); background: var(--success-soft); }
.status.failed { color: var(--danger); background: var(--danger-soft); }
.status.processing, .status.reserved { color: var(--warning); background: var(--warning-soft); }
.empty-cell { height: 150px; color: var(--muted); text-align: center; }
.empty-cell strong, .empty-cell span { display: block; }
.empty-cell strong { color: #c8cbd0; font-size: 13px; }
.empty-cell span { margin-top: 6px; font-size: 11px; }

.login-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(5, 6, 8, .88); backdrop-filter: blur(10px); }
.login-panel { width: min(430px, 100%); overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 30px 90px rgba(0,0,0,.45); }
.login-brand { min-height: 78px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #14161a; }
.login-brand img { width: 172px; max-height: 36px; object-fit: contain; object-position: left center; }
.login-brand span { color: var(--subtle); font-size: 9px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.login-body { padding: 26px 24px 24px; }
.login-body h2 { margin: 17px 0 7px; font-size: 23px; line-height: 1.15; letter-spacing: -.03em; }
.login-body p { margin: 0; max-width: 42ch; color: var(--muted); font-size: 12px; line-height: 1.55; }
.login-body label { display: block; margin: 23px 0 8px; color: #c7cad0; font-size: 11px; font-weight: 600; }
.login-body input { width: 100%; height: 45px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; outline: 0; background: #111316; color: var(--ink); font-family: var(--number-font); transition: border-color .18s, box-shadow .18s; }
.login-body input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-body button { width: 100%; height: 43px; margin-top: 14px; border: 0; border-radius: 8px; background: var(--accent); color: white; font-size: 12px; font-weight: 650; cursor: pointer; transition: filter .18s, transform .18s; }
.login-body button:hover { filter: brightness(1.1); }
.login-body button:active { transform: translateY(1px); }
.login-panel > small { display: block; padding: 0 24px 20px; color: var(--subtle); font-size: 9px; }
.form-error { margin-top: 10px; padding: 9px 10px; border-radius: 7px; color: #f18a90; background: var(--danger-soft); font-size: 10px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; max-width: 360px; padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 9px; background: #202329; color: var(--ink); box-shadow: 0 18px 55px rgba(0,0,0,.36); font-size: 11px; animation: toast-in .22s ease-out; }
.toast.error { border-color: rgba(225,92,100,.35); color: #f4b0b4; }
.toast.success { border-color: rgba(24,185,138,.35); color: #85dfc3; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
main:focus { outline: 0; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .overview-grid, .settings-grid { grid-template-columns: 1fr; }
  .settings-panel, .finance-panel, .usage-panel, .throughput-panel { min-height: 0; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: relative; width: 100%; height: auto; padding: 12px 16px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 18px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand { min-height: 0; padding: 0; border: 0; }
  .sidebar-brand img { width: 138px; }
  .sidebar-brand span { display: none; }
  .sidebar-nav { min-width: 0; max-width: 100%; padding: 0; flex-direction: row; justify-content: center; overflow-x: auto; }
  .sidebar-nav a { min-height: 38px; padding: 0 10px; white-space: nowrap; }
  .sidebar-nav a svg { display: none; }
  .sidebar-profile { margin: 0; min-height: 0; padding: 0; grid-template-columns: 30px; border: 0; }
  .sidebar-profile .avatar { display: none; }
  .sidebar-profile > div:not(.avatar) { display: none; }
  .sidebar-profile button { display: grid; }
  main { padding-top: 26px; }
}

@media (max-width: 620px) {
  .sidebar { grid-template-columns: 1fr auto; }
  .sidebar-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; }
  .system-status { flex: 1; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 132px; }
  .metric-card > strong { margin-top: 20px; }
  .finance-stats { grid-template-columns: 1fr; }
  .finance-stats div { border-right: 0; border-bottom: 1px solid var(--line); }
  .finance-stats div:last-child { border-bottom: 0; }
  .panel-heading { min-height: 70px; }
}

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