/* ============================================================
   AACCS Platform — Core CSS
   Light / Dark mode via CSS custom properties + data-theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── DESIGN TOKENS ───────────────────────────────────────── */
:root {
    /* Accent (same in both themes) */
    --accent:        #4F6EF7;
    --accent-light:  #6B87FA;
    --accent-dark:   #3A55D4;
    --accent-glow:   rgba(79, 110, 247, 0.15);
    --cyan:          #22D3EE;
    --green:         #10B981;
    --amber:         #F59E0B;
    --rose:          #F43F5E;
    --purple:        #8B5CF6;

    /* Spacing */
    --radius-sm:  6px;
    --radius:     10px;
    --radius-lg:  14px;
    --radius-xl:  18px;

    /* Typography */
    --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
    --font-mono:  'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

    /* Transitions */
    --transition: 0.18s ease;
}

/* ── DARK THEME (default) ────────────────────────────────── */
[data-theme="dark"] {
    --bg:           #0B0F1A;
    --surface:      #111827;
    --surface-2:    #161D2F;
    --card:         #161D2F;
    --card-hover:   #1C2540;
    --border:       #1E2A40;
    --border-2:     #243048;
    --text:         #E8EDF5;
    --text-muted:   #8A97B0;
    --text-faint:   #3D4D68;
    --input-bg:     #111827;
    --code-bg:      #0D1117;
    --shadow:       0 4px 24px rgba(0,0,0,0.4);
    --shadow-lg:    0 8px 40px rgba(0,0,0,0.6);
    color-scheme: dark;
}

/* ── LIGHT THEME ─────────────────────────────────────────── */
[data-theme="light"] {
    --bg:           #F1F5F9;
    --surface:      #FFFFFF;
    --surface-2:    #F8FAFC;
    --card:         #FFFFFF;
    --card-hover:   #F8FAFC;
    --border:       #E2E8F0;
    --border-2:     #CBD5E1;
    --text:         #0F172A;
    --text-muted:   #64748B;
    --text-faint:   #CBD5E1;
    --input-bg:     #F8FAFC;
    --code-bg:      #F1F5F9;
    --shadow:       0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg:    0 8px 32px rgba(0,0,0,0.12);
    color-scheme: light;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}

a { color: inherit; text-decoration: none; }

/* ── SCROLLBAR ───────────────────────────────────────────── */
::-webkit-scrollbar          { width: 5px; height: 5px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── SHELL LAYOUT ────────────────────────────────────────── */
.shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width var(--transition), transform var(--transition);
    z-index: 200;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 64px;
    min-width: 64px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active { display: block; }

/* Logo */
.sidebar-logo {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.logo-mark {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.logo-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.logo-sub {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 1px;
    white-space: nowrap;
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-section {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 12px 12px 4px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.nav-item:hover {
    background: var(--accent-glow);
    color: var(--text);
}

.nav-item.active {
    background: rgba(79, 110, 247, 0.12);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon svg { width: 16px; height: 16px; }

.nav-label { flex: 1; }

.nav-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.nav-logout {
    color: var(--rose);
    margin-top: 4px;
}

.nav-logout:hover {
    background: rgba(244, 63, 94, 0.08);
    color: var(--rose);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 10px 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: default;
    margin-bottom: 4px;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-info { overflow: hidden; }

.sidebar-user-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 10px;
    color: var(--text-muted);
}

/* Collapsed sidebar */
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .sidebar-user-info {
    display: none;
}

.sidebar.collapsed .sidebar-logo { justify-content: center; }
.sidebar.collapsed .sidebar-user { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-item.active::before { display: none; }

/* ── MAIN ────────────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── TOPBAR ──────────────────────────────────────────────── */
.topbar {
    height: 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow);
    z-index: 100;
}

.topbar-toggle {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
    flex-shrink: 0;
}

.topbar-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.breadcrumb-item { color: var(--text-muted); }
.breadcrumb-item.active { color: var(--text); font-weight: 600; }

/* Topbar right */
.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    height: 36px;
    width: 220px;
    transition: border-color var(--transition), width var(--transition);
}

.topbar-search:focus-within {
    border-color: var(--accent);
    width: 280px;
}

.search-icon { color: var(--text-faint); flex-shrink: 0; }
.search-icon svg { width: 14px; height: 14px; }

.search-input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 13px;
    font-family: var(--font-sans);
    width: 100%;
}

.search-input::placeholder { color: var(--text-faint); }

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
    position: relative;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.icon-btn svg { width: 16px; height: 16px; }

.notif-btn .notif-dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 7px;
    height: 7px;
    background: var(--rose);
    border-radius: 50%;
    border: 1.5px solid var(--surface);
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

/* ── FLASH MESSAGES ──────────────────────────────────────── */
.flash-zone { padding: 12px 20px 0; display: flex; flex-direction: column; gap: 8px; }

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    animation: slideDown 0.2s ease;
    border: 1px solid transparent;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.flash svg { width: 16px; height: 16px; flex-shrink: 0; }

.flash-success {
    background: rgba(16,185,129,0.1);
    border-color: rgba(16,185,129,0.25);
    color: var(--green);
}

.flash-error {
    background: rgba(244,63,94,0.1);
    border-color: rgba(244,63,94,0.25);
    color: var(--rose);
}

.flash-info {
    background: rgba(79,110,247,0.1);
    border-color: rgba(79,110,247,0.25);
    color: var(--accent);
}

.flash span { flex: 1; color: var(--text); }

.flash-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}

.flash-close:hover { color: var(--text); }
.flash-close svg { width: 14px; height: 14px; }

/* ── CONTENT ─────────────────────────────────────────────── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── PAGE HEADER ─────────────────────────────────────────── */
.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header-left {}
.page-title    { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.page-actions  { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── CARDS ───────────────────────────────────────────────── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition);
}

.card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.card-body { padding: 20px; }

/* ── STAT CARDS ──────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
    border-color: var(--stat-color, var(--accent));
    box-shadow: 0 0 0 1px var(--stat-color, var(--accent)) inset, var(--shadow);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--stat-color, var(--accent));
}

.stat-card-icon {
    position: absolute;
    top: 14px;
    right: 16px;
    opacity: 0.08;
    color: var(--stat-color, var(--accent));
}

.stat-card-icon svg { width: 52px; height: 52px; }

.stat-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1.5px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.stat-delta {
    font-size: 12px;
    font-weight: 500;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-delta svg { width: 12px; height: 12px; }

.stat-delta.up   { color: var(--green); }
.stat-delta.down { color: var(--rose); }

/* Mini sparkline */
.sparkline {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 28px;
    margin-top: 12px;
}

.spark-bar {
    border-radius: 2px 2px 0 0;
    flex: 1;
    min-width: 3px;
    background: var(--stat-color, var(--accent));
    transition: opacity var(--transition);
}

.spark-bar:not(:last-child) { opacity: 0.3; }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    white-space: nowrap;
    font-family: var(--font-sans);
    text-decoration: none;
    line-height: 1;
}

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79,110,247,0.3);
}

