/* Blamdom portal overhaul — layered over main.css.
   Client portal  = "Calm Cards": light, airy, rounded cards, left sidebar.
   Staff portal   = "Control Panel": dense, mono numerals, top bar with grouped menus.
   Scoped by body[data-portal]; theme still follows html[data-theme]. */

/* ───────────────────────── Tokens ───────────────────────── */
body[data-portal="client"] {
  --color-bg: #F4F6FA;
  --color-bg-alt: #EEF2F8;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F1F5FB;
  --color-surface-subtle: #F4F6FA;
  --color-border: #E3E9F2;
  --color-text: #14213D;
  --color-text-muted: #5A6A82;
  --color-text-subtle: #5A6A82;
  --color-accent: #2563EB;
  --color-primary: #2563EB;
  --color-primary-light: #1D4ED8;
  --color-success: #15803D;
  --color-danger: #DC2626;
  --card-shadow: 0 1px 2px rgba(20, 33, 61, .05), 0 6px 20px rgba(20, 33, 61, .05);
  --radius: 0.75rem;
}
:root[data-theme="dark"] body[data-portal="client"] {
  --color-bg: #0E1522;
  --color-bg-alt: #121B2B;
  --color-surface: #162033;
  --color-surface-hover: #1C2840;
  --color-surface-subtle: #121B2B;
  --color-border: #263449;
  --color-text: #E8EEF8;
  --color-text-muted: #9DAEC6;
  --color-text-subtle: #9DAEC6;
  --color-accent: #60A5FA;
  --color-primary: #3B82F6;
  --color-primary-light: #60A5FA;
  --color-success: #4ADE80;
  --color-danger: #F87171;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

body[data-portal="staff"] {
  --color-bg: #EDF1F6;
  --color-bg-alt: #E4EAF1;
  --color-surface: #FFFFFF;
  --color-surface-hover: #EEF3F8;
  --color-surface-subtle: #F3F6FA;
  --color-border: #D3DCE7;
  --color-text: #0F1B2A;
  --color-text-muted: #4D6075;
  --color-text-subtle: #4D6075;
  --color-accent: #0369A1;
  --color-primary: #0F2B46;
  --color-primary-light: #1A3D5C;
  --color-success: #047857;
  --color-danger: #B91C1C;
  --card-shadow: none;
  --radius: 0.5rem;
}
:root[data-theme="dark"] body[data-portal="staff"] {
  --color-bg: #0B1118;
  --color-bg-alt: #0F1822;
  --color-surface: #111A24;
  --color-surface-hover: #172331;
  --color-surface-subtle: #0F1822;
  --color-border: #223244;
  --color-text: #E6EDF3;
  --color-text-muted: #8FA3B7;
  --color-text-subtle: #8FA3B7;
  --color-accent: #38BDF8;
  --color-primary: #38BDF8;
  --color-primary-light: #7DD3FC;
  --color-success: #34D399;
  --color-danger: #F87171;
  --color-warning: #FBBF24;
}

body[data-portal] {
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
}
body[data-portal] .app-main { background: transparent; }

/* ───────────────────── Shared components ───────────────────── */
body[data-portal] .page-header h1 { color: var(--color-text); letter-spacing: -0.02em; }
body[data-portal] .text-muted, body[data-portal] .eyebrow { color: var(--color-text-muted); }
body[data-portal] .btn { border-radius: calc(var(--radius) - 0.125rem); font-weight: 600; min-height: 2.5rem; }
body[data-portal] .btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
body[data-portal] .btn-primary:hover { background: var(--color-primary-light); }
body[data-portal] .btn-ghost { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
body[data-portal] .btn-ghost:hover { background: var(--color-surface-hover); }
body[data-portal] .btn-danger { background: transparent; color: var(--color-danger); border: 1px solid color-mix(in srgb, var(--color-danger) 35%, transparent); }
body[data-portal] .btn-danger:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); color: var(--color-danger); }
:root[data-theme="dark"] body[data-portal="staff"] .btn-primary { color: #04141F; }
body[data-portal] .input, body[data-portal] input[type="text"], body[data-portal] input[type="email"],
body[data-portal] input[type="password"], body[data-portal] input[type="number"], body[data-portal] select, body[data-portal] textarea {
  border-radius: calc(var(--radius) - 0.125rem);
}
body[data-portal] :focus-visible { outline: 0.125rem solid var(--color-accent); outline-offset: 0.125rem; }

body[data-portal] .badge { border-radius: 99px; padding: 0.15rem 0.6rem; font-weight: 700; letter-spacing: 0.01em; }
body[data-portal] .badge-success { background: color-mix(in srgb, var(--color-success) 14%, transparent); color: var(--color-success); }
body[data-portal] .badge-danger  { background: color-mix(in srgb, var(--color-danger) 14%, transparent); color: var(--color-danger); }
body[data-portal] .badge-warning { background: color-mix(in srgb, var(--color-warning) 18%, transparent); color: #92400E; }
:root[data-theme="dark"] body[data-portal] .badge-warning { color: #FBBF24; }

body[data-portal] .data-table th {
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--color-border);
}
body[data-portal] .data-table tbody tr:hover { background: var(--color-surface-hover); }
body[data-portal] .table-wrapper { background-color: var(--color-surface); }

/* ───────────────────── CLIENT: Calm Cards ───────────────────── */
body[data-portal="client"] .admin-sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
}
body[data-portal="client"] .sidebar-brand { padding: 0.25rem 0.75rem 1.5rem; }
body[data-portal="client"] .sidebar-brand .logo { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
body[data-portal="client"] .admin-sidebar .nav-link {
  min-height: 2.75rem;
  border-radius: 0.75rem;
  font-weight: 500;
  padding: 0 0.85rem;
}
body[data-portal="client"] .admin-sidebar .nav-link:hover { background: var(--color-surface-hover); color: var(--color-text); }
body[data-portal="client"] .admin-sidebar .nav-link.active {
  background: color-mix(in srgb, var(--color-accent) 13%, transparent);
  color: var(--color-accent);
  font-weight: 700;
}
body[data-portal="client"] .admin-sidebar .nav-link.active::before { color: var(--color-accent); }
body[data-portal="client"] .client-credit-card {
  border-radius: 1rem;
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-surface));
  border: 1px solid color-mix(in srgb, var(--color-accent) 22%, var(--color-border));
}
body[data-portal="client"] .app-frame .site-header { background: color-mix(in srgb, var(--color-bg) 92%, transparent); border-bottom: 0; backdrop-filter: blur(0.5rem); }
body[data-portal="client"] .app-main { padding: 1.5rem 2.5rem 2.5rem; max-width: 76rem; width: 100%; margin: 0 auto; }
body[data-portal="client"] .page-header h1 { font-size: 1.75rem; font-weight: 800; }

body[data-portal="client"] .card,
body[data-portal="client"] .stat-card,
body[data-portal="client"] .table-wrapper,
body[data-portal="client"] .auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  box-shadow: var(--card-shadow);
}
body[data-portal="client"] .table-wrapper { overflow-x: auto; }
body[data-portal="client"] .stat-card { padding: 1.15rem 1.25rem; min-height: 0; }
body[data-portal="client"] .stat-label { font-size: 0.75rem; letter-spacing: 0.05em; }
body[data-portal="client"] .stat-value { font-size: 1.9rem; letter-spacing: -0.02em; color: var(--color-text); }
body[data-portal="client"] .card-header { border-bottom: 0; }
body[data-portal="client"] .data-table td { padding: 0.85rem 1.1rem; }
body[data-portal="client"] .data-table th { padding: 0.8rem 1.1rem; }

