:root {
    --primary: #0369a1;
    --primary-hover: #075985;
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #dbe3ee;
    --ok: #166534;
    --ok-bg: #ecfdf3;
    --alert: #b91c1c;
    --alert-bg: #fef2f2;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.85rem 1.5rem;
    background: #0f172a;
    color: white;
}

.brand { color: white; font-weight: 700; letter-spacing: 0.02em; }
.nav { display: flex; gap: 1rem; }
.nav a { color: #cbd5e1; }
.nav a.active {
    color: #fff;
    text-decoration: underline;
    text-decoration-color: #38bdf8;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.45em;
}
.who { margin-left: auto; display: flex; align-items: center; gap: 0.8rem; color: #e2e8f0; }
.who form { margin: 0; }

.linkish {
    background: none;
    border: none;
    color: #93c5fd;
    cursor: pointer;
    font: inherit;
}
.logout { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0; }
.logout-icon { flex: none; }
.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem; }

.hero, .panel, .login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 1.4rem 1.6rem;
    margin-bottom: 1.2rem;
}

.hero { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.lesson-filters { flex-wrap: wrap; justify-content: flex-end; }
.lesson-filters label { display: grid; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
details.connect-lesson > summary { cursor: pointer; }
details.connect-lesson > summary h2 { display: inline; }
details.connect-lesson[open] > summary { display: block; margin-bottom: 0.8rem; }
.hero h1, .panel h1, .panel h2, .login-card h1 { margin: 0.15rem 0 0.4rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.narrow { max-width: 560px; }

.stack { display: grid; gap: 0.9rem; }
.row { display: flex; gap: 0.6rem; align-items: end; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.split { display: grid; grid-template-columns: 1fr 1.4fr; gap: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.9rem; }

label { display: grid; gap: 0.35rem; font-size: 0.92rem; }
label.check { display: flex; align-items: center; gap: 0.4rem; }

input[type="text"], input[type="password"], input[type="datetime-local"], input[type="number"], select, input[type="file"], textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: white;
}

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font: inherit;
    cursor: pointer;
}

.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.ghost { background: #e2e8f0; color: var(--text); }
.btn.ghost:hover { background: #cbd5e1; }
.btn.danger { background: #b91c1c; }
.btn.danger:hover { background: #991b1b; }

.alert { background: var(--alert-bg); color: var(--alert); padding: 0.7rem 0.9rem; border-radius: 8px; }
.ok, .ok-panel { background: var(--ok-bg); }
.ok { color: var(--ok); padding: 0.7rem 0.9rem; border-radius: 8px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.plain { padding-left: 1.1rem; }

.lesson-card {
    display: block;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fbff;
    color: inherit;
}
.lesson-card:hover { border-color: #7dd3fc; text-decoration: none; }
.lesson-card h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.progress-line { margin: 0 0 0.5rem; }
.bar { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: #0284c7; }

.task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.7rem;
}
.task-stat {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.8rem;
    background: #f8fafc;
}
.task-stat header { font-weight: 600; font-size: 0.92rem; min-height: 2.6em; }
.big { font-size: 1.5rem; margin: 0.3rem 0; }

.badge {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}
.dim { opacity: 0.72; }
.extra-set tr.dim { opacity: 1; }
.extra-set tr.dim > td:not(.extra-name) { opacity: 0.72; }
.extra-set .extra-check { width: 2.2rem; }
.extra-name-label {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary);
}
.extra-name-title {
    display: block;
    margin-top: 0.15rem;
    font-weight: 600;
    color: var(--text);
}
.extra-delete-actions { margin: 0.8rem 0 0; }
.extra-icon { display: none; }
.extra-error, .extra-edited, .extra-context-note { display: block; }
.extra-error-row { display: none; }
.block-regular { margin: 0 0 0.6rem; }
.block-regular summary {
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}
.block-regular-task { margin-top: 0.8rem; }
.block-regular-task p { margin: 0.2rem 0; }
.extra-actions-bar { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.extra-actions form { margin: 0; }
.mob-label { display: none; }

@media (max-width: 800px) {
    body.extra-page { overflow-x: hidden; }
    body.extra-page .page { padding: 0.5rem; max-width: 100%; min-width: 0; }
    body.extra-page .panel,
    body.extra-page .hero { max-width: 100%; min-width: 0; padding: 0.7rem; }
    body.extra-page .table-wrap { max-width: 100%; }
    body.extra-page .extra-set-wrap { overflow-x: hidden; }
    .extra-set {
        table-layout: fixed;
        width: 100%;
    }
    .extra-set th,
    .extra-set td { padding: 0.35rem 0.15rem; }
    .extra-set .extra-name,
    .extra-set .extra-error { overflow-wrap: break-word; }
    .extra-set .extra-check { width: 7%; }
    .extra-set .extra-name-col,
    .extra-set .extra-name { width: 38%; }
    .extra-set .extra-v:nth-child(3),
    .extra-set .extra-level { width: 7%; }
    .extra-set .extra-v:nth-child(4),
    .extra-set .extra-context { width: 8%; }
    .extra-set .extra-v:nth-child(5),
    .extra-set .extra-status { width: 8%; }
    .extra-set .extra-narrow { width: 8%; font-size: 0.78rem; text-align: center; }
    .extra-set .num-pair { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
    .extra-set .num-sep { display: none; }
    .extra-set .extra-actions { width: 8%; }
    .extra-set .desk-label { display: none; }
    .extra-set .mob-label { display: inline; }
    .extra-set .extra-actions-bar { flex-direction: column; align-items: stretch; }
    .extra-set .extra-v {
        height: 7.4rem;
        vertical-align: bottom;
        text-align: center;
    }
    .extra-set .extra-v > span {
        display: inline-block;
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        white-space: nowrap;
        font-size: 0.82rem;
    }
    .extra-set .extra-status-stack {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.35rem;
    }
    .extra-set .extra-context-kind,
    .extra-set .extra-status-kind,
    .extra-set .extra-edited {
        display: inline-block;
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        white-space: nowrap;
        font-size: 0.82rem;
    }
    .extra-set .extra-context-note { font-size: 0.75rem; }
    .extra-set .extra-error { display: none; }
    .extra-set .extra-error-row { display: table-row; }
    .extra-set .extra-error-row td {
        overflow-wrap: break-word;
        font-size: 0.8rem;
        text-align: left;
    }
    .extra-set .extra-icon { display: block; }
    .extra-set .extra-icon-btn {
        position: relative;
        padding: 0.4rem;
        min-width: 0;
    }
    .extra-set .extra-icon-btn span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}
.visibility-form { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; }
.reveal-modes { display: flex; flex-wrap: wrap; gap: 0.45rem 0.9rem; }
.subnav + .visibility-form { margin-top: 0.75rem; }

.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 1rem;
}
.subnav a {
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: var(--text);
}
.subnav a:hover { text-decoration: none; background: #cbd5e1; }
.subnav a.active {
    background: var(--primary);
    color: white;
}

.lesson-share {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.8rem;
}
.lesson-share input {
    flex: 1 1 14rem;
    min-width: 0;
    font: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--text);
}

.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #16a34a;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15);
}

/* minmax(0, 1fr): иначе название в одну строку раздувает колонку по max-content */
.lecture-shell { display: grid; gap: 0.8rem; height: calc(100vh - 7rem); grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
.lecture-meta { display: flex; gap: 1rem; align-items: baseline; justify-content: space-between; }
.lecture-bar { display: flex; gap: 1rem; align-items: baseline; }
.lecture-back { flex: 0 0 auto; }
.lecture-heading { min-width: 0; flex: 1; }
.lecture-heading h1 { margin: 0 0 0.3rem; }
.lecture-heading p { margin: 0; }
.lecture-chip, .lecture-more, .lecture-progress, .lecture-sheet { display: none; }
.lecture-frame {
    width: 100%;
    height: 100%;
    min-height: 70vh;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
}
body.teacher-screen .topbar { display: none; }
body.teacher-screen .page { max-width: none; margin: 0; padding: 0; }
body.teacher-screen .lecture-shell { height: 100vh; gap: 0; }
body.teacher-screen .lecture-meta { display: none; }
body.teacher-screen .lecture-frame { border: none; border-radius: 0; min-height: 100vh; }
.screen-exit {
    position: fixed;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 20;
    background: rgba(15, 23, 42, 0.72);
    color: white;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
}
.screen-exit:hover { color: white; }
.sheet-link { background: none; border: none; color: var(--primary); font: inherit; text-align: left; padding: 0; cursor: pointer; }
.sheet-note { color: var(--muted); }

/* Мобильный вид занятия: конспекту — весь экран, кроме полосы-статуса */
@media (max-width: 800px) {
    body.student-lesson { overflow: hidden; }
    body.student-lesson .topbar { display: none; }
    body.student-lesson .page { max-width: none; margin: 0; padding: 0; }
    body.student-lesson .lecture-shell {
        height: 100vh;
        height: 100dvh;
        gap: 0;
        grid-template-rows: auto auto 1fr;
    }
    body.student-lesson .lecture-bar {
        align-items: center;
        gap: 0.5rem;
        min-height: 46px;
        padding: 0 0.6rem;
        background: #0f172a;
        color: white;
    }
    body.student-lesson .lecture-back { color: white; font-size: 1.15rem; line-height: 1; }
    body.student-lesson .lecture-back-text { display: none; }
    body.student-lesson .lecture-heading h1 {
        margin: 0;
        font-size: 0.95rem;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    body.student-lesson .lecture-heading p { display: none; }
    body.student-lesson .lecture-chip {
        display: inline-block;
        flex: 0 0 auto;
        background: #7c2d12;
        color: #fed7aa;
        border-radius: 999px;
        padding: 0.15rem 0.5rem;
        font-size: 0.78rem;
        font-weight: 700;
        white-space: nowrap;
    }
    body.student-lesson .lecture-chip.done { background: #14532d; color: #bbf7d0; }
    body.student-lesson .lecture-more {
        display: inline-block;
        flex: 0 0 auto;
        background: none;
        border: none;
        color: #cbd5e1;
        font-size: 1.1rem;
        line-height: 1;
        padding: 0.35rem 0.2rem;
        cursor: pointer;
    }
    body.student-lesson .lecture-progress { display: block; height: 3px; background: #1e293b; }
    body.student-lesson .lecture-progress i { display: block; height: 100%; background: #22c55e; transition: width 0.4s; }
    body.student-lesson .lecture-sheet:not([hidden]) {
        display: block;
        position: fixed;
        z-index: 30;
        top: 53px;
        left: 0.5rem;
        right: 0.5rem;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 12px;
        box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
        padding: 0.8rem 0.9rem;
    }
    body.student-lesson .lecture-sheet h2 { margin: 0 0 0.25rem; font-size: 1rem; }
    body.student-lesson .lecture-sheet p { margin: 0 0 0.5rem; font-size: 0.82rem; }
    body.student-lesson .lecture-sheet a,
    body.student-lesson .lecture-sheet .sheet-link { display: block; padding: 0.25rem 0; font-size: 0.92rem; }
    body.student-lesson .lecture-sheet form { margin: 0; }
    body.student-lesson .lecture-frame { border: none; border-radius: 0; min-height: 0; }
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 10% 10%, #e0f2fe, transparent 40%),
        radial-gradient(circle at 90% 80%, #fef3c7, transparent 35%),
        var(--bg);
}
.login-card { width: min(460px, 92vw); }

.checks { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 1rem; }
.heat-wrap h3 { margin: 1rem 0 0.4rem; font-size: 1rem; }
.heat { display: flex; align-items: end; gap: 3px; height: 110px; }
.heat-col { flex: 1; display: flex; flex-direction: column; justify-content: end; align-items: center; height: 100%; }
.heat-col i { display: block; width: 100%; background: #0284c7; border-radius: 3px 3px 0 0; min-height: 4px; }
.heat.dwell .heat-col i { background: #d97706; }
.heat-col span { font-size: 0.65rem; color: var(--muted); }

.task-stat.warn { border-color: #f59e0b; background: #fffbeb; }
.burst-row { background: #fff7ed; }
.dynamics-chart { margin-top: 0.75rem; min-height: 200px; overflow: visible; }
.dynamics-chart svg { width: 100%; height: auto; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; display: block; overflow: visible; }
.dynamics-chart .grid-line { stroke: #cbd5e1; stroke-width: 1; }
.dynamics-chart .axis-line { stroke: #475569; stroke-width: 1.4; }
.dynamics-chart .tick-label { fill: #334155; font-size: 12px; font-family: ui-sans-serif, system-ui, sans-serif; }
.dynamics-chart .axis-title { fill: #64748b; font-size: 12px; font-family: ui-sans-serif, system-ui, sans-serif; }
.dynamics-chart.compact { margin-top: 0.35rem; }
.student-charts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.9rem;
}
.student-chart-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 0.85rem 0.9rem;
    background: #fff;
}
.student-chart-card header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.7rem;
    align-items: baseline;
    margin-bottom: 0.2rem;
    font-weight: 600;
}
.ev-label {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
}
.ok-label { background: #dcfce7; color: #166534; }
.bad-label { background: #fee2e2; color: #991b1b; }
.soft-label { background: #e0f2fe; color: #075985; }

@media (max-width: 800px) {
    .hero, .split, .row { display: grid; }
    .topbar { flex-wrap: wrap; }
    .who { margin-left: 0; }
}

@media (max-width: 640px) {
    .topbar {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "brand who" "nav nav";
        gap: 0.35rem 1rem;
        padding: 0.6rem 1rem 0.7rem;
    }
    .brand { grid-area: brand; }
    .nav { grid-area: nav; flex-wrap: wrap; gap: 0.4rem 1.2rem; }
    .who { grid-area: who; margin-left: 0; }
    .who-name, .logout-text { display: none; }
    .logout {
        justify-content: center;
        width: 40px;
        height: 40px;
        margin: -0.5rem -0.6rem -0.5rem 0;
        padding: 0;
        border-radius: 10px;
    }
    .logout:active { background: rgba(148, 163, 184, 0.18); }
    .page { padding: 1rem; }
    .hero, .panel { padding: 1rem; border-radius: 14px; }
}
