:root {
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-border: #d9e0e7;
    --app-text: #1f2933;
    --app-muted: #697586;
    --app-primary: #2663eb;
    --app-primary-dark: #1e4fc2;
    --app-success: #15803d;
    --app-success-soft: #e9f8ef;
    --app-danger: #b42318;
    --app-danger-soft: #fff0ed;
    --app-warning: #b7791f;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
}

.auth-panel {
    display: grid;
    width: min(920px, 100%);
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 28px;
    align-items: center;
}

.auth-brand h1 {
    margin: 14px 0 6px;
    font-size: clamp(2rem, 7vw, 4rem);
    font-weight: 850;
}

.auth-card {
    border-color: var(--app-border);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.app-shell {
    min-height: 100vh;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    width: 270px;
    max-width: calc(100vw - 3rem);
    height: 100svh;
    min-height: 100dvh;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1rem;
    overflow-y: auto;
    border-right: 1px solid rgba(226, 232, 240, 0.85);
    background: #ffffff;
    color: var(--app-text);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

.app-sidebar.open {
    transform: translateX(0);
    box-shadow: 18px 0 55px rgba(15, 23, 42, 0.12);
}

body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1030;
    background: rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(2px);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--app-text);
    font-size: 1.05rem;
    font-weight: 750;
    text-decoration: none;
}

.app-sidebar .nav-link {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.7rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    font-size: 0.94rem;
    font-weight: 650;
    text-align: left;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    background: rgba(38, 99, 235, 0.1);
    color: var(--app-primary-dark);
}

.sidebar-note {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--app-border);
}

.sidebar-note strong,
.sidebar-note small {
    display: block;
}

.sidebar-note small {
    color: var(--app-muted);
}

.sidebar-user {
    display: flex;
    margin-top: auto;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 1rem;
    border-top: 1px solid var(--app-border);
}

.sidebar-user > div {
    min-width: 0;
}

.sidebar-user strong,
.sidebar-user small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user small {
    color: var(--app-muted);
}

.sidebar-user .btn {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    padding: 0;
}

.sidebar-user-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
}

.user-settings-profile {
    display: grid;
    gap: 2px;
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: #f9fbfd;
}

.user-settings-profile strong,
.user-settings-profile span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-settings-profile span {
    color: var(--app-muted);
    font-size: 0.84rem;
}

.settings-alert {
    margin-bottom: 14px;
}

.header-menu-btn {
    display: inline-flex;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(203, 213, 225, 0.82);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: #0f172a;
    box-shadow: 0 0.18rem 0.55rem rgba(15, 23, 42, 0.08);
}

.header-menu-btn i {
    font-size: 1.25rem;
}

.header-menu-btn:hover,
.header-menu-btn:focus-visible {
    border-color: rgba(38, 99, 235, 0.35);
    background: #ffffff;
    color: var(--app-primary);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid var(--app-border);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
}

.app-header .container-fluid,
.app-main .container-fluid {
    max-width: 1180px;
}

.app-header .container-fluid {
    padding: 12px 18px;
}

.app-main {
    padding: 18px 0 28px;
}

.brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.brand > div:not(.practice-type-chip) {
    min-width: 0;
}

.brand-mark {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 8px;
    background: #172033;
    color: #f8fafc;
    font-size: 1.2rem;
}

.brand-title {
    font-size: 1.05rem;
    font-weight: 750;
    line-height: 1.15;
}

.brand-subtitle {
    color: var(--app-muted);
    font-size: 0.82rem;
}

.header-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.quiz-view {
    display: grid;
    gap: 14px;
}

.dashboard-view {
    display: grid;
    gap: 14px;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.7fr);
    gap: 14px;
    align-items: start;
}

.panel-section {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: var(--app-surface);
}

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

.section-heading h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
}

.section-heading .btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.test-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
    gap: 8px;
    max-height: 510px;
    overflow: auto;
    padding-right: 2px;
}

