/* HaloPulse — base stylesheet
 *
 * Warm light palette (cornflower / lavender / sage), focus-to-edit field
 * pattern for inline profile editing. Single light theme.
 */

/* ---------- Self-hosted fonts ---------- */
@font-face {
    font-family: 'IBM Plex Sans';
    font-weight: 400; font-style: normal; font-display: swap;
    src: url('/static/fonts/IBMPlexSans-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'IBM Plex Sans';
    font-weight: 700; font-style: normal; font-display: swap;
    src: url('/static/fonts/IBMPlexSans-Bold.woff2') format('woff2');
}
@font-face {
    font-family: 'IBM Plex Mono';
    font-weight: 400; font-style: normal; font-display: swap;
    src: url('/static/fonts/IBMPlexMono-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'IBM Plex Mono';
    font-weight: 700; font-style: normal; font-display: swap;
    src: url('/static/fonts/IBMPlexMono-Bold.woff2') format('woff2');
}

/* ---------- Tokens — back-compat alias layer ----------
 *
 * Phase 1.7.5 step 7. The warm-light overrides from step 4 are gone;
 * canonical token values now flow from tokens.css:
 *   - dark by default (Primer dark palette)
 *   - light when <html data-theme="light"> (Primer light palette)
 *
 * Body font drops IBM Plex Sans in favor of tokens.css's system stack.
 * Both themes switch live in-place via halopulse.js's theme-changed
 * listener (step 6).
 *
 * What this block still does:
 *   1. Back-compat aliases for old token names (--bg, --accent, --sage,
 *      --text, --danger, --warning, ...). Step 11+ retires by renaming
 *      consumers to canonical tokens.css names.
 *   2. --space-1..6 — keeps the existing doubled-step scale to avoid
 *      layout drift. tokens.css also defines these names with a 4px-base
 *      canonical scale; this block shadows them globally.
 *   3. --max-width, --radius (alias), --focus-ring (alpha box-shadow tint
 *      derived from --accent-fg, overrides tokens.css's solid value).
 *
 * Two literals without a canonical equivalent in tokens.css:
 *   - --accent-alt: lavender (#A48FC9). Used in flash-info border +
 *     nav-badge-agent bg. Kept until step 11.
 *   - --text-mute: now aliased to --text-secondary (loses the slight
 *     dim/mute distinction the warm palette carried).
 * ----------------------------------------------------------------- */
:root {
    /* Focus halo — alpha box-shadow tint, derived from accent. */
    --focus-ring:       color-mix(in srgb, var(--accent-fg) 18%, transparent);

    /* Radius alias (tokens.css owns --radius-sm/-md/-lg/-full). */
    --radius:           var(--radius-md);

    /* Back-compat aliases — step 11+ retires by renaming consumers. */
    --bg:               var(--bg-canvas);
    --bg-raised:        var(--bg-subtle);
    --bg-elev:          var(--bg-emphasis);
    --input-rest:       var(--bg-inset);
    --border:           var(--border-muted);
    --border-hi:        var(--border-default);
    --text:             var(--text-primary);
    --text-dim:         var(--text-secondary);
    --text-mute:        var(--text-secondary);  /* lost the lighter-mute distinction */
    --text-on-accent:   var(--text-on-emphasis);
    --accent:           var(--accent-fg);
    --accent-hi:        var(--accent-emphasis);
    --accent-alt:       #A48FC9;                /* lavender — no canonical equivalent */
    --sage:             var(--success-fg);
    --sage-strong:      var(--success-emphasis);
    --danger:           var(--danger-fg);
    --warning:          var(--warning-fg);

    /* Local spacing scale — literal values preserved to avoid layout drift.
     * Step 11+ migrates consumers to the canonical tokens.css scale. */
    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2rem;
    --space-5: 3rem;
    --space-6: 4rem;

    /* Layout */
    --max-width: 1100px;
}

/* ---------- Responsive breakpoints (mobile-first) ----------
 *
 * Default rules target the smallest viewport (~375px). Media queries
 * scale UP from there. Canonical breakpoint literals (also documented
 * in tokens.css; CSS custom properties cannot be used in @media):
 *
 *   640px   sm  — large phones
 *   768px   md  — tablet portrait
 *   1024px  lg  — tablet landscape / laptops
 *   1280px  xl  — desktops
 *
 * Touch targets meet --touch-target-min (44px, Apple HIG).
 * iOS no-zoom requires input font-size >= 16px (1rem at default root).
 * Bottom-anchored UI respects env(safe-area-inset-bottom).
 * ------------------------------------------------------------ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
a { color: var(--text); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent); }
button { font-family: inherit; }
img, svg { display: block; max-width: 100%; }

/* ---------- Layout ---------- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-3);
}

/* ---------- Nav ---------- */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    max-width: var(--max-width);
    margin: 0 auto;
}
.nav-brand {
    display: flex; align-items: center; gap: var(--space-1);
    font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.nav-brand:hover { color: var(--text); }
.nav-glyph { display: inline-block; }
.nav-links {
    display: flex; align-items: center; gap: var(--space-3);
    font-family: var(--font-sans); font-size: 0.9rem;
}
.nav-form { margin: 0; }
.nav-link-btn {
    background: none; border: none; color: var(--text); cursor: pointer;
    padding: 0; font-size: 0.9rem; font-family: var(--font-sans);
}
.nav-link-btn:hover { color: var(--accent); }
.nav-cta {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent);
}
.nav-cta:hover { background: var(--accent); color: var(--text-on-accent); }

/* ---------- Hero ---------- */
.hero { padding: var(--space-6) 0 var(--space-5); }
.hero-title {
    font-family: var(--font-mono);
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
    margin: 0 0 var(--space-2);
    color: var(--text);
}
.hero-tagline {
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    color: var(--text-dim);
    max-width: 60ch;
    margin: 0 0 var(--space-4);
    line-height: 1.5;
}
.hero-cta { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    min-height: var(--touch-target-min);
    padding: 0.65rem 1.4rem;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 400;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-on-accent);
}
.btn-primary:hover {
    background: var(--accent-hi);
    border-color: var(--accent-hi);
    color: var(--text-on-accent);
}
.btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border-hi);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.85rem; min-height: auto; }

