/* ============================================================================
   NiClinic Vendor Console — design system
   A token-driven admin theme. "Clinical console": a teal accent on cool,
   slightly teal-biased neutrals, with a persistent deep-teal sidebar rail.
   Light + dark via prefers-color-scheme, overridable by [data-theme].
   System font stack only (no external webfonts — the portal may run offline).
   ============================================================================ */

/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
    /* Type */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;

    --fs-xs: 0.75rem;     /* 12 — micro labels */
    --fs-sm: 0.8125rem;   /* 13 — secondary / table cells */
    --fs-base: 0.9375rem; /* 15 — body / controls */
    --fs-md: 1.0625rem;   /* 17 — section titles */
    --fs-lg: 1.375rem;    /* 22 — page title */
    --fs-xl: 1.75rem;     /* 28 */
    --fs-metric: 2rem;    /* 32 — metric numbers */
    --lh-tight: 1.2;
    --lh-normal: 1.5;

    /* Spacing scale (4pt) */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

    /* Radius */
    --r-sm: 6px; --r-md: 9px; --r-lg: 12px; --r-xl: 16px; --r-pill: 999px;

    /* Neutrals + surfaces (LIGHT) — cool, biased toward the teal accent */
    --bg: #eef2f1;
    --surface: #ffffff;
    --surface-2: #f1f5f4;
    --surface-hover: #f0f6f4;
    --border: #dce4e2;
    --border-strong: #c7d2cf;

    --text: #0f1f1c;
    --text-muted: #566661;
    --text-subtle: #7c8b86;

    /* Accent — clinical teal (the ONE brand hue) */
    --accent: #0d7d72;
    --accent-hover: #0a655c;
    --accent-press: #084f48;
    --accent-soft: #e0f1ee;
    --accent-soft-text: #0a655c;
    --accent-contrast: #ffffff;

    /* Semantic — distinct from the accent */
    --good: #15803d;      --good-bg: #dcfce7;  --good-text: #14532d;   --good-border: #a7f3c4;
    --warn: #b45309;      --warn-bg: #fef3c7;  --warn-text: #854d0e;   --warn-border: #fcd88a;
    --critical: #dc2626;  --critical-bg: #fee2e2; --critical-text: #991b1b; --critical-border: #fbcaca;
    --neutral-pill-bg: #e5ebe9; --neutral-pill-text: #475551;

    /* Focus ring */
    --focus: #0d7d72;
    --focus-ring: 0 0 0 3px rgba(13, 125, 114, 0.28);

    /* Shadows (cool-tinted) */
    --shadow-sm: 0 1px 2px rgba(15, 31, 28, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 31, 28, 0.08);
    --shadow-lg: 0 20px 48px rgba(9, 24, 22, 0.22);

    /* Sidebar rail — a committed deep-teal surface in BOTH themes */
    --sidebar-bg: #0c1c1a;
    --sidebar-border: #1a302d;
    --sidebar-text: #c6d3cf;
    --sidebar-muted: #7f918d;
    --sidebar-hover: #14302c;
    --sidebar-active-bg: #123c37;
    --sidebar-active-text: #ffffff;
    --sidebar-accent: #2dd4bf;

    color-scheme: light;
}

/* Dark — via OS preference; token-level only, components never restyled here */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1312;
        --surface: #121d1b;
        --surface-2: #17221f;
        --surface-hover: #1a2622;
        --border: #24322f;
        --border-strong: #30403c;

        --text: #e7efec;
        --text-muted: #9aa8a4;
        --text-subtle: #7c8a86;

        --accent: #2dd4bf;
        --accent-hover: #5eead4;
        --accent-press: #99f6e4;
        --accent-soft: #123330;
        --accent-soft-text: #5eead4;
        --accent-contrast: #04211d;

        --good: #4ade80;   --good-bg: #0f2c1c;   --good-text: #86efac;  --good-border: #1c4a30;
        --warn: #fbbf24;   --warn-bg: #33270b;   --warn-text: #fcd34d;  --warn-border: #59440f;
        --critical: #f87171; --critical-bg: #351515; --critical-text: #fca5a5; --critical-border: #5a2323;
        --neutral-pill-bg: #202c29; --neutral-pill-text: #9aa8a4;

        --focus: #2dd4bf;
        --focus-ring: 0 0 0 3px rgba(45, 212, 191, 0.30);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
        --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);

        --sidebar-bg: #081210;
        --sidebar-border: #17221f;
        --sidebar-hover: #12211e;
        --sidebar-active-bg: #103330;

        color-scheme: dark;
    }
}

