:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f3f4f8;
    --text: #1f2937;
    --border: #e2e5eb;
    --error: #dc2626;
    --success: #16a34a;
    --radius: 10px;
}

* { box-sizing: border-box; }

[data-theme="dark"] {
    --bg: #14161c;
    --text: #e5e7eb;
    --border: #2a2d38;
    --primary-light: #2a2a45;
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .card, [data-theme="dark"] table, [data-theme="dark"] .auth-box,
[data-theme="dark"] .topbar, [data-theme="dark"] .filter-bar { background: #1c1f28; border-color: var(--border); }
[data-theme="dark"] table th { background: #20232d; color: #9ca3af; }
[data-theme="dark"] table tr:hover td { background: #22252f; }
[data-theme="dark"] table td { border-color: #262a35; }
[data-theme="dark"] form input, [data-theme="dark"] form select, [data-theme="dark"] form textarea {
    background: #14161c; color: var(--text); border-color: var(--border);
}
[data-theme="dark"] .btn-secondary { background: #262a35; color: #e5e7eb; }
[data-theme="dark"] .help-text { color: #8b8f9c; }
[data-theme="dark"] pre, [data-theme="dark"] #math-preview { background: #14161c !important; color: var(--text); }

.theme-toggle { background: none; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 0.85rem; color: inherit; }


body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
h1, h2, h3 { letter-spacing: -0.01em; }

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.auth-box {
    background: #fff;
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 380px;
}

.auth-box h1 { font-size: 1.4rem; margin: 0 0 4px; }
.subtitle { color: #6b7280; margin: 0 0 20px; font-size: 0.9rem; }

form label { display: block; margin: 12px 0 4px; font-size: 0.9rem; font-weight: 600; }
form input:not([type="checkbox"]):not([type="radio"]), form select, form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}
form input:not([type="checkbox"]):not([type="radio"]):focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--primary);
}
/* Checkbox/radio qlobal width:100% qaydasından İSTİSNA edilir - əks halda bütün sətri
   tutan nəhəng görünməz qutuya çevrilib yanındakı mətni sıxışdırır (bug idi). */
form input[type="checkbox"], form input[type="radio"] {
    width: auto;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.btn {
    display: inline-block;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; margin-top: 18px; }
.btn-primary:hover { background: var(--primary-dark); }

.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 0.9rem; }
.alert-error { background: #fee2e2; color: var(--error); }
.alert-success { background: #dcfce7; color: var(--success); }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    padding: 16px 28px;
    box-shadow: 0 1px 3px rgba(16,24,40,0.06);
    flex-wrap: wrap;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar a { color: var(--primary); text-decoration: none; font-weight: 600; }
.topbar-top-row { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topnav { display: flex; gap: 6px; }
.topnav a { color: #111827; font-weight: 500; font-size: 0.9rem; padding: 8px 14px; border-radius: 999px; transition: background .15s, color .15s; }
.topnav a:hover { background: var(--primary-light); color: var(--primary); }
[data-theme="dark"] .topnav a { color: #f3f4f6; }
[data-theme="dark"] .topnav a:hover { color: var(--primary); }
.container { max-width: 1150px; margin: 28px auto; padding: 0 20px 60px; }

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h2 { margin: 0; }

.btn-secondary { background: #e5e7eb; color: #1f2937; }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: #fee2e2; color: var(--error); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }

.filter-bar { background: #fff; padding: 16px; border-radius: var(--radius); margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filter-bar .field { display: flex; flex-direction: column; min-width: 140px; }
.filter-bar label { font-size: 0.8rem; font-weight: 600; margin-bottom: 4px; }
.filter-bar input, .filter-bar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(16,24,40,0.06); }
table th, table td { padding: 13px 14px; text-align: left; border-bottom: 1px solid #f0f1f5; font-size: 0.92rem; }
table th { background: #fafbfc; font-weight: 700; color: #6b7280; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #fafbff; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-easy { background: #dcfce7; color: #15803d; }
.badge-medium { background: #fef9c3; color: #a16207; }
.badge-hard { background: #fee2e2; color: #b91c1c; }
.badge-neutral { background: #e5e7eb; color: #374151; }

.card { background: #fff; padding: 24px; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(16,24,40,0.06); border: 1px solid var(--border); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.option-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.option-row input[type="text"] { flex: 1; }
.actions-row { margin-top: 20px; display: flex; gap: 10px; }
.empty-state { text-align: center; padding: 40px; color: #6b7280; }
.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: var(--radius); background: #fff; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: 0.85rem; }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.help-text { font-size: 0.8rem; color: #6b7280; margin-top: 4px; }

/* --- Mobil naviqasiya (hamburger) --- */
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.2rem;
    padding: 4px 10px;
    cursor: pointer;
    color: inherit;
}

/* --- Mobil uyğunluq (≤768px) --- */
@media (max-width: 768px) {
    .nav-toggle { display: inline-block; }

    .topbar {
        padding: 12px 16px;
        flex-wrap: nowrap;
        justify-content: space-between;
    }
    .topbar-left { gap: 10px; flex-wrap: nowrap; }
    .topbar-left strong { font-size: 0.95rem; }
    .user-info { font-size: 0.82rem; }

    .topnav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #fff;
        flex-direction: column;
        gap: 0;
        padding: 8px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        z-index: 20;
        max-height: 70vh;
        overflow-y: auto;
    }
    [data-theme="dark"] .topnav { background: #1c1f28; }
    .topnav.open { display: flex; }
    .topnav a { padding: 12px 14px; border-radius: 8px; }

    .container { padding: 0 12px 40px; margin: 16px auto; }

    .page-head { flex-direction: column; align-items: stretch; }
    .page-head h2 { font-size: 1.15rem; }
    .page-head > div { display: flex; flex-wrap: wrap; gap: 8px; }
    .page-head .btn, .page-head a.btn { flex: 1; text-align: center; }

    .card { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .field { min-width: 0; width: 100%; }
    .filter-bar input, .filter-bar select { width: 100%; }

    /* Cədvəllər üfüqi sürüşdürülə bilsin. YALNIZ table-ın özünü block edirik,
       daxili thead/tbody/tr-ə TOXUNMURUQ - əks halda sətirlər öz "ayrı cədvəli"nə
       çevrilib sütunlar uyğunsuzlaşır (bug idi, sətirlər üst-üstə düşürdü). */
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .btn-primary { margin-top: 12px; }
    .actions-row { flex-direction: column; }
    .actions-row .btn { width: 100%; text-align: center; }

    .option-row { flex-wrap: wrap; }

    .auth-box { padding: 24px 20px; }
}

@media (max-width: 420px) {
    .topbar-left strong { display: none; }
}
