/* ============================================================
   moonshot.css — Japifon Design System
   ============================================================ */

/* ── 1. Reset ────────────────────────────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
}
* {
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: var(--font-size);
    line-height: var(--leading);
    color: var(--text);
    background: var(--bg-content);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}
input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}
button {
    cursor: pointer;
}
p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}
a {
    color: inherit;
    text-decoration: none;
}
ul,
ol {
    list-style: none;
}
table {
    border-collapse: collapse;
    width: 100%;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
:focus:not(:focus-visible) {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── 2. Design Tokens ────────────────────────────────────── */

:root {
    --font-sans: "Inter", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
    --font-size: 16px;
    --leading: 1.5;

    --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;
    --sp-16: 64px;

    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 9px;
    --radius-full: 999px;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --duration: 150ms;

    --z-dropdown: 10;
    --z-sticky: 40;
    --z-overlay: 50;
    --z-sidebar: 100;
    --z-modal: 200;
    --z-toast: 9999;

    /* Accent */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-muted: rgba(79, 70, 229, 0.12);
    --accent-border: rgba(79, 70, 229, 0.4);

    /* Semantic */
    --error: #ef4444;
    --error-hover: #dc2626;
    --error-bg: rgba(239, 68, 68, 0.08);
    --error-border: rgba(239, 68, 68, 0.35);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.08);
    --success-border: rgba(34, 197, 94, 0.3);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.08);
    --warning-border: rgba(245, 158, 11, 0.3);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.08);
    --info-border: rgba(59, 130, 246, 0.3);

    /* Role badge palette — base groups */
    --role-superadmin: #f5c542;
    --role-superadmin-bg: rgba(245, 197, 66, 0.12);
    --role-superadmin-border: rgba(245, 197, 66, 0.3);
    --role-admin: #60a5fa;
    --role-admin-bg: rgba(96, 165, 250, 0.12);
    --role-admin-border: rgba(96, 165, 250, 0.3);
    --role-finance: #34d399;
    --role-finance-bg: rgba(52, 211, 153, 0.12);
    --role-finance-border: rgba(52, 211, 153, 0.3);
    --role-staff: #a78bfa;
    --role-staff-bg: rgba(167, 139, 250, 0.12);
    --role-staff-border: rgba(167, 139, 250, 0.3);
    --role-support: #fb923c;
    --role-support-bg: rgba(251, 146, 60, 0.12);
    --role-support-border: rgba(251, 146, 60, 0.3);
    --role-compliance: #94a3b8;
    --role-compliance-bg: rgba(148, 163, 184, 0.12);
    --role-compliance-border: rgba(148, 163, 184, 0.3);
    --role-account-manager: #fbbf24;
    --role-account-manager-bg: rgba(251, 191, 36, 0.12);
    --role-account-manager-border: rgba(251, 191, 36, 0.3);
    --role-viewer: #64748b;
    --role-viewer-bg: rgba(100, 116, 139, 0.12);
    --role-viewer-border: rgba(100, 116, 139, 0.3);

    /* Role aliases (same colors) */
    --role-owner: var(--role-superadmin);
    --role-owner-bg: var(--role-superadmin-bg);
    --role-owner-border: var(--role-superadmin-border);
    --role-developer: var(--role-staff);
    --role-developer-bg: var(--role-staff-bg);
    --role-developer-border: var(--role-staff-border);
    --role-billing: var(--role-support);
    --role-billing-bg: var(--role-support-bg);
    --role-billing-border: var(--role-support-border);
    --role-operations: var(--role-support);
    --role-operations-bg: var(--role-support-bg);
    --role-operations-border: var(--role-support-border);
    --role-user: var(--role-viewer);
    --role-user-bg: var(--role-viewer-bg);
    --role-user-border: var(--role-viewer-border);
}

/* ── Dark theme (default) ── */

