/* ============================================
   CBT SYSTEM - MAIN STYLESHEET
   Professional Educational Theme
   ============================================ */

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

:root {
    --primary: #3d1f05;
    --primary-light: #6b3a15;
    --accent: #e8b84b;
    --accent-dark: #b8860b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #8b4e20;
    --bg: #f7f0e1;
    --card: #ffffff;
    --text: #241505;
    --text-muted: #6b3f10;
    --border: #e5dcc8;
    --shadow: 0 4px 24px rgba(74,44,10,0.12);
    --shadow-lg: 0 8px 40px rgba(74,44,10,0.18);
    --radius: 12px;
    --radius-lg: 20px;
    --font: 'Sora', sans-serif;
    --mono: 'DM Mono', monospace;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
}

/* ============ TYPOGRAPHY ============ */
h1, h2, h3, h4, h5 { font-weight: 700; line-height: 1.25; color: var(--primary); }
h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.05rem; }
p { color: var(--text-muted); }

/* ============ LAYOUT ============ */
.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }
.gap-4 { gap: 32px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.full-width { width: 100%; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 13px; }

/* ============ CARD ============ */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { margin: 0; }

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); box-shadow: 0 4px 16px rgba(74,44,10,0.3); }
.btn-accent { background: var(--accent); color: var(--primary); }
.btn-accent:hover { background: var(--accent-dark); box-shadow: 0 4px 16px rgba(232,184,75,0.4); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 8px; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 16px;
    color: var(--text);
    background: #fff;
    transition: var(--transition);
    outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,44,10,0.08); }
.form-control::placeholder { color: #a68b5b; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* Compact variant for small toolbar/topbar controls.
   Use this instead of inline height:32px overrides — a fixed height combined
   with the default 11px vertical padding above clips/hides the text.
   This variant reduces padding to match, so text always stays visible. */
.form-control-compact {
    padding: 5px 10px;
    height: 32px;
    font-size: 12px;
    color: var(--text) !important;
    background: #fff !important;
}

/* ============ STICKY TABLE COLUMN ============
   Apply .sticky-col to a <th>/<td> (typically the name column) inside a
   .table-wrapper so it stays visible while the table scrolls horizontally.
   Works with the existing overflow-x:auto on .table-wrapper. */
.table-wrapper table.has-sticky-col { position: relative; }
.sticky-col {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--card);
    box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}
