/* ── Variables ─────────────────────────────────────────────── */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.container-narrow { max-width: 720px; }

/* ── Navbar ────────────────────────────────────────────────── */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 0.875rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--gray-900);
    text-decoration: none;
}

.logo:hover { text-decoration: none; }
.logo-icon { font-size: 1.5rem; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-user {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); color: var(--gray-900); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.875rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* ── Hero ──────────────────────────────────────────────────── */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: #fff;
    padding: 3.5rem 0;
    text-align: center;
}

.hero-title {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero-subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.hero-sm { padding: 2.5rem 0; }
.back-link-light { color: rgba(255,255,255,0.85); display: inline-block; margin-bottom: 0.75rem; }
.back-link-light:hover { color: #fff; }

.folder-card { border-color: var(--primary-light); }

.folder-card-link,
.test-card-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.folder-card-link:hover,
.test-card-link:hover {
    text-decoration: none;
    color: inherit;
}

.test-card-link .btn {
    pointer-events: none;
}

/* ── Tests Section ─────────────────────────────────────────── */
.tests-section { padding: 3rem 0; }

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}

.test-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.test-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    transition: all 0.25s;
    display: flex;
    flex-direction: column;
}

.test-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.test-card--locked {
    opacity: 0.85;
    background: var(--gray-50);
}

.test-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.test-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
}

.badge-open { background: #d1fae5; color: #065f46; }
.badge-locked { background: #fee2e2; color: #991b1b; }

.test-card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.test-card-desc {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    flex-grow: 1;
}

.test-card-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-bottom: 1.25rem;
}

.test-card-action { margin-top: auto; }

/* ── Auth ──────────────────────────────────────────────────── */
.auth-section {
    padding: 3rem 0;
    flex: 1;
    display: flex;
    align-items: center;
}

.auth-card {
    max-width: 420px;
    margin: 0 auto;
    background: #fff;
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.auth-header h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.auth-header p { color: var(--gray-500); font-size: 0.9rem; }

.auth-form { display: flex; flex-direction: column; gap: 1.25rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }
.form-group label { font-size: 0.875rem; font-weight: 500; color: var(--gray-700); }

.form-input {
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
    width: 100%;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-checkbox { width: 1.125rem; height: 1.125rem; accent-color: var(--primary); }
.form-error { color: var(--danger); font-size: 0.8rem; }
.form-help { color: var(--gray-500); font-size: 0.8rem; }

/* ── Test Taking ───────────────────────────────────────────── */
.test-taking { padding: 2rem 0 3rem; flex: 1; }

.test-header { margin-bottom: 2rem; }
.back-link { font-size: 0.9rem; color: var(--gray-500); display: inline-block; margin-bottom: 0.75rem; }
.test-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; }

.test-info-bar {
    display: flex;
    gap: 1.5rem;
    color: var(--gray-500);
    font-size: 0.9rem;
}

.question-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.question-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.question-text {
    font-size: 1.05rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--gray-900);
}

.rich-text {
    font-weight: 400;
    line-height: 1.7;
}

.rich-text img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 0.75rem 0;
    display: block;
}

.rich-text p { margin-bottom: 0.75rem; }
.rich-text ul, .rich-text ol { margin: 0.5rem 0 0.75rem 1.25rem; }
.rich-text h3, .rich-text h4 { margin: 0.75rem 0 0.5rem; font-weight: 600; }

.form-group-rich-editor .tox-tinymce {
    border-radius: 8px;
    border-color: var(--gray-200) !important;
}

.question-admin-text.rich-text {
    font-weight: 400;
    margin-bottom: 0.75rem;
}

.choices-list { display: flex; flex-direction: column; gap: 0.625rem; }

.choice-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.choice-label:hover { border-color: var(--primary); background: var(--primary-light); }

.choice-label input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.choice-label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.choice-text { font-size: 0.95rem; }

/* ── Result Page ───────────────────────────────────────────── */
.result-section { padding: 2rem 0 3rem; flex: 1; }

