/* ============================================
   DTM Test Platform - Styles v2.0
   ============================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #7c3aed;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text: #1e293b;
    --text-light: #64748b;
    --bg: #f1f5f9;
    --white: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
    --radius: 12px;
}

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

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

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---- Navbar ---- */
.navbar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.navbar .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.navbar-brand { color: #fff; text-decoration: none; font-size: 1.2rem; font-weight: 700; white-space: nowrap; }
.navbar-brand span { color: #93c5fd; }
.nav-links { display: flex; gap: 8px; }
.nav-links a { color: rgba(255,255,255,0.8); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 0.9rem; white-space: nowrap; transition: all 0.2s; }
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,0.15); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 0.9rem; white-space: nowrap; }
.logout-link { color: #fca5a5 !important; text-decoration: none; }
.streak { background: rgba(255,255,255,0.15); padding: 2px 8px; border-radius: 12px; font-size: 0.85rem; }
.user-badge { background: var(--warning); color: #000; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; font-weight: 700; }
.hamburger { display: none; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }

@media (max-width: 768px) {
    .hamburger { display: block; }
    .nav-links, .admin-nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--primary-dark); flex-direction: column; padding: 8px; z-index: 99; }
    .nav-links.show, .admin-nav.show { display: flex; }
    .nav-links a { padding: 10px 16px; }
    .nav-user { display: none; }
}