/* ───────────────────── STAFF: Control Panel ───────────────────── */
body[data-portal] .app-shell { display: block; }
body[data-portal] .app-frame { min-height: 100vh; }
body[data-portal] .site-header.topbar {
  position: sticky; top: 0; z-index: 60;
  height: 3.25rem; padding: 0 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
body[data-portal] .topbar .header-inner { height: 3.25rem; gap: 1.25rem; align-items: center; flex-wrap: nowrap; }
.topbar-brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 800; letter-spacing: 0.01em; color: var(--color-text); text-decoration: none; white-space: nowrap; }
.topbar-brand:hover { text-decoration: none; }
.topbar-brand .brand-icon { width: 1.5rem; height: 1.5rem; }
.topbar-badge { font-size: 0.6rem; letter-spacing: 0.12em; padding: 0.1rem 0.4rem; border-radius: 0.25rem; background: color-mix(in srgb, var(--color-accent) 16%, transparent); color: var(--color-accent); font-weight: 800; }

.topnav { display: flex; align-items: center; gap: 0.125rem; flex: 1; min-width: 0; }
.topnav .nav-link, .topnav .nav-group > summary {
  display: inline-flex; align-items: center; min-height: 2.25rem;
  padding: 0 0.75rem; border-radius: 0.4rem; border: 0; background: transparent;
  color: var(--color-text-muted); font: inherit; font-size: 0.875rem; font-weight: 500;
  cursor: pointer; list-style: none; text-decoration: none; white-space: nowrap;
}
.topnav .nav-group > summary::-webkit-details-marker { display: none; }
.topnav .nav-group > summary::after { content: "▾"; margin-left: 0.35rem; font-size: 0.7rem; opacity: 0.7; }
.topnav .nav-link:hover, .topnav .nav-group > summary:hover, .topnav .nav-group[open] > summary { background: var(--color-surface-hover); color: var(--color-text); }
.topnav .nav-link.active, .topnav .nav-group.has-active > summary {
  color: var(--color-text); background: var(--color-surface-hover);
  box-shadow: inset 0 -2px 0 var(--color-accent);
}
.topnav .nav-group { position: relative; }
.topnav .nav-group-panel {
  position: absolute; left: 0; top: calc(100% + 0.375rem); z-index: 70; min-width: 13rem; padding: 0.375rem;
  display: flex; flex-direction: column; gap: 0.125rem;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 0.6rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}
.topnav .nav-group-panel .nav-link { width: 100%; justify-content: flex-start; min-height: 2.5rem; }
.topnav .nav-group-panel .nav-link.active { box-shadow: inset 0.1875rem 0 0 var(--color-accent); }
.topnav .nav-logout-form { display: none; margin: 0; }
.topbar .header-actions { gap: 0.5rem; }
.topbar .theme-toggle { min-height: 2.25rem; padding: 0 0.65rem; font-size: 0.8rem; width: auto; border-radius: 0.4rem; }
.topbar .sidebar-toggle { display: none; }

body[data-portal="staff"] .app-main { padding: 1.1rem 1.25rem 2rem; max-width: 92rem; width: 100%; margin: 0 auto; }
body[data-portal="staff"] .page-header h1 { font-size: 1.4rem; font-weight: 800; }
body[data-portal="staff"] .card,
body[data-portal="staff"] .table-wrapper,
body[data-portal="staff"] .stat-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 0.5rem; box-shadow: none;
}
body[data-portal="staff"] .card { padding: 1rem 1.1rem; }
body[data-portal="staff"] .stat-card { padding: 0.7rem 0.85rem; min-height: 0; }
body[data-portal="staff"] .stat-label { font-size: 0.68rem; letter-spacing: 0.09em; }
body[data-portal="staff"] .stat-value { font: 700 1.4rem ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: -0.01em; color: var(--color-text); }
body[data-portal="staff"] .data-table { font-size: 0.8125rem; }
body[data-portal="staff"] .data-table th { padding: 0.55rem 0.85rem; background: var(--color-surface-subtle); }
body[data-portal="staff"] .data-table td { padding: 0.5rem 0.85rem; }
body[data-portal="staff"] .data-table .mono, body[data-portal="staff"] code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
body[data-portal="staff"] .site-footer { background: transparent; border-top: 1px solid var(--color-border); }

/* ───────────────────── Phones ───────────────────── */
@media (max-width: 900px) {
  body[data-portal="client"] .app-main { padding: 1rem 1rem 2rem; }
  body[data-portal] .topbar .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  body[data-portal] .topnav {
    display: none; position: fixed; left: 0; right: 0; top: 3.25rem; z-index: 80;
    flex-direction: column; align-items: stretch; gap: 0.25rem; padding: 0.75rem;
    max-height: calc(100vh - 3.25rem); overflow-y: auto;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  }
  body[data-portal] .topnav.is-open { display: flex; }
  .topnav .nav-link, .topnav .nav-group > summary { min-height: 2.75rem; }
  .topnav .nav-group-panel { position: static; box-shadow: none; border: 0; padding: 0 0 0 0.75rem; background: transparent; }
  .topnav .nav-logout-form { display: block; }
  .topbar-badge { display: none; }
  body[data-portal="staff"] .stats-grid.dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tables become stacked cards (labels are copied from the headings by portal-ui.js) */
@media (max-width: 720px) {
  body[data-portal] .table-wrapper { background: none; border: 0; box-shadow: none; overflow: visible; }
  body[data-portal] .table-wrapper table.data-table, body[data-portal] .table-wrapper .data-table { min-width: 0; width: 100%; }
  body[data-portal] table.data-table tbody td { white-space: normal; overflow-wrap: anywhere; }
  body[data-portal] table.data-table tbody td > * { min-width: 0; max-width: 100%; }
  body[data-portal] .app-main, body[data-portal] .app-frame { min-width: 0; max-width: 100vw; }
  body[data-portal] table.data-table, body[data-portal] table.data-table tbody { display: block; width: 100%; }
  body[data-portal] table.data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  body[data-portal] table.data-table tbody tr {
    display: block; margin-bottom: 0.75rem; padding: 0.35rem 0.9rem;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 0.9rem; box-shadow: var(--card-shadow);
  }
  body[data-portal="staff"] table.data-table tbody tr { border-radius: 0.5rem; }
  body[data-portal] table.data-table tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 0.55rem 0; border-bottom: 1px dashed var(--color-border); text-align: right; min-width: 0; word-break: break-word;
  }
  body[data-portal] table.data-table tbody td:last-child { border-bottom: 0; }
  body[data-portal] table.data-table tbody td[data-label]::before {
    content: attr(data-label); flex: none; max-width: 45%; text-align: left;
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-muted);
  }
  body[data-portal] table.data-table tbody td form, body[data-portal] table.data-table tbody td .inline-form { justify-content: flex-end; }
  body[data-portal] table.data-table tbody td:not([data-label]) { justify-content: flex-end; flex-wrap: wrap; }
  body[data-portal] table.data-table tbody td .input { width: 100%; max-width: 12rem; }
  body[data-portal] .data-table tbody tr:hover { background: var(--color-surface); }
}

/* Phones: cells that hold several controls (key limits, access rules) stack instead of crushing */
@media (max-width: 720px) {
  body[data-portal] table.data-table tbody td:has(details, button, form) { flex-wrap: wrap; row-gap: 0.4rem; }
  body[data-portal] table.data-table tbody td details,
  body[data-portal] table.data-table tbody td summary,
  body[data-portal] table.data-table tbody td .btn { min-width: max-content; white-space: nowrap; }
  body[data-portal] table.data-table tbody td .key-limits, body[data-portal] table.data-table tbody td .confirm-action { flex: 0 0 auto; }
  body[data-portal] .card-header { flex-wrap: wrap; gap: 0.75rem; }
  body[data-portal] .card-header form { width: 100%; }
}