:root,
html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f1117;
    --bg-content: #0f1117;
    --surface: #1a1d27;
    --surface-2: #1e2231;
    --surface-hover: rgba(255, 255, 255, 0.06);
    --text: #e1e4ea;
    --text-muted: #878d9c;
    --text-subtle: #7f8695;
    --border: #2a2e3a;
    --border-strong: #3a3f4d;

    --nav-text: #c2c7d0;
    --nav-text-hover: #a5b4fc;
    --nav-hover-bg: rgba(165, 180, 252, 0.12);
    --nav-active-text: #a5b4fc;
    --nav-active-bg: rgba(165, 180, 252, 0.12);
    --seg-active-bg: rgba(165, 180, 252, 0.15);
    --seg-active-text: #a5b4fc;
    --seg-hover-bg: rgba(165, 180, 252, 0.15);
    --seg-hover-text: #a5b4fc;

    --input-bg: #1a1d27;
    --input-border: #2a2e3a;
    --input-focus-border: var(--accent);
    --input-placeholder: #565b6b;
}

/* ── Light theme ── */

html[data-theme="light"] {
    color-scheme: light;

    --bg: #ffffff;
    --bg-content: #f8f9fb;
    --surface: #ffffff;
    --surface-2: #f5f6f8;
    --surface-hover: rgba(0, 0, 0, 0.04);
    --text: #1a1d27;
    --text-muted: #6b7080;
    --text-subtle: #9ca3af;
    --border: #dfe1e6;
    --border-strong: #c4c8d0;

    --accent: #4338ca;
    --accent-hover: #3730a3;
    --accent-muted: rgba(67, 56, 202, 0.1);
    --accent-border: rgba(67, 56, 202, 0.35);

    --nav-text: #4b5563;
    --nav-text-hover: var(--accent);
    --nav-hover-bg: var(--accent-muted);
    --nav-active-text: var(--accent);
    --nav-active-bg: var(--accent-muted);
    --seg-active-bg: var(--accent-muted);
    --seg-active-text: var(--accent);
    --seg-hover-bg: var(--accent-muted);
    --seg-hover-text: var(--accent);

    --error: #dc2626;
    --error-hover: #b91c1c;
    --error-bg: rgba(220, 38, 38, 0.06);
    --error-border: rgba(220, 38, 38, 0.25);
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.06);
    --success-border: rgba(22, 163, 74, 0.25);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.06);
    --warning-border: rgba(217, 119, 6, 0.25);
    --info: #2563eb;
    --info-bg: rgba(37, 99, 235, 0.06);
    --info-border: rgba(37, 99, 235, 0.25);

    /* Role base groups — stronger for light */
    --role-superadmin: #b45309;
    --role-superadmin-bg: rgba(180, 83, 9, 0.08);
    --role-superadmin-border: rgba(180, 83, 9, 0.25);
    --role-admin: #2563eb;
    --role-admin-bg: rgba(37, 99, 235, 0.08);
    --role-admin-border: rgba(37, 99, 235, 0.25);
    --role-finance: #059669;
    --role-finance-bg: rgba(5, 150, 105, 0.08);
    --role-finance-border: rgba(5, 150, 105, 0.25);
    --role-staff: #7c3aed;
    --role-staff-bg: rgba(124, 58, 237, 0.08);
    --role-staff-border: rgba(124, 58, 237, 0.25);
    --role-support: #ea580c;
    --role-support-bg: rgba(234, 88, 12, 0.08);
    --role-support-border: rgba(234, 88, 12, 0.25);
    --role-compliance: #475569;
    --role-compliance-bg: rgba(71, 85, 105, 0.08);
    --role-compliance-border: rgba(71, 85, 105, 0.25);
    --role-account-manager: #b45309;
    --role-account-manager-bg: rgba(180, 83, 9, 0.08);
    --role-account-manager-border: rgba(180, 83, 9, 0.25);
    --role-viewer: #475569;
    --role-viewer-bg: rgba(71, 85, 105, 0.08);
    --role-viewer-border: rgba(71, 85, 105, 0.25);

    --input-bg: #ffffff;
    --input-border: #dfe1e6;
    --input-focus-border: var(--accent);
    --input-placeholder: #9ca3af;
}