/* ---- Auth ---- */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); }
.auth-card { background: var(--white); border-radius: var(--radius); overflow: hidden; width: 100%; max-width: 440px; box-shadow: var(--shadow-lg); }
.auth-header { background: var(--primary); color: #fff; padding: 24px; text-align: center; }
.auth-header h1 { font-size: 1.5rem; margin-bottom: 4px; }
.auth-header p { opacity: 0.9; font-size: 0.9rem; }
.auth-body { padding: 24px; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.auth-tab { flex: 1; text-align: center; padding: 10px; cursor: pointer; font-weight: 600; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-form { }
.hidden { display: none !important; }

.divider { text-align: center; margin: 20px 0; position: relative; }
.divider::before { content: ''; position: absolute; left: 0; top: 50%; width: 100%; height: 1px; background: var(--border); }
.divider span { position: relative; background: var(--white); padding: 0 12px; font-size: 0.85rem; color: var(--text-light); }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 0.9rem; color: var(--text); }
.form-control { width: 100%; padding: 10px 14px; border: 2px solid var(--border); border-radius: 8px; font-size: 0.95rem; transition: border-color 0.2s; font-family: inherit; }
.form-control:focus { border-color: var(--primary); outline: none; }
textarea.form-control { resize: vertical; }
select.form-control { appearance: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* ---- Buttons ---- */
.btn { display: inline-block; padding: 8px 20px; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; transition: all 0.2s; font-family: inherit; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-block { display: block; width: 100%; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.mt-20 { margin-top: 20px; }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; line-height: 1.5; }
.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: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ---- Cards ---- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 16px 20px; font-weight: 700; font-size: 1rem; border-bottom: 1px solid var(--border); background: #fafafa; }
.card-body { padding: 20px; }

/* ---- Stats grid ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-2px); }
.stat-card-icon { font-size: 2rem; margin-bottom: 4px; }
.stat-card-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-card-label { font-size: 0.85rem; color: var(--text-light); }

/* ---- Subjects ---- */
.subjects-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }
.subject-card { background: var(--white); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; box-shadow: var(--shadow); transition: all 0.2s; border: 2px solid transparent; }
.subject-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.subject-icon { font-size: 2.5rem; margin-bottom: 8px; }
.subject-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.subject-desc { font-size: 0.85rem; color: var(--text-light); }

/* ---- Test ---- */
.test-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.timer { font-size: 1.5rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.timer.warning { color: var(--warning); }
.timer.danger { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.progress-bar-container { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s; }

.question-card { background: var(--white); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); user-select: none; }
.question-number { font-size: 0.85rem; color: var(--text-light); margin-bottom: 8px; }
.question-text { font-size: 1.1rem; font-weight: 600; margin-bottom: 20px; line-height: 1.6; }
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-item { display: flex; align-items: center; padding: 14px 16px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.option-item:hover { border-color: var(--primary); background: #eff6ff; }
.option-item.selected { border-color: var(--primary); background: #dbeafe; }
.option-letter { width: 32px; height: 32px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; margin-right: 12px; flex-shrink: 0; font-size: 0.9rem; }
.option-item.selected .option-letter { background: var(--primary); color: #fff; }
.option-text { flex: 1; }

.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }

/* Tab warning */
.tab-warning { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 1000; }
.tab-warning.active { display: flex; }
.tab-warning-content { background: var(--white); padding: 40px; border-radius: var(--radius); text-align: center; max-width: 400px; }
.tab-warning-icon { font-size: 3rem; margin-bottom: 12px; }

/* ---- Results ---- */
.results-card { background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 24px; }
.results-header { padding: 20px; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; text-align: center; }
.results-body { padding: 24px; text-align: center; }
.score-circle { width: 120px; height: 120px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; border: 4px solid; }
.score-circle.success { border-color: var(--success); color: var(--success); }
.score-circle.warning { border-color: var(--warning); color: var(--warning); }
.score-circle.danger { border-color: var(--danger); color: var(--danger); }
.score-value { font-size: 2rem; font-weight: 700; }
.results-stats { display: flex; justify-content: center; gap: 24px; flex-wrap: wrap; }
.result-stat { text-align: center; }
.result-stat-label { font-size: 0.8rem; color: var(--text-light); display: block; }
.result-stat-value { font-size: 1.3rem; font-weight: 700; }

.answer-card { background: var(--white); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border-left: 4px solid; box-shadow: var(--shadow); }
.answer-card.correct { border-color: var(--success); }
.answer-card.wrong { border-color: var(--danger); }
.answer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
.answer-badge { padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; }
.badge-correct { background: #d1fae5; color: #065f46; }
.badge-wrong { background: #fee2e2; color: #991b1b; }
.answer-question { font-size: 1rem; margin-bottom: 12px; line-height: 1.5; }
.answer-options { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
.answer-option { padding: 6px 10px; border-radius: 6px; }
.answer-option.option-correct { background: #d1fae5; font-weight: 600; }
.answer-option.option-wrong { background: #fee2e2; }
.answer-explanation { margin-top: 10px; padding: 10px; background: #fefce8; border-radius: 8px; font-size: 0.9rem; border: 1px solid #fde68a; }

/* ---- Rankings ---- */
.ranking-table { width: 100%; border-collapse: collapse; }
.ranking-table th { padding: 10px 14px; text-align: left; font-size: 0.85rem; color: var(--text-light); border-bottom: 2px solid var(--border); background: #fafafa; white-space: nowrap; }
.ranking-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.ranking-table tbody tr:hover { background: #f8fafc; }
.highlight-row { background: #dbeafe !important; }

.filter-row { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-group .btn { padding: 6px 12px; font-size: 0.85rem; }

/* ---- Profile ---- */
.profile-info { display: flex; flex-direction: column; gap: 10px; }
.profile-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; }

/* ---- Contest ---- */
.contest-banner { background: linear-gradient(135deg, var(--primary), var(--secondary)); border-radius: var(--radius); padding: 24px; color: #fff; margin-bottom: 24px; }
.contest-banner h3 { font-size: 1.3rem; margin-bottom: 6px; }
.contest-card { background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.contest-header { padding: 24px; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; text-align: center; }
.contest-dates { margin-top: 8px; font-size: 0.9rem; opacity: 0.9; }
.prizes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; padding: 24px; }
.prize-card { text-align: center; padding: 20px 12px; border-radius: var(--radius); border: 2px solid var(--border); }
.prize-card.gold { border-color: #f59e0b; background: #fffbeb; }
.prize-card.silver { border-color: #9ca3af; background: #f9fafb; }
.prize-card.bronze { border-color: #d97706; background: #fffbeb; }
.prize-place { font-size: 2rem; }
.prize-text { font-size: 0.85rem; color: var(--text-light); margin: 4px 0; }
.prize-value { font-weight: 700; font-size: 1rem; color: var(--text); }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 4rem; margin-bottom: 16px; }

/* ---- LaTeX ---- */
.latex-preview { margin-top: 4px; padding: 8px; background: #f8fafc; border-radius: 6px; min-height: 20px; font-size: 0.9rem; }
.latex-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.latex-toolbar .btn { padding: 4px 10px; font-size: 1rem; min-width: 36px; }

/* ---- Page ---- */
.page-wrapper { min-height: 100vh; }
.main-content { padding: 24px 0; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }

/* ============================================
   DARK MODE
   ============================================ */
body.dark-mode {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #8b5cf6;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --text: #e2e8f0;
    --text-light: #94a3b8;
    --bg: #0f172a;
    --white: #1e293b;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

body.dark-mode .navbar {
    background: linear-gradient(135deg, #1e3a5f, #1e40af);
}

body.dark-mode .auth-wrapper {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

body.dark-mode .card-header {
    background: #1a2332;
}

body.dark-mode .ranking-table th {
    background: #1a2332;
}

body.dark-mode .form-control {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
}

body.dark-mode .form-control:focus {
    border-color: #3b82f6;
}

body.dark-mode .option-item:hover {
    background: #1e3a5f;
}

body.dark-mode .option-item.selected {
    background: #1e3a5f;
    border-color: #3b82f6;
}

body.dark-mode .option-letter {
    background: #334155;
}

body.dark-mode .alert-info {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #2563eb;
}

body.dark-mode .alert-success {
    background: #064e3b;
    color: #6ee7b7;
    border-color: #10b981;
}

body.dark-mode .alert-danger {
    background: #7f1d1d;
    color: #fca5a5;
    border-color: #ef4444;
}

body.dark-mode .alert-warning {
    background: #78350f;
    color: #fcd34d;
    border-color: #f59e0b;
}

body.dark-mode .btn-outline {
    border-color: #475569;
    color: #cbd5e1;
}

body.dark-mode .btn-outline:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

body.dark-mode .ranking-table tbody tr:hover {
    background: #1a2332;
}

body.dark-mode .answer-explanation {
    background: #2a2000;
    border-color: #78350f;
}

body.dark-mode .question-card {
    background: var(--white);
}

body.dark-mode code {
    background: #334155;
    color: #f1f5f9;
}

/* Dark mode toggle */
.dark-toggle {
    background: none;
    border: 2px solid rgba(255,255,255,0.3);
    color: #fff;
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}
.dark-toggle:hover {
    border-color: rgba(255,255,255,0.6);
}

/* ---- Report cards ---- */
.report-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.report-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.report-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}
.report-question {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.report-user-comment {
    padding: 16px;
    background: #fffbeb;
    border-bottom: 1px solid var(--border);
}
.report-admin-response {
    padding: 16px;
}
.report-admin-response.response-approved {
    background: #ecfdf5;
    border-left: 4px solid var(--success);
}
.report-admin-response.response-rejected {
    background: #fef2f2;
    border-left: 4px solid var(--danger);
}
body.dark-mode .report-user-comment {
    background: #2a2000;
}
body.dark-mode .report-admin-response.response-approved {
    background: #042f1c;
}
body.dark-mode .report-admin-response.response-rejected {
    background: #350a0a;
}

/* ---- Referral card ---- */
.referral-card {
    background: linear-gradient(135deg, #7c3aed, #6366f1);
    border-radius: var(--radius);
    padding: 24px;
    color: #fff;
    margin-bottom: 20px;
}
.referral-code {
    background: rgba(255,255,255,0.2);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-align: center;
    margin: 12px 0;
    user-select: all;
    cursor: pointer;
    transition: background 0.3s;
}
.referral-code:hover {
    background: rgba(255,255,255,0.35);
}
.referral-code:active {
    background: rgba(16,185,129,0.3);
}
.referral-code-wrapper {
    position: relative;
}
.referral-copy-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.25);
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.2s;
}
.referral-copy-btn:hover {
    background: rgba(255,255,255,0.4);
}
.referral-stats {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.referral-stat {
    text-align: center;
}
.referral-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}
.referral-stat-label {
    font-size: 0.8rem;
    opacity: 0.85;
}

/* ---- Duel (Bellashuv) ---- */
.duel-invite-card {
    background: var(--white);
    border-radius: var(--radius);
    border-left: 4px solid var(--secondary);
    padding: 16px 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.duel-invite-info { flex: 1; min-width: 200px; }
.duel-invite-actions { display: flex; gap: 8px; }

.duel-result-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin-bottom: 24px;
}
.duel-result-header {
    padding: 32px 24px;
    text-align: center;
    color: #fff;
}
.duel-result-header.win { background: linear-gradient(135deg, #10b981, #059669); }
.duel-result-header.lose { background: linear-gradient(135deg, #ef4444, #dc2626); }
.duel-result-header.draw { background: linear-gradient(135deg, #f59e0b, #d97706); }
.duel-result-header.waiting { background: linear-gradient(135deg, #7c3aed, #6366f1); }
.duel-result-icon { font-size: 3rem; margin-bottom: 8px; }

.duel-scoreboard {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 16px;
}
.duel-player {
    flex: 1;
    text-align: center;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--bg);
}
.duel-player.winner {
    background: #d1fae5;
    border: 2px solid var(--success);
}
body.dark-mode .duel-player.winner {
    background: #042f1c;
    border-color: #10b981;
}
.duel-player-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 8px;
}
.duel-player-correct {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}
.duel-player-time {
    font-size: 0.85rem;
    color: var(--text-light);
    margin: 4px 0;
}
.duel-player-score {
    font-size: 0.9rem;
    font-weight: 600;
}
.duel-vs {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-light);
    padding: 0 8px;
}
.duel-bonus {
    text-align: center;
    padding: 16px;
    font-weight: 600;
    font-size: 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

@media (max-width: 600px) {
    .duel-scoreboard { flex-direction: column; }
    .duel-vs { transform: rotate(90deg); padding: 4px 0; }
    .duel-invite-card { flex-direction: column; text-align: center; }
    .duel-invite-actions { justify-content: center; }
}
