/* «Островок заботы» — мягкий стиль школьной службы сопровождения и профилактики.
   Mobile-first; светлая и тёмная темы; контраст не ниже WCAG AA; только системные шрифты. */

/* ── Токены: светлая тема ── */
:root {
  color-scheme: light;
  --bg: #FFF8EE;
  --surface: #FFFFFF;
  --surface-2: #FFF6E8;
  --ink: #25313E;
  --muted: #55606D;
  --line: #E5D9C6;
  --field-border: #8A7F70;

  --primary: #2B6496;
  --primary-hover: #214F78;
  --on-primary: #FFFFFF;
  --primary-soft: #E2EFFA;
  --primary-ink: #1F5585;

  --sun-soft: #FFF0C7;   --sun-ink: #6E5000;   --sun: #F2C14E;
  --mint-soft: #DCF2E6;  --mint-ink: #1D6342;  --mint: #4FB58A;
  --peach-soft: #FCE2D6; --peach-ink: #983A23; --peach: #EE8A68;
  --lilac-soft: #EAE4FA; --lilac-ink: #55409C; --lilac: #9B86DD;
  --pink-soft: #FBE2EE;  --pink-ink: #8C2F5A;  --pink: #E08AB3;
  --neutral-soft: #EAECEF; --neutral-ink: #48535F;

  --danger: #A8361C;
  --focus: #B07A00;
  --track: #F1E7D8;
  --overlay: rgba(37, 49, 62, .45);
  --shadow: 0 6px 24px rgba(91, 74, 46, .08);
  --shadow-lg: 0 20px 60px rgba(37, 49, 62, .25);

  --radius: 18px;
  --radius-sm: 12px;
  --sidebar-w: 256px;
  --ease: 180ms ease;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* ── Токены: тёмная тема (системная или выбранная) ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141A22; --surface: #1C2430; --surface-2: #222C39; --ink: #E9EEF4; --muted: #A9B5C3;
    --line: #313E4E; --field-border: #6F7E90;
    --primary: #7DB9EA; --primary-hover: #9BCBF0; --on-primary: #0D1A26; --primary-soft: #1D3246; --primary-ink: #A7D2F4;
    --sun-soft: #382F14; --sun-ink: #F3D57E; --sun: #D9A93A;
    --mint-soft: #163327; --mint-ink: #92DDB9; --mint: #4FB58A;
    --peach-soft: #3B231D; --peach-ink: #F5AD95; --peach: #E8805E;
    --lilac-soft: #2A2441; --lilac-ink: #C9BCF6; --lilac: #9B86DD;
    --pink-soft: #39202D; --pink-ink: #F1AACB; --pink: #D97CA6;
    --neutral-soft: #29323E; --neutral-ink: #C5CED8;
    --danger: #FF9C85; --focus: #F3C04C; --track: #2A3543;
    --overlay: rgba(0, 0, 0, .6); --shadow: 0 6px 24px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141A22; --surface: #1C2430; --surface-2: #222C39; --ink: #E9EEF4; --muted: #A9B5C3;
  --line: #313E4E; --field-border: #6F7E90;
  --primary: #7DB9EA; --primary-hover: #9BCBF0; --on-primary: #0D1A26; --primary-soft: #1D3246; --primary-ink: #A7D2F4;
  --sun-soft: #382F14; --sun-ink: #F3D57E; --sun: #D9A93A;
  --mint-soft: #163327; --mint-ink: #92DDB9; --mint: #4FB58A;
  --peach-soft: #3B231D; --peach-ink: #F5AD95; --peach: #E8805E;
  --lilac-soft: #2A2441; --lilac-ink: #C9BCF6; --lilac: #9B86DD;
  --pink-soft: #39202D; --pink-ink: #F1AACB; --pink: #D97CA6;
  --neutral-soft: #29323E; --neutral-ink: #C5CED8;
  --danger: #FF9C85; --focus: #F3C04C; --track: #2A3543;
  --overlay: rgba(0, 0, 0, .6); --shadow: 0 6px 24px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
}