.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: 0 4px 14px rgba(79,110,247,0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--card-hover);
    border-color: var(--border-2);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    margin-top: 4px;
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-2);
}

.btn-danger {
    background: rgba(244,63,94,0.1);
    color: var(--rose);
    border: 1px solid rgba(244,63,94,0.2);
}

.btn-danger:hover {
    background: rgba(244,63,94,0.2);
    border-color: rgba(244,63,94,0.4);
}

.btn-success {
    background: rgba(16,185,129,0.1);
    color: var(--green);
    border: 1px solid rgba(16,185,129,0.2);
}

.btn-sm  { padding: 5px 12px; font-size: 12px; }
.btn-lg  { padding: 11px 22px; font-size: 14px; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }

/* ── BADGE ───────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-active   { background: rgba(16,185,129,0.12);  color: var(--green); }
.badge-inactive { background: rgba(138,151,176,0.12); color: var(--text-muted); }
.badge-suspended{ background: rgba(244,63,94,0.12);   color: var(--rose); }
.badge-success  { background: rgba(16,185,129,0.12);  color: var(--green); }
.badge-warning  { background: rgba(245,158,11,0.12);  color: var(--amber); }
.badge-error    { background: rgba(244,63,94,0.12);   color: var(--rose); }
.badge-info     { background: rgba(79,110,247,0.12);  color: var(--accent); }

/* ── TABLE ───────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

tbody tr:last-child  { border-bottom: none; }
tbody tr:hover       { background: var(--surface-2); }

td {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text);
    vertical-align: middle;
}

.td-muted { color: var(--text-muted); font-size: 12px; }

/* User cell */
.user-cell { display: flex; align-items: center; gap: 10px; }

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 10px; }
.avatar-lg { width: 42px; height: 42px; font-size: 14px; }

.user-cell-name   { font-weight: 600; font-size: 13px; color: var(--text); }
.user-cell-email  { font-size: 11px; color: var(--text-muted); }

/* Table actions */
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-group  { display: flex; flex-direction: column; gap: 6px; }
.form-row    { display: grid; gap: 16px; margin-bottom: 16px; }
.form-cols-2 { grid-template-columns: 1fr 1fr; }
.form-cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

.form-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.form-label-link {
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
}

.form-label-link:hover { color: var(--accent-light); }

.form-input {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: var(--font-sans);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
    outline: none;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}

.form-input.is-error { border-color: var(--rose); }
.form-input.is-error:focus { box-shadow: 0 0 0 3px rgba(244,63,94,0.12); }

.form-input::placeholder { color: var(--text-faint); }