/* Auto-detect (no cookie set) */
@media (prefers-color-scheme: light) {
    html:not([data-theme]) {
        color-scheme: light;
        --bg: #ffffff;
        --bg-content: #f8f9fb;
        --surface: #ffffff;
        --surface-2: #f5f6f8;
        --surface-hover: rgba(0, 0, 0, 0.04);
        --text: #1a1d27;
        --text-muted: #6b7080;
        --text-subtle: #9ca3af;
        --border: #dfe1e6;
        --border-strong: #c4c8d0;
        --accent: #4338ca;
        --accent-hover: #3730a3;
        --accent-muted: rgba(67, 56, 202, 0.1);
        --accent-border: rgba(67, 56, 202, 0.35);
        --nav-text: #4b5563;
        --nav-text-hover: var(--accent);
        --nav-hover-bg: var(--accent-muted);
        --nav-active-text: var(--accent);
        --nav-active-bg: var(--accent-muted);
        --seg-active-bg: var(--accent-muted);
        --seg-active-text: var(--accent);
        --seg-hover-bg: var(--accent-muted);
        --seg-hover-text: var(--accent);
        --error: #dc2626;
        --error-hover: #b91c1c;
        --error-bg: rgba(220, 38, 38, 0.06);
        --error-border: rgba(220, 38, 38, 0.25);
        --success: #16a34a;
        --success-bg: rgba(22, 163, 74, 0.06);
        --success-border: rgba(22, 163, 74, 0.25);
        --warning: #d97706;
        --warning-bg: rgba(217, 119, 6, 0.06);
        --warning-border: rgba(217, 119, 6, 0.25);
        --info: #2563eb;
        --info-bg: rgba(37, 99, 235, 0.06);
        --info-border: rgba(37, 99, 235, 0.25);
        --input-bg: #ffffff;
        --input-border: #dfe1e6;
        --input-focus-border: var(--accent);
        --input-placeholder: #9ca3af;
    }
}


/* ── 3. Layout ─────────────────────────────────────────────── */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    width: 300px;
    min-width: 300px;
    height: 100vh;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: var(--z-sidebar);
}

.app-shell > main {
    flex: 1;
    min-width: 0;
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--sp-8);
    overflow-x: hidden;
}

.mobile-header,
.nav-overlay {
    display: none;
}

/* QA-5: at 768-1024px the desktop sidebar was hidden but the mobile
   hamburger only appeared below 768px, leaving tablets without any
   way to navigate. Lift the mobile shell breakpoint to 1024px so the
   hamburger covers the entire range where the sidebar is collapsed. */
@media (max-width: 1024px) {
    .app-shell {
        flex-direction: column;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--sp-3) var(--sp-4);
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: var(--z-sticky);
    }

    .mobile-header__toggle {
        display: flex;
        align-items: center;
        cursor: pointer;
        color: var(--text-muted);
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        min-width: 0;
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--duration) var(--ease),
                    visibility 0s linear var(--duration);
    }

    html, body { overflow-x: hidden; }

    .sidebar.nav--open {
        transform: translateX(0);
        visibility: visible;
        transition: transform var(--duration) var(--ease),
                    visibility 0s linear 0s;
    }

    .nav-overlay--visible {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-sidebar) - 1);
    }

    .app-shell > main {
        padding: var(--sp-4);
        width: 100%;
        max-width: 100%;
    }
    .page-header {
        padding: 0 var(--sp-3);
    }
    .access-panel,
    .profile-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* ── 4. Navigation ─────────────────────────────────────────── */

.nav {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: var(--sp-4) 0;
}
.nav__close {
    display: none;
}

.nav__brand {
    display: flex;
    justify-content: center;
    padding: 0 var(--sp-5) var(--sp-5);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--sp-4);
}

.nav__menu {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--sp-3);
}

.nav__section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-subtle);
    padding: var(--sp-5) var(--sp-3) var(--sp-2);
}

.nav__link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--nav-text);
    transition:
        background var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.nav__link:hover {
    background: var(--nav-hover-bg);
    color: var(--nav-text-hover);
}
.nav__link--active {
    background: var(--nav-active-bg);
    color: var(--nav-active-text);
    font-weight: 600;
}

.nav__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}
.nav__link:hover .nav__icon,
.nav__link--active .nav__icon {
    opacity: 1;
}
.nav__link--active .nav__icon {
    color: var(--accent);
}