/* ── База ── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  transition: background-color var(--ease), color var(--ease);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; display: flex; align-items: center; gap: .45em; }
p { margin: 0 0 .5em; }
a { color: var(--primary-ink); }
.muted { color: var(--muted); }
.tiny { font-size: .82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: middle;
}
.icon-inline { width: 16px; height: 16px; vertical-align: -3px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── Кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 44px; padding: .55em 1.2em;
  font: inherit; font-weight: 700; text-decoration: none; white-space: nowrap;
  border: 2px solid transparent; border-radius: 999px; cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease), transform 150ms ease, box-shadow var(--ease);
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not([disabled]) { background: var(--primary-hover); }
.btn-soft { background: var(--primary-soft); color: var(--primary-ink); }
.btn-soft:hover:not([disabled]) { border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not([disabled]) { background: var(--primary-soft); color: var(--primary-ink); }
.btn-mint { background: var(--mint-soft); color: var(--mint-ink); }
.btn-mint:hover:not([disabled]) { border-color: var(--mint); }
.btn-danger { background: var(--peach-soft); color: var(--danger); }
.btn-danger:hover:not([disabled]) { border-color: var(--danger); }
.btn-small { min-height: 36px; padding: .3em .9em; font-size: .88rem; }
.btn-lg { min-height: 52px; font-size: 1.02rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}
.icon-btn:hover:not([disabled]) { background: var(--primary-soft); color: var(--primary-ink); }
.icon-btn:active:not([disabled]) { transform: scale(.95); }
.icon-btn[disabled] { opacity: .45; cursor: not-allowed; }
.icon-btn.danger:hover:not([disabled]) { background: var(--peach-soft); color: var(--danger); }

/* ── Поля ── */
input, select, textarea {
  width: 100%; min-height: 44px; padding: .55em .8em;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--field-border); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled, input[readonly] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
label { display: block; font-weight: 700; font-size: .9rem; }
label > input, label > select, label > textarea, label > .copy-row { margin-top: .3em; font-weight: 400; }
label.check { display: flex; align-items: center; gap: .6em; min-height: 44px; font-weight: 600; cursor: pointer; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--primary); }
.err { display: block; color: var(--danger); font-weight: 600; font-size: .85rem; }
.err:empty { display: none; }
.hint { display: block; color: var(--muted); font-weight: 400; font-size: .82rem; margin-top: .25em; }
.hint:empty { display: none; }
.has-err > input, .has-err > select, .has-err > textarea { border-color: var(--danger); }
.form-error { color: var(--danger); font-weight: 600; margin: 0; }
.form-error:empty { display: none; }
.form-status { margin: 0; font-weight: 600; }
.form-status:empty { display: none; }
.form-status.ok { color: var(--mint-ink); }
.form-status.bad { color: var(--danger); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }

/* ── Вход ── */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  position: relative; width: 100%; max-width: 420px; padding: 24px;
  background: var(--surface); border-radius: 26px; box-shadow: var(--shadow); text-align: center;
}
.login-card form { display: grid; gap: 12px; margin: 12px 0; text-align: left; }
.login-theme { position: absolute; top: 10px; right: 10px; }
.sso-block { display: grid; gap: 6px; margin-top: 12px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; margin: 10px 0 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.notice { background: var(--sun-soft); color: var(--sun-ink); border-radius: var(--radius-sm); padding: 10px 12px; font-weight: 600; text-align: left; }
.notice.bad { background: var(--peach-soft); color: var(--danger); }

/* ── Каркас приложения (mobile-first) ── */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.sidebar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--sun-soft); color: var(--peach); flex: none; }
.brand-logo .icon { width: 22px; height: 22px; }
.brand-name { display: block; font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.brand-sub { display: block; font-size: .78rem; color: var(--muted); }

.top-menu {
  position: absolute; top: calc(100% + 6px); right: 8px; z-index: 30; width: min(300px, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 8px;
  animation: pop 160ms ease;
}
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 12px;
  font: inherit; font-weight: 600; color: var(--ink); background: none; border: 0; border-radius: 12px; cursor: pointer; text-align: left;
  transition: background-color var(--ease);
}
.menu-item:hover { background: var(--primary-soft); }

.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; min-width: 0; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--lilac-soft); color: var(--lilac-ink); font-weight: 800; }
.user-text { min-width: 0; }
.user-name { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: .8rem; color: var(--muted); }

