:root {
    --bg:           #0f172a;
    --surface:      #1e293b;
    --surface2:     #273549;
    --border:       #334155;
    --accent:       #e11d48;
    --accent-dim:   rgba(225,29,72,0.12);
    --accent-hover: #f43f5e;
    --text:         #f1f5f9;
    --muted:        #94a3b8;
    --success:      #10b981;
    --warning:      #f59e0b;
    --danger:       #ef4444;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ===== AUTH GATE ===== */
#authGate {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.auth-panel {
    width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo .logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--accent-dim);
    border: 1px solid rgba(225,29,72,0.3);
    border-radius: 12px;
    font-size: 22px;
    margin-bottom: 14px;
}

.auth-logo h1 {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.auth-logo p {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 11.5px;
    color: var(--muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225,29,72,0.12);
}

.form-group select option {
    background: var(--surface);
}

.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.15s;
}
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225,29,72,0.12);
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
    padding: 11px 16px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: rgba(225,29,72,0.12);
    color: var(--accent);
    border: 1px solid rgba(225,29,72,0.25);
}
.btn-secondary:hover:not(:disabled) { background: rgba(225,29,72,0.22); }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }

.btn-danger {
    background: rgba(239,68,68,0.12);
    color: var(--danger);
    border: 1px solid rgba(239,68,68,0.25);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.22); }

.btn-warn {
    background: rgba(245,158,11,0.12);
    color: var(--warning);
    border: 1px solid rgba(245,158,11,0.25);
}
.btn-warn:hover:not(:disabled) { background: rgba(245,158,11,0.22); }

.btn-success {
    background: rgba(16,185,129,0.12);
    color: var(--success);
    border: 1px solid rgba(16,185,129,0.25);
}
.btn-success:hover:not(:disabled) { background: rgba(16,185,129,0.22); }

.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }

.error-msg {
    color: var(--danger);
    font-size: 12.5px;
    margin-top: 10px;
    min-height: 18px;
}

/* ===== SPINNER ===== */
.spinner-wrap { text-align: center; padding: 32px 0; color: var(--muted); }
.spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ACCESS DENIED ===== */
.denied-wrap { text-align: center; }
.denied-icon { font-size: 44px; margin-bottom: 14px; }
.denied-wrap h2 { font-size: 18px; margin-bottom: 8px; }
.denied-wrap p  { color: var(--muted); font-size: 13px; line-height: 1.65; margin-bottom: 22px; }

/* ===== APP SHELL ===== */
#adminApp {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
#sidebar {
    width: 252px;
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sb-header {
    padding: 22px 18px 18px;
    border-bottom: 1px solid var(--border);
}

.sb-site-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 5px;
}

.sb-badge {
    display: inline-block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(225,29,72,0.3);
    font-weight: 600;
}

.sb-user {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.sb-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.sb-user-email {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 7px;
}

.sb-nav {
    flex: 1;
    padding: 10px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 7px;
    cursor: pointer;
    color: var(--muted);
    font-size: 13.5px;
    transition: all 0.12s;
    margin-bottom: 1px;
    border: 1px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: rgba(225,29,72,0.2);
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.sb-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
}

.sign-out-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: 7px;
    color: var(--muted);
    font-size: 13.5px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.12s;
    text-align: left;
}
.sign-out-btn:hover { background: rgba(239,68,68,0.1); color: var(--danger); }

/* ===== MAIN CONTENT ===== */
#mainContent {
    margin-left: 252px;
    flex: 1;
    padding: 36px 40px;
    min-height: 100vh;
    max-width: 1100px;
}

.section { display: none; }
.section.active { display: block; animation: fadeSection 0.2s ease; }
@keyframes fadeSection { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== STAT GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
}

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

/* ===== ROLE BADGES ===== */
.role-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.role-admin      { background: rgba(225,29,72,0.15);  color: #fb7185; border: 1px solid rgba(225,29,72,0.3); }
.role-researcher { background: rgba(99,102,241,0.15);  color: #818cf8; border: 1px solid rgba(99,102,241,0.3); }
.role-editor     { background: rgba(16,185,129,0.15);  color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.role-viewer     { background: rgba(245,158,11,0.15);  color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }

/* ===== PAGINATION ===== */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}
.pagination-info { color: var(--muted); }
.pagination-buttons { display: flex; align-items: center; gap: 4px; }
.pagination-buttons button:disabled { opacity: 0.3; cursor: default; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }

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

th {
    text-align: left;
    padding: 9px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 11px 14px;
    font-size: 13px;
    border-bottom: 1px solid rgba(51,65,85,0.45);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

.td-name  { font-weight: 600; }
.td-email { color: var(--muted); font-size: 12px; }
.td-meta  { color: var(--muted); font-size: 12px; }
.td-actions { display: flex; gap: 8px; align-items: center; }

/* ===== ROLE CHECKBOXES ===== */
.role-checkboxes { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.role-checkboxes label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.role-checkboxes input[type="checkbox"] { accent-color: var(--accent); }

/* ===== FORMS ===== */
.add-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr 150px 90px;
    gap: 12px;
    align-items: end;
}
.add-form-row .form-group { margin: 0; }

/* ===== STATUS BADGES ===== */
.status-active {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);
}
.status-disabled, .status-blocked, .status-failed {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3);
}
.status-pending, .status-queued {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3);
}
.status-done, .status-verified {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);
}
.status-detected {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3);
}
.status-rejected {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3);
}
.status-running, .status-downloading, .status-transcribing, .status-analyzing {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3);
}
.status-skipped {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(148,163,184,0.15); color: #94a3b8; border: 1px solid rgba(148,163,184,0.3);
}