/* Theme switch: every element fades with the same duration and easing, so colors,
   buttons and icons all move together. Only active during the swap (class set by theme.js). */
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: background-color .3s ease, color .3s ease, border-color .3s ease, fill .3s ease, stroke .3s ease, box-shadow .3s ease, opacity .3s ease !important;
}
@keyframes theme-icon-in { from { transform: rotate(-90deg) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
html.theme-switching .theme-toggle .theme-icon { animation: theme-icon-in .3s ease both; }
@media (prefers-reduced-motion: reduce) {
  html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: none !important; animation: none !important; }
}

/* Theme button: readable on the light and dark bars (legacy rule assumed a dark header) */
body[data-portal] .theme-toggle {
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  gap: 0.5rem;
}
body[data-portal] .theme-toggle:hover { background: var(--color-surface-hover); border-color: var(--color-accent); }
body[data-portal] .theme-toggle .theme-icon { flex: none; width: 1rem; height: 1rem; }

/* Edit pop-ups: a centered dialog over the page, never trapped inside the scrolling table */
body[data-portal] .row-editor[open]::before {
  content: ""; position: fixed; inset: 0; z-index: 200; background: rgba(5, 10, 18, 0.55);
  backdrop-filter: blur(2px); cursor: default;
}
body[data-portal] .row-editor[open] > .row-editor-panel {
  position: fixed; z-index: 210; top: 50%; left: 50%; right: auto; bottom: auto;
  transform: translate(-50%, -50%);
  width: min(32rem, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); overflow-y: auto;
  margin: 0; padding: 1.25rem 1.4rem;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: dialog-in .16s ease-out both;
}
@keyframes dialog-in { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } to { opacity: 1; transform: translate(-50%, -50%); } }
body[data-portal] .row-editor-panel h2 { margin: 0 2.5rem 1rem 0; font-size: 1.2rem; }
body[data-portal] .row-editor-close {
  position: absolute; top: 0.6rem; right: 0.7rem; width: 2.25rem; height: 2.25rem; border: 0; border-radius: 0.5rem;
  background: transparent; color: var(--color-text-muted); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
body[data-portal] .row-editor-close:hover { background: var(--color-surface-hover); color: var(--color-text); }
body:has(.row-editor[open]) { overflow: hidden; }
@media (max-width: 720px) {
  body[data-portal] .row-editor[open] > .row-editor-panel { width: calc(100vw - 1.5rem); max-height: calc(100vh - 1.5rem); }
}
@media (prefers-reduced-motion: reduce) { body[data-portal] .row-editor[open] > .row-editor-panel { animation: none; } }

/* Key Limits / Access rules: same centered dialog as the row editors */
body[data-portal] details.key-limits[open]::before {
  content: ""; position: fixed; inset: 0; z-index: 200; background: rgba(5, 10, 18, 0.55); backdrop-filter: blur(2px);
}
body[data-portal] details.key-limits[open] > .confirm-panel {
  position: fixed; z-index: 210; top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%);
  width: min(32rem, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); overflow-y: auto; margin: 0; padding: 1.25rem 1.4rem;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45); animation: dialog-in .16s ease-out both; text-align: left; white-space: normal;
}
body[data-portal] .key-limits .confirm-panel .row-editor-close { position: absolute; }
body[data-portal] .key-limits .confirm-panel > p:first-of-type { margin-right: 2.5rem; }
@media (prefers-reduced-motion: reduce) { body[data-portal] details.key-limits[open] > .confirm-panel { animation: none; } }

/* Form layout inside dialogs: one column, checkbox beside its label, full-width fields */
body[data-portal] .row-editor-panel .form-grid { grid-template-columns: 1fr; align-items: start; gap: 0.9rem; }
body[data-portal] .row-editor-panel .form-group { margin: 0; }
body[data-portal] .row-editor-panel .form-group > label:has(input[type="checkbox"]),
body[data-portal] .row-editor-panel label:has(> input[type="checkbox"]) {
  display: flex; align-items: center; gap: 0.6rem; min-height: 2.25rem; cursor: pointer;
}
body[data-portal] .row-editor-panel input[type="checkbox"] { width: 1.125rem; height: 1.125rem; flex: none; margin: 0; }
body[data-portal] .row-editor-panel select, body[data-portal] .row-editor-panel textarea, body[data-portal] .row-editor-panel input:not([type="checkbox"]) { width: 100%; box-sizing: border-box; }

/* Audit log filter row */
body[data-portal] .audit-export-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
body[data-portal] .audit-export-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-muted); }
body[data-portal] .audit-export-form input {
  min-height: 2.25rem; padding: 0.35rem 0.6rem; box-sizing: border-box; min-width: 10rem;
  background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-radius: 0.4rem;
  font: inherit; font-size: 0.875rem; text-transform: none; letter-spacing: 0; color-scheme: light;
}
:root[data-theme="dark"] body[data-portal] .audit-export-form input { color-scheme: dark; }
body[data-portal] .audit-export-form .btn {
  min-height: 2.25rem; display: inline-flex; align-items: center; background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); text-decoration: none; padding: 0 0.9rem;
}
body[data-portal] .audit-export-form .btn:hover { background: var(--color-surface-hover); border-color: var(--color-accent); }
body[data-portal] .audit-export-form a.btn { color: var(--color-accent); }

/* Staff API Keys: compact rows */
body[data-portal="staff"] .keys-table .alias-form { min-width: 0; flex-wrap: nowrap; gap: 0.4rem; }
body[data-portal="staff"] .keys-table .alias-form .input { flex: 1 1 8rem; min-width: 7rem; max-width: 14rem; }
body[data-portal="staff"] .keys-table td { vertical-align: middle; }
body[data-portal="staff"] .keys-table td details.key-limits { display: inline-block; margin: 0.35rem 0.4rem 0 0; vertical-align: top; }
body[data-portal="staff"] .keys-table .key-usage { margin-bottom: 0.1rem; }
body[data-portal] details.revoked-keys { margin-top: 1rem; }

/* Keys table: give Limits room for both buttons side by side; Alias no wider than needed */
@media (min-width: 721px) {
  body[data-portal="staff"] .keys-table th:nth-child(1), body[data-portal="staff"] .keys-table td:nth-child(1) { width: 20%; }
  body[data-portal="staff"] .keys-table th:nth-child(6), body[data-portal="staff"] .keys-table td:nth-child(6) { min-width: 15.5rem; }
  body[data-portal="staff"] .keys-table .key-usage { display: block; margin-bottom: 0.25rem; }
}
/* Key dialogs: full-width fields */
body[data-portal] .key-limits .confirm-panel input:not([type="checkbox"]):not([type="radio"]),
body[data-portal] .key-limits .confirm-panel select,
body[data-portal] .key-limits .confirm-panel textarea,
body[data-portal] .key-limits .confirm-panel .picker { width: 100%; box-sizing: border-box; }

/* Limits cell: spend line on top, both buttons side by side, status line underneath */
body[data-portal="staff"] .limits-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem; }
body[data-portal="staff"] .limits-cell > .key-usage { flex: 1 0 100%; margin: 0; }
body[data-portal="staff"] .limits-cell > .key-usage:nth-of-type(1) { order: 0; }
body[data-portal="staff"] .limits-cell > details:nth-of-type(1) { order: 1; margin: 0; }
body[data-portal="staff"] .limits-cell > details:nth-of-type(2) { order: 2; margin: 0; }
body[data-portal="staff"] .limits-cell > .key-usage:nth-of-type(2) { order: 3; }
body[data-portal="staff"] .limits-cell > .key-usage:empty { display: none; }
body[data-portal] .key-limits .confirm-panel .input,
body[data-portal] .key-limits .confirm-panel input:not([type="checkbox"]):not([type="radio"]),
body[data-portal] .key-limits .confirm-panel select,
body[data-portal] .key-limits .confirm-panel textarea,
body[data-portal] .row-editor-panel .input { max-width: none; }
@media (min-width: 721px) {
  body[data-portal="staff"] .keys-table td:nth-child(2), body[data-portal="staff"] .keys-table td:nth-child(3), body[data-portal="staff"] .keys-table td:nth-child(7) { white-space: nowrap; overflow-wrap: normal; }
  body[data-portal="staff"] .keys-table th:nth-child(1), body[data-portal="staff"] .keys-table td:nth-child(1) { width: 17%; }
}