.result-card {
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.result-header {
    padding: 2.5rem 2rem;
    text-align: center;
    color: #fff;
}

.result-passed { background: linear-gradient(135deg, #10b981, #059669); }
.result-failed { background: linear-gradient(135deg, #f59e0b, #d97706); }

.result-emoji { font-size: 3.5rem; margin-bottom: 0.5rem; }
.result-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
.result-header p { opacity: 0.9; }

.result-body { padding: 2rem; }

.result-test-name {
    text-align: center;
    font-size: 1.1rem;
    color: var(--gray-500);
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    max-width: 280px;
    margin: 0 auto 2rem;
}

.chart-center-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    text-align: center;
    pointer-events: none;
}

.chart-score {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1;
}

.chart-label {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    text-align: center;
    padding: 1rem;
    border-radius: 8px;
    background: var(--gray-50);
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.stat-correct .stat-value { color: var(--success); }
.stat-wrong .stat-value { color: var(--danger); }
.stat-total .stat-value { color: var(--primary); }

.result-pass-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 8px;
    font-size: 0.9rem;
}

.result-status { font-weight: 600; }
.status-pass { color: var(--success); }
.status-fail { color: var(--danger); }

.result-actions {
    display: flex;
    gap: 1rem;
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--gray-200);
}

.result-actions .btn { flex: 1; }

/* ── Alerts ────────────────────────────────────────────────── */
.messages-container { padding-top: 1rem; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { margin-bottom: 1rem; }

/* ── Footer ────────────────────────────────────────────────── */
.footer {
    margin-top: auto;
    padding: 1.5rem 0;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.85rem;
    border-top: 1px solid var(--gray-200);
    background: #fff;
}

.main-content { flex: 1; }

/* ── Admin Layout ──────────────────────────────────────────── */
.admin-body {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

.admin-sidebar {
    width: 250px;
    min-height: 100vh;
    background: var(--gray-900);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-nav {
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.sidebar-link {
    display: block;
    padding: 0.75rem 1.5rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-link-danger:hover { background: rgba(239,68,68,0.2); color: #fca5a5; }
.sidebar-divider { border: none; border-top: 1px solid rgba(255,255,255,0.1); margin: 0.5rem 1rem; }

.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.admin-topbar {
    background: #fff;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-page-title { font-size: 1.25rem; font-weight: 600; }
.admin-user { color: var(--gray-500); font-size: 0.9rem; }

.admin-messages { padding: 1rem 2rem 0; }
.admin-content { padding: 2rem; flex: 1; }

.admin-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    background: var(--gray-100);
}

/* ── Admin Components ──────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.stat-card-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.stat-card-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card-label { color: var(--gray-500); font-size: 0.9rem; margin-bottom: 0.75rem; }
.stat-card-link { font-size: 0.85rem; font-weight: 500; }

.admin-actions { display: flex; gap: 1rem; flex-wrap: wrap; }
.admin-toolbar { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.admin-table-wrap {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.admin-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.admin-table tr:last-child td { border-bottom: none; }
.actions-cell { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.inline-form { display: inline; }

.admin-form-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    max-width: 600px;
}

.admin-form-card-wide {
    max-width: 820px;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.form-section-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.form-context { margin-bottom: 1.5rem; color: var(--gray-500); }

.choices-formset { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

.choices-help { margin-bottom: 1rem; }

.choice-option-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--gray-50);
    border: 2px solid var(--gray-200);
    border-radius: 10px;
    transition: border-color 0.2s;
}

.choice-option-row:focus-within {
    border-color: var(--primary);
    background: var(--primary-light);
}

.choice-letter {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: 8px;
}

.choice-fields {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.choice-text-wrap {
    flex: 1;
    min-width: 0;
}

.choice-text-wrap .form-input {
    width: 100%;
}

.choice-correct-label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}

.choice-correct-label input {
    accent-color: var(--success);
}

.choice-remove-btn {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    min-width: 2rem;
    border-radius: 8px;
    font-size: 0.85rem;
}

.choice-remove-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.choice-add-btn {
    margin-bottom: 1.5rem;
}

.choice-form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    padding: 0.75rem;
    background: var(--gray-50);
    border-radius: 8px;
}

.form-group-inline { flex: 1; }

.form-group-checkboxes ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.form-group-checkboxes li label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    cursor: pointer;
}

.text-muted { color: var(--gray-500); font-size: 0.9rem; }

.admin-table .badge { margin-right: 0.25rem; margin-bottom: 0.25rem; }

.admin-clickable-row {
    cursor: pointer;
    transition: background 0.15s;
}

.admin-clickable-row:hover {
    background: var(--primary-light);
}

.admin-table-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.admin-table-link:hover {
    text-decoration: underline;
}

.test-info-banner {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.875rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.questions-admin-list { display: flex; flex-direction: column; gap: 1rem; }

.question-admin-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.question-admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.question-admin-num {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.question-admin-actions { display: flex; gap: 0.5rem; }
.question-admin-text { font-weight: 500; margin-bottom: 0.75rem; }

.choices-admin-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.choice-correct { color: var(--success); font-weight: 500; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .hero-title { font-size: 1.75rem; }
    .test-grid { grid-template-columns: 1fr; }
    .result-stats { grid-template-columns: 1fr; }
    .result-actions { flex-direction: column; }
    .admin-sidebar { display: none; }
    .admin-content { padding: 1rem; }
    .choice-form-row { flex-direction: column; }
}