.test-tile {
    display: grid;
    min-height: 116px;
    gap: 8px;
    align-content: start;
    padding: 11px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--app-text);
    text-align: left;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.045);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.test-tile:hover {
    border-color: #91a7d8;
    box-shadow: 0 10px 22px rgba(31, 41, 51, 0.1);
    transform: translateY(-1px);
}

.test-tile.is-done {
    border-color: #98d7ad;
    background: var(--app-success-soft);
}

.test-tile.is-done .test-code,
.test-tile.is-done .test-mini-progress span {
    background: var(--app-success);
}

.test-tile.is-progress {
    border-color: #f3ce8f;
    background: #fff8ea;
}

.test-tile.is-progress .test-code,
.test-tile.is-progress .test-mini-progress span {
    background: var(--app-warning);
}

.test-tile-main {
    display: flex;
    min-width: 0;
    align-items: center;
}

.test-code {
    display: inline-flex;
    min-width: 52px;
    height: 34px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 8px;
    background: var(--app-primary);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
}

.test-code i {
    font-size: 0.78rem;
}

.test-status {
    width: fit-content;
    padding: 3px 7px;
    border-radius: 999px;
    background: #eef2f7;
    color: var(--app-muted);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
}

.test-status.is-completed {
    background: var(--app-success-soft);
    color: var(--app-success);
}

.test-status.is-progress {
    background: #fff0cf;
    color: var(--app-warning);
}

.test-detail {
    color: var(--app-muted);
    font-size: 0.78rem;
    line-height: 1.15;
}

.test-mini-progress {
    display: block;
    width: 100%;
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: #e6ebf0;
}

.test-mini-progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--app-primary);
}

.recent-list {
    display: grid;
    gap: 8px;
}

.recent-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid #e7edf4;
    border-radius: 8px;
}

.recent-item strong,
.recent-item span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-item span,
.muted-line {
    color: var(--app-muted);
    font-size: 0.84rem;
}

.recent-score {
    font-weight: 800;
}

.quiz-toolbar {
    display: grid;
    gap: 12px;
}

.toolbar-summary {
    display: flex;
    align-items: center;
}

.filter-toggle-btn {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    font-weight: 800;
}

#filterToggleLabel {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-toggle-btn:hover,
.filter-toggle-btn:focus-visible {
    border-color: #91a7d8;
    color: var(--app-primary-dark);
}

.toolbar-filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr);
    gap: 10px;
}

.toolbar-filters:not(.is-open) {
    display: none;
}