/* Link-style button: text-only, no border or background. */
.btn-link {
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    padding: 0.35rem 0.6rem;
    min-height: auto;
}
.btn-link:hover {
    text-decoration: underline;
    background: transparent;
    border-color: transparent;
    color: var(--accent);
}

/* Danger modifier — composes with .btn-secondary or .btn-link. */
.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger);
}
.btn-link.btn-danger {
    border-color: transparent;
}
.btn-link.btn-danger:hover {
    border-color: transparent;
}

/* ---------- Features ---------- */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-3);
    padding: var(--space-4) 0 var(--space-6);
}
.feature {
    padding: var(--space-3);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}
.feature:hover { border-color: var(--border-hi); }
.feature-title {
    font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700;
    margin: 0 0 var(--space-1); color: var(--text);
}
.feature-body { margin: 0; color: var(--text-dim); font-size: 0.95rem; line-height: 1.6; }

/* ---------- Flash ---------- */
.flash-container {
    max-width: var(--max-width);
    margin: var(--space-2) auto 0;
    padding: 0 var(--space-3);
}
.flash {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
    background: var(--bg-raised);
    font-size: 0.95rem;
    margin-bottom: var(--space-1);
}
.flash-info    { border-left-color: var(--accent-alt); }
.flash-success { border-left-color: var(--sage); }
.flash-warning { border-left-color: var(--warning); }
.flash-error   { border-left-color: var(--danger); }

/* ---------- Footer ---------- */
.footer {
    border-top: 1px solid var(--border);
    padding: var(--space-3) 0 max(var(--space-3), env(safe-area-inset-bottom));
    margin-top: var(--space-6);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-mute);
}
.footer .container { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Forms (baseline) ---------- */
.form-field { margin-bottom: var(--space-2); }
.form-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-bottom: var(--space-1);
    color: var(--text-dim);
}
.form-input {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: 0.6rem 0.8rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 1rem;  /* >=16px to prevent iOS Safari focus auto-zoom */
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.form-input-error { border-color: var(--danger); }
.form-input-error:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger-fg) 18%, transparent);
}
.form-help {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    color: var(--text-mute);
    font-family: var(--font-mono);
}
.form-error {
    margin: 0.35rem 0 0;
    font-size: 0.85rem;
    color: var(--danger);
    font-family: var(--font-mono);
}
.form-hint {
    margin: 4px 0 0 0;
    color: var(--text-mute);
    font-size: 0.8rem;
}
.form-hint a { color: var(--accent); }
.form-submit { margin-top: var(--space-3); }
.form-submit .btn { width: 100%; }