thead .sticky-col { background: var(--primary); color: #fff; z-index: 3; }
tbody tr:nth-child(even) .sticky-col { background: #faf6ec; }
tbody tr:hover .sticky-col { background: #f8fafc; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ============ BADGES ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #f3e6c4; color: #3d1f05; }
.badge-primary { background: #e8d5a0; color: #3d1f05; }
.badge-gray { background: #f7f0e1; color: #6b3f10; }

/* ============ TABLE ============ */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--primary);
    color: #fff;
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
thead th:first-child { border-radius: 8px 0 0 0; }
thead th:last-child { border-radius: 0 8px 0 0; }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 12px 16px; font-size: 14px; }
tbody tr:nth-child(even) { background: #faf6ec; }
tbody tr:nth-child(even):hover { background: #f7f0e1; }

/* ============ ALERTS ============ */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-weight: 500;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: #f3e6c4; color: #3d1f05; border: 1px solid #d9b880; }

/* ============ STAT CARDS ============ */
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.blue { background: #f3e6c4; color: #6b3a15; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.gold { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

/* ============ PAGINATION ============ */
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 20px; }
.page-btn {
    padding: 6px 12px;
    border: 2px solid var(--border);
    background: #fff;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text);
}
.page-btn:hover, .page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(74,44,10,0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 560px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header { margin-bottom: 20px; }
.modal-footer { margin-top: 24px; display: flex; gap: 12px; justify-content: flex-end; }

/* ============ LOGIN PAGE ============ */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, #2b1200 50%, var(--primary-light) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.login-wrapper::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: rgba(232,184,75,0.06);
    top: -200px; right: -200px;
}
.login-wrapper::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    bottom: -100px; left: -100px;
}
.login-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.25);
    position: relative;
    z-index: 2;
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo img { width: 72px; height: 72px; border-radius: 16px; object-fit: cover; }
.login-logo .school-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    margin-top: 10px;
    line-height: 1.3;
}
.login-logo .portal-name {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.login-divider {
    width: 48px; height: 4px;
    background: var(--accent);
    border-radius: 2px;
    margin: 12px auto;
}

/* ============ ADMIN SIDEBAR ============ */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: var(--transition);
}
.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand .brand-name { font-size: 14px; font-weight: 700; color: #fff; line-height: 1.3; }
.sidebar-brand .brand-sub { font-size: 11px; color: rgba(255,255,255,0.5); margin-top: 2px; }
.sidebar-brand .brand-badge {
    display: inline-block;
    background: var(--accent);
    color: var(--primary);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    margin-top: 6px;
}
.sidebar-nav { padding: 16px 0; flex: 1; }
.nav-section {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255,255,255,0.35);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 20px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    border-left: 3px solid transparent;
    margin: 1px 0;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(232,184,75,0.15); color: var(--accent); border-left-color: var(--accent); }
.nav-item .nav-icon { font-size: 18px; width: 20px; text-align: center; }
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user .user-avatar {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--primary);
    font-size: 14px;
    flex-shrink: 0;
}
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-user .user-role { font-size: 11px; color: rgba(255,255,255,0.5); }

/* ============ MAIN CONTENT ============ */
.main-content { margin-left: 260px; flex: 1; min-height: 100vh; }
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 99;
    box-shadow: 0 1px 8px rgba(74,44,10,0.06);
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.breadcrumb { font-size: 13px; color: var(--text-muted); }
.breadcrumb span { color: var(--primary); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.page-content { padding: 28px; }

/* ============ EXAM INTERFACE ============ */
.exam-layout { display: flex; gap: 20px; align-items: flex-start; }
.exam-main { flex: 1; }
.exam-sidebar-panel {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 80px;
}
.exam-header {
    background: var(--primary);
    color: #fff;
    padding: 20px 24px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.exam-header .exam-title { font-size: 1.1rem; font-weight: 700; color: #fff; }
.exam-header .exam-meta { font-size: 13px; color: rgba(255,255,255,0.7); }
.timer-box {
    background: rgba(232,184,75,0.15);
    border: 2px solid var(--accent);
    border-radius: 10px;
    padding: 10px 20px;
    text-align: center;
}
.timer-box .timer-label { font-size: 11px; color: rgba(255,255,255,0.7); text-transform: uppercase; letter-spacing: 1px; }
.timer-box .timer-value { font-family: var(--mono); font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.timer-box.warning .timer-value { color: #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.question-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}
.question-number {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-dark);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.question-text { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 20px; line-height: 1.5; }
.options-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.option-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text);
}
.option-item:hover { border-color: var(--primary); background: #f8fafc; }
.option-item.selected { border-color: var(--primary); background: #faf6ec; color: var(--primary); font-weight: 600; }
.option-item.correct { border-color: var(--success); background: #d1fae5; color: #065f46; }
.option-item.wrong { border-color: var(--danger); background: #fee2e2; color: #991b1b; }
.option-label {
    width: 30px; height: 30px;
    background: var(--bg);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}
.option-item.selected .option-label { background: var(--primary); color: #fff; }
.option-item.correct .option-label { background: var(--success); color: #fff; }
.option-item.wrong .option-label { background: var(--danger); color: #fff; }

.question-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.q-btn {
    aspect-ratio: 1;
    border-radius: 6px;
    border: 2px solid var(--border);
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}
.q-btn:hover { border-color: var(--primary); }
.q-btn.answered { background: var(--primary); border-color: var(--primary); color: #fff; }
.q-btn.current { background: var(--accent); border-color: var(--accent-dark); color: var(--primary); }

/* ============ RESULT PAGE ============ */
.result-hero {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    color: #fff;
    margin-bottom: 24px;
}
.score-circle {
    width: 140px; height: 140px;
    border-radius: 50%;
    border: 6px solid var(--accent);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    background: rgba(255,255,255,0.08);
}
.score-circle .score-value { font-size: 2.5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.score-circle .score-label { font-size: 12px; color: rgba(255,255,255,0.7); }
.grade-display { font-size: 3rem; font-weight: 800; margin: 8px 0; }
.grade-A, .grade-B { color: var(--success); }
.grade-C, .grade-D { color: var(--warning); }
.grade-F { color: var(--danger); }

/* ============ SEARCH BAR ============ */
.search-box {
    position: relative;
    display: inline-block;
}
.search-box input {
    padding: 9px 16px 9px 38px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
    width: 240px;
}
.search-box input:focus { border-color: var(--primary); }
.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 15px;
}

/* ============ PROGRESS BAR ============ */
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--info));
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { color: var(--primary); margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; }

/* ============ SYNC STATUS ============ */
.sync-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.sync-badge.synced { background: #d1fae5; color: #065f46; }
.sync-badge.pending { background: #fef3c7; color: #92400e; }
.sync-badge.failed { background: #fee2e2; color: #991b1b; }

/* ============ PRINT STYLES ============ */
@media print {
    .sidebar, .topbar, .btn, .no-print { display: none !important; }
    .main-content { margin-left: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .exam-layout { flex-direction: column; }
    .exam-sidebar-panel { width: 100%; position: static; }
    .topbar { padding: 0 16px; }
    .page-content { padding: 16px; }
}

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.4s ease forwards; }
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