/* ───────── Staff admin polish: hierarchy, rhythm, depth ───────── */
body[data-portal="staff"] .app-main { max-width: 96rem; padding: 1.5rem 1.75rem 2.5rem; }
body[data-portal="staff"] .app-main > section, body[data-portal="staff"] .app-main > .card, body[data-portal="staff"] .app-main > form { margin-bottom: 1.25rem; }
body[data-portal="staff"] .app-main > section:last-child { margin-bottom: 0; }
body[data-portal="staff"] .page-header { margin-bottom: 1.25rem; align-items: center; }
body[data-portal="staff"] .page-header h1 { font-size: 1.75rem; letter-spacing: -.025em; }
body[data-portal="staff"] .page-header .text-muted { font-size: .9375rem; margin-top: .2rem; }
body[data-portal="staff"] .page-header .eyebrow { font-size: .6875rem; letter-spacing: .1em; }
body[data-portal="staff"] .card, body[data-portal="staff"] .stat-card, body[data-portal="staff"] .table-wrapper {
  border-radius: .75rem; box-shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 1px rgba(15,23,42,.04);
}
body[data-portal="staff"] .card + .card { margin-top: 0; }
body[data-portal="staff"] .card-heading h2 { font-size: 1.0625rem; font-weight: 700; letter-spacing: -.01em; }
body[data-portal="staff"] .card-heading .text-muted { font-size: .8125rem; }
body[data-portal="staff"] .text-link { font-size: .8125rem; font-weight: 600; color: var(--color-accent); text-decoration: none; }
body[data-portal="staff"] .text-link:hover { text-decoration: underline; }
body[data-portal="staff"] .stats-grid.dashboard-stats { gap: 1rem; margin-bottom: 1.25rem; }
body[data-portal="staff"] .stat-card { min-height: 0; padding: 1rem 1.1rem; transition: border-color .2s, box-shadow .2s, transform .2s; }
body[data-portal="staff"] .stat-card:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(15,23,42,.08); }
body[data-portal="staff"] .stat-label { font-size: .75rem; letter-spacing: .02em; text-transform: none; font-weight: 600; }
body[data-portal="staff"] .stat-icon { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; border-radius: .5rem; background: color-mix(in srgb, var(--color-accent) 12%, transparent); font-size: .95rem; }
body[data-portal="staff"] .stat-value { font-size: 2rem; font-weight: 800; margin-top: .75rem; line-height: 1.1; }
body[data-portal="staff"] .stat-meta { font-size: .8125rem; color: var(--color-text-muted); margin-top: .35rem; }
body[data-portal="staff"] .stat-meta.stat-positive { color: var(--color-text-muted); }
body[data-portal="staff"] .burn-rate-label { font-size: .75rem; color: var(--color-text-muted); }
body[data-portal="staff"] .status-pill { font-size: .8125rem; padding: .45rem .8rem; background: var(--color-surface); text-decoration: none; color: var(--color-text); font-weight: 600; }
body[data-portal="staff"] .status-pill span { width: .5rem; height: .5rem; border-radius: 50%; background: var(--color-success); display: inline-block; }
body[data-portal="staff"] .time-range-control { margin-bottom: 1rem; }
body[data-portal="staff"] .time-range-btn.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }

/* Attention: neutral when fine, loud only when something is wrong */
body[data-portal="staff"] .attention-list a.attn { background: var(--color-surface); border-radius: .625rem; }
body[data-portal="staff"] .attention-list a.attn-ok { border-left-color: var(--color-border); opacity: 1; }
body[data-portal="staff"] .attention-list a.attn-ok strong { color: var(--color-text-muted); font-weight: 600; }
body[data-portal="staff"] .attention-list a.attn:hover { box-shadow: 0 4px 12px rgba(15,23,42,.08); }
body[data-portal="staff"] .attention-panel.is-clear { padding-top: .75rem; padding-bottom: .75rem; }
body[data-portal="staff"] .attention-panel.is-clear .card-heading { margin-bottom: .5rem; }
body[data-portal="staff"] .attention-panel.is-clear .attention-list { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .5rem; }
body[data-portal="staff"] .attention-panel.is-clear a.attn { flex-direction: row; align-items: baseline; gap: .6rem; padding: .45rem .75rem; }
body[data-portal="staff"] .attention-panel.is-clear a.attn strong { font-size: 1rem; }
body[data-portal="staff"] .attention-panel.is-clear a.attn span { font-size: .8125rem; color: var(--color-text-muted); }

/* Analytics pair: align tops, shorter empty states */
body[data-portal="staff"] .analytics-grid { align-items: stretch; gap: 1.25rem; }
body[data-portal="staff"] .analytics-card { min-height: 0; margin: 0; }
body[data-portal="staff"] .analytics-card .empty-state { padding: 2rem 1rem; font-size: .875rem; border: 1px dashed var(--color-border); border-radius: .5rem; background: var(--color-surface-subtle, transparent); }
body[data-portal="staff"] .data-table th { font-size: .6875rem; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted); }
body[data-portal="staff"] .data-table tbody tr:hover { background: var(--color-surface-subtle, rgba(0,0,0,.02)); }
body[data-portal="staff"] .action-chip { border-radius: 999px; font-size: .75rem; }
body[data-portal="staff"] .btn { min-height: 2.25rem; }
@media (prefers-reduced-motion: reduce) { body[data-portal="staff"] .stat-card { transition: none; } body[data-portal="staff"] .stat-card:hover { transform: none; } }
@media (max-width: 720px) { body[data-portal="staff"] .app-main { padding: 1rem 1rem 2rem; } body[data-portal="staff"] .stat-value { font-size: 1.6rem; } }