/* ---------- Auth pages ---------- */
.auth { max-width: 460px; margin: var(--space-5) auto; padding: 0 var(--space-3); }
.auth-wide { max-width: 900px; }
.auth-title {
    font-family: var(--font-sans);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 var(--space-2);
}
.auth-subtitle, .auth-body { color: var(--text-dim); margin: 0 0 var(--space-3); line-height: 1.6; }
.auth-muted { color: var(--text-mute); font-size: 0.95rem; }
.auth-form { margin-top: var(--space-3); }
.auth-alt { margin-top: var(--space-4); font-size: 0.95rem; color: var(--text-dim); }
.auth-alt a { color: var(--accent); }
.auth-alt a:hover { color: var(--accent-hi); }

/* ---------- Sessions table ---------- */
.sessions-table { width: 100%; border-collapse: collapse; margin-top: var(--space-3); font-size: 0.9rem; }
.sessions-table th, .sessions-table td {
    text-align: left;
    padding: var(--space-1) var(--space-2);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.sessions-table th {
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sessions-table td code { font-family: var(--font-mono); font-size: 0.85rem; color: var(--text-dim); }
.session-current { color: var(--accent); font-family: var(--font-mono); font-size: 0.8rem; margin-left: var(--space-1); }
.session-revoked td { color: var(--text-mute); font-style: italic; }
.session-revoked-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* ---------- Profile page ---------- */
.section-heading {
    font-family: var(--font-sans);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-top: var(--space-4);
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-1);
    border-bottom: 1px solid var(--border);
}
.section-subnote { color: var(--text-mute); font-size: 0.85rem; margin: -8px 0 var(--space-2) 0; }
.profile-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-1) var(--space-3);
    margin: 0 0 var(--space-3) 0;
    font-size: 0.9rem;
}
.profile-meta dt { color: var(--text-mute); font-family: var(--font-mono); font-size: 0.85rem; }
.profile-meta dd { margin: 0; color: var(--text); }
.profile-meta dd code { font-family: var(--font-mono); color: var(--accent); }
.profile-actions { list-style: none; padding: 0; margin: var(--space-2) 0; }
.profile-actions li { margin: var(--space-1) 0; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    margin-left: var(--space-1);
}
.badge-ok {
    background: color-mix(in srgb, var(--success-fg) 18%, transparent);
    color: var(--sage-strong);
    border: 1px solid color-mix(in srgb, var(--success-fg) 50%, transparent);
}
.badge-warn {
    background: color-mix(in srgb, var(--warning-fg) 18%, transparent);
    color: #7A5418;
    border: 1px solid color-mix(in srgb, var(--warning-fg) 50%, transparent);
}