.nav__footer {
    padding: var(--sp-4) var(--sp-4) 0;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.nav__segmented {
    display: flex;
    gap: 2px;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 2px;
}

.nav__seg-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-1);
    padding: var(--sp-1) var(--sp-2);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    transition:
        background var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.nav__seg-btn:hover {
    background: var(--seg-hover-bg);
    color: var(--seg-hover-text);
}
.nav__seg-btn--active {
    background: var(--seg-active-bg);
    color: var(--seg-active-text);
    font-weight: 600;
}
.nav__seg-flag {
    font-size: 14px;
    line-height: 1;
}
.nav__seg-code {
    font-size: 11px;
    letter-spacing: 0.04em;
}
.nav__seg-icon {
    width: 16px;
    height: 16px;
}

.nav__logout {
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
    transition:
        background var(--duration) var(--ease),
        color var(--duration) var(--ease),
        border-color var(--duration) var(--ease);
}

.nav__logout:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
}

/* Logo theme toggle */
html[data-theme="dark"] .logo-light,
html:not([data-theme]) .logo-light {
    display: none;
}
html[data-theme="dark"] .logo-dark,
html:not([data-theme]) .logo-dark {
    display: inline;
}
html[data-theme="light"] .logo-light {
    display: inline;
}
html[data-theme="light"] .logo-dark {
    display: none;
}

@media (prefers-color-scheme: light) {
    html:not([data-theme]) .logo-light {
        display: inline;
    }
    html:not([data-theme]) .logo-dark {
        display: none;
    }
}

/* ── 5. Base Elements ──────────────────────────────────────── */

h1 {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}
h2 {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
}
h3 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}
h4 {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
}
small {
    font-size: 12px;
    color: var(--text-muted);
}

article {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
}
article header {
    margin: calc(var(--sp-5) * -1) calc(var(--sp-5) * -1) var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.dash-kpi article strong {
    font-size: 22px;
    font-weight: 700;
}

th,
td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
}
th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    text-align: left;
}
td {
    font-size: 14px;
}
tbody tr:last-child td {
    border-bottom: none;
}
tbody tr:hover {
    background: var(--surface-hover);
}

@media (max-width: 768px) {
    table.responsive thead {
        display: none;
    }
    table.responsive tbody tr {
        display: flex;
        flex-direction: column;
        padding: var(--sp-3) var(--sp-4);
        border-bottom: 1px solid var(--border);
    }
    table.responsive tbody tr:last-child {
        border-bottom: none;
    }
    table.responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--sp-1) 0;
        border-bottom: none;
        font-size: 13px;
    }
    table.responsive td:before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        flex-shrink: 0;
        margin-right: var(--sp-3);
    }
    table.responsive td:first-child a {
        font-weight: 600;
        color: var(--accent);
        padding: var(--sp-1) 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    table.responsive td:last-child {
        justify-content: flex-end;
        gap: var(--sp-2);
        margin-top: var(--sp-2);
        flex-wrap: wrap;
    }
}

/* Controls (shared sizing) */
button,
[role="button"],
input,
select,
textarea {
    padding: var(--sp-2) var(--sp-3);
    font-size: 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    transition:
        background var(--duration) var(--ease),
        border-color var(--duration) var(--ease);
}

button,
[role="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    font-weight: 500;
    background: var(--accent);
    color: #fff;
}

button:hover,
[role="button"]:hover {
    background: var(--accent-hover);
}
button.sm,
[role="button"].sm {
    padding: var(--sp-1) var(--sp-3);
    font-size: 13px;
}
button.xs,
[role="button"].xs {
    padding: var(--sp-1) var(--sp-3);
    font-size: 13px;
    min-height: 32px;
}

button.outline,
button.secondary,
[role="button"].outline {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
}

button.outline:hover,
button.secondary:hover,
[role="button"].outline:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text);
}

button.danger {
    background: var(--error);
}
button.danger:hover {
    background: var(--error-hover);
}

input,
select,
textarea {
    width: 100%;
    background: var(--input-bg);
    border-color: var(--input-border);
}
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23878d9c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--sp-3) center;
    padding-right: var(--sp-8);
}
input:focus,
select:focus,
textarea:focus {
    border-color: var(--input-focus-border);
    outline: none;
}
input::placeholder,
textarea::placeholder {
    color: var(--input-placeholder);
}
label {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: var(--sp-3);
}
label > span {
    line-height: 1.3;
}
.grid label {
    margin-bottom: 0;
}
label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    margin-bottom: var(--sp-2);
}