.main { flex: 1; width: 100%; min-width: 0; padding: 16px; } /* min-width: 0 — широкие таблицы прокручиваются внутри карточки, а не растягивают страницу */
.tab-panel { min-width: 0; }
/* Подвал с запасом снизу: иконка сервиса не перекрывает контент */
.app-footer { color: var(--muted); text-align: center; padding: 8px 16px calc(96px + env(safe-area-inset-bottom)); }
.page-footer { color: var(--muted); text-align: center; padding: 0 16px 16px; }
.app-footer .heart { color: var(--peach); }

/* Иконка сервиса и нижняя панель разделов (телефон) */
.fab {
  position: fixed; z-index: 40;
  right: calc(16px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid; place-items: center; width: 60px; height: 60px; border: 0; border-radius: 50%;
  background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-lg); cursor: pointer;
  transition: transform var(--ease), background-color var(--ease);
}
.fab:hover { background: var(--primary-hover); }
.fab:active { transform: scale(.94); }
.fab .icon { width: 28px; height: 28px; grid-area: 1 / 1; transition: opacity var(--ease), transform var(--ease); }
.fab .fab-close { opacity: 0; transform: rotate(-90deg); }
.fab[aria-expanded="true"] .fab-open { opacity: 0; transform: rotate(90deg); }
.fab[aria-expanded="true"] .fab-close { opacity: 1; transform: none; }

.bottom-sheet {
  position: fixed; z-index: 35; left: 8px; right: 8px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px;
  padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg);
  animation: rise 180ms ease;
}
.sheet-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px; padding: 8px 4px; font: inherit; font-size: .8rem; font-weight: 700; line-height: 1.2;
  color: var(--ink); background: none; border: 0; border-radius: 14px; cursor: pointer; text-align: center;
  transition: background-color var(--ease), color var(--ease);
}
.sheet-item .icon { width: 24px; height: 24px; }
.sheet-item:hover { background: var(--primary-soft); }
.sheet-item.active { background: var(--primary-soft); color: var(--primary-ink); }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── Шапка раздела ── */
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head > div { flex: 1 1 320px; min-width: 0; }
.panel-head p { margin: 0; }
.head-search { flex: 1 1 260px; max-width: 360px; }

/* ── Баннер ── */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  background: var(--peach-soft); color: var(--peach-ink); border: 2px dashed var(--peach);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-weight: 600;
}
.banner-info { background: var(--primary-soft); color: var(--primary-ink); border-color: var(--primary); }
.banner-icon { width: 24px; height: 24px; }
.banner-text { flex: 1 1 240px; }