/* ---------- Field rows: borderless edit-on-focus, halo on save/error ---------- */
.field-list {
    margin-bottom: var(--space-3);
}
.field-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-1) 0;
}
.field-control {
    display: contents;
}
.field-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
    flex-wrap: wrap;
}
.field-label {
    display: block;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
}
.field-input-wrap {
    position: relative;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.field-input-wrap:has(select)::after {
    content: '▾';
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-mute);
    font-size: 0.95rem;
    pointer-events: none;
}
select.field-input {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}
.field-input {
    width: 100%;
    min-height: 32px;
    padding: 0.35rem 2.5rem 0.35rem 0.7rem;
    background: var(--input-rest);
    border: 1px solid #cdd1d6;
    border-radius: 4px;
    resize: none;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 1rem;  /* >=16px to prevent iOS Safari focus auto-zoom */
    line-height: 1.4;
    transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
    resize: vertical;
}
textarea.field-input {
    min-height: 4.5rem;
    line-height: 1.5;
    resize: vertical;
}
.field-input::placeholder { color: var(--text-mute); }
.field-input:hover { background: var(--bg-elev); }
.field-input:focus {
    outline: none;
    background: var(--bg-raised);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.field-check {
    position: absolute;
    right: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    color: var(--sage);
    opacity: 0;
    pointer-events: none;
}
.field-hint {
    margin-top: var(--space-1);
    font-size: 0.8125rem;
    color: var(--text-mute);
    font-family: var(--font-sans);
    line-height: 1.5;
}
.field-error {
    margin-top: var(--space-1);
    font-size: 0.8125rem;
    color: var(--danger);
    font-family: var(--font-sans);
    line-height: 1.5;
}

/* Saved: sage halo bursts outward and fades; check pops in/out at middle-right */
.field-row.is-saved .field-input-wrap {
    animation: halo-saved 1400ms ease-out;
}
.field-row.is-saved .field-check {
    animation: check-pop 1400ms ease-out forwards;
}
@keyframes halo-saved {
    0%   { box-shadow: 0 0 0 0    color-mix(in srgb, var(--success-fg) 55%, transparent); }
    40%  { box-shadow: 0 0 0 6px  color-mix(in srgb, var(--success-fg) 45%, transparent); }
    100% { box-shadow: 0 0 0 16px color-mix(in srgb, var(--success-fg) 0%, transparent); }
}
@keyframes check-pop {
    0%   { opacity: 0;   transform: translateY(-50%) scale(0.7); }
    20%  { opacity: 0.7; transform: translateY(-50%) scale(1.1); }
    40%  { opacity: 0.7; transform: translateY(-50%) scale(1); }
    100% { opacity: 0;   transform: translateY(-50%) scale(1); }
}

/* Error: terracotta halo bursts and fades; border + tint persist until refocus */
.field-row.is-error .field-input-wrap {
    animation: halo-error 1400ms ease-out;
}
.field-row.is-error .field-input {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger-fg) 8%, transparent);
}
.field-row.is-error .field-input:focus {
    background: var(--bg-raised);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
@keyframes halo-error {
    0%   { box-shadow: 0 0 0 0    color-mix(in srgb, var(--danger-fg) 55%, transparent); }
    40%  { box-shadow: 0 0 0 6px  color-mix(in srgb, var(--danger-fg) 45%, transparent); }
    100% { box-shadow: 0 0 0 16px color-mix(in srgb, var(--danger-fg) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
    .field-row.is-saved .field-input-wrap,
    .field-row.is-error .field-input-wrap { animation: none; }
    .field-row.is-saved .field-check { animation: none; opacity: 0; }
}

/* ---------- Two-column profile layout: actions sidebar + main ---------- */
.profile-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: var(--space-4);
    align-items: start;
    margin-top: var(--space-2);
}
.profile-sidebar { position: sticky; top: var(--space-3); }
.profile-sidebar .section-heading {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-mute);
    margin-top: var(--space-3);
    margin-bottom: var(--space-1);
    padding-bottom: 0;
    border-bottom: none;
}
.profile-sidebar .section-heading:first-child { margin-top: 0; }
.profile-main { min-width: 0; max-width: 768px; }

/* Data tables need more horizontal room than profile forms.
   When the main contains a .users-table, allow it the full available width. */
.profile-main:has(.users-table) { max-width: none; }

.profile-actions a {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 0.9rem;
    transition: background 0.12s ease, color 0.12s ease;
}
.profile-actions a:hover {
    background: var(--bg-elev);
    color: var(--text);
    border-bottom: none;
}
.profile-actions a.is-current {
    background: var(--bg-elev);
    color: var(--text);
    font-weight: 500;
}

/* GitHub Settings-style sidebar nav */
.profile-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0;
    padding: 0;
}
.profile-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 12px;
    border-left: 3px solid transparent;
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    line-height: 1.4;
    border-radius: 4px;
    transition: background 0.12s ease, border-color 0.12s ease;
    position: relative;
}
.profile-nav-item:hover {
    background: var(--bg-elev);
    text-decoration: none;
    color: var(--text);
}
.profile-nav-item.is-current {
    background: var(--bg-elev);
    font-weight: 600;
}
.profile-nav-item.is-current::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: var(--accent-fg);
    border-radius: 2px;
}
.profile-nav-count {
    margin-left: auto;
    color: var(--text-mute);
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

/* Profile page identity strip (Wikipedia-style infobox top) */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
}
.profile-header-avatar {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent-fg);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1;
}
.profile-header-text {
    flex: 1;
    min-width: 0;
}
.profile-header-name {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text);
    margin: 0;
}
.profile-header-subtext {
    font-size: 0.875rem;
    color: var(--text-mute);
    margin: 4px 0 0 0;
}
.profile-header-role {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 2px 8px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    vertical-align: middle;
    border: 1px solid var(--border);
    color: var(--text-mute);
    background: var(--bg-canvas);
}
.profile-header-role-admin {
    color: var(--accent-fg);
    border-color: var(--accent-fg);
}
.profile-header-role-agent {
    color: var(--warning-fg);
    border-color: var(--warning-fg);
}