/* Explicit theme overrides (viewer toggle stamps data-theme — must win both ways) */
:root[data-theme="light"] {
    --bg: #eef2f1; --surface: #ffffff; --surface-2: #f1f5f4; --surface-hover: #f0f6f4;
    --border: #dce4e2; --border-strong: #c7d2cf;
    --text: #0f1f1c; --text-muted: #566661; --text-subtle: #7c8b86;
    --accent: #0d7d72; --accent-hover: #0a655c; --accent-press: #084f48;
    --accent-soft: #e0f1ee; --accent-soft-text: #0a655c; --accent-contrast: #ffffff;
    --good: #15803d; --good-bg: #dcfce7; --good-text: #14532d; --good-border: #a7f3c4;
    --warn: #b45309; --warn-bg: #fef3c7; --warn-text: #854d0e; --warn-border: #fcd88a;
    --critical: #dc2626; --critical-bg: #fee2e2; --critical-text: #991b1b; --critical-border: #fbcaca;
    --neutral-pill-bg: #e5ebe9; --neutral-pill-text: #475551;
    --focus: #0d7d72; --focus-ring: 0 0 0 3px rgba(13, 125, 114, 0.28);
    --shadow-sm: 0 1px 2px rgba(15,31,28,0.06); --shadow-md: 0 4px 14px rgba(15,31,28,0.08); --shadow-lg: 0 20px 48px rgba(9,24,22,0.22);
    --sidebar-bg: #0c1c1a; --sidebar-border: #1a302d; --sidebar-hover: #14302c; --sidebar-active-bg: #123c37;
    color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0b1312; --surface: #121d1b; --surface-2: #17221f; --surface-hover: #1a2622;
    --border: #24322f; --border-strong: #30403c;
    --text: #e7efec; --text-muted: #9aa8a4; --text-subtle: #7c8a86;
    --accent: #2dd4bf; --accent-hover: #5eead4; --accent-press: #99f6e4;
    --accent-soft: #123330; --accent-soft-text: #5eead4; --accent-contrast: #04211d;
    --good: #4ade80; --good-bg: #0f2c1c; --good-text: #86efac; --good-border: #1c4a30;
    --warn: #fbbf24; --warn-bg: #33270b; --warn-text: #fcd34d; --warn-border: #59440f;
    --critical: #f87171; --critical-bg: #351515; --critical-text: #fca5a5; --critical-border: #5a2323;
    --neutral-pill-bg: #202c29; --neutral-pill-text: #9aa8a4;
    --focus: #2dd4bf; --focus-ring: 0 0 0 3px rgba(45,212,191,0.30);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4); --shadow-md: 0 4px 16px rgba(0,0,0,0.45); --shadow-lg: 0 20px 48px rgba(0,0,0,0.6);
    --sidebar-bg: #081210; --sidebar-border: #17221f; --sidebar-hover: #12211e; --sidebar-active-bg: #103330;
    color-scheme: dark;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; font-weight: 650; line-height: var(--lh-tight); text-wrap: balance; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.92em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

/* ── App shell ──────────────────────────────────────────────────────────────── */
.portal-app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* Sidebar rail */
.portal-sidebar {
    grid-column: 1;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    padding: var(--sp-5) var(--sp-3) var(--sp-4);
    gap: var(--sp-6);
    position: sticky; top: 0; height: 100vh;
}
.portal-logo { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); }
.portal-logo-mark {
    width: 38px; height: 38px; border-radius: 10px; flex: none;
    display: grid; place-items: center;
    background: linear-gradient(150deg, #14b8a6, #0d7d72);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), var(--shadow-sm);
}
.portal-logo-mark svg { width: 22px; height: 22px; color: #ffffff; }
.portal-logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.portal-logo-name { font-weight: 700; font-size: 0.95rem; color: #fff; letter-spacing: -0.01em; }
.portal-logo-sub { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--sidebar-muted); margin-top: 2px; }

.portal-nav { display: flex; flex-direction: column; gap: 2px; }
.portal-nav-heading { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.13em; color: var(--sidebar-muted); padding: 0 var(--sp-3) var(--sp-2); }
.portal-navitem {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 9px var(--sp-3); border-radius: var(--r-md);
    color: var(--sidebar-text); text-decoration: none;
    font-size: var(--fs-base); font-weight: 500;
    position: relative; transition: background 120ms ease, color 120ms ease;
}
.portal-navitem svg { width: 18px; height: 18px; flex: none; color: var(--sidebar-muted); transition: color 120ms ease; }
.portal-navitem:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.portal-navitem:hover svg { color: var(--sidebar-text); }
.portal-navitem.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.portal-navitem.active svg { color: var(--sidebar-accent); }
.portal-navitem.active::before {
    content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0; background: var(--sidebar-accent);
}
.portal-sidebar-foot { margin-top: auto; font-size: 0.72rem; color: var(--sidebar-muted); padding: 0 var(--sp-3); }

/* Main column */
.portal-body { grid-column: 2; display: flex; flex-direction: column; min-width: 0; }
.portal-topbar {
    display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-4);
    height: 60px; padding: 0 var(--sp-8);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
    backdrop-filter: saturate(1.4) blur(8px);
}
.portal-operator { display: flex; align-items: center; gap: var(--sp-4); white-space: nowrap; }
.portal-operator-id { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }
.portal-avatar {
    width: 30px; height: 30px; border-radius: var(--r-pill); flex: none;
    display: grid; place-items: center; font-size: 0.75rem; font-weight: 700;
    background: var(--accent-soft); color: var(--accent-soft-text);
}
.portal-operator-name { font-weight: 600; color: var(--text); }
.portal-signout {
    background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
    border-radius: var(--r-md); padding: 7px 13px; font-size: var(--fs-sm); font-weight: 500;
    cursor: pointer; transition: background 120ms ease, border-color 120ms ease;
}
.portal-signout:hover { background: var(--surface-hover); border-color: var(--accent); }

.portal-main { padding: var(--sp-8); max-width: 1120px; width: 100%; margin: 0 auto; }
.portal-main > h1 { font-size: var(--fs-lg); letter-spacing: -0.015em; margin-bottom: var(--sp-6); }

/* Page header (title + optional subtitle) */
.portal-pagehead { margin-bottom: var(--sp-6); }
.portal-pagehead h1 { font-size: var(--fs-lg); letter-spacing: -0.015em; }
.portal-pagehead p { margin: 6px 0 0; color: var(--text-muted); font-size: var(--fs-base); }
/* A pagehead with a trailing primary action (e.g. "New customer") — title block left, button right. */
.portal-pagehead-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.portal-pagehead-row .portal-pagehead { margin-bottom: 0; flex: 1 1 320px; }

/* ── Login shell ────────────────────────────────────────────────────────────── */
.portal-login-shell {
    min-height: 100vh; display: grid; place-items: center; padding: var(--sp-6);
    background:
        radial-gradient(1100px 620px at 12% -8%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
        radial-gradient(900px 560px at 100% 108%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
        var(--bg);
}
.portal-login-wrap { width: 100%; max-width: 400px; }
.portal-login-brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); text-align: center; }
.portal-login-brand .portal-logo-mark { width: 52px; height: 52px; border-radius: 14px; }
.portal-login-brand .portal-logo-mark svg { width: 30px; height: 30px; }
.portal-login-name { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.portal-login-sub { font-size: var(--fs-sm); color: var(--text-muted); }

/* ── Cards / sections ───────────────────────────────────────────────────────── */
.portal-section {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: var(--sp-6); margin: 0 0 var(--sp-5); box-shadow: var(--shadow-sm);
}
.portal-section > h2 {
    margin: 0 0 var(--sp-4); font-size: var(--fs-md); font-weight: 650; letter-spacing: -0.01em;
    display: flex; align-items: center; gap: var(--sp-3);
}
.portal-section-note { color: var(--text-muted); font-size: var(--fs-sm); margin: 0 0 var(--sp-4); }

/* Metric cards */
.portal-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-2); }
.portal-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2);
    box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.portal-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: 0.9; }