/* polish round 2 */
body[data-portal="staff"] .card-heading { display: flex; flex-wrap: nowrap; align-items: flex-start; justify-content: space-between; gap: .75rem; }
body[data-portal="staff"] .card-heading > div { min-width: 0; flex: 1 1 auto; }
body[data-portal="staff"] .card-heading > .text-link { flex: none; white-space: nowrap; line-height: 1.6; }
body[data-portal="staff"] .analytics-card .empty-state { min-height: 9rem; display: flex; align-items: center; justify-content: center; }
body[data-portal="staff"] .stats-grid.dashboard-stats, body[data-portal="staff"] .attention-list, body[data-portal="staff"] .analytics-grid { gap: 1rem; }
body[data-portal="staff"] .stat-value { font-family: inherit; font-variant-numeric: tabular-nums; font-feature-settings: "zero" 0; letter-spacing: -.02em; }
body[data-portal="staff"] .stat-icon { background: color-mix(in srgb, var(--color-accent) 16%, transparent); color: var(--color-accent); font-weight: 700; width: 1.9rem; height: 1.9rem; font-size: 1rem; line-height: 1; }
body[data-portal="staff"] .burn-rate-progress { width: 100%; height: .5rem; border-radius: 999px; overflow: hidden; background: color-mix(in srgb, var(--color-text-muted) 38%, transparent); border: 0; appearance: none; }
body[data-portal="staff"] .burn-rate-progress::-webkit-progress-bar { background: color-mix(in srgb, var(--color-text-muted) 38%, transparent); border-radius: 999px; }
body[data-portal="staff"] .burn-rate-bar { margin-top: .6rem; }
body[data-portal="staff"] .attention-list a.attn { position: relative; }
body[data-portal="staff"] .attention-list a.attn-warn::after, body[data-portal="staff"] .attention-list a.attn-danger::after { content: "→"; position: absolute; top: .75rem; right: .9rem; color: var(--color-text-muted); }
body[data-portal="staff"] .analytics-card .card-heading .text-muted { line-height: 1.4; min-height: 2.8em; }
body[data-portal="staff"] .stat-icon { font-weight: 900; color: color-mix(in srgb, var(--color-accent) 80%, #000); }

/* Staff fleet cards: native links, with independent selected and status states. */
body[data-portal="staff"] .fleet-picker { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%, 15rem),1fr)); gap:.7rem; }
body[data-portal="staff"] .fleet-picker-card { min-width:0; display:grid; align-content:start; gap:.35rem; padding:.85rem; color:var(--color-text); background:var(--color-surface-subtle); border:1px solid var(--color-border); border-radius:var(--radius); text-decoration:none; overflow-wrap:anywhere; }
body[data-portal="staff"] .fleet-picker-card:hover { background:var(--color-surface-hover); }
body[data-portal="staff"] .fleet-picker-card[aria-current="true"] { border-color:var(--color-accent); box-shadow:inset 0 0 0 1px var(--color-accent); }
body[data-portal="staff"] .fleet-picker-card:focus-visible { outline:2px solid var(--color-accent); outline-offset:2px; }
body[data-portal="staff"] .fleet-picker-card .badge { justify-self:start; white-space:normal; }
body[data-portal="staff"] .fleet-picker-card .fleet-picker-top { display:flex; gap:.4rem .7rem; flex-wrap:wrap; align-items:baseline; justify-content:space-between; }
body[data-portal="staff"] .fleet-picker-card .fleet-picker-cta { color:var(--color-accent); font-weight:650; font-size:.8rem; }
body[data-portal="staff"] .fleet-compare .table-wrapper { overflow-x:auto; max-width:100%; }
body[data-portal="staff"] .fleet-layout-heading { flex-wrap:wrap; gap:.75rem; }
body[data-portal="staff"] .fleet-view-switch { display:flex; flex-wrap:wrap; gap:.25rem; padding:.25rem; background:var(--color-surface-subtle); border:1px solid var(--color-border); border-radius:var(--radius); }
body[data-portal="staff"] .fleet-view-switch a { display:inline-flex; align-items:center; justify-content:center; min-height:2.75rem; padding:.35rem .65rem; font-size:.84rem; font-weight:650; color:var(--color-text-muted); text-decoration:none; border:1px solid transparent; border-radius:calc(var(--radius) * .75); }
body[data-portal="staff"] .fleet-view-switch a:hover { background:var(--color-surface-hover); }
body[data-portal="staff"] .fleet-view-switch a[aria-current="true"] { background:var(--color-surface); border-color:var(--color-accent); color:var(--color-text); }
body[data-portal="staff"] .fleet-view-switch a:focus-visible, body[data-portal="staff"] .fleet-compare-link:focus-visible { outline:.125rem solid var(--color-accent); outline-offset:.12rem; }
body[data-portal="staff"] .fleet-workbench { display:grid; grid-template-columns:minmax(13rem,1fr) minmax(0,2.15fr); align-items:start; gap:1rem; }
body[data-portal="staff"] .fleet-workbench .fleet-picker { grid-template-columns:minmax(0,1fr); }
body[data-portal="staff"] .fleet-picker-section .fleet-selected-detail { margin:0; min-width:0; }
body[data-portal="staff"] .fleet-selected-detail { overflow-wrap:anywhere; }
body[data-portal="staff"] .fleet-selected-detail, body[data-portal="staff"] #fleet-picker-title { scroll-margin-top:4.75rem; }
body[data-portal="staff"] .fleet-detail-summary { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.55rem; margin:0 0 .75rem; }
body[data-portal="staff"] .fleet-detail-summary div { background:var(--color-surface-subtle); border:1px solid var(--color-border); border-radius:var(--radius); padding:.65rem; }
body[data-portal="staff"] .fleet-detail-summary dt, body[data-portal="staff"] .fleet-compare-reading small { color:var(--color-text-muted); font-size:.78rem; }
body[data-portal="staff"] .fleet-detail-summary dd { margin:.15rem 0 0; font-size:1.15rem; font-weight:700; font-variant-numeric:tabular-nums; }
body[data-portal="staff"] .fleet-detail-links { display:flex; flex-wrap:wrap; gap:.65rem 1rem; margin-top:.65rem; }
body[data-portal="staff"] .fleet-compare-note { margin:0 0 .75rem; font-size:.83rem; }
body[data-portal="staff"] .fleet-compare-rows { list-style:none; padding:0; margin:0; display:grid; gap:.55rem; }
body[data-portal="staff"] .fleet-compare-row { min-width:0; border:1px solid var(--color-border); border-radius:var(--radius); }
body[data-portal="staff"] .fleet-compare-link { display:grid; grid-template-columns:minmax(0,1.65fr) repeat(3,minmax(0,1fr)) auto; gap:.75rem; align-items:center; padding:.7rem; color:var(--color-text); background:var(--color-surface-subtle); text-decoration:none; border:1px solid transparent; border-radius:var(--radius); overflow-wrap:anywhere; }
body[data-portal="staff"] .fleet-compare-link:hover { background:var(--color-surface-hover); }
body[data-portal="staff"] .fleet-compare-link[aria-current="true"] { border-color:var(--color-accent); }
body[data-portal="staff"] .fleet-compare-identity, body[data-portal="staff"] .fleet-compare-reading { display:grid; justify-items:start; }
body[data-portal="staff"] .fleet-compare-reading strong { font-variant-numeric:tabular-nums; }
body[data-portal="staff"] .fleet-compare-identity .badge { margin-top:.25rem; white-space:normal; }
body[data-portal="staff"] .fleet-compare-action { color:var(--color-accent); font-size:.8rem; font-weight:650; }
body[data-portal="staff"] .fleet-compare-row .fleet-selected-detail { margin:.45rem; }
@media (max-width:48rem) {
  body[data-portal="staff"] .fleet-workbench { grid-template-columns:minmax(0,1fr); }
  body[data-portal="staff"] .fleet-compare-link { grid-template-columns:repeat(3,minmax(0,1fr)); gap:.45rem; }
  body[data-portal="staff"] .fleet-compare-identity, body[data-portal="staff"] .fleet-compare-action { grid-column:1/-1; }
}