.text--success {
    color: var(--success);
}
.text--danger {
    color: var(--error);
}
.text--warning {
    color: var(--warning);
}

code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--surface-2);
    padding: 2px var(--sp-2);
    border-radius: var(--radius-sm);
}

hgroup {
    margin-bottom: var(--sp-1);
}
hgroup p {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: var(--sp-1);
}

.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: var(--sp-4);
}
.alert--error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
}

/* ── 6. Components ─────────────────────────────────────────── */

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-6);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--sp-2);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge--active {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}
.badge--inactive,
.badge--muted {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.badge--xs {
    font-size: 10px;
    padding: 1px var(--sp-1);
}
.badge--accent {
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid transparent;
}

/* Platform role badges */
.platform-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--sp-2);
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.platform-badge--superadmin {
    background: var(--role-superadmin-bg);
    color: var(--role-superadmin);
    border-color: var(--role-superadmin-border);
}
.platform-badge--admin {
    background: var(--role-admin-bg);
    color: var(--role-admin);
    border-color: var(--role-admin-border);
}
.platform-badge--staff {
    background: var(--role-staff-bg);
    color: var(--role-staff);
    border-color: var(--role-staff-border);
}
.platform-badge--finance {
    background: var(--role-finance-bg);
    color: var(--role-finance);
    border-color: var(--role-finance-border);
}
.platform-badge--support {
    background: var(--role-support-bg);
    color: var(--role-support);
    border-color: var(--role-support-border);
}
.platform-badge--compliance {
    background: var(--role-compliance-bg);
    color: var(--role-compliance);
    border-color: var(--role-compliance-border);
}
.platform-badge--account-manager {
    background: var(--role-account-manager-bg);
    color: var(--role-account-manager);
    border-color: var(--role-account-manager-border);
}
.platform-badge--viewer {
    background: var(--role-viewer-bg);
    color: var(--role-viewer);
    border-color: var(--role-viewer-border);
}
.platform-badge--owner {
    background: var(--role-owner-bg);
    color: var(--role-owner);
    border-color: var(--role-owner-border);
}
.platform-badge--developer {
    background: var(--role-developer-bg);
    color: var(--role-developer);
    border-color: var(--role-developer-border);
}
.platform-badge--billing {
    background: var(--role-billing-bg);
    color: var(--role-billing);
    border-color: var(--role-billing-border);
}
.platform-badge--operations {
    background: var(--role-operations-bg);
    color: var(--role-operations);
    border-color: var(--role-operations-border);
}
.platform-badge--user {
    background: var(--role-user-bg);
    color: var(--role-user);
    border-color: var(--role-user-border);
}

/* Profile card */
.profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--sp-5);
    overflow: hidden;
}

.profile-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.profile-card__title {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}
.profile-card__title h1 {
    font-size: 20px;
}

.profile-card__details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    padding: 0;
    gap: 1px;
    background: var(--border);
}

.profile-card__field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    font-size: 14px;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
}
.profile-card__label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Table container */
.access-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin: var(--sp-5) 0;
    overflow: hidden;
}

.access-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
}