/* ===== SEVERITY BADGES ===== */
.severity-minor    { background: rgba(148,163,184,0.15); color: #94a3b8; border: 1px solid rgba(148,163,184,0.3); }
.severity-moderate { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.severity-major    { background: rgba(251,146,60,0.15); color: #fb923c; border: 1px solid rgba(251,146,60,0.3); }
.severity-extreme  { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 300;
}
.modal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    width: 500px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-panel h3 { font-size: 16px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== SEARCH BAR ===== */
.search-bar {
    display: flex; gap: 10px; margin-bottom: 18px;
}
.search-bar input {
    flex: 1; padding: 9px 14px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 13px; font-family: inherit;
}
.search-bar input:focus { outline: none; border-color: var(--accent); }

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center;
}
.filter-bar select, .filter-bar input {
    padding: 7px 12px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 13px; font-family: inherit;
}
.filter-bar select:focus, .filter-bar input:focus { outline: none; border-color: var(--accent); }

/* ===== SUB TABS ===== */
.sub-tabs {
    display: flex; gap: 4px; margin-bottom: 20px;
    border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.sub-tab {
    padding: 8px 18px; font-size: 13px; font-weight: 500;
    color: var(--muted); cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ===== TOAST ===== */
#toast {
    position: fixed;
    bottom: 24px; right: 24px;
    padding: 11px 18px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 500;
    z-index: 999;
    display: none;
    animation: toastIn 0.25s ease;
    max-width: 320px;
}
#toast.success { background: var(--success); color: #fff; }
#toast.error   { background: var(--danger);  color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== PLACEHOLDER SECTIONS ===== */
.placeholder-card { text-align: center; padding: 56px 24px; }
.ph-icon { font-size: 44px; margin-bottom: 14px; }
.placeholder-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.placeholder-card p  { color: var(--muted); font-size: 13px; line-height: 1.65; max-width: 420px; margin: 0 auto; }

/* ===== TRANSCRIPT VIEWER ===== */
.transcript-segment {
    padding: 8px 12px; border-radius: 6px;
    margin-bottom: 4px; cursor: pointer;
    transition: background 0.15s;
}
.transcript-segment:hover { background: rgba(255,255,255,0.03); }
.transcript-segment .ts-time {
    font-size: 11px; color: var(--accent); font-weight: 600;
    font-family: monospace; margin-right: 10px;
}
.transcript-segment .ts-speaker {
    font-size: 11px; color: var(--muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.transcript-segment .ts-text { font-size: 13px; line-height: 1.6; }

/* ===== FLIP SPLIT VIEW ===== */
.flip-split {
    display: grid; grid-template-columns: 350px 1fr; gap: 20px;
}
.flip-list { max-height: 80vh; overflow-y: auto; }
.flip-list-item {
    padding: 12px 14px; border-radius: 8px;
    border: 1px solid var(--border); margin-bottom: 8px;
    cursor: pointer; transition: all 0.15s;
}
.flip-list-item:hover { border-color: var(--accent); }
.flip-list-item.active { border-color: var(--accent); background: var(--accent-dim); }
.flip-list-item .fli-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.flip-list-item .fli-meta { font-size: 11px; color: var(--muted); }

.flip-detail { }
.flip-detail .fd-title { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.flip-detail .fd-summary { color: var(--muted); font-size: 13px; line-height: 1.7; margin-bottom: 20px; }

.statement-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
    padding: 16px; margin-bottom: 12px;
}
.statement-card .sc-date { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.statement-card .sc-text { font-size: 14px; line-height: 1.6; }
.statement-card .sc-context { font-size: 12px; color: var(--muted); margin-top: 8px; }

.status-completed {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);
}
.status-scripting, .status-generating {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3);
}
.status-published {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(16,185,129,0.15); color: #10b981; border: 1px solid rgba(16,185,129,0.3);
}
.status-online {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);
}
.status-offline {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3);
}
.status-deploying {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3);
}
.status-claimed {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3);
}
.status-cancelled {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
    background: rgba(148,163,184,0.15); color: #94a3b8; border: 1px solid rgba(148,163,184,0.3);
}

.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .flip-split { grid-template-columns: 1fr; }
    .add-form-row { grid-template-columns: 1fr; }
}