/* ── Client visual pass: align the client portal with the staff portal's polish ── */
body[data-portal="client"] .stats-grid.dashboard-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (min-width: 1700px) { body[data-portal="client"] .stats-grid.dashboard-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 700px) { body[data-portal="client"] .stats-grid.dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
body[data-portal="client"] .stat-card { min-height: 8.5rem; padding: 1.1rem 1.2rem; border-radius: .875rem; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease; }
body[data-portal="client"] .stat-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15, 23, 42, .07); }
body[data-portal="client"] .stat-label { font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--color-text-muted); }
body[data-portal="client"] .stat-value { margin-top: 1rem; font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
body[data-portal="client"] .stat-meta { font-size: .75rem; }
body[data-portal="client"] .stat-trend { margin-top: .5rem; font-size: .75rem; font-weight: 600; }
body[data-portal="client"] .card, body[data-portal="client"] .analytics-card { border-radius: .875rem; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
body[data-portal="client"] .card-heading h2 { font-size: 1.0625rem; font-weight: 700; letter-spacing: -.01em; }
body[data-portal="client"] .text-link { font-weight: 600; font-size: .8125rem; }
body[data-portal="client"] .page-header { margin-bottom: 1.5rem; }
body[data-portal="client"] .page-header .text-muted { margin-top: .25rem; font-size: .9375rem; }
body[data-portal="client"] .sidebar-nav .nav-link { position: relative; font-weight: 500; border-radius: .625rem; }
body[data-portal="client"] .sidebar-nav .nav-link.active { font-weight: 700; }
body[data-portal="client"] .sidebar-nav .nav-link.active::after { content: ""; position: absolute; left: -.5rem; top: .5rem; bottom: .5rem; width: .1875rem; border-radius: 1rem; background: var(--color-accent); }
body[data-portal="client"] .topnav .nav-logout-form .nav-link { font-family: inherit; font-size: 13px; font-weight: 500; color: var(--color-text-muted); padding: 0 .85rem; min-height: 2.75rem; display: flex; align-items: center; }
body[data-portal="client"] .chart-axis { display: none; }
body[data-portal="client"] .nav-logout-form .nav-link:hover { color: var(--color-text); }
body[data-portal="client"] table { border-collapse: separate; border-spacing: 0; }
body[data-portal="client"] th { font-size: .6875rem; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted); font-weight: 700; }
body[data-portal="client"] tbody tr:hover td { background: color-mix(in srgb, var(--color-accent) 5%, transparent); }
body[data-portal="client"] .empty-state { padding: 2.5rem 1rem; color: var(--color-text-muted); }
@media (prefers-reduced-motion: reduce) { body[data-portal="client"] .stat-card { transition: none; } body[data-portal="client"] .stat-card:hover { transform: none; } }

/* ── Client shell = staff top bar (brand · pill nav · theme · account menu) ── */
body[data-portal="client"] .app-main { max-width: 80rem; margin: 0 auto; width: 100%; padding: 1.75rem 1.5rem 3rem; }
body[data-portal="client"] .topnav .nav-link.active::after { display: none; }
body[data-portal="client"] .user-menu-panel { min-width: 17rem; }
body[data-portal="client"] .user-menu-panel .client-credit-card { margin: .5rem; }
body[data-portal="client"] .user-menu-panel .mode-toggle-label { margin: .25rem .75rem .5rem; }
body[data-portal="client"] .topnav .nav-link { min-height: 2.25rem; padding: 0 .8rem; border-radius: .5rem; font-size: .8125rem; font-weight: 600; }
body[data-portal="client"] .topnav .nav-link.active { background: color-mix(in srgb, var(--color-accent) 13%, transparent); color: var(--color-accent); }
@media (max-width: 900px) { body[data-portal="client"] .topnav .nav-link { min-height: 2.75rem; } body[data-portal="client"] .app-main { padding: 1rem 1rem 2rem; } }
@media (max-width: 900px) {
  body[data-portal] .topbar { padding: 0 .75rem; }
  body[data-portal] .topbar .header-inner { gap: .5rem; }
  body[data-portal] .topbar .header-actions { margin-left: auto; gap: .4rem; min-width: 0; }
  body[data-portal] .topbar .theme-label { display: none; }
  body[data-portal] .topbar .theme-toggle { padding: 0 .5rem; }
  body[data-portal] .topbar .sidebar-toggle { margin-left: 0; }
}
body[data-portal="client"] .stats-grid:not(.dashboard-stats) { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
@media (min-width: 901px) {
  body[data-portal="client"] .stats-grid.dashboard-stats:has(> :nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  body[data-portal="client"] .stats-grid.dashboard-stats:has(> :nth-child(5):last-child) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* ── Credit runway: heads-up banner + plain-English line on dashboards ── */
body[data-portal="client"] .runway-banner { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: baseline; padding: .8rem 1rem; margin-bottom: 1rem; border-radius: .75rem; border: 1px solid; font-size: .9375rem; }
body[data-portal="client"] .runway-banner a { margin-left: auto; font-weight: 700; text-decoration: none; }
body[data-portal="client"] .runway-banner-urgent { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: color-mix(in srgb, var(--color-danger) 35%, transparent); color: var(--color-text); }
body[data-portal="client"] .runway-banner-warning { background: color-mix(in srgb, var(--color-warning, #b45309) 12%, transparent); border-color: color-mix(in srgb, var(--color-warning, #b45309) 40%, transparent); }
body[data-portal="client"] .runway-summary { margin: 0 0 1rem; font-size: .9375rem; color: var(--color-text-muted); }
body[data-portal="client"] .runway-summary.runway-urgent { color: var(--color-danger, #b91c1c); font-weight: 600; }
body[data-portal="client"] .runway-summary.runway-warning { color: var(--color-warning, #b45309); font-weight: 600; }
@media (max-width: 900px) { body[data-portal="client"] .runway-banner a { margin-left: 0; width: 100%; } }

/* ── Hermes setup wizard ── */
body[data-portal="client"] .hermes-setup { margin-top: 1.5rem; }
body[data-portal="client"] .hermes-steps { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; grid-template-columns: minmax(0,1fr); gap: 1rem; }
body[data-portal="client"] .hermes-step { padding: 1rem 1.15rem; border: 1px solid var(--color-border, #e2e8f0); border-radius: .75rem; }
body[data-portal="client"] .hermes-step h3 { margin: 0 0 .4rem; font-size: 1rem; font-weight: 700; }
body[data-portal="client"] .hermes-step p { margin: 0 0 .6rem; }
body[data-portal="client"] .hermes-step .copy-field code { white-space: pre-wrap; word-break: break-word; }
@media (min-width: 1100px) { body[data-portal="client"] .hermes-steps { grid-template-columns: 1fr 1fr; } }
body[data-portal="client"] .model-id-hint { font-weight: 400; color: var(--color-text-muted); }

/* ── Main-page rework: hero credit + connect-first layout ── */
body[data-portal="client"] .hero-credit { display: grid; grid-template-columns: minmax(0,1fr) minmax(220px,300px); gap: 1.5rem; padding: 1.5rem 1.75rem; margin-bottom: 1.25rem; border-left: 3px solid var(--color-accent, #2563eb); }
body[data-portal="client"] .hero-credit-urgent { border-left-color: var(--color-danger, #dc2626); }
body[data-portal="client"] .hero-credit-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: .25rem; }
body[data-portal="client"] .hero-credit-balance { font-size: clamp(2.25rem, 5vw, 3rem); font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
body[data-portal="client"] .hero-credit-main .runway-summary { margin: .35rem 0 1rem; font-size: 1.0625rem; }
body[data-portal="client"] .hero-credit-side { display: flex; flex-direction: column; gap: .9rem; align-items: flex-start; justify-content: center; }
body[data-portal="client"] .hero-credit-chips { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; width: 100%; }
body[data-portal="client"] .chip { display: flex; flex-direction: column; padding: .6rem .75rem; border: 1px solid var(--color-border, #e2e8f0); border-radius: .6rem; background: var(--color-bg, #fff); }
body[data-portal="client"] .chip-num { font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; }
body[data-portal="client"] .chip-label { font-size: .75rem; color: var(--color-text-muted); }
body[data-portal="client"] .hero-connect { margin-bottom: 1.25rem; }
body[data-portal="client"] .connect-steps { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: minmax(0,1fr); gap: 1rem; }
body[data-portal="client"] .connect-step { padding: 1rem 1.15rem; border: 1px solid var(--color-border, #e2e8f0); border-radius: .75rem; }
body[data-portal="client"] .connect-step p { margin: .35rem 0 .65rem; }
body[data-portal="client"] .connect-connected { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; padding: .75rem 0 0; }
body[data-portal="client"] .connected-badge { font-weight: 700; color: var(--color-success, #16a34a); }
body[data-portal="client"] .simple-balance-grid { margin-bottom: 1.25rem; }
@media (max-width: 900px) {
  body[data-portal="client"] .hero-credit { grid-template-columns: 1fr; }
  body[data-portal="client"] .hero-credit-side { align-items: stretch; }
  body[data-portal="client"] .hero-credit-chips { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile: keep code blocks from blowing out the hero connect card ── */
body[data-portal="client"] .connect-step .copy-field code { white-space: pre-wrap; word-break: break-all; }
body[data-portal="client"] .hero-credit-balance { word-break: break-word; }

/* ── New hero-connect layout overrides the old flex .connect-step ── */
body[data-portal="client"] .connect-steps .connect-step { display: block; }
body[data-portal="client"] .hero-connect .connect-step { display: block; }
body[data-portal="client"] .service-strip { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: 1rem 1.25rem; }
body[data-portal="client"] .service-strip-value { font-weight: 700; }
body[data-portal="client"] .service-strip-value.good { color: var(--color-success, #16a34a); }
body[data-portal="client"] .service-strip-value.bad { color: var(--color-danger, #dc2626); }
body[data-portal="client"] .service-strip a.text-link { margin-left: auto; }

/* ═══════════════════════════════════════════════════════════════
   Client portal — dark navy theme (approved mobile concept B)
   Applied to every client page (both modes) + login; staff stays light.
   ═══════════════════════════════════════════════════════════════ */
body[data-portal="client"] {
  color-scheme: dark;
  --color-primary: #3498DB;
  --color-primary-light: #4fc3f7;
  --color-header: #0b1420;
  --color-accent: #3498DB;
  --color-border: #1d3350;
  --color-bg: #0f1724;
  --color-bg-alt: #13223a;
  --color-surface: #13223a;
  --color-surface-hover: #182c46;
  --color-surface-subtle: #0f1d31;
  --surface-0: #13223a;
  --surface-1: #102034;
  --surface-2: #0f1d31;
  --color-text: #eef2f8;
  --color-text-muted: #8fb2d4;
  --color-text-subtle: #8fb2d4;
  --color-text-faint: #6f8db0;
  --color-success: #4ade80;
  --color-danger: #f87171;
  --color-warning: #fbbf24;
  --shadow: 0 1px 3px rgba(0,0,0,.35);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.45);
}
body[data-portal="client"] .theme-toggle { display: none; }
body[data-portal="client"] input::placeholder,
body[data-portal="client"] ::placeholder { color: #93a9c4; }

/* ── Concept-B home (plain-English document style) ─────────────── */
.home-doc { max-width: 46rem; padding-top: 2.25rem; }
.home-greeting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.home-greeting { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; color: var(--color-text); }
.home-status { display: inline-flex; align-items: center; gap: .45rem; font-size: .8125rem; font-weight: 700; text-decoration: none; }
.home-status .home-status-dot { width: .5rem; height: .5rem; border-radius: 50%; display: inline-block; }
.home-status.ok { color: #4ade80; }
.home-status.ok .home-status-dot { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.home-status.down { color: #f87171; }
.home-status.down .home-status-dot { background: #f87171; box-shadow: 0 0 8px #f87171; }
.home-lede { margin-top: 1rem; font-size: 1.1875rem; line-height: 1.75; color: var(--color-text); }
.home-lede b { color: #4fc3f7; font-weight: 700; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1.5rem; }
.home-btn { display: block; text-align: center; padding: .875rem 1rem; border-radius: .875rem; font-size: 1rem; font-weight: 700; text-decoration: none; }
.home-btn:active { transform: scale(.97); }
.home-btn.primary { background: var(--color-accent); color: #081018; }
.home-btn.ghost { background: transparent; color: var(--color-text); border: 1.5px solid #2c4a6e; }
.home-divider { border: none; height: 1px; background: var(--color-border); margin: 2rem 0 1.5rem; }
.home-section-h { font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: .75rem; }
.home-bars { height: 4rem; }
.home-bars svg { display: block; width: 100%; height: 100%; }
.home-bar { fill: #23405f; }
.home-bar.today { fill: var(--color-accent); }
.home-bar-labels { display: flex; justify-content: space-between; margin-top: .375rem; font-size: .6563rem; color: var(--color-text-muted); }
.home-bar-labels span { flex: 1; text-align: center; }
.home-cap { margin-top: .5rem; font-size: .7813rem; color: var(--color-text-muted); }
.home-recent { margin-top: .25rem; }
.home-recent-row { display: flex; align-items: baseline; gap: .625rem; padding: .6875rem 0; border-bottom: 1px dashed var(--color-border); font-size: .9375rem; }
.home-recent-row:last-child { border-bottom: none; }
.home-recent-when { font-size: .7188rem; color: var(--color-text-muted); min-width: 4.5rem; }
.home-recent-name { flex: 1; }
.home-recent-cost { font-weight: 700; color: #4fc3f7; }
.home-foot { margin-top: 2rem; font-size: .875rem; color: var(--color-text-muted); }

/* ── Mobile bottom tab bar (client portal, both modes) ─────────── */
.bottom-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: #0b1420; border-top: 1px solid #1d3350;
  padding: .375rem .5rem calc(.5rem + env(safe-area-inset-bottom));
  gap: .25rem;
}
.bottom-tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1875rem;
  padding: .4375rem .25rem; border-radius: .625rem; text-decoration: none;
  color: #9db4d0; font-size: .6563rem; font-weight: 600;
}
.bottom-tabs a svg { width: 1.25rem; height: 1.25rem; }
.bottom-tabs a.on { color: var(--color-accent); background: rgba(52,152,219,.12); }
@media (max-width: 768px) {
  body[data-portal="client"] .bottom-tabs { display: flex; }
  body[data-portal="client"] .app-main { padding-bottom: 5.5rem; }
  /* Simple mode: bottom tabs replace the top nav + hamburger entirely */
  body[data-portal="client"][data-portal-mode="simple"] .sidebar-toggle,
  body[data-portal="client"][data-portal-mode="simple"] #topnav { display: none; }
  .home-actions { grid-template-columns: 1fr; }
}

/* ── Keys table: clean row anatomy (approved keys-layout pass) ───── */
body[data-portal="client"] .data-table tbody td { vertical-align: middle; }
.key-name-cell { min-width: 9rem; }
.key-name-input {
  background: transparent; border: 1px solid transparent;
  font-weight: 700; color: var(--color-text); border-radius: .5rem;
  min-width: 7rem; text-align: left; padding: .35rem .5rem;
}
.key-name-input:hover { border-color: var(--color-border); }
.key-name-input:focus { outline: none; border-color: var(--color-primary); background: var(--color-surface-subtle); }
.key-alias-save { visibility: hidden; }
.alias-form:focus-within .key-alias-save,
.alias-form:hover .key-alias-save { visibility: visible; }
.key-prefix { display: block; margin-top: .2rem; font-size: .6875rem; color: var(--color-text-muted); }
.key-manage-panel { width: 100%; max-width: 26rem; }
.key-manage-panel > .confirm-action > .btn { display: block; margin: .25rem 0; }
.key-manage-panel .key-usage small { display: none; }
.manage-sep { border: none; border-top: 1px solid var(--color-border); margin: .75rem 0; }
@media (max-width: 720px) {
  .key-name-cell .key-name-input { width: 100%; min-width: 0; }
  .alias-form { display: flex; gap: .375rem; align-items: center; }
  .key-alias-save { visibility: visible; }
}

/* ── Keys v3: compact rows, name as text, popover actions ───────── */
body[data-portal="client"] .data-table .key-name-input {
  background: transparent !important; border: 1px solid transparent !important;
  box-shadow: none; padding: .125rem .375rem; margin-left: -.375rem;
  font-size: .9375rem; font-weight: 700; min-height: 0; width: 100%; max-width: 14rem;
}
body[data-portal="client"] .data-table .key-name-input::placeholder { color: var(--color-text-muted); font-weight: 500; }
body[data-portal="client"] .data-table .key-name-input:hover { border-color: var(--color-border) !important; }
body[data-portal="client"] .data-table .key-name-input:focus { border-color: var(--color-primary) !important; background: var(--color-surface-subtle) !important; }
.key-usage { font-weight: 600; white-space: nowrap; }
.key-actions { white-space: nowrap; text-align: right; }
.key-actions > details { display: inline-block; vertical-align: middle; margin-left: .375rem; position: relative; }
.key-actions .confirm-panel { margin: 0; }
@media (min-width: 721px) {
  body[data-portal="client"] .table-wrapper { overflow: visible; }
  .key-actions .confirm-panel {
    position: absolute; right: 0; top: calc(100% + .375rem); z-index: 30; text-align: left;
    width: 18rem; padding: .875rem; background: var(--color-surface);
    border: 1px solid var(--color-border); border-radius: .75rem; box-shadow: 0 .75rem 2rem rgba(0,0,0,.5);
  }
  .key-actions .key-manage-panel { width: 22rem; }
}
.key-manage-panel > .confirm-action > .btn { display: block; width: 100%; text-align: left; margin: .25rem 0; }
@media (max-width: 720px) { .key-actions { text-align: left; } }
.key-manage-panel summary.btn { display: flex; align-items: center; min-height: 2.5rem; }
@media (min-width: 721px) { body[data-portal="client"] .data-table td:has(> .key-usage) { display: table-cell; vertical-align: middle; } }
.key-usage { margin: 0; }
body[data-portal="client"] .data-table th:last-child { text-align: right; }
body[data-portal="client"] .data-table tbody td { padding-block: .875rem; }
/* Manage = plain menu; every item inside opens the shared centered modal (key-limits). */
.key-manage-panel details.key-limits { display: block; }
.key-manage-panel details.key-limits > summary { width: 100%; }

/* ── What's new: banner + updates page ── */
.whats-new-banner { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  margin: 0 0 1rem; padding: .625rem .875rem; border-radius: .75rem; font-size: .875rem;
  background: rgba(52,152,219,.14); border: 1px solid rgba(79,195,247,.35); color: var(--color-text); }
.whats-new-actions { display: inline-flex; align-items: center; gap: .5rem; }
.whats-new-actions a { font-weight: 700; color: var(--color-primary-light, #4fc3f7); white-space: nowrap; }
.whats-new-dismiss { background: transparent; border: 0; color: var(--color-text-muted); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: .25rem .5rem; min-height: 2.75rem; min-width: 2.75rem; }
.update-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.update-head h2 { margin: 0; }
.update-list { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .75rem; }
.update-list li { display: grid; gap: .125rem; padding-left: .875rem; border-left: .1875rem solid var(--color-primary); }
.update-list li span { color: var(--color-text-muted); font-size: .9375rem; }
.site-footer .footer-inner a { color: var(--color-text-muted); }

/* Model Servers fleet view (staff) */
.fleet-meta { font-size: .8rem; margin: 0 0 .75rem; }
.fleet-windows { display: flex; gap: .4rem; align-items: center; }
.fleet-table th, .fleet-table td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.fleet-host { font-size: .75rem; font-weight: 400; }
.fleet-bad { color: var(--color-danger); font-weight: 600; }
.fleet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr)); gap: 1rem; margin: 1rem 0; }
.fleet-card.fleet-blocked { border-left: .25rem solid var(--color-danger); }
.fleet-card.fleet-unknown { border-left: .25rem solid var(--color-warning); }
.fleet-card.fleet-ok { border-left: .25rem solid var(--color-success); }
.fleet-card.fleet-disabled { opacity: .7; }
/* Fixed-height status slot so a stale card never desynchronises the fleet row. */
.fleet-alert { min-height: 1.9rem; margin: 0 0 .6rem; }
.fleet-alert-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; font-size: .74rem; font-weight: 600; border-radius: 999px; color: var(--color-warning); background: color-mix(in srgb, var(--color-warning) 12%, transparent); border: .0625rem solid color-mix(in srgb, var(--color-warning) 45%, transparent); }
.fleet-alert-chip.is-waiting { color: var(--color-text-muted); background: var(--color-surface-subtle); border-color: var(--color-border); }
/* Headline strip: identical position on every card so servers compare at a glance. */
.fleet-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: .5rem; margin: 0 0 .6rem; }
.fleet-hero div { min-width: 0; padding: .55rem .65rem; background: var(--color-surface-subtle); border: 1px solid var(--color-border); border-radius: var(--radius); }
.fleet-hero dt { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); }
.fleet-hero dd { margin: .1rem 0 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fleet-hero dd small { display: block; font-size: .68rem; font-weight: 400; color: var(--color-text-muted); }
/* Secondary metrics as dense label/value chips — missing readings read as absent, not zero. */
.fleet-chips { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .35rem; padding: 0; margin: 0 0 1rem; }
.fleet-chips li { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; min-width: 0; padding: .3rem .55rem; background: var(--color-surface-subtle); border-radius: calc(var(--radius) * .75); }
.fleet-chips span { font-size: .72rem; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-chips b { font-size: .92rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.fleet-chips li.is-missing b, .fleet-hero div.is-missing dd { color: var(--color-text-muted); font-weight: 500; }
.fleet-sparks { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.fleet-sparks figure { margin: 0; min-width: 0; }
.fleet-sparks figcaption { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; font-size: .7rem; color: var(--color-text-muted); margin-bottom: .2rem; }
.fleet-sparks figcaption b { font-size: .7rem; font-weight: 650; color: var(--color-text-secondary, #4b5563); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fleet-spark { width: 100%; height: 3rem; display: block; background: var(--color-surface-subtle); border: 1px solid var(--color-border); border-radius: calc(var(--radius) * .75); }
.fleet-spark-base { stroke: var(--color-border); stroke-width: 1; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.fleet-spark-fill { fill: var(--color-accent, #2563eb); opacity: .14; stroke: none; }
.fleet-spark-line { stroke: var(--color-accent, #2563eb); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.fleet-spark-dot { fill: var(--color-accent, #2563eb); }
.fleet-spark-peak { fill: var(--color-accent, #2563eb); stroke: var(--color-surface, #fff); stroke-width: 1; vector-effect: non-scaling-stroke; }
.fleet-spark-empty { height: 3rem; display: flex; align-items: center; justify-content: center; font-size: .75rem; color: var(--color-text-muted); border: 1px dashed var(--color-border, #8884); border-radius: calc(var(--radius) * .75); background: transparent; }
/* 24 h gateway block: inset ledger panel, right-aligned tabular figures. */
.fleet-gateway { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .1rem 1.25rem; margin: 0 0 .6rem; padding: .6rem .8rem; background: var(--color-surface-subtle); border: 1px solid var(--color-border); border-radius: var(--radius); }
.fleet-gateway > div { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; min-width: 0; padding: .16rem 0; border-bottom: 1px solid color-mix(in srgb, var(--color-border) 45%, transparent); }
.fleet-gateway > div:last-child { border-bottom: 0; }
.fleet-gateway dt { font-size: .72rem; color: var(--color-text-muted); white-space: nowrap; }
.fleet-gateway dd { margin: 0; font-size: .92rem; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.fleet-gateway dd small { font-size: .68rem; font-weight: 400; color: var(--color-text-muted); margin-left: .3rem; }
.fleet-gateway-empty { margin: 0 0 .6rem; padding: .6rem .8rem; background: var(--color-surface-subtle); border: 1px solid var(--color-border); border-radius: var(--radius); }
@media (max-width: 34rem) { .fleet-gateway { grid-template-columns: minmax(0, 1fr); } }
.fleet-sub { font-size: .8rem; margin: .5rem 0 .25rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .03em; }
.fleet-foot { font-size: .75rem; margin: .5rem 0 0; }
#fleet-root[data-error]::after { content: "Live refresh paused \2013  reload to sign in again."; display: block; font-size: .75rem; color: var(--color-warning); }
@media (max-width: 40rem) { .fleet-table { font-size: .8rem; } }
/* equal-height cards per row: no ragged dead space under shorter cards */
.fleet-grid { align-items: stretch; }
.fleet-grid > .fleet-card { margin: 0; }
.fleet-compare { margin-bottom: 1rem; }
.fleet-table td { text-align: right; }
.fleet-table td:nth-child(2) { text-align: left; }
.fleet-table th[scope="col"]:not(:first-child):not(:nth-child(2)) { text-align: right; }
.fleet-meta { margin-top: 0; }
.fleet-hero dt, .fleet-chips span, .fleet-gateway dt, .fleet-sparks figcaption, .fleet-meta { color: var(--color-text-secondary, #4b5563); }
.fleet-card .card-heading p { overflow-wrap: anywhere; }