.access-panel__subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: var(--sp-1);
}
.access-panel__empty {
    padding: var(--sp-8) var(--sp-5);
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
}
.access-panel__assign-form {
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.access-panel__assign-form form {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.access-panel__assign-form select,
.access-panel__assign-form input,
.access-panel__assign-form button {
    margin-bottom: 0;
    height: 36px;
    padding: 0 var(--sp-3);
}
.access-panel__assign-form input {
    flex: 1;
    min-width: 0;
}
.access-panel__assign-form select {
    width: auto;
    min-width: 140px;
    padding-right: var(--sp-8);
}
.access-panel__assign-form button {
    width: auto;
    flex: none;
    white-space: nowrap;
}
.access-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.access-row:last-child {
    border-bottom: none;
}
.access-row__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}
.access-row__avatar--inherited {
    background: var(--surface-2);
    color: var(--text-muted);
}
.access-row__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.access-row__name {
    font-weight: 500;
    font-size: 13px;
}
.access-row__email {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}
.access-row__origin {
    font-size: 11px;
    color: var(--text-muted);
}
.access-row__revoke {
    background: none;
    border: none;
    padding: var(--sp-1) var(--sp-2);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 12px;
    line-height: 1;
}
.access-row__revoke:hover {
    background: var(--error-bg);
    color: var(--error);
}
.access-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: var(--radius);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}
.access-badge--inherited {
    opacity: 0.55;
}
.access-badge--owner {
    background: var(--role-owner-bg);
    color: var(--role-owner);
    border-color: var(--role-owner-border);
}
.access-badge--admin {
    background: var(--role-admin-bg);
    color: var(--role-admin);
    border-color: var(--role-admin-border);
}
.access-badge--finance {
    background: var(--role-finance-bg);
    color: var(--role-finance);
    border-color: var(--role-finance-border);
}
.access-badge--billing {
    background: var(--role-billing-bg);
    color: var(--role-billing);
    border-color: var(--role-billing-border);
}
.access-badge--developer {
    background: var(--role-developer-bg);
    color: var(--role-developer);
    border-color: var(--role-developer-border);
}
.access-badge--operations {
    background: var(--role-operations-bg);
    color: var(--role-operations);
    border-color: var(--role-operations-border);
}
.access-badge--compliance {
    background: var(--role-compliance-bg);
    color: var(--role-compliance);
    border-color: var(--role-compliance-border);
}
.access-badge--account_manager {
    background: var(--role-account-manager-bg);
    color: var(--role-account-manager);
    border-color: var(--role-account-manager-border);
}
.access-badge--viewer {
    background: var(--role-viewer-bg);
    color: var(--role-viewer);
    border-color: var(--role-viewer-border);
}

@media (max-width: 768px) {
    .access-panel__assign-form,
    .access-panel__assign-form form {
        flex-direction: column;
        align-items: stretch;
    }
    .access-row {
        flex-wrap: wrap;
    }
}

/* Channels / Services panel */
.channels-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-top: var(--sp-5);
    overflow: hidden;
}
.channels-panel__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.channels-panel__title {
    font-weight: 600;
    font-size: 16px;
}
.channels-panel__subtitle {
    font-size: 13px;
    color: var(--text-muted);
}
.channels-panel__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
}
.channel-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-5) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
}
.channel-card--active {
    background: var(--accent-muted);
    border-color: var(--accent);
}
.channel-card--inactive {
    background: var(--error-bg);
}
.channel-card--blocked {
    opacity: 0.4;
}
.channel-card__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text-muted);
}
.channel-card--active .channel-card__icon {
    background: var(--accent-muted);
    color: var(--accent);
}
.channel-card__info {
    text-align: center;
}
.channel-card__name {
    display: block;
    font-weight: 600;
    font-size: 14px;
}
.channel-card__status {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}
.channel-card__status--on {
    color: var(--success);
}
.channel-card__status--off {
    color: var(--text-muted);
}
.channel-card__status--blocked {
    color: var(--error);
}
.channel-card__detail {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}
.channel-card__actions {
    margin-top: var(--sp-1);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.pagination a {
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--radius);
    color: var(--text-muted);
    transition:
        background var(--duration) var(--ease),
        color var(--duration) var(--ease);
}

.pagination a:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.pagination .active {
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.pagination .disabled {
    padding: var(--sp-1) var(--sp-3);
    color: var(--text-subtle);
}
.pagination .info {
    margin-left: auto;
    color: var(--text-muted);
}

/* Danger zone */
.danger-zone {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    margin-top: var(--sp-8);
}

.danger-zone h4 {
    color: var(--error);
}

.danger-zone__action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4);
    margin-top: var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--error-border);
    border-radius: var(--radius);
}

.danger-zone__action p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: var(--sp-1);
}

/* Forms */
.grid {
    display: flex;
    gap: var(--sp-4);
    align-items: start;
}
.grid > * {
    flex: 1;
    min-width: 0;
}

