:root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --line: #dde3ec;
    --text: #1f2733;
    --muted: #6b7688;
    --brand: #2f6fed;
    --brand-dark: #2454bd;
    --ok: #1d8a4e;
    --err: #d13b3b;
    --warn: #d98411;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 10px 20px;
    background: #1b2433;
    color: #fff;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar .brand a { color: #fff; font-weight: 700; font-size: 17px; text-decoration: none; }
.mainnav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; flex: 1; }
.mainnav a {
    color: #d8e1ef;
    padding: 7px 11px;
    border-radius: 7px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid transparent;
}
.mainnav a:hover { background: #2b374a; border-color: #3d4a60; color: #fff; text-decoration: none; }
.mainnav a.active {
    background: var(--brand);
    border-color: #6f9dff;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .18), inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.mainnav .sep { width: 1px; height: 22px; background: #3a465c; margin: 0 6px; }
.userbox { display: flex; align-items: center; gap: 10px; color: #cdd4e0; }
.userbox a { color: #fff; }
.userbox .link { background: none; border: 0; color: #9fb0c8; cursor: pointer; font-size: 14px; }
.userbox .link:hover { color: #fff; text-decoration: underline; }

.container { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }

h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.ok { background: #e6f6ec; color: var(--ok); border: 1px solid #b8e6c9; }
.alert.err { background: #fdeaea; color: var(--err); border: 1px solid #f3bcbc; }
.alert ul { margin: 0; padding-left: 18px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
table.tbl th, table.tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl th { background: #eef2f8; font-size: 13px; color: #44506b; font-weight: 600; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.cancelled td { color: #a0a7b5; text-decoration: line-through; }

.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
    font: inherit; padding: 7px 9px; border: 1px solid #c6ceda; border-radius: 7px; background: #fff; color: var(--text); min-width: 130px;
}
textarea { min-width: 240px; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd0f7; border-color: var(--brand); }

.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid #c6ceda; background: #fff; color: var(--text); cursor: pointer; font: inherit; }
.btn:hover { background: #f1f4f9; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.danger { color: var(--err); border-color: #f0bcbc; }
.btn.danger:hover { background: #fdeaea; }

form.inline { display: inline; }
.link { background: none; border: none; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.link:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; }
.badge.red { background: #fdeaea; color: var(--err); }
.badge.orange { background: #fdf1e0; color: var(--warn); }
.badge.blue { background: #e7effe; color: var(--brand); }
.badge.green { background: #e6f6ec; color: var(--ok); }
.badge.gray { background: #eef1f6; color: var(--muted); }

.day-block { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.day-block h3 { margin: 0 0 8px; }

.day-sep { display: flex; align-items: center; gap: 12px; margin: 30px 0 4px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.day-sep::before, .day-sep::after { content: ''; height: 1px; background: var(--line); flex: 1; }

.att-grid { width: 100%; border-collapse: collapse; }
.att-grid th, .att-grid td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; }
.att-grid th { background: #eef2f8; font-size: 13px; }
.att-grid .opt { display: inline-flex; align-items: center; gap: 4px; margin-right: 10px; font-size: 13px; }

/* ------- страница отметки посещаемости --------------------------------- */
.page-head { margin-bottom: 14px; }
.page-head h1 { margin-bottom: 8px; }

.head-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.picker-groups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.picker-groups .btn { padding: 6px 12px; }
.chip {
    display: inline-block; padding: 3px 12px; border-radius: 20px; font-size: 13px;
    background: #eef2f8; border: 1px solid #dde3ec; color: #44506b;
}
.chip-strong { background: #1b2433; border-color: #1b2433; color: #fff; font-weight: 600; }

.pair-head {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 4px solid var(--brand);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
}
.pair-head .pair-title { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pair-head .pair-meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.pair-head.is-cancelled { border-left-color: var(--err); }
.pair-head.is-cancelled .pair-title { color: var(--muted); text-decoration: line-through; }

.att-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.att-tools .att-hint { font-size: 13px; }

.att-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }

.att-grid { width: 100%; border-collapse: collapse; }
.att-grid thead th {
    background: #e9eef7;
    color: #3b4761;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    padding: 10px 12px;
    border-bottom: 2px solid #d3dcea;
    text-align: left;
}
.att-grid td { padding: 8px 12px; border-bottom: 1px solid #edf1f7; vertical-align: middle; }
.att-grid tbody tr:nth-child(even) { background: #fafbfe; }
.att-grid tbody tr:hover { background: #f2f6ff; }
.att-grid tbody tr:last-child td { border-bottom: none; }
.att-grid .idx { width: 46px; color: var(--muted); }
.att-grid .name { font-weight: 600; }

.att-row { border-left: 4px solid var(--edge, transparent); }
.att-row.status-present { --edge: #3aa76d; }
.att-row.status-absent { --edge: #d95c5c; }
.att-row.status-late { --edge: #dfa02b; }
.att-row.status-excused { --edge: #4b86f0; }
.att-row.status-empty { --edge: #c3ccdb; }

.status-select {
    min-width: 230px;
    padding: 8px 10px;
    font-weight: 600;
    cursor: pointer;
}
.status-select.status-present { color: #12683f; background: #edfaf3; border-color: #a6e0c0; }
.status-select.status-absent { color: #a52a2a; background: #fdf0f0; border-color: #efb4b4; }
.status-select.status-late { color: #96600a; background: #fdf6e8; border-color: #efd29a; }
.status-select.status-excused { color: #2454bd; background: #eef4ff; border-color: #b6cbf6; }
.status-select.status-empty { color: #6b7688; background: #f6f8fb; border-color: #d5dce7; font-weight: 500; }

.grade-input { width: 78px; min-width: 78px; text-align: center; font-weight: 700; font-size: 15px; }
.note-input { width: 100%; min-width: 160px; }

.save-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 16px;
    box-shadow: 0 -6px 18px rgba(24, 36, 64, .07);
}
.save-summary { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.save-summary .sum b { font-size: 15px; margin-right: 2px; }
.save-summary .sum-present b { color: #12683f; }
.save-summary .sum-absent b { color: #a52a2a; }
.save-summary .sum-late b { color: #96600a; }
.save-summary .sum-excused b { color: #2454bd; }
.save-summary .sum-empty b { color: #6b7688; }

.save-actions { display: flex; align-items: center; gap: 12px; }
.save-state { font-size: 13px; color: var(--muted); }
.save-state.saving { color: var(--warn); }
.save-state.saved { color: var(--ok); }
.save-state.error { color: var(--err); }


.auth-wrap { max-width: 420px; margin: 60px auto; }
.auth-wrap .card { padding: 24px; }
.auth-wrap h1 { text-align: center; }

.footer { text-align: center; color: var(--muted); padding: 16px; font-size: 12px; }

.pagination { display: flex; gap: 6px; list-style: none; padding: 0; flex-wrap: wrap; margin: 0; }
.pagination li span, .pagination li a { display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; line-height: 1.3; }
.pagination li a { text-decoration: none; }
.pagination li a:hover { background: #eef2f8; }
.pagination li.active span { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination li.disabled span { color: #b6bdca; background: #f7f9fc; cursor: default; }
.pagination svg { width: 1em; height: 1em; display: inline-block; vertical-align: -0.1em; }

.pager { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin: 14px 0 4px; }
.pager .pager-info { font-size: 13px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; background: #eef1f6; color: var(--muted); }
.pill.pending { background: #fdf1e0; color: var(--warn); }
.pill.active { background: #e6f6ec; color: var(--ok); }
.pill.blocked { background: #fdeaea; color: var(--err); }

/* ------- журнал посещаемости ------------------------------------------- */
.filters label.chk {
    flex-direction: row;
    align-items: center;
    gap: 7px;
    font-size: 14px;
    color: var(--text);
    padding-bottom: 7px;
}
.filters label.chk input[type=checkbox] { width: 18px; height: 18px; min-width: 0; }

a.chip { background: #e7effe; border-color: #c3d5fb; color: var(--brand); font-weight: 600; }
a.chip:hover { background: #dbe7ff; text-decoration: none; }

.j-legend { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 16px; font-size: 13px; }
.j-leg { padding: 2px 10px; border-radius: 20px; border: 1px solid var(--line); background: #fff; font-weight: 600; }
.j-leg.st-present { background: #edfaf3; border-color: #a6e0c0; color: #12683f; }
.j-leg.st-absent { background: #fdeeee; border-color: #eeb3ae; color: #b3261e; }
.j-leg.st-late { background: #fff7e0; border-color: #ecd39a; color: #a06a00; }
.j-leg.st-excused { background: #eef4ff; border-color: #b6cbf6; color: #2454bd; }
.j-leg-note { color: var(--muted); }

.j-summary { padding: 12px 16px; }
.j-sum-row { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; font-size: 14px; }
.j-sum .t-present, .j-sum .t-absent, .j-sum .t-late, .j-sum .t-excused { font-weight: 700; margin-right: 8px; }

.j-subject { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 26px 0 8px; }
.j-subject h2 { margin: 0; }

.j-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 6px; }

table.j-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
table.j-table th, table.j-table td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    padding: 7px 8px;
    vertical-align: top;
    font-size: 13px;
}
table.j-table th:last-child, table.j-table td:last-child { border-right: 0; }
table.j-table thead th { background: #eef2f8; color: #44506b; font-weight: 600; text-align: center; white-space: nowrap; }

/* первая колонка со студентом закреплена: таблица широкая, листается вбок */
table.j-table th.j-name, table.j-table td.j-name {
    text-align: left;
    white-space: nowrap;
    min-width: 210px;
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 2;
}
table.j-table thead th.j-name { background: #eef2f8; z-index: 3; }
table.j-table .j-name .j-idx { display: inline-block; min-width: 18px; color: var(--muted); font-size: 12px; margin-right: 6px; }

table.j-table th.j-date { min-width: 56px; }
table.j-table th.j-date .j-d { display: block; font-weight: 700; color: var(--text); }
table.j-table th.j-date .j-p { display: block; font-weight: 500; color: var(--muted); }

table.j-table td.j-cell { text-align: center; white-space: nowrap; font-weight: 700; }
table.j-table td.j-cell.st-present { background: #f2fbf6; color: #12683f; }
table.j-table td.j-cell.st-absent { background: #fdeeee; color: #b3261e; }
table.j-table td.j-cell.st-late { background: #fff7e0; color: #a06a00; }
table.j-table td.j-cell.st-excused { background: #f3f7ff; color: #2454bd; }
table.j-table td.j-cell.st-none { color: #b6bdca; font-weight: 400; }
table.j-table .j-grade { font-weight: 700; margin-left: 1px; }

table.j-table td.j-total { min-width: 120px; text-align: left; white-space: nowrap; }
table.j-table td.j-total span, table.j-table td.j-foot span { display: inline-block; margin: 0 6px 2px 0; font-weight: 700; }
table.j-table .j-avg { font-weight: 600; color: var(--muted); }

table.j-table tfoot td { background: #f7f9fc; font-size: 12px; }
table.j-table tbody tr:nth-child(even) td.j-name,
table.j-table tbody tr:nth-child(even) td.j-total { background: #fafbfe; }
table.j-table tbody tr:hover td.j-name,
table.j-table tbody tr:hover td.j-total { background: #f2f6ff; }

.t-present { color: #12683f; }
.t-absent { color: #b3261e; }
.t-late { color: #a06a00; }
.t-excused { color: #2454bd; }

/* полное ФИО — на широком экране, инициалы — на телефоне (см. медиазапросы) */
.nm-short { display: none; }
.j-hint { display: none; }
table.j-table td.j-cell { cursor: pointer; }

/* всплывающая карточка отметки */
.j-pop-back { position: fixed; inset: 0; background: rgba(20, 28, 48, .22); z-index: 60; }
.j-pop {
    position: fixed;
    z-index: 61;
    width: 320px;
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 14px 38px rgba(20, 30, 60, .24);
    padding: 12px 14px;
}
.j-pop-close {
    position: absolute;
    top: 4px;
    right: 6px;
    border: 0;
    background: none;
    padding: 2px 6px;
    font-size: 20px;
    line-height: 1.2;
    color: var(--muted);
    cursor: pointer;
}
.j-pop-close:hover { color: var(--text); }
.j-pop-title { margin: 0 22px 8px 0; font-size: 14px; font-weight: 700; }
.j-pop-row { display: flex; gap: 8px; padding: 4px 0; border-top: 1px solid #eef1f7; font-size: 13px; }
.j-pop-l { flex: 0 0 100px; color: var(--muted); }
.j-pop-v { flex: 1 1 auto; word-break: break-word; }

/* ------- график дежурств ---------------------------------------------- */
.crumbs { margin: 0 0 6px; font-size: 14px; }
.duty-card { padding: 16px 18px; }
.duty-title { margin: 0 0 6px; font-size: 19px; }
.duty-title a { color: inherit; }
.duty-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.duty-meta span { word-break: break-word; }
.duty-actions { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.duty-viewer { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #f4f6fa; }
.duty-viewer iframe { display: block; width: 100%; height: 78vh; min-height: 420px; border: 0; }
.duty-image { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; }

/* --- таблицы графика --------------------------------------------------- */
.plan-docs { margin-top: 28px; }
.duty-plan { padding: 16px 18px; }
.plan-title { margin: 0 0 6px; font-size: 20px; }
.plan-block { margin-top: 14px; }
.plan-h3 { margin: 14px 0 2px; font-size: 16px; }
.plan-sub { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

.plan-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
table.plan-table { width: 100%; min-width: 540px; border-collapse: collapse; }
table.plan-table th, table.plan-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}
table.plan-table th:last-child, table.plan-table td:last-child { border-right: 0; }
table.plan-table tbody tr:last-child th, table.plan-table tbody tr:last-child td { border-bottom: none; }
table.plan-table thead th {
    background: #eef2f8;
    color: #44506b;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}
table.plan-table tbody th.plan-first {
    background: #f7f9fc;
    font-weight: 700;
    white-space: nowrap;
    width: 1%;
}
table.plan-table tbody tr.is-today th,
table.plan-table tbody tr.is-today td { background: #eef6ff; color: #1f4fb8; font-weight: 600; }
table.plan-table tbody tr.is-today th.plan-first { border-left: 3px solid var(--brand); }

/* --- «сегодня дежурят» ------------------------------------------------- */
.today-duty { border-left: 4px solid var(--brand); padding: 14px 16px; }
.today-duty-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.today-duty-row { display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 8px 0; border-top: 1px solid #eef1f7; }
.today-duty-what { font-weight: 700; min-width: 180px; }
.today-duty-who { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 14px; }
.who-item b { color: var(--muted); font-weight: 600; }

/* --- редактор таблиц в админке ---------------------------------------- */
.plan-edit-head { margin-top: 4px; }
.plan-edit-head h2 { margin-bottom: 6px; }
.plan-edit-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.plan-rows { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 13px; min-height: 150px; }
.plan-edit .row { margin-bottom: 0; }

@media print {
    .j-pop, .j-pop-back { display: none !important; }
}

@media print {
    .topbar, .footer, .filters, .no-print { display: none !important; }
    body { background: #fff; font-size: 12px; }
    .container { max-width: none; padding: 0; }
    .card { border-color: #ccc; }
    .j-scroll { overflow: visible; }
    table.j-table { border-color: #999; }
    table.j-table th, table.j-table td { border-color: #bbb; }
    table.j-table th.j-name, table.j-table td.j-name { position: static; }
    table.j-table thead th { border-color: #999; }
    .j-subject { margin-top: 16px; page-break-after: avoid; }
}

/* ===== телефон и другие узкие экраны ================================== */
@media (max-width: 720px) {
    body { font-size: 14px; }
    .container { padding: 14px 12px 48px; }
    h1 { font-size: 20px; }
    h2 { font-size: 17px; margin: 18px 0 8px; }

    /* --- шапка: меню прокручивается вбок одной строкой --- */
    .topbar { padding: 8px 12px; gap: 8px 10px; }
    .topbar .brand { flex: 1 1 auto; }
    .topbar .brand a { font-size: 16px; }
    .userbox { order: 2; font-size: 14px; }
    .mainnav {
        order: 3;
        flex: 0 0 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 2px;
        padding-bottom: 2px;
        scrollbar-width: none;
    }
    .mainnav::-webkit-scrollbar { display: none; }
    .mainnav a { padding: 6px 10px; font-size: 14px; }
    .mainnav .sep { flex: 0 0 1px; margin: 0 4px; }

    /* --- фильтры: в столбик, во всю ширину --- */
    .filters { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; }
    .filters > label { width: 100%; }
    .filters > div { display: flex; gap: 8px; flex-wrap: wrap; }
    .filters > div .btn { flex: 1 1 40%; text-align: center; }
    .filters input, .filters select { width: 100%; }

    /* --- поля: 16px, иначе iPhone увеличивает страницу при вводе --- */
    input[type=text], input[type=email], input[type=password], input[type=date],
    input[type=number], select, textarea { font-size: 16px; min-width: 0; }
    .field input, .field select, .field textarea, .card textarea { width: 100%; min-width: 0; }
    textarea { min-width: 0; }

    /* --- блоки --- */
    .card { padding: 14px; }
    .day-block { background: none; border: 0; padding: 0; margin-bottom: 16px; }
    .day-block h3 {
        background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
        padding: 8px 12px; margin-bottom: 8px;
    }
    .pair-head { padding: 10px 12px; }
    .pair-head .pair-title { font-size: 16px; }
    .day-sep { margin: 20px 0 4px; }
    .auth-wrap { margin: 20px auto; }
    .auth-wrap .card { padding: 18px; }

    /* --- широкие таблицы прокручиваются вбок --- */
    table.tbl:not(.cards) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* --- журнал посещаемости --- */
    .j-legend { font-size: 12px; gap: 6px 8px; }
    .j-legend .j-leg-note { flex: 1 1 100%; }
    .j-summary { padding: 10px 12px; }
    .j-sum-row { gap: 6px 14px; font-size: 13px; }
    .j-sum-row .btn { flex: 1 1 auto; }
    .j-subject { margin: 20px 0 6px; gap: 6px; }
    .j-subject h2 { font-size: 16px; }
    .j-hint { display: block; margin: 0 0 10px; font-size: 13px; }
    table.j-table th, table.j-table td { padding: 5px 6px; font-size: 12px; }
    /* на узком экране показываем «Баранов И. Ю.» вместо полного ФИО */
    .nm-full { display: none; }
    .nm-short { display: inline; }
    table.j-table th.j-name, table.j-table td.j-name { min-width: 104px; }
    table.j-table .j-name .j-idx { min-width: 13px; margin-right: 4px; }
    table.j-table th.j-date { min-width: 44px; }
    table.j-table td.j-total { min-width: 92px; font-size: 11px; }
    table.j-table td.j-total span, table.j-table td.j-foot span { margin: 0 4px 1px 0; }
    .j-pop { width: calc(100vw - 20px); padding: 11px 13px; }
    .j-pop-l { flex: 0 0 84px; }
    .j-pop-row { font-size: 14px; }

    /* --- расписание: каждая пара — карточка --- */
    table.tbl.cards { display: block; background: none; border: 0; border-radius: 0; }
    table.tbl.cards thead { display: none; }
    table.tbl.cards tbody { display: block; }
    table.tbl.cards tr {
        position: relative;
        display: block;
        background: var(--panel);
        border: 1px solid var(--line);
        border-left: 4px solid var(--brand);
        border-radius: 10px;
        padding: 9px 12px;
        margin-bottom: 10px;
    }
    table.tbl.cards tr.cancelled { border-left-color: var(--err); }
    table.tbl.cards tr.empty { border-left-color: var(--line); background: #f8fafc; }
    table.tbl.cards td { display: block; width: auto; border: 0; padding: 2px 0; }
    table.tbl.cards td[data-label]::before { content: attr(data-label) ': '; color: var(--muted); font-size: 12px; }
    table.tbl.cards td.subject,
    table.tbl.cards td.sub-date { font-weight: 600; font-size: 15px; padding-bottom: 4px; }
    table.tbl.cards td.pair-no { position: absolute; top: 9px; right: 12px; font-weight: 700; color: var(--muted); }
    table.tbl.cards td.act { padding-top: 8px; }
    table.tbl.cards td.act .btn { display: block; text-align: center; }

    /* --- посещаемость: каждый студент — карточка --- */
    .att-card { border: 0; background: none; border-radius: 0; }
    .att-grid thead { display: none; }
    .att-grid, .att-grid tbody { display: block; }
    .att-grid tbody tr:nth-child(even) { background: var(--panel); }
    .att-grid tbody tr:hover { background: var(--panel); }
    .att-grid tr.att-row {
        position: relative;
        display: block;
        background: var(--panel);
        border: 1px solid var(--line);
        border-left: 4px solid var(--edge, var(--line));
        border-radius: 10px;
        padding: 10px 40px 10px 12px;
        margin-bottom: 10px;
    }
    .att-grid td { display: block; border: 0; padding: 3px 0; }
    .att-grid .idx { position: absolute; top: 10px; right: 12px; width: auto; font-size: 12px; }
    .att-grid .name { padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
    .att-grid td.status-cell, .att-grid td.grade-cell, .att-grid td.note-cell { display: flex; align-items: center; gap: 8px; }
    .att-grid td.status-cell::before,
    .att-grid td.grade-cell::before,
    .att-grid td.note-cell::before { content: attr(data-label) ': '; flex: 0 0 84px; color: var(--muted); font-size: 12px; }
    .att-grid td.status-cell .status-select { flex: 1 1 auto; width: auto; }
    .att-grid td.grade-cell .grade-input { flex: 0 0 92px; }
    .att-grid td.note-cell .note-input { flex: 1 1 auto; width: auto; min-width: 0; }
    .status-select { min-width: 0; width: 100%; padding: 9px 10px; }

    .att-tools { gap: 6px; }
    .att-tools .btn { flex: 1 1 45%; text-align: center; }
    .att-tools .att-hint { flex: 1 1 100%; }

    .save-bar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
    .save-summary { gap: 4px 12px; font-size: 12px; }
    .save-actions { gap: 10px; }
    .save-actions .btn { flex: 1 1 auto; text-align: center; }

    /* --- пагинация: постраничные кнопки крупнее, чтобы попадать пальцем --- */
    .pagination li span, .pagination li a { padding: 8px 12px; }
    .pager { justify-content: center; gap: 8px; }

    .mainnav { -webkit-overflow-scrolling: touch; }

    /* --- график дежурств: просмотр PDF на телефоне --- */
    .duty-viewer iframe { height: 70vh; min-height: 300px; }
    .duty-title { font-size: 17px; }

    /* --- график дежурств: таблица превращается в список карточек --- */
    .plan-scroll { overflow-x: visible; background: none; border: 0; border-radius: 0; }
    table.plan-table { min-width: 0; display: block; }
    table.plan-table thead { display: none; }
    table.plan-table tbody { display: block; }
    table.plan-table tbody tr {
        display: block;
        background: var(--panel);
        border: 1px solid var(--line);
        border-left: 4px solid var(--brand);
        border-radius: 10px;
        padding: 9px 12px;
        margin-bottom: 10px;
    }
    table.plan-table tbody tr.is-today { background: #eef6ff; }
    table.plan-table tbody tr.is-today th,
    table.plan-table tbody tr.is-today td { background: none; color: inherit; }
    table.plan-table tbody tr.is-today th.plan-first { color: #1f4fb8; }
    table.plan-table tbody th.plan-first {
        display: block;
        width: auto;
        background: none;
        border: 0;
        padding: 0 0 6px;
        font-size: 15px;
        white-space: normal;
    }
    table.plan-table tbody td { display: block; border: 0; padding: 2px 0; }
    table.plan-table tbody td[data-label]::before {
        content: attr(data-label) ': ';
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
    }
    .today-duty { padding: 12px 14px; }
    .today-duty-row { flex-direction: column; gap: 3px; }
    .today-duty-what { min-width: 0; }
    .plan-docs { margin-top: 22px; }
    .plan-rows { min-height: 130px; }
    .plan-edit-top { align-items: center; }
}

/* --- совсем узкие телефоны (320–380 px) --- */
@media (max-width: 380px) {
    .container { padding: 12px 10px 44px; }
    .mainnav a { padding: 6px 8px; font-size: 13px; }
    .att-grid tr.att-row { padding-right: 28px; }
    .att-grid td.status-cell::before,
    .att-grid td.grade-cell::before,
    .att-grid td.note-cell::before { flex: 0 0 66px; }
    .att-grid td.grade-cell .grade-input { flex: 0 0 74px; }
    .att-tools .btn { flex: 1 1 100%; }
    .save-summary { gap: 3px 10px; }
    table.j-table th.j-name, table.j-table td.j-name { min-width: 96px; }
    table.j-table td.j-total { min-width: 84px; }
    .j-pop-l { flex: 0 0 74px; }
}
