:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --ink: #17243b;
    --muted: #77849a;
    --line: #e7ecf3;
    --primary: #2456d6;
    --primary-dark: #1947bd;
    --primary-soft: #edf3ff;
    --sidebar: #15233d;
    --sidebar-muted: #9eabc2;
    --success: #16845b;
    --danger: #c94e58;
    --shadow: 0 18px 55px rgba(28, 49, 85, .08);
    --radius: 18px;
    font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
::selection { background: #dce7ff; }

.surface { background: var(--surface); border: 1px solid rgba(224, 231, 242, .9); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.eyebrow { color: #8b98ad; font-size: 10px; font-weight: 800; letter-spacing: .14em; margin-bottom: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(25px, 3vw, 32px); line-height: 1.2; letter-spacing: -.045em; font-weight: 750; }
h2 { margin-bottom: 5px; font-size: 17px; letter-spacing: -.025em; }

/* Кнопки и поля */
.btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 1px solid transparent; border-radius: 11px; padding: 0 16px; font-size: 13px; font-weight: 700; transition: background .15s ease, border-color .15s ease, transform .15s ease; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 7px 16px rgba(36, 86, 214, .15); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { color: #34517f; background: #f4f7fc; border-color: #e6ebf4; }
.btn-secondary:hover, .btn-quiet:hover { background: #eaf0fa; }
.btn-quiet { color: #60718c; background: transparent; border-color: #e8edf5; }
.btn-danger-quiet { color: var(--danger); background: #fff7f7; border-color: #f5e5e6; }
.btn-danger-quiet:hover { background: #ffeded; }
.btn-small { min-height: 33px; border-radius: 8px; padding: 0 11px; font-size: 11px; }
.btn-wide { width: 100%; min-height: 50px; }
.field { min-width: 0; display: flex; flex-direction: column; gap: 7px; color: #53627a; font-size: 12px; font-weight: 650; }
.field span small { color: #9aa5b6; font-size: 11px; font-weight: 500; }
.field input, .field select, .field textarea,
.filter-bar input, .filter-bar select { width: 100%; height: 43px; padding: 0 13px; color: var(--ink); outline: none; border: 1px solid #e3e9f2; border-radius: 10px; background: #fff; font-size: 13px; font-weight: 500; transition: border-color .15s, box-shadow .15s; }
.field textarea { height: auto; min-height: 82px; padding-top: 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .filter-bar input:focus, .filter-bar select:focus { border-color: #7e9ce9; box-shadow: 0 0 0 3px rgba(36, 86, 214, .09); }
.field input::placeholder { color: #aab4c3; font-weight: 400; }
.form-stack { display: flex; flex-direction: column; gap: 17px; }
.alert { padding: 12px 14px; border-radius: 11px; margin: 0 0 17px; font-size: 12px; font-weight: 600; }
.alert-error, .toast-error { color: #a33a45; background: #fff0f0; border: 1px solid #f6dede; }
.alert-success, .toast-success { color: #176c50; background: #edfaf4; border: 1px solid #d6f1e4; }
.alert-warning, .toast-warning { color: #8a6418; background: #fff8e9; border: 1px solid #f4e8c8; }
.toast { width: min(440px, calc(100% - 32px)); position: fixed; z-index: 40; top: 18px; left: 50%; transform: translateX(-50%); padding: 12px 16px; text-align: center; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; font-size: 12px; }

/* Публичная часть */
.public-body { min-height: 100vh; background: radial-gradient(circle at 50% 18%, #e9f0ff 0, #f4f7fb 43%, #f4f7fb 100%); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.login-card { width: min(100%, 420px); padding: 39px 38px 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #1d2b45; font-size: 14px; font-weight: 800; letter-spacing: -.025em; }
.brand-mark { width: 34px; height: 34px; display: inline-grid; place-items: center; flex: 0 0 34px; color: #fff; border-radius: 11px; background: linear-gradient(145deg, #3b70ed, #1b4cc5); font-size: 18px; font-weight: 800; box-shadow: 0 6px 13px rgba(36,86,214,.19); }
.brand-center { display: flex; justify-content: center; margin: 0 auto 37px; }
.login-heading { text-align: center; margin-bottom: 25px; }
.login-heading h1 { font-size: 25px; margin-bottom: 7px; }
.login-heading p { color: var(--muted); margin: 0; font-size: 13px; }
.field-code input { height: 60px; text-align: center; font-size: 23px; font-weight: 700; letter-spacing: .38em; border-color: #dfe6f2; background: #fbfcff; }
.field-code input::placeholder { color: #c6cfdd; letter-spacing: .3em; }
.field-code input:focus { background: #fff; }
.teacher-entry { display: block; width: max-content; margin: 22px auto 0; color: #71809a; font-size: 12px; font-weight: 600; transition: color .15s; }
.teacher-entry:hover { color: var(--primary); }

/* Установка */
.install-body { min-height: 100vh; background: radial-gradient(circle at 50% 12%, #e8efff, #f4f7fb 56%); padding: 34px 16px; }
.install-wrap { width: min(100%, 590px); margin: 0 auto; }
.install-brand { display: flex; align-items: center; justify-content: center; gap: 11px; margin-bottom: 22px; font-weight: 800; font-size: 14px; }
.install-card { padding: 34px; }
.install-card h1 { font-size: 27px; }
.install-card > .muted { margin-bottom: 24px; }
.form-section-title { margin: 9px 0 0; padding-top: 15px; border-top: 1px solid var(--line); font-size: 13px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; color: #586782; font-size: 12px; font-weight: 550; }
.check-row input { width: 16px; height: 16px; accent-color: var(--primary); }
.install-footnote { margin: 14px 8px 0; text-align: center; color: #8b97aa; font-size: 11px; }
.install-warning { padding: 13px; margin: 22px 0 0; border-radius: 10px; background: #fff8e9; color: #86621c; font-size: 12px; }
.success-mark { width: 46px; height: 46px; display: grid; place-items: center; margin-bottom: 18px; color: #fff; background: #1d9b6a; border-radius: 50%; font-size: 23px; font-weight: 800; }

/* Кабинет преподавателя */
.admin-body { min-height: 100vh; background: var(--bg); }
.admin-shell { min-height: 100vh; }
.sidebar { width: 248px; position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; flex-direction: column; padding: 26px 17px 17px; background: var(--sidebar); color: #fff; }
.brand-sidebar { color: #fff; font-size: 15px; padding: 0 8px; }
.sidebar-caption { margin: 43px 11px 14px; color: #687c9d; font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.side-nav { display: flex; flex-direction: column; gap: 5px; }
.nav-link { min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border-radius: 10px; color: var(--sidebar-muted); font-size: 12px; font-weight: 600; transition: background .15s, color .15s; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-link.active { color: #fff; background: #294b84; box-shadow: inset 3px 0 #80a7ff; }
.nav-icon { width: 20px; text-align: center; color: #9db5df; font-size: 18px; line-height: 1; }
.sidebar-bottom { margin-top: auto; padding-top: 17px; border-top: 1px solid rgba(255,255,255,.09); }
.nav-logout { margin-top: 5px; color: #e3a7ac; }
.admin-main { min-height: 100vh; margin-left: 248px; }
.topbar { height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 38px; background: rgba(255,255,255,.84); border-bottom: 1px solid var(--line); }
.topbar-title { color: #44536d; font-size: 12px; font-weight: 650; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: #71809a; font-size: 11px; font-weight: 650; }
.avatar { width: 33px; height: 33px; display: inline-grid; place-items: center; border-radius: 50%; background: #eaf0ff; color: #315bc3; font-size: 13px; font-weight: 800; }
.avatar-large { width: 46px; height: 46px; font-size: 18px; }
.mobile-menu-btn { display: none; }
.content { width: min(100%, 1500px); margin: 0 auto; padding: 34px 38px 56px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 25px; }
.page-intro h1 { margin-bottom: 5px; }
.page-intro p { margin: 0; font-size: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; }
.stat-card { min-height: 142px; display: flex; flex-direction: column; padding: 19px 20px 16px; background: #fff; border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 7px 22px rgba(28,49,85,.035); transition: transform .15s, box-shadow .15s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-label { color: #8190a6; font-size: 11px; font-weight: 650; }
.stat-card strong { margin: 8px 0 9px; font-size: 32px; line-height: 1; letter-spacing: -.05em; }
.stat-foot { display: flex; justify-content: space-between; margin-top: auto; color: #8b98aa; font-size: 10px; }
.stat-foot span { color: var(--primary); font-size: 15px; }

.panel-section, .form-panel { padding: 24px; margin-bottom: 20px; }
.section-heading-row, .panel-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 19px; }
.section-heading-row p, .panel-title p { margin: 0; font-size: 11px; }
.text-link { color: var(--primary); font-size: 11px; font-weight: 700; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; }
.field-grow { flex: 1 1 auto; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; align-items: end; }
.form-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-full { grid-column: 1 / -1; }
.field-button .btn { width: 100%; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 9px; margin-bottom: 18px; }
.filter-bar .field { min-width: 145px; }
.filter-search { flex: 1 1 230px; }
.filter-inline select { height: 39px; min-width: 160px; border: 1px solid var(--line); border-radius: 9px; padding: 0 11px; background: #fff; color: #44536d; outline: none; font-size: 11px; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 11px; }
.data-table th { padding: 12px 13px; text-align: left; color: #8a97aa; background: #f8fafd; border-top: 1px solid #edf1f6; border-bottom: 1px solid #edf1f6; font-size: 9px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.data-table th:first-child { border-radius: 8px 0 0 8px; }
.data-table th:last-child { border-radius: 0 8px 8px 0; }
.data-table td { padding: 13px; color: #52617a; vertical-align: middle; border-bottom: 1px solid #edf1f6; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fcfdff; }
.actions-cell { text-align: right !important; white-space: nowrap; }
.table-edit-form { display: flex; align-items: center; gap: 8px; min-width: 300px; }
.table-edit-form input, .student-edit-form input, .student-edit-form select { min-width: 0; height: 34px; border: 1px solid #e6ebf3; border-radius: 8px; padding: 0 9px; font-size: 11px; color: var(--ink); }
.table-edit-form input { flex: 1 1 auto; }
.student-edit-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 270px; }
.student-edit-form input { flex: 1 1 120px; }
.student-edit-form select { max-width: 110px; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
.inline-action { display: inline-flex; }
.empty-state { padding: 35px 15px !important; text-align: center; color: #9aa5b6 !important; }
.empty-inline { padding: 14px; border-radius: 10px; color: #7e6a3a; background: #fff8e9; font-size: 12px; }
.code-cell { display: inline-flex; align-items: center; gap: 7px; padding: 5px 7px 5px 10px; border-radius: 8px; background: #f2f6ff; color: #244da9; }
.code-cell code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.copy-btn { width: 24px; height: 24px; border: 0; border-radius: 6px; background: #e4edff; color: #315bc3; font-size: 15px; }
.copy-btn:hover { background: #d7e4ff; }
.small-note { margin: 14px 0 0; color: #94a0b1; font-size: 10px; }
.grade-pill { min-width: 27px; height: 27px; display: inline-grid; place-items: center; border-radius: 8px; color: #fff; font-size: 12px; font-weight: 800; }
.grade-5 { background: #24966c; }
.grade-4 { background: #3976d8; }
.grade-3 { background: #d49a37; }
.grade-2 { background: #cf5b62; }

/* Настройки */
.settings-card { max-width: 680px; padding: 25px; }
.settings-account-row { display: flex; align-items: center; gap: 14px; margin-bottom: 23px; }
.settings-account-row h2 { margin-bottom: 4px; }
.settings-account-row p { margin: 0; font-size: 11px; }
.settings-divider { display: flex; align-items: center; gap: 12px; color: #8f9aad; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.settings-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.settings-form { max-width: 460px; }
.settings-actions { padding-top: 4px; }

/* Дневник ученика */
.student-page { width: min(100% - 48px, 1120px); margin: 0 auto; padding-bottom: 45px; }
.student-topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e6ebf3; }
.student-welcome { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding: 36px 0 24px; }
.student-welcome h1 { margin-bottom: 6px; }
.student-welcome p { margin: 0; font-size: 12px; }
.average-card { min-width: 154px; padding: 14px 18px; border: 1px solid #e4eafb; border-radius: 14px; background: #fff; box-shadow: 0 6px 18px rgba(28,49,85,.04); }
.average-card span { display: block; color: #8491a6; font-size: 10px; font-weight: 650; }
.average-card strong { display: block; margin-top: 3px; color: #2456d6; font-size: 27px; letter-spacing: -.05em; }
.subject-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-bottom: 20px; }
.subject-summary { display: flex; flex-direction: column; gap: 5px; min-height: 105px; padding: 15px 17px; background: #fff; border: 1px solid var(--line); border-radius: 13px; transition: border-color .15s, background .15s; }
.subject-summary:hover, .subject-summary.selected { border-color: #a9bef4; background: #f9fbff; }
.subject-summary span { color: #64738a; font-size: 11px; font-weight: 650; }
.subject-summary strong { color: #1b315e; font-size: 22px; line-height: 1.1; letter-spacing: -.04em; }
.subject-summary small { color: #9aa5b6; font-size: 10px; }
.grades-surface { padding: 22px; }
.grades-surface h2 { margin-bottom: 3px; }
.grades-surface .section-heading-row { margin-bottom: 15px; }
.student-grade-table th { text-transform: none; font-size: 10px; letter-spacing: 0; }
.student-grade-table td { font-size: 12px; }
.clear-filter { display: inline-block; margin-top: 12px; color: var(--primary); font-size: 11px; font-weight: 650; }
.student-footer { padding: 23px 0 0; text-align: center; color: #a3adbc; font-size: 10px; }

@media (max-width: 1120px) {
    .sidebar { width: 220px; }
    .admin-main { margin-left: 220px; }
    .content { padding-right: 25px; padding-left: 25px; }
    .topbar { padding: 0 25px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 820px) {
    .sidebar { width: 260px; transform: translateX(-105%); transition: transform .22s ease; box-shadow: 15px 0 35px rgba(15,28,51,.16); }
    .sidebar.is-open { transform: translateX(0); }
    .admin-main { margin-left: 0; }
    .topbar { height: 64px; padding: 0 19px; }
    .mobile-menu-btn { width: 37px; height: 37px; display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
    .mobile-menu-btn span { height: 2px; width: 100%; display: block; border-radius: 4px; background: #51617a; }
    .topbar-title { margin-right: auto; }
    .content { padding: 27px 19px 42px; }
    .page-intro { align-items: flex-start; }
    .form-grid, .form-grid-three { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .field-full { grid-column: 1 / -1; }
    .subject-summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 600px) {
    .login-card { padding: 30px 23px 24px; border-radius: 16px; }
    .brand-center { margin-bottom: 31px; }
    .install-body { padding: 20px 12px; }
    .install-card { padding: 23px 18px; }
    .install-card h1 { font-size: 24px; }
    .content { padding: 22px 13px 35px; }
    .topbar { padding: 0 13px; }
    .topbar-user-label { display: none; }
    .page-intro { display: block; margin-bottom: 18px; }
    .page-intro > .btn, .page-intro .btn { margin-top: 13px; }
    .stats-grid { gap: 9px; grid-template-columns: repeat(2, minmax(0,1fr)); }
    .stat-card { min-height: 119px; padding: 15px; }
    .stat-card strong { font-size: 27px; }
    .panel-section, .form-panel { padding: 17px 14px; margin-bottom: 14px; border-radius: 14px; }
    .section-heading-row, .panel-title { align-items: flex-start; }
    .section-heading-row { flex-wrap: wrap; }
    .inline-form { align-items: stretch; flex-direction: column; }
    .inline-form .btn { width: 100%; }
    .form-grid, .form-grid-three { grid-template-columns: 1fr; gap: 12px; }
    .field-full { grid-column: auto; }
    .filter-bar { align-items: stretch; }
    .filter-bar .field { flex: 1 1 100%; }
    .filter-bar .btn { flex: 1 1 auto; }
    .table-wrap { overflow: visible; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table thead { display: none; }
    .data-table tbody { display: grid; gap: 10px; }
    .data-table tr { overflow: hidden; border: 1px solid #edf1f6; border-radius: 11px; background: #fff; }
    .data-table td { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 9px 11px; border-bottom: 1px solid #f0f3f7; text-align: right; }
    .data-table td:last-child { border-bottom: 0; }
    .data-table td::before { content: attr(data-label); flex: 0 0 82px; color: #93a0b3; text-align: left; font-size: 9px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
    .data-table td.empty-state { display: block; text-align: center; }
    .data-table td.empty-state::before { content: none; }
    .actions-cell { text-align: left !important; }
    .row-actions { flex-wrap: wrap; justify-content: flex-end; }
    .table-edit-form, .student-edit-form { min-width: 0; flex: 1; flex-wrap: wrap; justify-content: flex-end; }
    .table-edit-form input, .student-edit-form input { flex: 1 1 100%; }
    .student-edit-form select { flex: 1 1 100%; max-width: none; }
    .table-edit-form .btn, .student-edit-form .btn { margin-left: auto; }
    .students-table td[data-label="Ученик"] { align-items: flex-start; }
    .code-cell { flex: 0 0 auto; }
    .student-page { width: calc(100% - 28px); }
    .student-topbar { height: 64px; }
    .student-topbar .brand { font-size: 12px; }
    .student-topbar .brand-mark { width: 30px; height: 30px; flex-basis: 30px; }
    .student-welcome { align-items: flex-start; flex-direction: column; padding: 28px 0 19px; }
    .student-welcome h1 { font-size: 25px; }
    .average-card { width: 100%; min-width: 0; display: flex; align-items: center; justify-content: space-between; }
    .average-card strong { margin: 0; }
    .subject-summary-grid { gap: 8px; grid-template-columns: repeat(2, minmax(0,1fr)); }
    .subject-summary { min-height: 91px; padding: 12px; }
    .subject-summary span { font-size: 10px; }
    .subject-summary strong { font-size: 20px; }
    .grades-surface { padding: 16px 12px; }
    .grades-surface .section-heading-row { align-items: flex-start; }
    .filter-inline { width: 100%; }
    .filter-inline select { width: 100%; }
    .student-grade-table td { text-align: right; }
    .settings-card { padding: 18px; }
    .settings-account-row { align-items: flex-start; }
    .settings-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