fieldset {
    border: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
fieldset > legend {
    display: flex;
    width: 100%;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding-bottom: var(--sp-2);
    margin-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}
fieldset small {
    display: block;
}
fieldset label {
    margin-bottom: 0;
}

.input-group {
    display: flex;
    align-items: stretch;
}
.input-prefix {
    display: flex;
    align-items: center;
    padding: 0 var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--input-border);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.input-group input {
    border-radius: 0;
}
.input-prefix + input:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}
.input-group > input:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}
.input-suffix {
    display: flex;
    align-items: center;
    padding: 0 var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--input-border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
button[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
button[disabled] .spinner {
    display: inline-block;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Dialog */
dialog {
    border: none;
    background: transparent;
    padding: 0;
    width: min(640px, calc(100vw - var(--sp-8)));
    min-width: min(420px, 100vw);
    border-radius: var(--radius-lg);
    overflow: visible;
    margin: auto;
}
dialog[open] ~ *,
body:has(dialog[open]) {
    overflow: hidden;
}
dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}
dialog > article {
    padding: 0;
    max-height: calc(100vh - var(--sp-16));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
dialog > article header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-shrink: 0;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
}
dialog > article header h3,
dialog > article header h2 {
    font-size: 16px;
}
dialog .dialog-close {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
dialog .dialog-close:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
}

dialog > article > form {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--sp-4) var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
dialog > article > form label {
    margin-bottom: 0;
}
dialog > article > form > button[type="submit"] {
    width: 100%;
    margin-top: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    background: var(--accent);
}
dialog > article > form > button[type="submit"]:hover {
    background: var(--accent-hover);
}

/* ── 7. Dashboard ──────────────────────────────────────────── */

.dash-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-4);
    margin: var(--sp-5) 0;
}

.dash-kpi article {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.dash-kpi small {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.dash-section {
    margin: var(--sp-6) 0;
}

.dash-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-5);
}

.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-bottom: var(--sp-4);
}
.access-panel > .filter-bar {
    margin: 0;
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
}
.filter-bar > select,
.filter-bar > input {
    width: auto;
    min-width: 120px;
    height: 36px;
    margin: 0;
}
.filter-bar > select {
    padding-right: var(--sp-8);
}
.filter-bar__field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
}
.filter-bar__field span {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}
.filter-bar__field input {
    width: auto;
    min-width: 140px;
    height: 36px;
}
.filter-bar > label {
    flex: 1;
    min-width: 140px;
    margin-bottom: 0;
}
.filter-bar button,
.filter-bar [role="button"] {
    height: 36px;
}
.filter-bar__actions {
    display: flex;
    gap: var(--sp-2);
}
.filter-bar > label > select,
.filter-bar > label > input {
    height: 36px;
}
.filter-bar__mobile-toggle {
    display: none;
}

@media (max-width: 768px) {
    .filter-bar {
        flex-direction: column;
    }
    .filter-bar > label,
    .filter-bar > select,
    .filter-bar > input,
    .filter-bar__field,
    .filter-bar__actions {
        width: 100%;
    }
    .filter-bar__mobile-toggle {
        display: flex;
        align-items: center;
        gap: var(--sp-2);
        font-size: 13px;
        font-weight: 500;
        color: var(--accent);
        cursor: pointer;
        margin-bottom: var(--sp-3);
    }
    .filter-bar__mobile-toggle svg {
        width: 16px;
        height: 16px;
        stroke: var(--accent);
    }
}

.dash-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--sp-4);
    margin: var(--sp-5) 0;
}

.dash-charts article {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.dash-charts article > div {
    flex: 1;
    min-height: 0;
}

.dash-activity header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
}

.dash-activity__totals {
    display: flex;
    gap: var(--sp-5);
}
.dash-activity__totals span {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 13px;
}

/* ── 8. Auth Page ─────────────────────────────────────────── */

.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--sp-4);
}
.auth-page main {
    width: 100%;
    max-width: 400px;
}
/* Reset article header: base applies negative margin + bg + border */
.auth-page article header {
    margin: 0 0 var(--sp-5);
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
}

/* Logo theme toggle — already defined in §4 Navigation */

/* Auth preferences (lang/theme toggles) */
.auth-prefs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    margin-top: var(--sp-6);
}
.auth-prefs__group {
    display: inline-flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.auth-prefs__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-1) var(--sp-3);
    font-size: 11px;
    color: var(--text-muted);
    transition:
        background var(--duration) var(--ease),
        color var(--duration) var(--ease);
}
.auth-prefs__btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.auth-prefs__btn--active {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 500;
}
.auth-prefs__icon {
    width: 14px;
    height: 14px;
}
