:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --text: #1e293b;
    --muted: #64748b;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --accent: #eaf0f8;
    --danger: #dc2626;
    --warn-bg: #fff6dc;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.app-shell { min-height: 100vh; }

.app-header {
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--primary-dark);
    color: #fff;
    padding: 0 24px;
    height: 56px;
    box-shadow: var(--shadow);
}

.app-header .brand { font-weight: 600; font-size: 16px; }

.app-header nav { display: flex; gap: 6px; }

.app-header nav a {
    color: #dbe4f5;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-weight: 500;
}

.app-header nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.app-header nav a.active { background: rgba(255, 255, 255, .2); color: #fff; }

.app-main { max-width: 1180px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 10px; }

/* ---- toolbar / fields ---- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field.grow { flex: 1; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; }

.control {
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    min-width: 180px;
}
textarea.control { min-width: 320px; resize: vertical; }
.control:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ---- buttons ---- */
.btn {
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
    border-radius: 7px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #f3bcbc; }
.btn.danger:hover { background: #fef2f2; }
.btn.big { padding: 11px 22px; font-size: 15px; }

/* ---- hints ---- */
.hint { color: var(--muted); margin: 14px 0; }
.hint-box {
    background: #f1f5f9;
    border-left: 3px solid var(--primary);
    padding: 8px 12px;
    border-radius: 6px;
    color: #334155;
    margin-bottom: 12px;
    font-size: 13px;
}
.error { color: var(--danger); margin: 8px 0; font-size: 13px; }
.readonly-points {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-dark);
}

/* ---- totals bar ---- */
.totals-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.total-chip {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    min-width: 96px;
    box-shadow: var(--shadow);
}
.total-chip .sec-num { font-size: 11px; color: var(--muted); font-weight: 600; }
.total-chip .sec-val { font-size: 18px; font-weight: 700; }
.total-chip.capped { border-color: #f0c36b; background: var(--warn-bg); }
.total-chip.grand { background: var(--primary); border-color: var(--primary); }
.total-chip.grand .sec-num, .total-chip.grand .sec-val { color: #fff; }

/* ---- grid table ---- */
.grid {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.grid th, .grid td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.grid th { background: #f8fafc; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid td.comment { color: var(--muted); font-size: 13px; }
.grid td.actions { white-space: nowrap; display: flex; gap: 6px; }
.grid .detail { color: var(--muted); font-size: 13px; }
.grid tr.section-row td {
    background: var(--accent);
    font-weight: 600;
    font-style: italic;
    color: #334155;
}
.grid tr.subtotal-row td { font-weight: 600; background: #fafafa; }
.grid tr.grand-row td { font-weight: 700; background: var(--warn-bg); }

/* ---- footer action ---- */
.footer-actions { display: flex; justify-content: flex-end; margin: 8px 0 40px; }

/* ---- modal ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 7vh;
    z-index: 50;
}
.modal {
    background: #fff;
    border-radius: 12px;
    padding: 22px;
    width: 440px;
    max-width: 92vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 86vh;
    overflow-y: auto;
}
.modal.wide { width: 620px; }
.modal h3 { margin: 0; }
.modal .field { gap: 6px; }
.modal .control { width: 100%; min-width: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---- report selection panel ---- */
.select-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 22px;
}
.select-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}
.select-head > div { display: flex; gap: 8px; }
.dept-block { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.dept-block:last-child { border-bottom: none; }
.dept-line { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; }
.teacher-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px 24px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
}
.chip:hover { background: #e2e8f0; }

/* ---- report output ---- */
.report-head { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 16px; }
.export-actions { display: flex; gap: 10px; }
.report-teacher {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 22px;
}
.report-teacher .grid { box-shadow: none; margin-bottom: 14px; }
.signature {
    display: flex;
    align-items: center;
    gap: 20px;
    padding-top: 8px;
    color: #334155;
}
.signature .stamp {
    margin-left: auto;
    border: 1px dashed var(--line-strong);
    border-radius: 50%;
    width: 84px;
    height: 84px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 13px;
}

/* ---- header user box ---- */
.app-header .user-box {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.app-header .user-box .user-name { color: #dbe4f5; font-weight: 500; }
.app-header .user-box form { margin: 0; }

/* ---- login ---- */
.login-card {
    max-width: 360px;
    margin: 8vh auto 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .control { width: 100%; min-width: 0; }
.login-card .btn.big { width: 100%; }

/* ---- sheet (таблица ввода) ---- */
.grid.sheet td { vertical-align: middle; }
.grid.sheet .control { min-width: 0; width: 100%; }
.grid.sheet .control.narrow { width: 90px; }
.grid.sheet .comment-input { width: 100%; }
.grid .hint.small { font-size: 12px; margin: 2px 0 0; }
.cell-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.sheet-actions { align-items: center; gap: 14px; }
.save-msg { color: #047857; font-weight: 600; margin-right: auto; }

/* ---- info "?" + instruction modal ---- */
.wt-title { display: flex; align-items: flex-start; gap: 8px; }
.info-btn {
    flex: 0 0 auto;
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 1px solid var(--primary);
    background: #fff;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    margin-top: 1px;
}
.info-btn:hover { background: var(--primary); color: #fff; }
.instr-text { white-space: pre-line; line-height: 1.5; color: #334155; max-height: 60vh; overflow-y: auto; }

/* ---- file cell ---- */
.grid.sheet .file-cell { font-size: 12px; }
.grid.sheet .file-cell input[type=file] { max-width: 170px; font-size: 12px; }

/* ---- sheet alignment: всё по центру, «Вид работы» — по левому краю ---- */
.grid.sheet th,
.grid.sheet td,
.grid.sheet td.num { text-align: center; }
.grid.sheet td.wt-cell { text-align: left; }
.grid.sheet td.wt-cell .wt-title { justify-content: flex-start; }
.grid.sheet .file-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* ---- "?" внутри плашек подытогов ---- */
.total-chip .sec-val { display: inline-flex; align-items: center; gap: 6px; }
.total-chip .info-btn { width: 16px; height: 16px; font-size: 11px; }
.total-chip.grand .info-btn { border-color: #fff; color: #fff; background: transparent; }
.total-chip.grand .info-btn:hover { background: #fff; color: var(--primary); }

/* ===== Итерация: закрепление шапки, кнопки очистки, «?», файл ===== */

/* прокручиваемая область таблицы: шапка и заголовок раздела остаются видимыми */
.sheet-scroll {
    overflow: auto;
    max-height: calc(100vh - 320px);
    min-height: 260px;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.grid.sheet {
    margin: 0;
    border: none;
    border-collapse: separate;
    border-spacing: 0;
    overflow: visible;
    box-shadow: none;
}
.grid.sheet thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #eef2f8;
    border-bottom: 1px solid var(--line);
}
.grid.sheet tbody tr.section-row td {
    position: sticky;
    top: 33px;              /* высота строки шапки */
    z-index: 2;
    background: #e8eef7;
    border-bottom: 1px solid var(--line);
}

/* тулбар: кнопки действий справа, всегда видимы (над прокруткой) */
.toolbar .grow { flex: 1 1 auto; }
.toolbar-actions { justify-content: flex-end; align-items: center; gap: 12px; }

/* «Очистить таблицу» рядом с баллами */
.totals-bar { align-items: center; }
.clear-all { margin-left: 12px; }

/* «Очистить раздел» у заголовка раздела */
.section-row .clear-sec { margin-left: 14px; }
.section-row .sec-title-text { font-weight: 700; }

/* «?» — аккуратный кружок с центрированным знаком */
.grid.sheet td.wt-cell .wt-title { align-items: center; }
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

/* столбец «Файл»: возвращаем нормальную ячейку таблицы, содержимое — в блоке */
.grid.sheet td.file-cell { display: table-cell; text-align: center; vertical-align: middle; }
.file-box { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; }
.file-box input[type=file] { max-width: 165px; font-size: 12px; }
.file-link {
    max-width: 165px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

/* ---- статусы заполнения в отчётах ---- */
.status-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--muted);
    padding: 6px 2px 12px;
    border-bottom: 1px dashed var(--line);
    margin-bottom: 12px;
}
.status-legend .lg { font-weight: 600; }
.lg-done, .chip.status-done { color: #15803d; }      /* зелёный */
.lg-partial, .chip.status-partial { color: #ca8a04; } /* жёлтый */
.lg-empty, .chip.status-empty { color: #dc2626; }    /* красный */
.chip.status-done, .chip.status-partial, .chip.status-empty { font-weight: 600; }

/* ---- несколько файлов на строку ---- */
.file-box { align-items: stretch; }
.file-item { display: flex; align-items: center; gap: 4px; justify-content: center; }
.file-item .file-link { max-width: 140px; }
.file-x {
    border: none;
    background: none;
    color: #dc2626;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.file-x:hover { color: #991b1b; }

/* кнопка «Заполнено» в отмеченном состоянии */
.btn.success { background: #15803d; border-color: #15803d; color: #fff; }
.btn.success:hover { background: #166534; }

/* ---- стабильные кнопки в тулбаре ---- */
.toolbar-actions { display: flex; }
.btn-complete { min-width: 150px; justify-content: center; text-align: center; }

/* ---- индикатор выполнения ---- */
.busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(248, 250, 252, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.busy-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: 600;
    color: #334155;
}
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #cbd5e1;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