.topic-filters {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.topic-filters .btn {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.practice-type-chip {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    font-weight: 800;
    white-space: nowrap;
}

.brand .practice-type-chip {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 0.84rem;
}

.practice-type-chip.is-topic {
    border-color: #b8d7c7;
    background: #effaf3;
    color: var(--app-success);
}

.practice-type-chip.is-test {
    border-color: #b9c8ef;
    background: #f2f6ff;
    color: var(--app-primary-dark);
}

.toolbar-field .form-label {
    margin-bottom: 6px;
    color: var(--app-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

.toolbar-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(86px, 1fr));
    gap: 8px;
}

.stat-box {
    min-height: 58px;
    padding: 8px 12px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: var(--app-surface);
}

.stat-box span {
    display: block;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.1;
}

.stat-box small {
    color: var(--app-muted);
    font-size: 0.78rem;
}

.stat-ok span {
    color: var(--app-success);
}

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

.quiz-progress {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.progress {
    height: 10px;
    border-radius: 999px;
    background: #e6ebf0;
}

.progress-bar {
    background: var(--app-primary);
}

.progress-label {
    min-width: 54px;
    color: var(--app-muted);
    font-size: 0.86rem;
    text-align: right;
}

.question-panel,
.empty-state {
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: var(--app-surface);
}

.question-panel {
    display: grid;
    gap: 16px;
    padding: 18px;
}

.question-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.question-meta .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.question-status-badge {
    display: inline-flex;
    min-height: 24px;
    align-items: center;
    padding: 3px 9px;
    border: 1px solid var(--app-border);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
}

.question-status-badge.is-pending {
    background: #eef2f7;
    color: #475569;
}

.question-status-badge.is-correct {
    border-color: #91d5a8;
    background: var(--app-success-soft);
    color: var(--app-success);
}

.question-status-badge.is-wrong {
    border-color: #f2a39b;
    background: var(--app-danger-soft);
    color: var(--app-danger);
}

.question-title {
    margin: 0;
    font-size: clamp(1.18rem, 2.4vw, 1.65rem);
    font-weight: 780;
    line-height: 1.25;
}

.question-title p,
.answer-text p,
.feedback-body p {
    margin: 0;
}

.question-media {
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 10px;
    border: 1px solid #e7edf4;
    border-radius: 8px;
    background: #f9fbfd;
}

.question-media img {
    display: block;
    max-width: 100%;
    max-height: 360px;
    object-fit: contain;
}

.answers-list {
    display: grid;
    gap: 10px;
}

.answer-option {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    width: 100%;
    min-height: 58px;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--app-text);
    text-align: left;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.answer-option:not(:disabled):hover {
    border-color: #91a7d8;
    box-shadow: 0 8px 20px rgba(31, 41, 51, 0.08);
    transform: translateY(-1px);
}

.answer-option:disabled {
    opacity: 1;
}

.answer-label {
    display: grid;
    min-height: 58px;
    place-items: center;
    background: #eef2f7;
    color: #344054;
    font-weight: 800;
}

.answer-text {
    align-self: center;
    padding: 12px 14px;
    line-height: 1.35;
}

.answer-option.is-correct {
    border-color: #6fcf91;
    background: var(--app-success-soft);
}

.answer-option.is-correct .answer-label {
    background: var(--app-success);
    color: #ffffff;
}

.answer-option.is-wrong {
    border-color: #f2a39b;
    background: var(--app-danger-soft);
}

.answer-option.is-wrong .answer-label {
    background: var(--app-danger);
    color: #ffffff;
}

.answer-feedback {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 8px;
    line-height: 1.4;
}

.answer-feedback.is-correct {
    border: 1px solid #91d5a8;
    background: var(--app-success-soft);
}

.answer-feedback.is-wrong {
    border: 1px solid #f2a39b;
    background: var(--app-danger-soft);
}

.feedback-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.answer-feedback.is-correct .feedback-title {
    color: var(--app-success);
}

.answer-feedback.is-wrong .feedback-title {
    color: var(--app-danger);
}

.explanation-modal-body {
    line-height: 1.45;
}

.explanation-modal-body p:last-child,
.explanation-modal-body ul:last-child {
    margin-bottom: 0;
}

.video-frame {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 8px;
    background: #111827;
    aspect-ratio: 16 / 9;
}

.video-frame iframe,
.video-frame video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.quiz-navigation {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}

.quiz-navigation .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 120px;
}

.question-pager {
    display: grid;
    grid-template-columns: minmax(150px, 230px) auto;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.question-pager span {
    min-width: 52px;
    color: var(--app-muted);
    font-weight: 750;
    text-align: right;
}

.empty-state {
    display: grid;
    min-height: 280px;
    place-items: center;
    padding: 28px;
    color: var(--app-muted);
    text-align: center;
}

.empty-state i {
    color: var(--app-warning);
    font-size: 2rem;
}

.empty-state p {
    margin: 8px 0 0;
    font-weight: 650;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.58);
    backdrop-filter: blur(2px);
}

.loading-car {
    display: grid;
    width: min(180px, calc(100vw - 48px));
    justify-items: center;
    gap: 10px;
    padding: 16px 18px;
    border: 1px solid rgba(217, 224, 231, 0.85);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.12);
}

.loading-car-road {
    position: relative;
    width: 136px;
    height: 48px;
    overflow: hidden;
}

.loading-car-road::before {
    content: "";
    position: absolute;
    right: 0;
    bottom: 4px;
    left: 0;
    height: 4px;
    border-radius: 999px;
    background: #d9e0e7;
}

.loading-car-road span {
    position: absolute;
    right: 0;
    bottom: 5px;
    left: 0;
    height: 2px;
    background: repeating-linear-gradient(90deg, transparent 0 14px, #ffffff 14px 28px);
    animation: roadMove 0.7s linear infinite;
}

.loading-car-body {
    position: absolute;
    top: 3px;
    left: 25px;
    width: 86px;
    height: 38px;
    animation: carBounce 0.72s ease-in-out infinite;
}

.loading-car-top {
    position: absolute;
    top: 2px;
    left: 21px;
    width: 40px;
    height: 18px;
    border-radius: 8px 11px 3px 3px;
    background: var(--app-primary-dark);
}

.loading-car-base {
    position: absolute;
    right: 4px;
    bottom: 9px;
    left: 4px;
    height: 20px;
    border-radius: 10px 13px 7px 7px;
    background: var(--app-primary);
}

.loading-car-base::before,
.loading-car-base::after {
    content: "";
    position: absolute;
    top: 6px;
    width: 8px;
    height: 5px;
    border-radius: 999px;
    background: #eaf1ff;
}

.loading-car-base::before {
    left: 8px;
}

.loading-car-base::after {
    right: 8px;
}

.loading-car-wheel {
    position: absolute;
    bottom: 3px;
    width: 13px;
    height: 13px;
    border: 3px solid #111827;
    border-radius: 50%;
    background: #ffffff;
    animation: wheelSpin 0.5s linear infinite;
}

.loading-car-wheel-left {
    left: 16px;
}

.loading-car-wheel-right {
    right: 16px;
}

.loading-car-text {
    color: var(--app-muted);
    font-size: 0.8rem;
    font-weight: 800;
}

@keyframes roadMove {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-28px);
    }
}