/* Profile section dividers + heading restyle (scoped to .profile-section) */
.profile-section {
    padding-top: var(--space-3);
    margin-top: var(--space-3);
    border-top: 1px solid var(--border);
}
.profile-section:first-of-type {
    padding-top: 0;
    margin-top: 0;
    border-top: none;
}
.profile-section .section-heading {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-top: 0;
    margin-bottom: var(--space-2);
    padding-bottom: 0;
    border-bottom: none;
}

@media (max-width: 767px) {
    .profile-layout { grid-template-columns: 1fr; gap: var(--space-2); }
    .profile-sidebar { position: static; }
}

/* Profile page only: drop .container max-width so sidebar reaches viewport edge */
main.container:has(.profile-layout) { max-width: none; }
.profile-layout { grid-template-columns: 220px minmax(0, 1fr); }


/* Staff elevation badge in the nav */
.nav-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    margin-right: 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    border-radius: 999px;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.nav-badge-admin {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.nav-badge-agent {
    background: color-mix(in srgb, var(--accent-alt) 12%, transparent);
    color: var(--accent-alt);
    border-color: color-mix(in srgb, var(--accent-alt) 30%, transparent);
}


/* TODO 1.7.5 step 11: this /users page section uses GitHub-Primer-dark
 * hardcoded hex colors (#e6edf3, #8b949e, #c9d1d9, #21262d, #161b22, the
 * role/status badge palette, #7A5418) intentionally as a one-off. Restyle
 * this block as part of the per-page design pass; hardcodes stay till then. */
/* ── Users page ─────────────────────────────────────────────────────────── */

.users-page {
  max-width: 1100px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.users-header {
  margin-bottom: 2rem;
}

.users-title {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: #e6edf3;
  margin: 0 0 0.35rem;
}

.users-subtitle {
  font-size: 0.85rem;
  color: #8b949e;
  margin: 0;
}

.users-table-wrap {
  overflow-x: auto;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  border: 1px solid #cdd1d6;
  border-radius: 4px;
  overflow: hidden;
}

.users-table th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.users-table td {
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}

.users-table tbody tr:last-child td {
  border-bottom: none;
}

.users-table tbody tr:hover td {
  background: var(--bg-subtle);
}

.users-mono {
  font-family: var(--font-mono);
  font-size: 0.825rem;
}

.users-ts {
  color: var(--text-secondary);
  font-size: 0.825rem;
  white-space: nowrap;
}

/* ─── Empty state, table action row, row action cluster (1.7.7.15) ── */
.empty-state {
  margin-top: var(--space-4);
  color: var(--text-secondary);
}

.table-action-row {
  margin-bottom: var(--space-4);
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.table-row-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

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

.users-empty {
  color: #8b949e;
  font-size: 0.9rem;
  padding: 2rem 0;
}

/* ---------- Components (mini-step A) ----------
 *
 * Reusable primitives consumed by the diagnostic dashboard (steps 8-10) and
 * any future page. Mini-step B adds toast / infobox / breadcrumbs / nav.
 * ------------------------------------------------------ */

/* Octicon base — fill follows currentColor so wrapper text-color rules recolor it. */
.octicon {
    display: inline-block;
    vertical-align: text-bottom;
    fill: currentColor;
    overflow: visible;
}

/* Card — used standalone and inside .card-grid. Status-tinted left accent. */
.card {
    background: var(--bg-subtle);
    border: 1px solid var(--border-default);
    border-left: 3px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
/* Status-tinted left accent. Idle keeps the default --border-default. */
.card.is-success { border-left-color: var(--success-fg); }
.card.is-danger  { border-left-color: var(--danger-fg); }
.card.is-warning { border-left-color: var(--warning-fg); }
.card.is-running { border-left-color: var(--accent-fg); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.card-title {
    margin: 0;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}
.card-body {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}
.card-body-mono {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    word-break: break-word;
}
.card-body-mono.is-danger { color: var(--danger-fg); }
.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}
.icon-text {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

/* Card grid — auto-fill density; cards naturally size to content. */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-3);
}

/* Status pill — small color-coded badge with optional icon. */
/* KPI card — extends .card with metric emphasis (big number, label,
   description). Used as a clickable <a class="card kpi-card"> on the
   /users overview page; the state modifiers color the value and add a
   left-border accent. */
.kpi-card {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.12s ease;
}
.kpi-card:hover {
    border-color: var(--accent);
}
.kpi-card-label {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-mute);
}
.kpi-card-value {
    font-family: var(--font-sans);
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.2;
    margin-top: var(--space-1);
    color: var(--text);
}
.kpi-card-meta {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-mute);
    margin-top: var(--space-2);
}
.kpi-card-warning { border-left: 3px solid var(--warning); }
.kpi-card-warning .kpi-card-value { color: var(--warning); }
.kpi-card-success { border-left: 3px solid var(--sage); }
.kpi-card-success .kpi-card-value { color: var(--sage); }
.kpi-card-danger { border-left: 3px solid var(--danger); }
.kpi-card-danger .kpi-card-value { color: var(--danger); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.4;
    min-height: auto;
}
.status-pill-success {
    background: color-mix(in srgb, var(--success-fg) 12%, transparent);
    color: var(--success-fg);
    border: 1px solid color-mix(in srgb, var(--success-fg) 30%, transparent);
}
.status-pill-danger {
    background: color-mix(in srgb, var(--danger-fg) 12%, transparent);
    color: var(--danger-fg);
    border: 1px solid color-mix(in srgb, var(--danger-fg) 30%, transparent);
}
.status-pill-warning {
    background: color-mix(in srgb, var(--warning-fg) 12%, transparent);
    color: var(--warning-fg);
    border: 1px solid color-mix(in srgb, var(--warning-fg) 30%, transparent);
}
.status-pill-idle {
    background: var(--bg-emphasis);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}
.status-pill-running {
    background: color-mix(in srgb, var(--accent-fg) 12%, transparent);
    color: var(--accent-fg);
    border: 1px solid color-mix(in srgb, var(--accent-fg) 30%, transparent);
}

/* Footnotes — Wikipedia-style source/provenance block. */
.footnotes {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-muted);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}
.footnotes ol { padding-left: var(--space-4); margin: 0; }
.footnotes li { margin: var(--space-1) 0; }
.footnote-marker {
    vertical-align: super;
    font-size: var(--font-size-xs);
    color: var(--accent-fg);
    text-decoration: none;
}