.portal-card-label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.portal-card-value { font-size: var(--fs-metric); font-weight: 700; color: var(--text); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.portal-card-accent-good::before { background: var(--good); }
.portal-card-accent-warn::before { background: var(--warn); }
.portal-card-accent-critical::before { background: var(--critical); }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.portal-tablewrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.portal-table { width: 100%; border-collapse: collapse; }
.portal-table th, .portal-table td { text-align: left; padding: 11px var(--sp-4); font-size: var(--fs-sm); border-bottom: 1px solid var(--border); }
.portal-table thead th {
    color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs);
    text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface-2);
    position: sticky; top: 0;
}
.portal-table tbody tr:last-child td { border-bottom: none; }
.portal-table-compact { max-width: 340px; }
.portal-num { text-align: right; font-variant-numeric: tabular-nums; }
.portal-row-link { cursor: pointer; transition: background 100ms ease; }
.portal-row-link:hover td { background: var(--surface-hover); }
.portal-key { color: var(--text-muted); font-family: var(--font-mono); font-size: var(--fs-xs); }

/* ── Pills / status ─────────────────────────────────────────────────────────── */
.portal-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill);
    font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; border: 1px solid transparent;
}
.portal-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.portal-pill-active { background: var(--good-bg); color: var(--good-text); border-color: var(--good-border); }
.portal-pill-trial { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.portal-pill-suspended { background: var(--critical-bg); color: var(--critical-text); border-color: var(--critical-border); }
.portal-pill-churned { background: var(--neutral-pill-bg); color: var(--neutral-pill-text); }
.portal-warn { color: var(--warn); font-weight: 600; }

/* ── Detail / definition lists ──────────────────────────────────────────────── */
.portal-details { display: grid; grid-template-columns: 150px 1fr; gap: var(--sp-3) var(--sp-4); margin: 0; }
.portal-details dt { color: var(--text-muted); font-size: var(--fs-sm); }
.portal-details dd { margin: 0; font-size: var(--fs-base); color: var(--text); }
.portal-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.portal-list li { font-size: var(--fs-base); padding: 8px 12px; border-radius: var(--r-sm); background: var(--surface-2); }
.portal-crumb { margin: 0 0 var(--sp-4); }
.portal-crumb a { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; }
.portal-crumb a:hover { color: var(--accent); }

/* ── Toolbar / search / pager ───────────────────────────────────────────────── */
.portal-toolbar { display: flex; gap: var(--sp-3); align-items: center; margin: 0 0 var(--sp-5); flex-wrap: wrap; }
.portal-search {
    flex: 1 1 260px; max-width: 380px; padding: 10px 12px;
    border: 1px solid var(--border-strong); border-radius: var(--r-md);
    font-size: var(--fs-base); font-family: inherit; background: var(--surface); color: var(--text);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.portal-search::placeholder { color: var(--text-subtle); }
.portal-search:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
/* A narrow numeric input for inline table-row editing (e.g. Plans price/seat limits) — same look as
   .portal-search but sized for a few digits, right-aligned to match its numeric column. */
.portal-input-num {
    width: 90px; max-width: 90px; padding: 8px 10px; text-align: right;
    border: 1px solid var(--border-strong); border-radius: var(--r-md);
    font-size: var(--fs-base); font-family: inherit; background: var(--surface); color: var(--text);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.portal-input-num:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.portal-pager { display: flex; gap: var(--sp-4); align-items: center; justify-content: flex-end; margin-top: var(--sp-4); }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.portal-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.portal-field label { font-size: var(--fs-sm); color: var(--text); font-weight: 600; }
.portal-field input, .portal-field select {
    padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
    font-size: var(--fs-base); font-family: inherit; background: var(--surface); color: var(--text);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.portal-field input:focus, .portal-field select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.portal-primary, .portal-secondary, .portal-danger {
    font-family: inherit; font-size: var(--fs-base); font-weight: 600; border-radius: var(--r-md);
    cursor: pointer; padding: 10px 16px; border: 1px solid transparent; line-height: 1.2;
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 60ms ease;
}
.portal-primary:active:not(:disabled), .portal-secondary:active:not(:disabled), .portal-danger:active:not(:disabled) { transform: translateY(1px); }
.portal-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-sm); }
.portal-primary:hover:not(:disabled) { background: var(--accent-hover); }
.portal-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.portal-secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--accent); }
.portal-danger { background: var(--critical); color: #fff; box-shadow: var(--shadow-sm); }
.portal-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--critical) 84%, #000); }
.portal-primary:disabled, .portal-secondary:disabled, .portal-danger:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.portal-btn-full { width: 100%; justify-content: center; }

