:root {
  /* Copilot-inspired light palette */
  --brand: #2b62d9;
  --brand-deep: #2352bd;
  --brand-soft: #e8efff;
  --bg: #f1f3f8;
  --bg-elevated: #ffffff;
  --bg-raised: #f6f7fb;
  --border: #e4e8f0;
  --text: #121a2b;
  --muted: #8a94a8;
  --accent: var(--brand);
  --accent-strong: var(--brand);
  --ok: #22c55e;
  --warn: #f97316;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 6px 20px rgba(30, 41, 59, 0.08);
  --shadow-sm: 0 2px 8px rgba(30, 41, 59, 0.06);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  /* Type scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --fs-xl: 24px;

  /* Derived surfaces */
  --grid: rgba(18, 26, 43, 0.08);
  --hover: rgba(43, 98, 217, 0.05);
  --danger-border: #fecaca;
  --warn-border: #fed7aa;
  --ok-border: #bbf7d0;
  --meter-track: #eceff5;
  --meter-fill: var(--ok);
  --meter-fill-text: #0b1220;
  --meter-ok: #34d17a;
  --meter-warn: #fb923c;
  --meter-danger: #f87171;
  --tap: 44px;

  /* Chart palette */
  --chart-1: #2b62d9;
  --chart-2: #7c5cff;
  --chart-3: #22c55e;
  --chart-4: #f97316;
  --chart-5: #ef4444;
  --chart-6: #0ea5e9;
  --chart-7: #ec4899;
  --chart-8: #84cc16;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  min-height: 100vh;
}

.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;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: #fff;
  color: var(--brand);
  padding: 8px 12px;
  z-index: 100;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px 8px;
  background: var(--brand);
  color: #fff;
}

.topbar .muted {
  color: rgba(255, 255, 255, 0.72);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: var(--fs-lg);
  margin: 0;
}

.brand p {
  margin: 0;
  font-size: var(--fs-sm);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #fff;
  color: var(--brand);
  font-weight: 800;
  letter-spacing: 0.5px;
}

.brand h1 {
  font-weight: 800;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  /* The band continues below the tabs so the first card overlaps it. */
  padding: 6px 24px 64px;
  background: var(--brand);
  overflow-x: auto;
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  border-radius: var(--radius-pill);
  color: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 9px 16px;
  white-space: nowrap;
}

.tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.tab.is-active {
  color: var(--brand);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

main {
  position: relative;
  z-index: 1;
  padding: 0 var(--s-5) var(--s-6);
  max-width: 1200px;
  margin: -48px auto 0;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-4);
}

h2 {
  font-size: 20px;
  font-weight: 800;
  margin: 0;
}

/* Section labels in the Copilot style: small caps, muted. */
.status {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  font-size: var(--fs-xs);
}

.actions {
  display: flex;
  gap: 8px;
}

.btn {
  appearance: none;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  border-color: #cfd6e4;
  background: var(--bg-raised);
}

.btn:focus-visible,
.tab:focus-visible,
.seg:focus-visible,
.toast-close:focus-visible,
input[type="checkbox"]:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[disabled],
.btn[aria-busy="true"] {
  opacity: 0.6;
  cursor: progress;
}

.btn[disabled]:not([aria-busy="true"]) {
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-deep);
  border-color: var(--brand-deep);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger-border);
  background: #fff5f5;
}

.btn-small {
  padding: 4px 9px;
  font-size: var(--fs-sm);
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: var(--fs-sm);
  margin: 6px 0;
}

.status.is-error,
.form-error {
  color: var(--danger);
}

.hint {
  color: var(--muted);
  font-size: var(--fs-sm);
}

code {
  font-family: var(--mono);
  background: var(--bg-raised);
  padding: 1px 5px;
  border-radius: 5px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--hover);
}

