:root {
    --ink: #172033;
    --muted: #687187;
    --line: #e5e8ef;
    --surface: #ffffff;
    --soft: #f5f7fb;
    --accent: #3157d5;
    --accent-dark: #2445b5;
    --success: #19966d;
    --danger: #c53b4a;
    --shadow: 0 16px 44px rgba(26, 37, 64, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { height: 100%; }
body {
    color: var(--ink);
    background: var(--soft);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
}
body.page-course {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100vh;
    overflow: hidden;
}
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.03em; }
h2 { margin-bottom: 8px; }
small { color: var(--muted); }

.topbar {
    position: relative;
    z-index: 30;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(160px, 240px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    min-height: 64px;
    padding: 0 20px 0 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.98);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; width: fit-content; }
.brand-mark, .auth-logo {
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--accent);
    font-weight: 800;
    letter-spacing: -.08em;
}
.brand-mark { width: 38px; height: 38px; border-radius: 11px; font-size: 16px; flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text small { margin-top: 2px; font-size: 11px; }
.topbar-center { min-width: 0; }
.topbar-doc {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    padding: 6px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--soft);
}
.topbar-doc-main { display: grid; gap: 2px; min-width: 0; }
.topbar-doc-section {
    color: var(--accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.topbar-doc-title {
    overflow: hidden;
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-doc-progress {
    display: grid;
    flex: 0 0 auto;
    text-align: right;
}
.topbar-doc-progress strong {
    color: var(--accent);
    font-size: 16px;
    line-height: 1.1;
}
.topbar-doc-progress small { font-size: 10px; }
.topbar-page-title {
    font-size: 16px;
    font-weight: 750;
    letter-spacing: -.02em;
}
.user-menu {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    font-weight: 600;
}
.user-name { color: var(--muted); font-size: 13px; }
.burger-wrap { position: relative; }
.burger-button {
    display: grid;
    width: 40px;
    height: 40px;
    place-content: center;
    gap: 5px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}
.burger-button span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 99px;
    background: var(--ink);
}
.burger-wrap.open .burger-button { border-color: #c5cde0; background: var(--soft); }
.burger-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    display: grid;
    min-width: 180px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow);
}
.burger-menu[hidden] { display: none; }
.burger-menu a,
.burger-logout {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    background: none;
    font: inherit;
    font-weight: 650;
    text-align: left;
    cursor: pointer;
}
.burger-menu a:hover,
.burger-logout:hover { background: var(--soft); }
.burger-menu a.active { color: var(--accent); background: #edf1ff; }
.burger-menu form { margin: 0; }
.burger-logout { color: var(--danger); }
.link-button, .link-danger {
    padding: 0;
    border: 0;
    color: var(--muted);
    background: none;
    cursor: pointer;
}
.link-button:hover { color: var(--ink); }
.link-danger { color: var(--danger); }

.flash {
    position: fixed;
    z-index: 100;
    top: 80px;
    left: 50%;
    max-width: min(560px, calc(100% - 32px));
    padding: 12px 18px;
    transform: translateX(-50%);
    border-radius: 10px;
    box-shadow: var(--shadow);
    color: #fff;
}
.flash-success { background: var(--success); }
.flash-error { background: var(--danger); }

.auth-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 32px;
    background:
        radial-gradient(circle at 15% 20%, rgba(49,87,213,.16), transparent 30%),
        radial-gradient(circle at 90% 80%, rgba(25,150,109,.10), transparent 28%),
        #f3f5fa;
}
.auth-card {
    width: min(440px, 100%);
    padding: 42px;
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 24px;
    background: rgba(255,255,255,.95);
    box-shadow: var(--shadow);
}
.auth-logo { width: 52px; height: 52px; margin-bottom: 32px; border-radius: 15px; font-size: 21px; }
.eyebrow {
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .11em;
    text-transform: uppercase;
}
.muted { color: var(--muted); line-height: 1.55; }
.form-stack { display: grid; gap: 17px; margin-top: 28px; }
.form-stack label { display: grid; gap: 7px; color: #3f485b; font-size: 13px; font-weight: 650; }
input, select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #d8dce6;
    border-radius: 9px;
    outline: none;
    color: var(--ink);
    background: #fff;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(49,87,213,.10); }
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 17px;
    border: 1px solid #d9dde7;
    border-radius: 9px;
    color: var(--ink);
    background: var(--surface);
    font-weight: 700;
    cursor: pointer;
}
.button-primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-small { min-height: 34px; padding: 6px 11px; font-size: 12px; }

.course-layout {
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: 340px minmax(0, 1fr);
    min-height: 0;
    height: auto;
    overflow: hidden;
}
.course-sidebar {
    display: flex;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--line);
    background: #fff;
}
.sidebar-summary { flex: 0 0 auto; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.sidebar-summary > div:first-child { display: flex; align-items: center; justify-content: space-between; }
.sidebar-summary strong { color: var(--accent); font-size: 21px; }
.sidebar-summary small { display: block; margin-top: 9px; font-size: 11px; }
.progress-track, .table-progress { overflow: hidden; height: 6px; margin-top: 12px; border-radius: 99px; background: #e8ebf2; }
.progress-track span, .table-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.contents-title { flex: 0 0 auto; padding: 14px 22px 8px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.contents { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 0 12px 24px; -webkit-overflow-scrolling: touch; }
.section { margin-top: 6px; }
.section summary {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 10px;
    border-radius: 10px;
    cursor: pointer;
    list-style: none;
}
.section summary::-webkit-details-marker { display: none; }
.section summary:hover { background: var(--soft); }
.section-number {
    display: inline-grid;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 9px;
    color: var(--accent);
    background: #edf1ff;
    font-weight: 800;
}
.section-heading { display: grid; min-width: 0; gap: 3px; }
.section-heading strong { overflow: hidden; font-size: 12px; line-height: 1.25; text-overflow: ellipsis; }
.section-heading small { font-size: 10px; }
.document-list { padding: 2px 0 7px 14px; }
.topic-label { padding: 10px 10px 5px 42px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.document-link {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 7px;
    align-items: start;
    padding: 8px;
    border-radius: 8px;
    color: #596174;
    font-size: 11px;
    line-height: 1.4;
}
.document-link:hover { color: var(--ink); background: var(--soft); }
.document-link.active { color: var(--accent); background: #edf1ff; font-weight: 650; }
.document-link.completed { color: #39765f; }
.document-state { color: #8b93a5; font-size: 9px; font-weight: 800; text-align: center; }
.document-link.completed .document-state { color: var(--success); font-size: 13px; }

.viewer-panel {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: #eef1f6;
}
.viewer-chrome {
    flex: 0 0 auto;
    border-bottom: 1px solid var(--line);
    background: #fff;
}
.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 52px;
    padding: 10px 16px;
    flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.toolbar-nav {
    flex: 1 1 auto;
    justify-content: space-between;
    gap: 10px;
}
.toolbar-zoom { flex: 0 0 auto; }
.page-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--soft);
}
.nav-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 240px;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    transition: border-color .15s ease, background .15s ease;
}
.nav-chip:hover { border-color: #c5cde0; background: #f8f9fc; }
.nav-chip.disabled { opacity: .35; pointer-events: none; }
.nav-chip-next { text-align: right; }
.nav-chip-arrow { flex: 0 0 auto; color: var(--accent); font-weight: 800; }
.nav-chip-text {
    display: grid;
    min-width: 0;
    gap: 1px;
}
.nav-chip-text small {
    overflow: hidden;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-chip-text b {
    overflow: hidden;
    font-size: 11px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.icon-button, .text-button {
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-weight: 800;
    cursor: pointer;
}
.icon-button:disabled { cursor: not-allowed; opacity: .4; }
.page-control { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.page-control input { width: 56px; min-height: 34px; text-align: center; }
.pdf-stage {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
#pdf-canvas { display: none; align-self: flex-start; max-width: none; background: #fff; box-shadow: 0 8px 30px rgba(34,43,68,.18); }
.pdf-loading { display: flex; align-items: center; align-self: center; gap: 10px; margin: auto; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2px solid #d7dce8; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.admin-shell { width: min(1320px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 80px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.stats-grid-four { grid-template-columns: repeat(4, 1fr); }
.stats-grid article { display: grid; gap: 9px; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.stats-grid span { color: var(--muted); font-size: 12px; }
.stats-grid strong { font-size: 25px; }
.panel { margin-bottom: 20px; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: 0 5px 20px rgba(28,38,65,.035); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 14px 16px; color: var(--muted); background: #fafbfc; font-size: 10px; letter-spacing: .05em; text-align: left; text-transform: uppercase; }
td { padding: 15px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
td > strong, td > small { display: block; }
.badge { padding: 5px 8px; border-radius: 99px; color: #4e5b73; background: var(--soft); font-size: 10px; font-weight: 700; }
.table-progress { width: 100px; margin: 0 0 5px; }
.modal { width: min(480px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 17px; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(18,25,40,.48); backdrop-filter: blur(3px); }
.modal .form-stack { margin: 0; padding: 28px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; }
.modal-close { padding: 0; border: 0; color: var(--muted); background: none; font-size: 26px; cursor: pointer; }
.checkbox { display: flex !important; grid-template-columns: 20px 1fr; align-items: center; }
.checkbox input { width: 18px; min-height: 18px; }
.danger-zone { padding: 18px 28px; border-top: 1px solid var(--line); }
.back-link { display: inline-block; margin-bottom: 20px; color: var(--accent); font-weight: 700; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-header > div { display: flex; align-items: center; gap: 12px; }
.panel-header h2 { margin: 0; font-size: 17px; }
.panel-header > div:last-child { display: grid; text-align: right; }
.panel-header > div:last-child strong { color: var(--accent); font-size: 20px; }
.report-list { padding: 0 20px; }
.report-row { display: grid; grid-template-columns: 12px minmax(0,1fr) 100px 90px 55px; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.report-row:last-child { border-bottom: 0; }
.report-row > div { display: grid; gap: 3px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #d9dde6; }
.status-dot.started { background: #e8ab3d; }
.status-dot.done { background: var(--success); }
.empty-state { display: grid; min-height: 50vh; place-content: center; padding: 40px; text-align: center; }
.empty-state .path-hint { margin-top: 14px; }
.empty-state code { display: inline-block; margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: #e8ebf2; color: var(--ink); font-size: 12px; }
.diag-list { margin: 10px auto 0; padding: 0; max-width: 640px; list-style: none; text-align: left; color: var(--muted); font-size: 12px; }
.diag-list li { padding: 4px 0; }
.path-hint { margin: 0 0 18px; color: var(--muted); font-size: 12px; word-break: break-all; }
.flash-inline { margin-bottom: 18px; padding: 14px 16px; border-radius: 10px; color: #fff; }
.flash-inline.flash-error { background: var(--danger); }
.flash-inline small, .flash-inline code { color: rgba(255,255,255,.9); }
.empty-table { padding: 28px 16px !important; color: var(--muted); text-align: center; }

@media (max-width: 1100px) {
    .nav-chip { max-width: 160px; }
    .nav-chip-text small { display: none; }
}

.sidebar-open,
.sidebar-mobile-head,
.sidebar-backdrop {
    display: none;
}

@media (max-width: 900px) {
    body.page-course {
        height: 100%;
        max-height: 100dvh;
        overflow: hidden;
    }
    body.sidebar-drawer-open {
        overflow: hidden;
    }

    .topbar {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        min-height: 56px;
        padding: 6px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    .brand-text,
    .user-name { display: none; }
    .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 14px; }
    .topbar-doc {
        gap: 8px;
        padding: 5px 8px;
        border-radius: 10px;
    }
    .topbar-doc-section { font-size: 9px; }
    .topbar-doc-title { font-size: 11px; }
    .topbar-doc-progress strong { font-size: 13px; }
    .topbar-doc-progress small { display: none; }
    .burger-button { width: 36px; height: 36px; }

    .course-layout {
        position: relative;
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        height: auto;
        min-height: 0;
        overflow: hidden;
    }

    .sidebar-open {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        min-height: 40px;
        margin: 8px 10px 0;
        padding: 0 14px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fff;
        color: var(--accent);
        font-weight: 750;
        cursor: pointer;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 45;
        border: 0;
        background: rgba(18, 25, 40, .45);
    }
    .sidebar-backdrop[hidden] { display: none; }

    .course-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 50;
        display: flex;
        width: min(340px, 88vw);
        height: 100%;
        max-height: 100dvh;
        flex-direction: column;
        border-right: 1px solid var(--line);
        border-bottom: 0;
        background: #fff;
        box-shadow: 12px 0 40px rgba(20, 30, 55, .18);
        transform: translateX(-105%);
        transition: transform .2s ease;
    }
    .course-layout.sidebar-open .course-sidebar {
        transform: translateX(0);
    }
    .sidebar-mobile-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex: 0 0 auto;
        gap: 12px;
        padding: 14px 14px 10px;
        padding-top: max(14px, env(safe-area-inset-top));
        border-bottom: 1px solid var(--line);
    }
    .sidebar-mobile-head strong { font-size: 15px; }
    .sidebar-close {
        width: 36px;
        height: 36px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fff;
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
    }

    .viewer-panel {
        display: flex;
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        flex-direction: column;
        overflow: hidden;
    }
    .viewer-chrome { flex: 0 0 auto; }
    .viewer-toolbar {
        gap: 8px;
        min-height: 0;
        padding: 8px 10px;
    }
    .toolbar-nav {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 6px;
    }
    .nav-chip {
        flex: 0 0 auto;
        max-width: none;
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
        padding: 0 10px;
    }
    .nav-chip-text { display: none; }
    .page-nav {
        flex: 1 1 auto;
        justify-content: center;
        order: 0;
        min-width: 0;
        padding: 3px 6px;
    }
    .page-control { font-size: 11px; gap: 4px; }
    .page-control input { width: 46px; min-height: 32px; }
    .page-label { display: none; }
    .toolbar-zoom {
        width: 100%;
        justify-content: center;
        gap: 10px;
    }
    .pdf-stage {
        flex: 1 1 auto;
        min-height: 0;
        padding: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .stats-grid, .stats-grid-four { grid-template-columns: repeat(2, 1fr); }
    .admin-shell { width: min(100% - 28px, 1320px); }
    .report-row { grid-template-columns: 12px minmax(0,1fr) 70px 45px; }
    .report-row > span:nth-of-type(2) { display: none; }
}

@media (max-width: 600px) {
    .auth-shell { padding: 20px 16px; }
    .auth-card { padding: 24px 18px; border-radius: 18px; }
    .page-header { display: grid; gap: 14px; }
    .stats-grid, .stats-grid-four { grid-template-columns: 1fr; }
    .admin-shell { width: calc(100% - 20px); padding: 24px 0 48px; }
    .panel-header { display: grid; gap: 8px; }
    .panel-header > div:last-child { text-align: left; }
    .table-wrap { margin: 0 -4px; }
    th, td { padding: 12px 10px; }
    .icon-button, .text-button, .nav-chip { min-height: 44px; min-width: 44px; }
    .burger-menu { min-width: 200px; }
    .burger-menu a,
    .burger-logout { min-height: 44px; }
}