@keyframes carBounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

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

@media (prefers-reduced-motion: reduce) {
    .loading-car-road span,
    .loading-car-body,
    .loading-car-wheel {
        animation: none;
    }
}

@media (max-width: 760px) {
    .auth-panel {
        grid-template-columns: 1fr;
    }

    .auth-brand {
        text-align: center;
    }

    .app-header .container-fluid,
    .app-main .container-fluid {
        padding-right: 12px;
        padding-left: 12px;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
    }

    .brand-subtitle,
    .header-actions span {
        display: none;
    }

    .quiz-toolbar {
        grid-template-columns: 1fr;
    }

    .toolbar-summary {
        display: grid;
        grid-template-columns: 1fr;
    }

    .filter-toggle-btn {
        width: 100%;
        justify-content: space-between;
    }

    .topic-filters {
        grid-template-columns: 1fr;
    }

    .practice-type-chip {
        justify-content: flex-start;
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .test-grid {
        max-height: none;
        grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    }

    .toolbar-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stat-box {
        min-width: 0;
        padding: 8px;
    }

    .stat-box small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .question-panel {
        padding: 14px;
    }

    .question-meta .btn {
        width: 100%;
        justify-content: center;
        margin-left: 0 !important;
    }

    .question-media img {
        max-height: 260px;
    }

    .quiz-navigation {
        grid-template-columns: 1fr 1fr;
    }

    .question-pager {
        grid-column: 1 / -1;
        grid-row: 1;
        grid-template-columns: minmax(0, 1fr) auto;
        justify-content: stretch;
    }

    .quiz-navigation .btn {
        min-width: 0;
    }
}

@media (max-width: 420px) {
    .answer-option {
        grid-template-columns: 36px minmax(0, 1fr);
    }

    .answer-label {
        min-height: 54px;
    }

    .answer-text {
        padding: 10px 12px;
    }
}