td.numeric {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

td.actions-cell {
  white-space: nowrap;
  text-align: right;
}

td.actions-cell .btn {
  margin-left: 4px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.unsupported {
  margin-top: 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
}

.unsupported summary {
  cursor: pointer;
  color: var(--muted);
}

.unsupported ul {
  columns: 2;
  margin: 10px 0 0;
  padding-left: 18px;
}

.unsupported li {
  font-size: var(--fs-sm);
  color: var(--muted);
  margin-bottom: 4px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg {
  appearance: none;
  background: var(--bg-raised);
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 7px 14px;
}

.seg:last-child {
  border-right: 0;
}

.seg.is-active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.card {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-label {
  color: var(--muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card strong {
  font-size: var(--fs-xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.chart {
  margin: 0;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 14px;
}

.chart figcaption {
  color: var(--muted);
  font-size: var(--fs-sm);
  margin-bottom: 10px;
}

.chart-box {
  position: relative;
  height: 280px;
}

.dialog {
  background: var(--bg-elevated);
  color: var(--text);
  border: 0;
  box-shadow: 0 24px 60px rgba(18, 26, 43, 0.25);
  border-radius: 18px;
  padding: 20px;
  width: min(460px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(18, 26, 43, 0.45);
}

.dialog h3 {
  font-weight: 800;
}

.dialog h3 {
  margin-top: 0;
}

.dialog label {
  display: block;
  margin: 12px 0 4px;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.dialog select,
.dialog input {
  width: 100%;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font: inherit;
}

.dialog select:focus-visible,
.dialog input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.form-error {
  font-size: var(--fs-sm);
  margin: 10px 0 0;
}

.fallback {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.fallback summary {
  cursor: pointer;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.fallback .btn {
  margin-top: 10px;
}

.remote-hint {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.08);
  color: var(--warn);
  font-size: var(--fs-sm);
}

.key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.key-value {
  flex: 1;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  overflow-wrap: anywhere;
}

.toast[hidden] {
  display: none;
}

.toast {
  color: var(--text);
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  box-shadow: 0 12px 30px rgba(18, 26, 43, 0.18);
  z-index: 200;
  max-width: min(90vw, 520px);
}

.toast.is-error {
  border-color: var(--danger-border);
  color: var(--danger);
}

.toast-close {
  appearance: none;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  opacity: 0.7;
}

.toast-close:hover {
  opacity: 1;
  background: var(--hover);
}

/* ── Confirm dialog ─────────────────────────────────────────────────── */

.dialog-confirm {
  width: min(400px, calc(100vw - 32px));
}

.confirm-message {
  color: var(--muted);
  margin: 0;
  overflow-wrap: anywhere;
}

/* ── Quota meters ───────────────────────────────────────────────────── */

.meter-stack {
  display: grid;
  gap: var(--s-2);
}

.meter {
  --pct: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  height: 36px;
  padding: 0 var(--s-3);
  border-radius: var(--radius-pill);
  background: var(--meter-track);
  overflow: hidden;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.meter-label {
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text);
  white-space: nowrap;
}

.meter-value {
  white-space: nowrap;
}

/* The fill is a clipped window over a dark-text copy of the same row. */
.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--pct) * 1%);
  background: var(--meter-fill);
  border-radius: var(--radius-pill);
  overflow: hidden;
  transition: width 240ms ease;
}

.meter-fill-inner {
  position: absolute;
  inset: 0;
  width: calc(100% * 100 / max(var(--pct), 0.01));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  color: var(--meter-fill-text);
}

.meter-fill-inner .meter-label,
.meter-fill-inner .meter-value {
  color: var(--meter-fill-text);
}

.meter.is-ok .meter-fill {
  background: var(--meter-ok);
}

.meter.is-warn .meter-fill {
  background: var(--meter-warn);
}

.meter.is-danger .meter-fill {
  background: var(--meter-danger);
}

.meter.is-neutral .meter-fill {
  background: #d7dde9;
}

/* ── Account cells ──────────────────────────────────────────────────── */

.account-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.account-meta {
  font-size: var(--fs-xs);
  color: var(--muted);
  overflow-wrap: break-word;
}

.mono {
  font-family: var(--mono);
  font-size: var(--fs-sm);
}

.badge-provider {
  font-family: var(--mono);
  text-transform: none;
  background: var(--brand-soft);
  color: var(--brand);
  border-color: transparent;
  font-weight: 700;
}

tr.is-inactive .account-name,
tr.is-inactive .badge-provider {
  opacity: 0.55;
}

.toggle-cell input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Error summaries ────────────────────────────────────────────────── */

.error-summary {
  display: grid;
  gap: var(--s-1);
  max-width: 320px;
}

.error-summary .badge {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
  padding: 3px 9px;
}

.error-link {
  color: inherit;
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.error-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.error-raw {
  margin: var(--s-1) 0 0;
  padding: var(--s-2);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

td.error-cell {
  max-width: 360px;
}

.badge {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  font-size: var(--fs-xs);
  border: 1px solid var(--border);
}

.badge-ok {
  color: var(--ok);
  border-color: var(--ok-border);
}

.badge-off {
  color: var(--muted);
}

.badge-err {
  color: var(--danger);
  border-color: var(--danger-border);
}

.quota-line {
  font-size: var(--fs-xs);
  color: var(--muted);
}

/* ── Header session ──────────────────────────────────────────────────── */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .btn {
  background: rgba(255, 255, 255, 0.14);
  border-color: transparent;
  color: #fff;
  box-shadow: none;
}

.topbar .btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.user-badge {
  color: #fff;
  font-size: var(--fs-sm);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Login ───────────────────────────────────────────────────────────── */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--brand) 0 42%, var(--bg) 42%);
}

.login-card {
  width: min(380px, 100%);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 28px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0;
}

.login-card label {
  display: block;
  margin: 14px 0 4px;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.login-card input {
  width: 100%;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font: inherit;
}

.login-card input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-submit {
  width: 100%;
  margin-top: 18px;
}

.login-submit[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-hint {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: var(--fs-sm);
  color: var(--muted);
  margin: 14px 0 0;
}

.login-hint code {
  display: inline-block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

/* ── Chains ──────────────────────────────────────────────────────────── */

.chains-list {
  display: grid;
  gap: 14px;
  margin: 16px 0;
}

.chain-card {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.chain-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chain-head h3 {
  margin: 0;
  font-size: 16px;
}

.chain-badges {
  display: flex;
  gap: 6px;
}

.chain-items-list {
  margin: 10px 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
}

.chain-items-list li {
  margin-bottom: 3px;
}

.chain-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chain-test {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.test-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-size: var(--fs-sm);
}

.test-ready {
  color: var(--ok);
}

.test-skip {
  color: var(--muted);
}

.dialog-wide {
  width: min(680px, calc(100vw - 32px));
}

.row-checks {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 14px;
}

.items-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  padding: 12px;
}

.items-fieldset legend {
  color: var(--muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px;
}

.chain-items {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.chain-item {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 0.8fr 0.7fr auto auto auto;
  gap: 6px;
  align-items: center;
}

.chain-item select,
.chain-item input {
  width: 100%;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  font: inherit;
  font-size: var(--fs-sm);
}

.account-detail {
  padding: 6px 2px 14px;
}

.account-detail-inner {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.detail-effort {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.detail-effort select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font: inherit;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 14px;
}

.model-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  color: var(--text);
}

.model-toggle .badge {
  margin-left: auto;
}

.model-toggle .badge + .badge {
  margin-left: 0;
}

.model-name {
  overflow-wrap: anywhere;
}

.badge-custom {
  color: var(--warn);
  border-color: var(--warn-border);
}

/* A14: a model's effort levels rendered as one small tag (e.g. low · high · max). */
.badge-effort {
  color: var(--brand);
  border-color: var(--brand);
  font-family: var(--mono);
  letter-spacing: 0.01em;
}

.custom-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.custom-add input {
  flex: 1;
  min-width: 180px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: var(--fs-sm);
}

.snippet-wrap {
  margin-top: 24px;
}

.snippet-wrap h3 {
  font-weight: 800;
}

.snippet {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
}


/* ── Provider selection strategy (FEATURE-LB) ───────────────────────── */

.provider-settings {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--s-4);
  margin: 12px 0;
}

.provider-settings h3 {
  margin: 0 0 4px;
  font-size: var(--fs-md);
}

.provider-settings-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-3);
}

.provider-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.provider-settings-name {
  color: var(--muted);
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-settings-row select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font: inherit;
}

.provider-settings-row select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.provider-sticky-group {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.provider-sticky-ttl {
  width: 64px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font: inherit;
}

.provider-sticky:focus-visible,
.provider-sticky-ttl:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Account cards ──────────────────────────────────────────────────── */

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: var(--s-4);
}

.empty-card {
  grid-column: 1 / -1;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.account-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s-4) var(--s-4) var(--s-3);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.account-card:hover {
  box-shadow: 0 10px 28px rgba(30, 41, 59, 0.12);
}

.account-card.is-expanded {
  grid-column: 1 / -1;
}

.account-card.is-inactive {
  opacity: 0.72;
}

.account-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
  font-size: var(--fs-sm);
  overflow: hidden;
}

.avatar.has-image {
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--border);
}

.avatar img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.account-title {
  flex: 1;
  min-width: 0;
}

.account-title .account-name {
  font-size: var(--fs-lg);
  font-weight: 800;
  line-height: 1.2;
}

.account-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
  margin-top: var(--s-2);
}

.tag {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--bg-raised);
  color: var(--muted);
}

.tag-oauth {
  background: var(--brand-soft);
  color: var(--brand);
}

.tag-key {
  background: #ecfdf3;
  color: #15803d;
}

.tag-warn {
  background: #fff4e6;
  color: #c2410c;
}

.tag-danger {
  background: #fef2f2;
  color: #b91c1c;
}

/* iOS-style switch */
.switch {
  flex: none;
  display: inline-block;
  position: relative;
  width: 46px;
  height: 28px;
  cursor: pointer;
}

.switch-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: #d5dbe7;
  transition: background 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 160ms ease;
}

.switch-input:checked + .switch-track {
  background: var(--ok);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.quota-block {
  display: grid;
  gap: var(--s-2);
}

.quota-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.quota-empty {
  color: var(--muted);
  font-size: var(--fs-sm);
  padding: var(--s-3);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.account-error {
  display: grid;
  gap: var(--s-1);
  padding: var(--s-3);
  border-radius: var(--radius-sm);
  background: #fff7f7;
}

.account-error .error-summary {
  max-width: none;
}

.account-actions {
  display: flex;
  gap: var(--s-2);
  padding-top: var(--s-3);
  border-top: 1px solid var(--grid);
  margin-top: auto;
}

.account-actions .btn {
  flex: 1;
}

.account-card .account-detail {
  padding: 0;
}

.account-card .account-detail-inner {
  border: 0;
  border-top: 1px solid var(--grid);
  border-radius: 0;
  padding: var(--s-3) 0 0;
}


/* ── Chain and key cards ────────────────────────────────────────────── */

.chains-grid {
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  margin: 0 0 var(--s-5);
}

.avatar-chain {
  background: linear-gradient(140deg, var(--brand), #7c5cff);
  color: #fff;
}

.avatar-key {
  background: #ecfdf3;
  color: #15803d;
}

.mono-name {
  font-family: var(--mono);
}

.chain-card.is-default {
  box-shadow: var(--shadow), 0 0 0 2px var(--brand-soft);
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--s-2);
}

.step {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
}

.step .avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 11px;
}

.step .avatar img {
  width: 24px;
  height: 24px;
}

.step-index {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.step-body {
  min-width: 0;
  flex: 1;
}

.step-model {
  font-weight: 700;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.step-body .account-tags {
  margin-top: var(--s-1);
}

.chain-test {
  margin: 0;
  padding: var(--s-3);
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  border: 0;
}

.test-list li {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-1);
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin: 0;
}

.facts div {
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
  padding: var(--s-2) var(--s-3);
}

.facts dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.facts dd {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: var(--fs-sm);
}


/* ── Requests log ───────────────────────────────────────────────────── */

.request-list {
  display: grid;
  gap: var(--s-2);
}

.list-day {
  margin: var(--s-4) 0 var(--s-1);
}

.list-day:first-child {
  margin-top: 0;
}

.request-card {
  padding: 0;
  gap: 0;
}

.request-card.is-failed {
  box-shadow: var(--shadow-sm), inset 3px 0 0 var(--danger);
}

.request-details summary {
  list-style: none;
  cursor: pointer;
}

.request-details summary::-webkit-details-marker {
  display: none;
}

.request-summary {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
}

.request-summary .avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 11px;
}

.request-summary .avatar img {
  width: 24px;
  height: 24px;
}

.request-time {
  flex: none;
  width: 44px;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.request-figures {
  flex: none;
  text-align: right;
  display: grid;
  line-height: 1.2;
}

.request-tokens {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.request-body {
  padding: 0 var(--s-4) var(--s-4);
  display: grid;
  gap: var(--s-3);
}

.facts-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* ── Usage ──────────────────────────────────────────────────────────── */

.usage-hero {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
}

.hero-stat {
  display: grid;
  gap: var(--s-1);
}

.hero-stat strong {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hero-stat-right {
  text-align: right;
}

.ring {
  --pct: 0;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(var(--brand) calc(var(--pct) * 1%), var(--meter-track) 0);
  display: grid;
  place-items: center;
}

.ring-inner {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 2px;
}

.ring-inner strong {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  margin-top: var(--s-5);
}

.breakdown h3 {
  margin: 0 0 var(--s-2);
}

.share-meter {
  height: 26px;
  margin-top: var(--s-1);
  font-size: var(--fs-xs);
}

.segmented {
  border: 0;
  background: var(--bg-raised);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.seg {
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  font-weight: 700;
}

.seg.is-active {
  background: var(--bg-elevated);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}


/* ── Chain editor ───────────────────────────────────────────────────── */

.chain-form .dialog label + input,
.chain-form select {
  margin-bottom: 0;
}

.chain-name-hint {
  margin: var(--s-2) 0 0;
}

.switch-rows {
  display: grid;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

.dialog label.switch-row,
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3);
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: 0;
  font-size: var(--fs-md);
  color: var(--text);
}

.switch-copy {
  display: grid;
  gap: 2px;
}

.switch-title {
  font-weight: 700;
}

.steps-head {
  margin-top: var(--s-5);
  margin-bottom: var(--s-2);
}

.chain-items {
  gap: var(--s-2);
}

.step-editor {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-3);
  display: grid;
  gap: var(--s-3);
  transition: box-shadow 120ms ease, opacity 120ms ease;
}

.step-editor.is-dragging {
  opacity: 0.4;
}

.step-editor.is-over {
  box-shadow: 0 0 0 2px var(--brand);
}

/* A14: the PUT items 400 marks the step whose effort is invalid. */
.step-editor.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.step-editor-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  letter-spacing: -3px;
  font-size: 14px;
  padding: 0 2px;
  user-select: none;
}

.step-editor .avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 11px;
}

.step-editor .avatar img {
  width: 24px;
  height: 24px;
}

.step-tools {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 16px;
}

.icon-btn:hover {
  background: var(--bg-raised);
  color: var(--text);
}

.icon-btn-danger:hover {
  background: #fff5f5;
  color: var(--danger);
}

.step-editor-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.field {
  display: grid;
  gap: var(--s-1);
  margin: 0;
}

.field-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field select,
.field input[type="range"] {
  width: 100%;
}

.field select:disabled {
  opacity: 0.6;
}

.step-options summary {
  cursor: pointer;
  color: var(--brand);
  font-size: var(--fs-sm);
  font-weight: 700;
}

.step-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin-top: var(--s-2);
}

.range-value {
  color: var(--brand);
}

input[type="range"] {
  accent-color: var(--brand);
  height: 36px;
}

.btn-add-step {
  appearance: none;
  width: 100%;
  margin-top: var(--s-2);
  padding: var(--s-3);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-add-step:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.switch-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
}

.switch-inline .switch {
  width: 40px;
  height: 24px;
}

.switch-inline .switch-track::after {
  width: 18px;
  height: 18px;
}

.switch-inline .switch-input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch-inline-label .account-meta {
  font-weight: 400;
}

.panel-head .actions {
  align-items: center;
  flex-wrap: wrap;
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .chain-item {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .usage-hero {
    grid-template-columns: 1fr 1fr;
  }

  .ring-wrap {
    grid-column: 1 / -1;
    justify-self: center;
    order: -1;
  }

  .hero-stat strong {
    font-size: 22px;
  }

  .facts-4 {
    grid-template-columns: 1fr 1fr;
  }

  .request-time {
    display: none;
  }

  .chains-grid {
    grid-template-columns: 1fr;
  }

  main {
    padding: var(--s-4);
  }

  .topbar {
    padding: var(--s-3) var(--s-4) var(--s-1);
    flex-wrap: wrap;
  }

  .tabs {
    padding-bottom: 56px;
  }

  main {
    margin-top: -40px;
    padding: 0 var(--s-4) var(--s-5);
  }

  .brand-text p {
    display: none;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .tabs {
    padding-left: var(--s-4);
    padding-right: var(--s-4);
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    /* Fade hints that the tab strip scrolls. */
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }

  .tab {
    padding: var(--s-3) var(--s-3);
    white-space: nowrap;
    min-height: var(--tap);
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head .actions,
  .panel-head > .btn {
    width: 100%;
  }

  .panel-head .actions .btn {
    flex: 1;
  }

  .btn,
  .seg {
    min-height: var(--tap);
  }

  .btn-small {
    min-height: 40px;
    padding: var(--s-2) var(--s-3);
  }

  .unsupported ul {
    columns: 1;
  }

  .step-editor-fields,
  .step-options-grid {
    grid-template-columns: 1fr;
  }

  /* Tables become stacked cards. Each cell shows its column name from data-label. */
  .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  .table-cards,
  .table-cards tbody,
  .table-cards tr,
  .table-cards td {
    display: block;
    width: 100%;
  }

  .table-cards thead {
    display: none;
  }

  .table-cards tr {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius);
    padding: var(--s-2) var(--s-3);
    margin-bottom: var(--s-3);
  }

  .table-cards tr:hover {
    background: var(--bg-elevated);
  }

  .table-cards td {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: var(--s-2);
    align-items: start;
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--grid);
  }

  .table-cards td:last-child {
    border-bottom: 0;
  }

  .table-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 2px;
  }

  .table-cards td.empty,
  .table-cards td[colspan] {
    display: block;
  }

  .table-cards td.empty::before,
  .table-cards td[colspan]::before {
    content: none;
  }

  .meter-stack {
    min-width: 0;
  }

  .error-summary {
    max-width: none;
  }

  td.actions-cell {
    white-space: normal;
  }

  /* Dialogs take the full screen on phones. */
  .dialog,
  .dialog-wide,
  .dialog-confirm {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: var(--s-5) var(--s-4);
    overflow-y: auto;
  }

  .dialog-confirm {
    height: auto;
    max-height: none;
    width: calc(100vw - 32px);
    margin: auto;
    border-radius: 18px;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    background: var(--bg-elevated);
    padding-top: var(--s-3);
    margin-top: var(--s-5);
  }

  .dialog-actions .btn {
    flex: 1;
  }

  .toast {
    left: var(--s-4);
    right: var(--s-4);
    transform: none;
    max-width: none;
  }

  .chart-box {
    height: 220px;
  }
}

@media (hover: none) {
  tbody tr:hover {
    background: transparent;
  }
}
