:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252836;
    --bg-hover: #2a2d3a;
    --border: #2e3140;
    --text: #e4e4e7;
    --text-muted: #8b8fa3;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ---- Screens ---- */
.screen { display: none; }
.screen.active { display: block; }

/* ---- Login ---- */
#login-screen {
    display: none;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f1117 0%, #1a1040 50%, #0f1117 100%);
}
#login-screen.active { display: flex; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    text-align: center;
    min-width: 380px;
    box-shadow: var(--shadow);
}

.login-logo {
    color: var(--primary);
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
}

#google-signin-btn {
    display: flex;
    justify-content: center;
}

.error-message {
    margin-top: 16px;
    padding: 10px 14px;
    background: rgba(239, 68, 68, .12);
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 13px;
}

/* ---- Topbar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
}

.topbar-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-email {
    font-size: 13px;
    color: var(--text-muted);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 4px;
    padding: 12px 24px 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all .15s;
}

.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ---- Content ---- */
.content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.panel-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.panel-description {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ---- Tables ---- */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.mono {
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge-admin { background: rgba(99,102,241,.15); color: var(--primary-hover); }
.badge-user  { background: rgba(139,143,163,.12); color: var(--text-muted); }
.badge-active { background: rgba(34,197,94,.12); color: var(--success); }
.badge-revoked { background: rgba(239,68,68,.12); color: var(--danger); }
.badge-pending { background: rgba(245,158,11,.12); color: var(--warning); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all .15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
    background: none;
    color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

.btn-danger {
    background: rgba(239,68,68,.12);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(239,68,68,.2); color: var(--danger-hover); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.action-btns {
    display: flex;
    gap: 6px;
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 440px;
    max-width: 90vw;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 20px;
}

/* ---- Form ---- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow);
    z-index: 200;
    animation: slideIn .2s ease-out;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--danger); }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- User Detail ---- */
.detail-header {
    margin-bottom: 24px;
}

.detail-user-info {
    margin-top: 16px;
}

.detail-user-info h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.detail-meta {
    display: flex;
    gap: 8px;
}

.detail-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 16px;
}

.roles-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 24px;
}

/* ---- Access Grid ---- */
.access-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.access-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.access-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.access-card-info {
    flex: 1;
    min-width: 0;
}

.access-card-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.access-card-audience {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.access-card-scopes {
    padding: 16px 20px;
}

.scopes-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 10px;
}

.scopes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.scope-check {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.scope-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.scope-check input[type="checkbox"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.scope-check-label {
    font-size: 13px;
    color: var(--text);
}

/* ---- Toggle Switch ---- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    transition: all .2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all .2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: #fff;
}

/* ---- Form helpers ---- */
.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -8px;
}

.input-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.text-muted {
    color: var(--text-muted);
    font-size: 12px;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .login-card { min-width: auto; width: 90vw; padding: 32px 20px; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .tabs { padding: 8px 16px 0; }
}