select.form-input {
    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='%238A97B0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}

.field-error { font-size: 11px; color: var(--rose); font-weight: 500; }

/* Input with icon */
.input-wrap { position: relative; }

.input-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input-icon svg { width: 15px; height: 15px; }
.input-with-icon { padding-left: 36px; }
.input-with-toggle { padding-right: 38px; }

.pw-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    transition: color var(--transition);
}

.pw-toggle:hover { color: var(--text); }
.pw-toggle svg { width: 15px; height: 15px; }

/* Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    user-select: none;
}

.checkbox-input { display: none; }

.checkbox-custom {
    width: 17px;
    height: 17px;
    border-radius: 4px;
    border: 1.5px solid var(--border-2);
    background: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.checkbox-input:checked + .checkbox-custom {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-input:checked + .checkbox-custom::after {
    content: '';
    width: 9px;
    height: 5px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
    display: block;
}

/* Toggle switch */
.toggle-switch {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: var(--border-2);
    cursor: pointer;
    position: relative;
    transition: background var(--transition);
    border: none;
    flex-shrink: 0;
}

.toggle-switch.on { background: var(--green); }

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: left var(--transition);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle-switch.on::after { left: 20px; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(16px) scale(0.98);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-head {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

.modal-title { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-body  { padding: 24px; }
.modal-foot  {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: var(--card);
}

/* ── PERMISSIONS GRID ────────────────────────────────────── */
.perm-section { margin-bottom: 20px; }

.perm-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.perm-section-name {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 7px;
}

.perm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.perm-item:hover  { border-color: var(--border-2); background: var(--card-hover); }
.perm-item.active { border-color: var(--accent); background: rgba(79,110,247,0.08); }

.perm-check {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1.5px solid var(--border-2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.perm-item.active .perm-check {
    background: var(--accent);
    border-color: var(--accent);
}

.perm-item.active .perm-check svg { display: block; }
.perm-item:not(.active) .perm-check svg { display: none; }
.perm-check svg { width: 11px; height: 11px; color: #fff; stroke-width: 3; }

.perm-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.perm-item.active .perm-name { color: var(--text); }

/* ── ROLE CARDS ──────────────────────────────────────────── */
.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.role-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-top: 3px solid var(--role-color, var(--accent));
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.role-card:hover {
    border-color: var(--role-color, var(--accent));
    box-shadow: var(--shadow);
}

.role-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.role-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 5px;
}

.role-name { font-size: 15px; font-weight: 700; color: var(--text); }
.role-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.role-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 12px;
}

.role-tag {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.role-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.role-meta-item { font-size: 12px; color: var(--text-muted); }
.role-meta-item strong { color: var(--text); font-weight: 700; }

.role-perm-bar {
    margin-left: auto;
    height: 4px;
    width: 80px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.role-perm-fill {
    height: 100%;
    border-radius: 2px;
}

/* ── ACTIVITY FEED ───────────────────────────────────────── */
.activity-feed { padding: 0 20px; }

.activity-item {
    display: flex;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}

.activity-text  { font-size: 13px; color: var(--text); line-height: 1.5; }
.activity-time  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── PAGINATION ──────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; padding: 14px 20px; border-top: 1px solid var(--border); }

.page-btn {
    min-width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border: 1px solid transparent;
    cursor: pointer;
    padding: 0 8px;
    background: none;
    transition: all var(--transition);
    font-family: var(--font-sans);
}

.page-btn:hover { background: var(--surface-2); color: var(--text); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* ── PERMISSION MATRIX TABLE ─────────────────────────────── */
.matrix-check {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.matrix-check svg { width: 12px; height: 12px; }
.matrix-check.has    { background: var(--accent); }
.matrix-check.has svg { color: #fff; stroke-width: 3; }
.matrix-check.no  { background: var(--border); }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 1024px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-cols-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100vh;
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .topbar-search { width: 140px; }
    .topbar-search:focus-within { width: 180px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .content { padding: 16px; }
    .form-cols-2, .form-cols-3 { grid-template-columns: 1fr; }
    .role-grid { grid-template-columns: 1fr; }
    .perm-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; }
    .page-actions { width: 100%; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .topbar-search { display: none; }
    .perm-grid { grid-template-columns: 1fr; }
}

/* ── UTILITIES ───────────────────────────────────────────── */
.mono       { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-xs    { font-size: 11px; }
.text-sm    { font-size: 12px; }
.text-accent { color: var(--accent); }
.text-green  { color: var(--green); }
.text-rose   { color: var(--rose); }
.text-amber  { color: var(--amber); }
.fw-700      { font-weight: 700; }
.gap-8       { gap: 8px; }
.flex-center { display: flex; align-items: center; }
.flex-between{ display: flex; align-items: center; justify-content: space-between; }
.mt-16       { margin-top: 16px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.divider     { height: 1px; background: var(--border); margin: 20px 0; }

/* Spin animation */
@keyframes spin { to { transform: rotate(360deg); } }
.spin-icon { animation: spin 0.8s linear infinite; }

/* Section divider label */
.section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