/* ── Control rows (plan / policy / entitlements) ────────────────────────────── */
.portal-control-row { display: flex; gap: var(--sp-3); align-items: center; margin: var(--sp-4) 0; flex-wrap: wrap; }
.portal-control-label { font-size: var(--fs-sm); color: var(--text); font-weight: 600; }
.portal-select {
    padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
    font-size: var(--fs-base); font-family: inherit; background: var(--surface); color: var(--text);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.portal-select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.portal-select:disabled { opacity: 0.55; cursor: not-allowed; }

.portal-entitlements { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.portal-checks { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin: var(--sp-3) 0 var(--sp-4); }
.portal-check {
    display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
    padding: 8px 12px; cursor: pointer; transition: border-color 120ms ease, background 120ms ease;
}
.portal-check:hover { border-color: var(--accent); }
.portal-check input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.portal-toast {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
    padding: 12px var(--sp-4); border-radius: var(--r-md); margin: var(--sp-4) 0; font-size: var(--fs-base);
    border: 1px solid transparent; box-shadow: var(--shadow-sm);
}
.portal-toast-ok { background: var(--good-bg); border-color: var(--good-border); color: var(--good-text); }
.portal-toast-error { background: var(--critical-bg); border-color: var(--critical-border); color: var(--critical-text); }
.portal-toast-x { background: transparent; border: none; font-size: 1.25rem; cursor: pointer; color: inherit; line-height: 1; padding: 0 4px; opacity: 0.7; }
.portal-toast-x:hover { opacity: 1; }

/* ── Shown-once key box ─────────────────────────────────────────────────────── */
.portal-keybox { background: var(--good-bg); border: 1px solid var(--good-border); border-radius: var(--r-md); padding: var(--sp-4); margin: var(--sp-4) 0; color: var(--good-text); }
.portal-keybox strong { color: var(--good-text); }
.portal-keybox-row { display: flex; gap: var(--sp-3); align-items: center; margin-top: var(--sp-3); flex-wrap: wrap; }
.portal-keyfull {
    font-family: var(--font-mono); font-size: var(--fs-base); background: var(--surface);
    border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--r-sm);
    padding: 8px 12px; user-select: all; word-break: break-all; flex: 1 1 240px;
}

/* ── License row actions (inline link buttons) ──────────────────────────────── */
.portal-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.portal-linkbtn {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    font-size: var(--fs-xs); font-weight: 600; cursor: pointer; padding: 5px 10px; border-radius: var(--r-sm);
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.portal-linkbtn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--accent); color: var(--accent); }
.portal-linkbtn:disabled { opacity: 0.5; cursor: not-allowed; }
.portal-linkbtn-danger:hover:not(:disabled) { border-color: var(--critical); color: var(--critical); }
.portal-seatcell { background: var(--surface-2); }

