:root {
  --header-h: 68px;
  --sidebar-w: 224px;
  --content-max: 1420px;
  --r-xs: 7px;
  --r-sm: 10px;
  --r: 18px;
  --r-lg: 22px;
  --ease: cubic-bezier(.2,.75,.25,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

* { box-sizing: border-box; }
body {
  /* Resolve aliases against the active platform palette. */
  --ink: var(--fg);
  --muted: var(--mut);
  --surface-soft: var(--surface-2);
  --page: var(--bg);
  --teal: var(--acc);
  --teal-dark: var(--acc-hover);
  --teal-soft: var(--acc-soft);
  --coral: var(--brand);
  --coral-soft: var(--danger-soft);
  --green: var(--success);
  --red: var(--danger);
  --shadow: var(--sh);
  min-width: 320px;
  margin: 0;
  color: var(--fg);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.portal-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 0 20px;
}
.header-inner {
  width: 100%;
  max-width: 1680px;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
}
.brand { min-width: 0; display: inline-flex; flex: 0 0 auto; align-items: center; gap: 11px; color: inherit; text-decoration: none; white-space: nowrap; }
.brand-copy { min-width: 0; display: grid; gap: 1px; }
.brand strong { color: var(--fg-strong); font-size: 16px; font-weight: 650; letter-spacing: .2px; }
.brand small { line-height: 1.2; letter-spacing: .3px; }
.badge-lite { margin-left: 6px; padding: 2px 7px; border-radius: 6px; color: var(--acc); background: var(--acc-soft); font-size: 10px; font-weight: 600; letter-spacing: .5px; vertical-align: middle; }
.portal-modes { display: flex; align-items: center; gap: 3px; margin-left: auto; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.portal-mode-link { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 13px; border: 1px solid transparent; border-radius: 999px; color: var(--mut); font-size: 12px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.portal-mode-link:hover { color: var(--fg); background: var(--surface-2); }
.portal-mode-link[aria-current="page"] { border-color: var(--acc-ring); color: var(--acc); background: var(--acc-soft); }
.portal-mode-link:focus-visible, .theme-switch button:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.header-actions { flex-shrink: 0; gap: 8px; }
.theme-switch button { display: grid; place-items: center; }
.identity { color: var(--muted); font-size: 12px; }

.page-shell { width: min(1260px, calc(100% - 48px)); margin: 0 auto; padding: 32px 0 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding-bottom: 22px; }
.page-heading h1 { margin: 0; color: var(--fg-strong); font-size: clamp(25px, 2vw, 28px); line-height: 1.32; font-weight: 700; }
.eyebrow { margin: 0 0 6px; color: var(--teal); font-size: 10px; font-weight: 700; }
.balance-large { color: var(--teal-dark); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 18px; min-height: 44px; border-bottom: 1px solid var(--line); }
.tab { position: relative; padding: 0 2px 10px; border: 0; color: var(--muted); background: transparent; font-size: 13px; font-weight: 600; }
.tab-link { display: inline-flex; align-items: center; text-decoration: none; }
.tab-link:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--teal-dark); }
.tab.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--teal); content: ""; }
.tab-panel { padding: 18px 22px 22px; border: 1px solid var(--border-card); border-radius: var(--r); background: var(--surface-card); box-shadow: var(--sh-card); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; font-size: 16px; font-weight: 650; }
.section-heading h3 { margin: 0; font-size: 14px; }
.muted { color: var(--muted); }
.section-heading .muted { margin: 5px 0 0; font-size: 11px; }
.call-filter { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: var(--mut); font-size: 13px; }
.call-filter select { width: auto; min-width: 92px; }
.call-table .call-data { min-width: 126px; white-space: normal; overflow-wrap: anywhere; }
.call-detail { display: block; margin-top: 3px; color: var(--mut); font-size: 12px; }

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  font-size: 12px;
  font-weight: 630;
  white-space: nowrap;
}
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { color: #fff; background: var(--teal); }
.button-primary:hover { background: var(--teal-dark); }
.button-quiet { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button-quiet:hover { background: var(--surface-soft); }
.button-danger { color: var(--red); background: var(--coral-soft); border-color: var(--danger-soft); }
.button-danger:hover { background: var(--danger-soft); }

.summary-strip { display: flex; gap: 48px; padding: 15px 0 19px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-strip div { display: grid; gap: 4px; }
.summary-strip span { color: var(--muted); font-size: 11px; }
.summary-strip strong { font-size: 20px; font-weight: 680; font-variant-numeric: tabular-nums; }
.table-scroll { width: 100%; overflow: auto; border: 1px solid var(--line-soft); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
thead { color: var(--muted); background: var(--control-hover); }
th { padding: 10px 12px; font-size: 10px; font-weight: 650; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--acc-soft); }
td .button { min-height: 29px; padding: 0 8px; font-size: 10px; }
.empty-cell { height: 68px; color: var(--muted); text-align: center; }
.table-more { margin-top: 12px; }
.ledger-heading { margin-top: 28px; }
.ledger-heading h2 { font-size: 14px; }
.amount-positive { color: var(--green); font-variant-numeric: tabular-nums; }
.amount-negative { color: var(--red); font-variant-numeric: tabular-nums; }
.status-text { display: inline-flex; align-items: center; gap: 6px; }
.status-text::before { width: 7px; height: 7px; border-radius: 50%; background: var(--green); content: ""; }
.status-text[data-status="suspended"]::before, .status-text[data-status="failed"]::before { background: var(--red); }
.status-text[data-status="running"]::before { background: #c48824; }

.settings-form { width: min(620px, 100%); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.settings-form label, .form-stack label, .dialog-form label {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.settings-form input, .form-stack input,
.dialog-form input, .dialog-form select, .search-form input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--control-line);
  border-radius: var(--r-xs);
  outline: none;
  color: var(--fg);
  background: var(--control-bg);
  font-size: 12px;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--acc-ring); }
input[readonly] { background: var(--surface-soft); color: var(--muted); }
.settings-form .form-message, .settings-form button, .settings-form .field-note { grid-column: 1 / -1; }
.field-note { color: var(--muted); font-size: 10px; font-weight: 400; }
.form-message { min-height: 16px; margin: 0; color: var(--muted); font-size: 11px; }
.form-message[data-tone="error"] { color: var(--red); }
.form-message[data-tone="success"] { color: var(--green); }
.divider { height: 1px; margin: 30px 0 24px; background: var(--line); }

.search-form { display: flex; gap: 7px; width: min(400px, 100%); }
.search-form input { min-width: 0; flex: 1; }
.user-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.provider-list { display: grid; gap: var(--admin-gap, 16px); }
.provider-card-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; }
.provider-card-header > div { min-width: 0; overflow-wrap: anywhere; }
.provider-title { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.provider-title h2 { margin: 0; color: var(--fg-strong); font-size: 15px; }
.provider-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.provider-recommended { padding: 1px 7px; border-radius: 999px; color: var(--acc); background: var(--acc-soft); font-size: 11px; }
.provider-model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 10px;
  min-width: 0;
  padding: 0;
  margin: 0;
  list-style: none;
}
.provider-model-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  background: var(--surface-soft);
  overflow-wrap: anywhere;
}
.provider-model-card strong { color: var(--fg-strong); font-size: 13px; }
.model-card-state, .model-card-price { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.model-card-price { font-variant-numeric: tabular-nums; }
.model-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.model-service-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.provider-model-card .model-service-actions { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.model-toggle-button {
  --model-toggle-blue: light-dark(#1d4ed8, #9ebcff);
  width: 36px;
  padding: 0;
  color: var(--model-toggle-blue);
  border-color: light-dark(#c6d6fb, #405a87);
  background: light-dark(#eef4ff, #202e45);
}
.model-toggle-button:not(:disabled):hover { background: light-dark(#dee9ff, #30456a); }
.model-toggle-button:focus-visible { outline: 2px solid var(--model-toggle-blue); outline-offset: 2px; }
.model-toggle-icon { position: relative; width: 20px; height: 12px; border: 1px solid currentColor; border-radius: 8px; }
.model-toggle-icon::after { content: ""; position: absolute; top: 2px; left: 2px; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.model-toggle-button[data-enabled="true"] .model-toggle-icon { background: currentColor; }
.model-toggle-button[data-enabled="true"] .model-toggle-icon::after { left: 10px; background: light-dark(#fff, #18263d); }
.model-pricing-unit { margin: 0; }
.model-card-test-result:not(:empty) { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.model-card-test-result:empty { min-height: 0; }
#model-image-test-preview { max-width: 100%; max-height: min(54vh, 384px); object-fit: contain; justify-self: center; border-radius: var(--r-xs); }
#model-pricing-dialog:has(#model-cny-pricing:not([hidden])) { width: min(960px, calc(100% - 28px)); }
#model-pricing-form, .pricing-fields { grid-template-columns: minmax(0, 1fr); }
.pricing-fields { display: grid; gap: 12px; min-width: 0; }
.pricing-summary { display: grid; grid-template-columns: minmax(105px, 160px) minmax(0, 1fr); gap: 20px; align-items: center; }
.pricing-summary > div { display: grid; gap: 2px; }
.pricing-summary strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.pricing-summary small { color: var(--muted); }
.pricing-tier-options { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.dialog-form .pricing-tier-toggle, .dialog-form .pricing-threshold { display: inline-flex; align-items: center; gap: 8px; }
.dialog-form .pricing-tier-toggle input { flex: none; width: 16px; height: 16px; min-height: 16px; padding: 0; margin: 0; accent-color: var(--fg-strong); }
.dialog-form .pricing-threshold input { width: 110px; min-height: 32px; }
.pricing-table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-xs); }
.pricing-table-scroll:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.pricing-table { width: 100%; min-width: 690px; table-layout: fixed; }
.pricing-tier-column { width: 88px; }
.pricing-label-column { width: 84px; }
.pricing-table th, .pricing-table td { padding: 8px; text-align: left; font-size: 11px; }
.pricing-table tbody th { color: var(--muted); font-weight: 500; background: none; }
.pricing-table tbody .pricing-tier-name { color: var(--fg-strong); font-weight: 650; }
.pricing-tier-boundary { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap; }
.pricing-tier-boundary:empty { display: none; }
#model-pricing-threshold-equivalent { min-width: 38px; color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.pricing-table tbody:last-child tr:last-child > *, .pricing-table tbody:last-child .pricing-tier-name { border-bottom: 0; }
.pricing-table tbody tr:hover { background: inherit; }
.pricing-table tbody .pricing-sale-row { background: var(--surface-soft); }
.pricing-table td[data-sale-for] { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pricing-table input { min-width: 0; min-height: 34px; padding: 5px 7px; }
.model-sale-price, .pricing-table tbody .pricing-sale-row th, .pricing-table td[data-sale-for] {
  color: light-dark(#1d4ed8, #9ebcff);
  font-weight: 600;
}
.model-category-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.model-category-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.model-category-filters button[aria-pressed="true"] { background: var(--fg-strong); color: var(--surface); }
.model-category-count { margin-inline-start: 6px; font-variant-numeric: tabular-nums; }
.model-category-count:empty { display: none; }
.platform-settings-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 12px;
}
.platform-setting-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
}
.platform-setting-card[data-visible="true"] { border-color: var(--acc-ring); }
.platform-setting-card strong { font-size: 14px; }
.platform-card-state {
  justify-self: start;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
}
.platform-setting-card[data-visible="true"] .platform-card-state { color: var(--teal-dark); background: var(--teal-soft); }
.platform-setting-card input {
  appearance: none;
  position: relative;
  grid-row: 1 / 3;
  grid-column: 2;
  width: 38px;
  height: 22px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  cursor: pointer;
}
.platform-setting-card input::before {
  position: absolute;
  inset: 3px auto 3px 3px;
  width: 14px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
}
.platform-setting-card input:checked { border-color: var(--teal); background: var(--teal); }
.platform-setting-card input:checked::before { transform: translateX(16px); background: #fff; }
.copy-form { display: grid; gap: 10px; max-width: 720px; }
.copy-form .button { justify-self: start; }
.copy-form textarea { resize: vertical; }
.copy-result { max-width: 720px; margin-top: 22px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-sm); }
#copy-answer { white-space: pre-wrap; overflow-wrap: anywhere; }

.auth-layout { min-height: calc(100vh - 68px); display: grid; place-items: start center; padding: 76px 20px; }
.auth-panel { width: min(440px, 100%); padding: 34px; background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--r-lg); box-shadow: var(--sh-card); }
.auth-heading h1 { margin: 0; font-size: 25px; line-height: 1.2; }
.auth-heading .muted { margin: 9px 0 24px; font-size: 12px; }
.auth-heading .eyebrow { margin-bottom: 9px; }
.form-stack { display: grid; gap: 14px; }
.form-stack .button { width: 100%; margin-top: 2px; }
.auth-switch { margin: 18px 0 0; color: var(--muted); font-size: 11px; }
.auth-switch a { color: var(--teal-dark); font-weight: 650; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.dialog { width: min(480px, calc(100% - 28px)); max-height: min(88vh, 760px); padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg); color: var(--ink); background: var(--surface); box-shadow: var(--sh-lg); }
.dialog::backdrop { background: var(--scrim); }
.dialog-form { display: grid; gap: 14px; padding: 22px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 16px; }
.dialog-description { margin: 0; line-height: 1.65; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.icon-button { min-height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface); font-size: 10px; }
.secret-output { display: block; padding: 12px; border: 1px dashed var(--line); border-radius: var(--r-xs); background: var(--surface-soft); font-family: ui-monospace, monospace; overflow-wrap: anywhere; user-select: all; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#provider-dialog { width: min(540px, calc(100% - 28px)); max-height: none; overflow: hidden; }
#provider-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: min(88vh, 760px);
  max-height: min(88dvh, 760px);
  padding: 0;
}
#provider-form .dialog-heading { flex: none; padding: 20px 22px 16px; }
.provider-fields { display: grid; gap: 12px; min-height: 0; padding: 4px 22px 16px; overflow: auto; }
.provider-fieldset { min-width: 0; border: 0; padding: 0; margin: 0; }
.provider-subfields { display: grid; gap: 12px; }
.provider-connection { grid-template-columns: minmax(0, 1fr) minmax(135px, 32%); }
.provider-fields > .field-note { margin: -6px 0 0; }
.model-picker-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.model-picker-actions { display: flex; gap: 6px; }
.video-resolution-prices { display: grid; gap: 10px; margin: 0; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: var(--r-xs); min-width: 0; }
.video-resolution-price-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); gap: 12px; align-items: end; }
.video-resolution-price-row > div { padding-bottom: 9px; font-size: 12px; }
.video-resolution-price-row strong { display: block; color: var(--acc); }
.model-picker-row .button { min-height: 38px; }
.model-list-box { display: grid; gap: 7px; padding: 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--page); }
.model-list-box p { margin: 0; color: var(--muted); font-size: 10px; font-weight: 650; }
.model-checkboxes { max-height: 150px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; overflow: auto; }
.dialog-form .model-option { display: flex; align-items: flex-start; gap: 7px; color: var(--ink); font-size: 11px; font-weight: 500; overflow-wrap: anywhere; }
.model-option input { flex: none; width: 15px; height: 15px; min-height: 15px; margin: 0; accent-color: var(--teal); }
.provider-footer { flex: none; padding: 12px 22px 16px; border-top: 1px solid var(--line); }
.provider-footer .form-message { min-height: 0; overflow-wrap: anywhere; }
.provider-footer .form-message:not(:empty) { margin-bottom: 8px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(420px, calc(100% - 40px)); padding: 10px 13px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(5px); transition: opacity .16s ease, transform .16s ease; }
.toast.visible { opacity: 1; transform: none; }

.admin-shell { --admin-gap: 16px; --admin-card-padding: 20px; min-width: 0; }
.admin-module { display: grid; gap: var(--admin-gap); min-width: 0; }
.admin-module-heading, .admin-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.admin-module-heading { min-height: 52px; }
.admin-module-heading h1, .admin-card-heading h2 { margin: 0; color: var(--fg-strong); line-height: 1.3; }
.admin-module-heading h1 { font-size: 24px; font-weight: 680; }
.admin-card-heading h2 { font-size: 16px; font-weight: 650; }
.admin-module-heading p, .admin-card-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.admin-module-heading h1 + p:not(:empty) { margin-top: 4px; }
.admin-card-heading p { font-size: 12px; }
.admin-card {
  display: grid;
  gap: var(--admin-gap);
  min-width: 0;
  padding: var(--admin-card-padding);
  border: 1px solid var(--border-card);
  border-radius: var(--r);
  background: var(--surface-card);
  box-shadow: var(--sh-card);
}
.admin-card > .button { justify-self: start; }
.admin-card .table-scroll { width: 100%; margin: 0; }
.admin-card table { min-width: 640px; font-size: 13px; }
.admin-card th { font-size: 11px; }
.admin-card tbody tr:last-child td { border-bottom: 0; }
.admin-card td { overflow-wrap: anywhere; }
.admin-empty { margin: 0; padding: 24px 12px; color: var(--muted); text-align: center; }
.admin-card .form-message:empty, .admin-card .platform-settings-list:empty { display: none; }
.admin-menu-item:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

@media (max-width: 760px) {
  .portal-header { padding: 0 14px; }
  .header-inner { min-height: 68px; flex-wrap: wrap; gap: 8px 10px; padding: 9px 0; }
  .brand { flex: 1 1 auto; }
  .header-actions { gap: 8px; }
  .portal-modes { order: 3; flex: 1 0 100%; justify-content: flex-start; margin-left: 0; overflow-x: auto; }
  .portal-mode-link { flex: 0 0 auto; }
  .page-shell { width: calc(100% - 32px); padding-top: 24px; }
  .auth-layout { min-height: calc(100vh - 68px); padding-top: 42px; }
  .page-heading h1 { font-size: 22px; }
  .tab-panel { padding: 18px; }
  .settings-form { grid-template-columns: 1fr; }
  .settings-form .form-message, .settings-form button, .settings-form .field-note { grid-column: auto; }
  .search-form { width: 100%; }
}
@media (max-width: 520px) {
  .auth-layout { padding: 24px 12px; }
  .auth-panel { padding: 24px 19px; }
  .page-shell { width: calc(100% - 24px); }
  .page-heading { align-items: center; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .button { align-self: flex-start; }
  .summary-strip { gap: 28px; }
  .portal-mode-link { min-height: 32px; padding: 0 11px; font-size: 11px; }
  .field-grid { grid-template-columns: 1fr; }
  #provider-form .dialog-heading, .provider-fields, .provider-footer { padding-inline: 16px; }
  .model-checkboxes { grid-template-columns: minmax(0, 1fr); }
  .model-checkboxes { grid-template-columns: 1fr; }
  .table-scroll { margin-right: -12px; width: calc(100% + 12px); }
  th, td { padding-right: 9px; padding-left: 9px; }
  .identity { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* The portal uses the same theme controls and platform styles as the workbench. */
.portal-nav-toggle {
  display: none;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--mut);
  background: var(--surface);
}
.portal-nav-toggle:hover { color: var(--fg); background: var(--surface-2); }
.portal-nav-toggle svg { width: 17px; height: 17px; }
.portal-platform-switch {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
}
.portal-platform-switch::-webkit-scrollbar { display: none; }
.portal-platform-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 0 0 auto;
  padding: 5px 10px;
  background: transparent;
  white-space: nowrap;
}
.portal-platform-switch button:disabled { opacity: .42; cursor: not-allowed; }
.portal-platform-switch svg { width: 14px; height: 14px; }
.portal-command {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.portal-command svg { width: 15px; height: 15px; color: var(--mut); }
.portal-service {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  color: var(--mut);
  background: var(--glass-well-bg);
  box-shadow: var(--glass-specular);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}
.portal-service-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}
.portal-app-shell {
  position: relative;
  width: min(1680px, 100%);
  min-height: calc(100dvh - var(--header-h));
  display: flex;
  align-items: flex-start;
  margin: 0 auto;
}
.portal-sidebar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  flex: 0 0 var(--sidebar-w);
  min-height: calc(100dvh - var(--header-h));
  max-height: calc(100dvh - var(--header-h));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 18px 12px 28px;
  border-right: 1px solid var(--glass-border);
  background: var(--glass-sidebar-bg);
  backdrop-filter: blur(18px) saturate(165%);
  -webkit-backdrop-filter: blur(18px) saturate(165%);
  box-shadow: inset -1px 0 0 var(--glass-rim);
  scrollbar-width: none;
}
.portal-sidebar::-webkit-scrollbar { display: none; }
.portal-sidebar-mobile-head { display: none; }
.portal-nav { min-width: 0; min-height: 0; flex: 1; display: grid; align-content: start; gap: 4px; overflow-x: hidden; overflow-y: auto; scrollbar-width: none; }
.portal-nav::-webkit-scrollbar { display: none; }
.portal-nav-section { min-width: 0; display: grid; gap: 4px; }
.portal-nav-label {
  padding: 18px 13px 6px;
  color: var(--mut-2);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
}
.portal-navitem {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 11px;
  position: relative;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--mut);
  background: transparent;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.4;
  text-decoration: none;
  transition: color .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.portal-navitem:hover { color: var(--fg-strong); background-color: color-mix(in srgb, var(--fg) 5%, transparent); border-color: color-mix(in srgb, var(--glass-border) 65%, transparent); }
.portal-navitem.active,
.portal-navitem[aria-current="page"] {
  border-color: var(--choice-fill);
  color: var(--choice-ink);
  background: var(--choice-fill);
  font-weight: 650;
}
.portal-navitem svg { width: 18px; height: 18px; flex: 0 0 18px; }
.portal-navitem span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-nav-badge {
  min-width: 20px;
  height: 20px;
  display: inline-grid !important;
  place-items: center;
  margin-left: auto;
  padding: 0 5px;
  border: 1px solid var(--acc-ring);
  border-radius: 999px;
  color: var(--acc);
  background: var(--surface);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.portal-navitem:is(.active,[aria-current="page"]) .portal-nav-badge {
  border-color: transparent;
  color: inherit;
  background: color-mix(in srgb, var(--choice-ink) 17%, var(--choice-fill));
}
.portal-sidebar-footer {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--line-soft);
  background: var(--glass-sidebar-bg);
}
.portal-sidebar-footer .identity {
  min-width: 0;
  overflow: hidden;
  color: var(--mut);
  font-size: 11px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portal-sidebar-footer #logout { min-height: 30px; flex: 0 0 auto; padding: 0 9px; font-size: 10px; }
.portal-main {
  min-width: 0;
  max-width: var(--content-max);
  flex: 1;
  margin: 0 auto;
  padding: 24px 32px 56px;
}
.portal-main > .page-shell,
.portal-main > .admin-shell {
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
}
.portal-main > .auth-layout {
  min-height: calc(100vh - 132px);
  align-items: center;
  padding: 28px 20px;
}
.portal-page-heading {
  align-items: center;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line-soft);
}
.portal-page-context { min-width: 0; }
.portal-page-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  color: var(--mut);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
}
.portal-page-platform {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border: 1px solid color-mix(in srgb, var(--acc) 24%, var(--glass-border));
  border-radius: 999px;
  color: var(--acc);
  background: var(--acc-soft);
  box-shadow: inset 0 1px 0 var(--glass-rim);
}
.portal-page-platform::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}
.portal-page-heading h1 { font-size: 25px; }
.portal-page-desc { margin: 6px 0 0; color: var(--mut); font-size: 13.5px; line-height: 1.65; }
.portal-main .tabs { margin-top: 16px; }
.portal-main .tab-panel { margin-top: 12px; }
.portal-admin-section .admin-menu { display: grid; gap: 4px; min-width: 0; }
.portal-admin-section .admin-menu-item { width: 100%; min-width: 0; }
.portal-admin-return { margin-bottom: 8px; }
.portal-admin-assistant { margin-top: 8px; }
body[data-page="admin"] .portal-admin-section {
  order: -1;
  margin-top: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
body[data-page="admin"] .portal-header .header-inner { justify-content: flex-end; }
body[data-page="admin"] .portal-header .brand { margin-right: auto; }
.portal-nav-backdrop { display: none; }

@media (min-width: 1101px) and (max-width: 1380px) {
  .portal-command kbd { display: none; }
}
@media (max-width: 1200px) {
  .portal-main { padding: 22px 24px; }
}
@media (max-width: 1100px) {
  .portal-command { justify-content: center; }
}
@media (max-width: 860px) {
  body:has(.portal-platform-switch:not([hidden])) { --header-h: 118px; }
  .portal-header { padding: 0 14px; }
  .portal-header .header-inner { min-height: var(--header-h); flex-wrap: wrap; gap: 8px 10px; padding: 9px 0; }
  .portal-nav-toggle { display: grid; }
  .portal-header .brand { flex: 1 1 auto; }
  .portal-platform-switch { order: 4; flex: 1 0 100%; width: 100%; }
  .portal-header .header-actions { gap: 7px; margin-left: auto; }
  .portal-service { display: none; }
  .portal-sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 45;
    width: min(286px, 86vw);
    min-width: 0;
    max-height: none;
    visibility: hidden;
    transform: translateX(-102%);
    transition: transform .2s var(--ease-out);
    box-shadow: var(--sh-lg);
  }
  .portal-app-shell.is-nav-open .portal-sidebar { visibility: visible; transform: translateX(0); }
  .portal-sidebar-mobile-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding: 0 10px; color: var(--fg-strong); font-size: 13px; }
  .portal-nav-close { width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--mut); background: var(--surface); font-size: 20px; line-height: 1; }
  .portal-nav-backdrop { position: fixed; inset: var(--header-h) 0 0; z-index: 40; display: block; border: 0; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .portal-app-shell.is-nav-open .portal-nav-backdrop { opacity: 1; pointer-events: auto; }
  .portal-main { width: 100%; padding: 24px 16px 54px; }
  .portal-main > .auth-layout { min-height: calc(100vh - 148px); padding: 24px 10px; }
}
@media (max-width: 520px) {
  .portal-main { padding-right: 12px; padding-left: 12px; }
  .portal-main > .auth-layout { padding: 18px 0; }
  .portal-page-heading h1 { font-size: 22px; }
  .portal-page-desc { font-size: 11px; }
  .admin-shell { --admin-card-padding: 14px; --admin-gap: 12px; }
  .admin-module-heading h1 { font-size: 22px; }
  .admin-module-heading .search-form { flex: 1 1 100%; }
}