/* ── Фильтры и таблицы ── */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
.filters input[type=search] { grid-column: 1 / -1; }
.table-card { position: relative; padding: 4px; overflow-x: auto; } /* relative — скрытые подписи не растягивают страницу */
.card-title { padding: 12px 12px 4px; margin: 0; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 760px; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px; white-space: nowrap; }
.table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background-color var(--ease); }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.is-left td { color: var(--muted); }
.fio { font-weight: 700; }
.note-preview { display: block; max-width: 360px; font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { white-space: nowrap; text-align: right; }
.actions > * + * { margin-left: 4px; }

.pill { display: inline-flex; align-items: center; gap: .3em; padding: .15em .7em; border-radius: 999px; font-weight: 700; font-size: .82rem; white-space: nowrap; }
.pill-class { background: var(--sun-soft); color: var(--sun-ink); }
.pill-active { background: var(--mint-soft); color: var(--mint-ink); }
.pill-left { background: var(--neutral-soft); color: var(--neutral-ink); }
.pill-warn { background: var(--sun-soft); color: var(--sun-ink); }
.pill-role { background: var(--lilac-soft); color: var(--lilac-ink); }
.pill-role.admin { background: var(--peach-soft); color: var(--peach-ink); }
.pill-role.deputy { background: var(--primary-soft); color: var(--primary-ink); }
.pmpk-ok { color: var(--mint-ink); }
.pmpk-soon { color: var(--sun-ink); font-weight: 700; }
.pmpk-expired { color: var(--danger); font-weight: 700; }
.pmpk-none { color: var(--muted); font-style: italic; }
.tag { font-size: .75rem; font-weight: 700; color: var(--muted); margin-left: 6px; }

.cat { display: inline-block; padding: .15em .7em; border-radius: 999px; font-weight: 700; font-size: .82rem; white-space: nowrap; }
.cat-0 { background: var(--primary-soft); color: var(--primary-ink); }
.cat-1 { background: var(--mint-soft); color: var(--mint-ink); }
.cat-2 { background: var(--peach-soft); color: var(--peach-ink); }
.cat-3 { background: var(--lilac-soft); color: var(--lilac-ink); }
.cat-4 { background: var(--sun-soft); color: var(--sun-ink); }
.cat-5 { background: var(--pink-soft); color: var(--pink-ink); }

.doc-btn {
  display: inline-flex; align-items: center; gap: .35em; min-height: 36px; padding: 0 .8em;
  font: inherit; font-weight: 700; font-size: .85rem; color: var(--primary-ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px; cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}
.doc-btn .icon { width: 16px; height: 16px; }
.doc-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.doc-btn.zero { color: var(--muted); }

.empty { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 40px 16px; color: var(--muted); }
.empty.small { padding: 16px; }
.empty-icon { width: 40px; height: 40px; color: var(--mint); }

/* ── Аналитика и мониторинг ── */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.kpi-label { font-weight: 600; font-size: .88rem; }
.kpi-sky { background: var(--primary-soft); color: var(--primary-ink); }
.kpi-mint { background: var(--mint-soft); color: var(--mint-ink); }
.kpi-sun { background: var(--sun-soft); color: var(--sun-ink); }
.kpi-peach { background: var(--peach-soft); color: var(--peach-ink); }
.kpi-lilac { background: var(--lilac-soft); color: var(--lilac-ink); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 16px; }
.stack { display: grid; align-content: start; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) 36px; align-items: center; gap: 10px; }
.bar-label { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--track); border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--primary); transition: width .6s ease; }
.bar-value { font-weight: 800; text-align: right; }
.f-0 { background: var(--primary); } .f-1 { background: var(--mint); } .f-2 { background: var(--peach); }
.f-3 { background: var(--lilac); } .f-4 { background: var(--sun); } .f-5 { background: var(--pink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.levels { margin-top: 14px; }
.chip { background: var(--sun-soft); color: var(--sun-ink); border-radius: 999px; padding: .35em .9em; font-weight: 700; }
.chip b { color: var(--ink); margin-left: .3em; }

.card-warn { border-top: 6px solid var(--sun); }
.card-danger { border-top: 6px solid var(--peach); }
.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.alerts li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.alerts .who { font-weight: 700; }
.alerts .meta { font-size: .82rem; color: var(--muted); }
.alerts .days { font-weight: 800; white-space: nowrap; }
.alerts .empty-li { justify-content: center; color: var(--muted); background: transparent; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }

/* ── Формы настроек ── */
.form-card { display: grid; gap: 12px; align-content: start; }
.form-card h2 { margin: 0; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.copy-row { display: flex; gap: 6px; align-items: center; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin: 12px 0 8px; }

/* ── Диалоги ── */
dialog {
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  padding: 20px; border: 0; border-radius: 24px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog[open] { animation: pop 180ms ease; }
dialog::backdrop { background: var(--overlay); }
dialog.wide { width: min(860px, calc(100vw - 24px)); }
dialog.narrow { width: min(440px, calc(100vw - 24px)); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dialog-head p { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* Загрузка документов */
.upload { background: var(--primary-soft); border-radius: var(--radius); padding: 12px; margin: 16px 0; }
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 18px; background: var(--surface); border: 2px dashed var(--field-border); border-radius: var(--radius-sm);
  transition: border-color var(--ease), background-color var(--ease);
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone.has-file { border-style: solid; border-color: var(--mint); background: var(--mint-soft); color: var(--mint-ink); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-icon { width: 28px; height: 28px; color: var(--primary-ink); }
.dz-text { font-weight: 700; }
.dz-hint { color: var(--muted); }
.upload-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: end; margin-top: 10px; }

.doc-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.doc-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.doc-ext { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; font-weight: 800; font-size: .72rem; text-transform: uppercase; }
.ext-pdf { background: var(--peach-soft); color: var(--peach-ink); }
.ext-doc { background: var(--primary-soft); color: var(--primary-ink); }
.ext-xls { background: var(--mint-soft); color: var(--mint-ink); }
.ext-img { background: var(--lilac-soft); color: var(--lilac-ink); }
.ext-txt { background: var(--sun-soft); color: var(--sun-ink); }
.doc-title { font-weight: 700; overflow-wrap: anywhere; }
.doc-meta { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.doc-actions { display: flex; }

/* Матрица ролей */
.matrix { min-width: 640px; }
.matrix th.role-col { text-align: center; vertical-align: bottom; min-width: 120px; }
.role-head { display: flex; flex-direction: column; align-items: center; gap: 2px; text-transform: none; letter-spacing: 0; }
.role-title { font-size: .95rem; font-weight: 800; color: var(--ink); }
.role-users { font-size: .75rem; font-weight: 600; }
.matrix td.cell { text-align: center; }
.matrix tr.group td { background: var(--sun-soft); color: var(--sun-ink); font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; padding: 8px 12px; }
.perm-title { font-weight: 600; }
.perm-code { display: block; font-size: .75rem; color: var(--muted); font-family: var(--mono); }

.toggle { position: relative; display: inline-grid; place-items: center; width: 52px; height: 44px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle span { position: relative; width: 44px; height: 24px; border-radius: 999px; background: var(--track); border: 2px solid var(--field-border); transition: background-color var(--ease), border-color var(--ease); }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform var(--ease), background-color var(--ease); }
.toggle input:checked + span { background: var(--mint); border-color: var(--mint); }
.toggle input:checked + span::after { transform: translateX(20px); background: #FFFFFF; }
.toggle input:disabled { cursor: not-allowed; }
.toggle input:disabled + span { opacity: .55; }
.toggle input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Уведомление */
.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); padding: .7em 1.3em; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow-lg);
  animation: rise 180ms ease;
}

/* ── Планшет ── */
@media (min-width: 640px) {
  .main { padding: 20px 24px; }
  .filters { grid-template-columns: 2fr 1fr 1.4fr 1fr auto; }
  .filters input[type=search] { grid-column: auto; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: 1 / -1; }
  .upload-fields { grid-template-columns: 1fr 1.4fr auto; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 120px minmax(0, 1fr) 40px; }
  h1 { font-size: 1.7rem; }
}

/* ── Десктоп: интерфейс на весь экран с боковой панелью ── */
@media (min-width: 1024px) {
  .shell {
    display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: 1fr auto;
    height: 100vh; height: 100dvh; min-height: 0;
  }
  .topbar, .fab, .bottom-sheet { display: none !important; }
  .sidebar {
    grid-row: 1 / span 2; display: flex; flex-direction: column; gap: 8px; min-height: 0;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
  }
  .sidebar .brand { padding: 4px 8px 12px; }
  .side-nav { display: grid; gap: 2px; align-content: start; flex: 1; }
  .nav-group { margin: 14px 12px 4px; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
  .nav-item {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px;
    font: inherit; font-weight: 700; color: var(--ink); background: none; border: 0; border-radius: 12px; cursor: pointer; text-align: left;
    transition: background-color var(--ease), color var(--ease);
  }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.active { background: var(--primary-soft); color: var(--primary-ink); }
  .nav-badge { margin-left: auto; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--peach-soft); color: var(--peach-ink); font-size: .75rem; text-align: center; }
  .side-footer { border-top: 1px solid var(--line); padding-top: 8px; }
  .side-actions { display: flex; gap: 4px; padding: 0 4px; }
  .version { color: var(--muted); padding: 4px 12px 0; margin: 0; }

  .main { grid-column: 2; overflow-y: auto; padding: 24px 32px; }
  .app-footer { grid-column: 2; margin: 0; padding: 8px 32px 12px; border-top: 1px solid var(--line); text-align: left; }
  .toast { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

@media (min-width: 1600px) {
  :root { --sidebar-w: 280px; }
  .main { padding: 28px 48px; }
  .settings-grid { grid-template-columns: 1.1fr 1fr; }
}

/* Нижняя навигация не нужна в боковой разметке, а боковые пункты — на телефоне */
@media (max-width: 1023px) {
  .nav-group { grid-column: 1 / -1; margin: 6px 6px 0; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Список школы ── */
.school-quick { margin-bottom: 12px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: .4em; min-height: 40px; padding: .3em 1em;
  font: inherit; font-weight: 700; border: 2px solid transparent; border-radius: 999px; cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}
.chip-btn b { font-weight: 800; }
.chip-btn.early { background: var(--mint-soft); color: var(--mint-ink); }
.chip-btn.late { background: var(--sun-soft); color: var(--sun-ink); }
.chip-btn.total { background: var(--primary-soft); color: var(--primary-ink); }
.chip-btn:hover, .chip-btn[aria-pressed="true"] { border-color: currentColor; }
.filters-school { grid-template-columns: 1fr 1fr; }
.pill-early { background: var(--mint-soft); color: var(--mint-ink); }
.pill-late { background: var(--sun-soft); color: var(--sun-ink); }
.pill-far { background: var(--peach-soft); color: var(--peach-ink); }
.row-link { cursor: pointer; }
.row-link:focus-visible td { background: var(--primary-soft); }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 6px; }
.sheet-note { display: block; font-size: .75rem; color: var(--muted); }
@media (min-width: 640px) {
  .filters-school { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters-school input[type=search] { grid-column: 1 / -1; }
}
@media (min-width: 1100px) {
  .filters-school { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters-school input[type=search] { grid-column: span 2; }
}
@media (min-width: 1680px) {
  .filters-school { grid-template-columns: 1.6fr repeat(5, minmax(0, 1fr)) auto; }
  .filters-school input[type=search] { grid-column: auto; }
}

/* ── Сроки документов и история ── */
.upload-dates { margin-top: 10px; }
@media (min-width: 640px) {
  .upload-fields { grid-template-columns: 1fr 1.4fr; }
  .upload-dates { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
}
.pmpk-source {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: -4px 0 0;
  padding: 8px 12px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-ink); font-size: .88rem; font-weight: 600;
}
.pmpk-source.manual { background: var(--surface-2); color: var(--muted); }
.link-btn {
  display: inline-flex; align-items: center; gap: .3em; min-height: 32px; padding: 0 .2em;
  font: inherit; font-weight: 700; color: var(--primary-ink); background: none; border: 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { text-decoration-thickness: 2px; }
.link-btn .icon { width: 16px; height: 16px; }
.dialog-left { margin-right: auto; }
.doc-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pill-current { background: var(--mint-soft); color: var(--mint-ink); }
.pill-expired { background: var(--peach-soft); color: var(--peach-ink); }
.pill-plain { background: var(--neutral-soft); color: var(--neutral-ink); }

.seg { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin: 14px 0; background: var(--surface-2); border-radius: 14px; }
.seg button {
  flex: 1 1 auto; min-height: 40px; padding: 0 12px; font: inherit; font-weight: 700; color: var(--muted);
  background: none; border: 0; border-radius: 10px; cursor: pointer; transition: background-color var(--ease), color var(--ease);
}
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--primary-ink); box-shadow: var(--shadow); }
.history-body { min-height: 200px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.timeline li.current { background: var(--mint-soft); }
.tl-dot { width: 12px; height: 12px; margin-top: 6px; border-radius: 50%; background: var(--field-border); }
.timeline li.current .tl-dot { background: var(--mint); }
.tl-main { font-weight: 700; }
.tl-meta { font-size: .82rem; color: var(--muted); }
.tl-diff { font-size: .88rem; margin-top: 2px; }
.tl-diff del { color: var(--danger); text-decoration-thickness: 1px; }
.tl-diff ins { color: var(--mint-ink); text-decoration: none; font-weight: 700; }

/* ── Логотип: дракончик-доктор ── */
.login-art { display: block; width: auto; height: 200px; max-width: 100%; margin: 0 auto 8px; object-fit: contain; }
.login-art-small { height: 140px; }
.brand-logo { overflow: hidden; background: #FFF0C7; } /* цвет фона самой иконки — без ободка в тёмной теме */
.brand-logo img { width: 100%; height: 100%; display: block; }
.fab { overflow: hidden; background: #FFF0C7; border: 3px solid var(--primary); }
.fab:hover { background: #FFF0C7; border-color: var(--primary-hover); }
.fab .fab-open { grid-area: 1 / 1; width: 100%; height: 100%; border-radius: 50%; transition: opacity var(--ease), transform var(--ease); }
.fab[aria-expanded="true"] { background: var(--primary); }
.fab[aria-expanded="true"] .fab-close { color: var(--on-primary); }
@media (max-height: 700px) { .login-art { height: 140px; } }