/* Collapsible — native <details>/<summary>, no JS. Add class="collapsible". */
.collapsible > summary {
    cursor: pointer;
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) 0;
    color: var(--accent-fg);
    font-size: var(--font-size-sm);
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary .octicon {
    transition: transform 0.15s ease;
}
.collapsible[open] > summary .octicon {
    transform: rotate(180deg);
}
.collapsible > summary:hover { text-decoration: underline; }
.collapsible-body {
    margin-top: var(--space-2);
    padding-left: var(--space-3);
    border-left: 2px solid var(--border-muted);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

/* Icon-only nav link (inbox bell; future top bar icons) */
.nav-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: background 0.12s ease;
}
.nav-icon-link:hover {
    background: var(--bg-elev);
    text-decoration: none;
}

/* .section-heading on anchor elements — used for clickable section headers
   like the Overview link in /admin sidebar. */
a.section-heading {
    display: block;
    text-decoration: none;
    border-radius: 4px;
    position: relative;
}
a.section-heading:hover {
    background: var(--bg-elev);
    color: var(--text);
    text-decoration: none;
}
a.section-heading.is-current {
    background: var(--bg-elev);
    color: var(--accent-fg);
}
a.section-heading.is-current::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: var(--accent-fg);
    border-radius: 2px;
}

/* Tighter section-heading rhythm when stacked inside a sidebar nav */
.profile-nav .section-heading {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
    border-left: 3px solid transparent;
}
.profile-nav .section-heading:first-child {
    padding-top: 0;
}



/* Each contact card (primary email + recovery channels) gets its own
   bordered group for clear visual separation on /profile. */
#email-card.field-row,
#contacts-area > .field-row {
    border: 1px solid #cdd1d6;
    border-radius: 4px;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
}