/* ── Confirm modal ──────────────────────────────────────────────────────────── */
.portal-modal-backdrop {
    position: fixed; inset: 0; background: rgba(6, 18, 16, 0.55); display: flex;
    align-items: center; justify-content: center; z-index: 60; padding: var(--sp-4);
    backdrop-filter: blur(2px);
}
.portal-modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6); max-width: 460px; width: 100%; box-shadow: var(--shadow-lg); }
.portal-modal h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-md); }
.portal-modal p { margin: 0 0 var(--sp-4); font-size: var(--fs-base); color: var(--text-muted); }

/* ── Notices / states ───────────────────────────────────────────────────────── */
.portal-notice {
    background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text);
    padding: var(--sp-4) var(--sp-5); border-radius: var(--r-md);
}
.portal-notice strong { color: var(--warn-text); }
.portal-notice p { margin: 6px 0 0; font-size: var(--fs-sm); }
.portal-notice code { background: color-mix(in srgb, var(--warn-text) 12%, transparent); padding: 1px 5px; border-radius: 4px; }
.portal-notice-error { background: var(--critical-bg); border-color: var(--critical-border); color: var(--critical-text); }
.portal-notice-error strong { color: var(--critical-text); }
.portal-error { color: var(--critical); font-size: var(--fs-sm); font-weight: 500; }
.portal-field-error { color: var(--critical); font-size: var(--fs-sm); margin: 0 0 var(--sp-3); display: flex; align-items: center; gap: 6px; }
.portal-muted { color: var(--text-muted); font-size: var(--fs-base); }

/* Empty / loading state */
.portal-empty { text-align: center; color: var(--text-muted); padding: var(--sp-8) var(--sp-4); font-size: var(--fs-base); }
.portal-skeleton { color: var(--text-subtle); font-size: var(--fs-sm); padding: var(--sp-4) 0; display: flex; align-items: center; gap: var(--sp-2); }

/* ── Responsive: sidebar stacks to a top bar on narrow ──────────────────────── */
@media (max-width: 880px) {
    .portal-app { grid-template-columns: 1fr; }
    .portal-sidebar {
        grid-column: 1; position: sticky; top: 0; height: auto; flex-direction: row; align-items: center;
        gap: var(--sp-4); padding: var(--sp-3) var(--sp-4); border-right: none; border-bottom: 1px solid var(--sidebar-border);
        overflow-x: auto;
    }
    .portal-logo-sub { display: none; }
    .portal-nav { flex-direction: row; gap: var(--sp-1); }
    .portal-nav-heading, .portal-sidebar-foot { display: none; }
    .portal-navitem { padding: 8px 12px; }
    .portal-navitem.active::before { left: 0; right: 0; top: auto; bottom: -12px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
    .portal-main { padding: var(--sp-5) var(--sp-4); }
    .portal-topbar { padding: 0 var(--sp-4); }
    .portal-details { grid-template-columns: 1fr; gap: 2px; }
    .portal-details dt { margin-top: var(--sp-2); }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
