/* ===== CSS Variables ===== */
:root {
    --bg-main: #0f111a;
    --bg-panel: #1a1d2d;
    --bg-card: #23263a;
    --bg-hover: #2a2d42;
    --border: #2e3248;
    --text-main: #e2e8f0;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --success-dim: rgba(34, 197, 94, 0.15);
    --warning: #fbbf24;
    --danger: #ef4444;
    --danger-dim: rgba(239, 68, 68, 0.15);
    --info: #3b82f6;
    --info-dim: rgba(59, 130, 246, 0.15);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Header ===== */
.admin-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.admin-email {
    color: var(--info);
    font-weight: 500;
    font-size: 0.9rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-card);
    color: var(--text-main);
}

.btn-export {
    background: var(--success);
    color: white;
}

.btn-export:hover {
    background: #16a34a;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* ===== Auth Gate ===== */
.auth-gate {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 70px);
}

.auth-message {
    text-align: center;
    padding: 40px;
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.auth-message h2 {
    margin-bottom: 12px;
}

.auth-message p {
    color: var(--text-dim);
}

/* ===== Main Content ===== */
.main-content {
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

.hidden {
    display: none !important;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
}

.tab-btn {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    background: var(--bg-card);
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

/* ===== Tab Panels ===== */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Section Headers ===== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box input {
    padding: 10px 16px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.9rem;
    min-width: 280px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.select-filter {
    padding: 10px 16px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.9rem;
    cursor: pointer;
}

/* ===== Tables ===== */
.table-container {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

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

th, td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-card);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover {
    background: var(--bg-hover);
}

tr:last-child td {
    border-bottom: none;
}

.num {
    font-family: 'SF Mono', 'Monaco', monospace;
    color: var(--warning);
}

.good {
    color: var(--success);
}

.bad {
    color: var(--danger);
}

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 40px !important;
}

/* ===== Tests Grid ===== */
.tests-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.test-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.test-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

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

.test-card-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.test-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-active {
    background: var(--success-dim);
    color: var(--success);
}

.status-ended {
    background: var(--danger-dim);
    color: var(--danger);
}

.status-upcoming {
    background: var(--info-dim);
    color: var(--info);
}

.test-card-meta {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.test-card-stats {
    display: flex;
    gap: 16px;
    font-size: 0.9rem;
}

.test-card-stats span {
    color: var(--text-dim);
}

.test-card-stats strong {
    color: var(--text-main);
}

/* ===== Export Grid ===== */
.export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.export-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.export-card h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.export-card p {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.export-card .select-filter {
    width: 100%;
    margin-bottom: 12px;
}

.export-card .btn-export {
    width: 100%;
}

/* ===== Modals ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-height: 90vh;
    overflow-y: auto;
    width: 100%;
    max-width: 600px;
}

.modal-large {
    max-width: 900px;
}

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

.modal-header h2 {
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 24px;
}

/* ===== Test Stats Row ===== */
.test-stats-row {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.test-stat {
    background: var(--bg-card);
    padding: 12px 20px;
    border-radius: var(--radius);
}

.test-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
}

.test-stat-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

/* ===== Submission Filters ===== */
.submission-filters {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
}

.filter-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}

.filter-panel h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    color: var(--text-main);
}

.filter-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.filter-input {
    padding: 8px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.85rem;
    min-width: 180px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary);
}

.date-input {
    padding: 8px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.85rem;
}

.filter-custom-dates {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-custom-dates span {
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* ===== Submission Details ===== */
.submission-puzzle {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.submission-puzzle-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.submission-puzzle-title {
    font-weight: 600;
}

.submission-puzzle-status {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.submission-puzzle-status.correct {
    background: var(--success-dim);
    color: var(--success);
}

.submission-puzzle-status.incorrect {
    background: var(--danger-dim);
    color: var(--danger);
}

.submission-code {
    background: var(--bg-main);
    padding: 12px;
    border-radius: var(--radius);
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    white-space: pre-wrap;
    color: var(--text-dim);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 17, 26, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Status Badges ===== */
.badge-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-status.pending {
    background: var(--warning);
    color: #1a1d2d;
}

.badge-status.reviewed {
    background: var(--info);
    color: white;
}

.badge-status.resolved {
    background: var(--success);
    color: white;
}

.badge-status.dismissed {
    background: var(--text-muted);
    color: white;
}

/* ===== Flags Table Styles ===== */
.flag-status-select {
    font-size: 0.8rem;
    padding: 4px 8px;
    min-width: 100px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .admin-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .header-right {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .tab-nav {
        overflow-x: auto;
        padding-bottom: 8px;
    }
    
    .tab-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
        white-space: nowrap;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .toolbar {
        flex-direction: column;
    }
    
    .search-box input {
        width: 100%;
        min-width: unset;
    }
}