/* Label row that floats a status pill to the right of the field label. */
.field-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-2);
}
/* Tighten hint text up against the input/value above it. */
.field-hint {
    margin: 0;
    line-height: 1.4;
}


/* Bordered group container for the Identity fields. */
.field-list.field-list-bordered {
    border: 1px solid #cdd1d6;
    border-radius: 4px;
    padding: var(--space-1) var(--space-3);
}
/* Sections that should sit flush against the section above
   (no top margin, no top border, no top padding). */
.profile-section.profile-section-tight {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

/* Defensive: pin Handle and Display Name as non-resizable, regardless
   of element type or any inherited textarea rules. */
#field-handle,
#field-display_name {
    resize: none !important;
}

/* ─── Telegram verified-state inline row (Phase 1.7.7.14) ─────────── */
.telegram-confirm-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.telegram-confirm-row .field-help {
  margin: 0;
  flex: 0 0 auto;
}
.telegram-confirm-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
}

/* ─── Send invitation page polish (Phase 1.7.7.17) ────────────────── */
.invite-form-single .field-input-wrap {
  max-width: 24rem;
}

.invalid-emails-list {
  margin: var(--space-1) 0 0;
  padding-left: var(--space-5);
}
.invalid-emails-list li {
  margin-top: var(--space-1);
}
.invalid-emails-list code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ─── Send invitation page — bordered card + tightening (1.7.7.17.1) ─ */
.form-card {
  border: 1px solid #cdd1d6;
  border-radius: 4px;
  padding: var(--space-2) var(--space-3);
}

/* Hint sitting directly above an input/textarea — collapse the gap. */
.field-hint-tight {
  margin: 0 0 var(--space-1) 0;
}

/* Vertical breathing room below the Send / Send all buttons. */
.invite-form .btn {
  margin-top: var(--space-2);
}

/* ─── Send invitation — tighten heading-to-card gap (1.7.7.17.2) ──── */
/* When a section-heading directly precedes an .form-card, treat the
   heading as a label for the card rather than a divider above it:
   strip the heading's border + bottom space and pull the card tight. */
.section-heading:has(+ .form-card),
.profile-main .section-heading:has(+ .form-card) {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.section-heading + .form-card {
  margin-top: var(--space-1);
}

/* When a tight section follows another form-card section, keep the
   no-divider visual grouping but restore vertical breathing room. */
.profile-section:has(.form-card) + .profile-section-tight {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
}

/* Suppress the resize handle on single-line text/email inputs.
   Textareas keep their vertical resize (set elsewhere via .field-input
   on textarea). */
.form-card input.field-input {
  resize: none;
}

/* ─── Change password page polish (Phase 1.7.7.19) ────────────────── */
/* Form-level action row: primary submit + secondary link/button.
   Replaces the undefined .auth-actions class used on auth pages.
   Sits below the form sections with breathing room. */
.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

/* When .form-card wraps multiple .field-row children (as on the
   change-password new-password card), give them vertical separation
   without altering single-row form-card behavior. */
.form-card > .field-row + .field-row {
  margin-top: var(--space-2);
}

/* Profile section as a bordered card — GitHub Box pattern.
   Header strip on --bg-subtle, content padded below. Applied per-section
   via the modifier class; propagate after visual sign-off.
   (sentinel: profile_section_card_v1) */
.profile-section.profile-section-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    overflow: hidden;  /* clip the header strip to the radius */
}
.profile-section.profile-section-card:first-of-type {
    border: 1px solid var(--border);  /* restore — base :first-of-type strips border-top */
}
.profile-section.profile-section-card .section-heading {
    margin: 0;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
}
.profile-section.profile-section-card .field-list {
    padding: var(--space-2) var(--space-3);
    margin-bottom: 0;
}
/* An inner bordered list would double-border inside a card — flatten it. */
.profile-section.profile-section-card .field-list.field-list-bordered {
    border: none;
    border-radius: 0;
}
/* Non-field-list card content (dl, p, contact cards) gets the same inset.
   (sentinel: profile_section_card_v2) */
.profile-section.profile-section-card > :not(.section-heading):not(.field-list) {
    margin-left: var(--space-3);
    margin-right: var(--space-3);
}
.profile-section.profile-section-card > :last-child:not(.section-heading) {
    margin-bottom: var(--space-3);
}

