/* Этюдник — репетиционный журнал: холодная бумага, чернила, сценический красный.
   Слева — месячный календарь, справа — «программка» выбранного дня. */
:root {
  --bg: #eff1f4;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --ink: #15171c;
  --muted: #565c68;
  --line: #d6dae1;
  --accent: #a3221b;
  --accent-ink: #ffffff;
  --accent-soft: #f7e4e2;
  --slate: #2c4a70;
  --slate-soft: #e3eaf3;
  --ok: #2d6a3e;
  --ochre: #8a5a00;
  --ochre-soft: #f6ead2;
  --shadow: 0 1px 2px rgba(20, 24, 33, .06), 0 6px 20px rgba(20, 24, 33, .06);

  --f-display: "Prata", "Georgia", "Times New Roman", serif;
  --f-body: "Golos Text", "Segoe UI", "Helvetica Neue", sans-serif;
  --f-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

  --r: 10px;
  color-scheme: light;
}
/* Тема всегда светлая — и на компьютере, и на телефоне, независимо от настроек системы */


* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap {
  max-width: 1240px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink);
  font-weight: 500; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--surface);
}
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.brand b { font: 400 24px/1 var(--f-display); letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: 13px; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

.demo-banner {
  background: var(--slate-soft); color: var(--slate); font-size: 13.5px;
}
.demo-banner .wrap { padding-block: 8px; }

/* ---------- основная сетка ---------- */
.layout {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 24px; align-items: start; padding-block: 24px 64px;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }

/* ---------- календарь ---------- */
.cal { padding: 16px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); }
@media (max-width: 900px) { .cal { position: static; } }
.cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.cal-head h2 { margin: 0 auto 0 4px; font: 400 21px/1.2 var(--f-display); text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-dow { text-align: center; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 4px 0; }
.cal-dow.we { color: var(--accent); }
.day {
  position: relative; aspect-ratio: 1 / 1.05; min-height: 44px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 6px 0 4px; font-variant-numeric: tabular-nums;
}
.day:hover { background: var(--surface-2); }
.day.out { color: var(--muted); opacity: .5; }
.day.today { border-color: var(--accent); }
.day.sel { background: var(--accent); color: var(--accent-ink); }
.day .n { font-weight: 600; font-size: 15px; line-height: 1.2; }
.day .marks { display: flex; gap: 3px; margin-top: auto; align-items: center; height: 14px; }
.mark-s { width: 6px; height: 6px; border-radius: 50%; background: var(--slate); }
.mark-b {
  font: 600 10px/14px var(--f-mono); padding: 0 4px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
}
.day.sel .mark-s { background: var(--accent-ink); }
.day.sel .mark-b { background: var(--accent-ink); color: var(--accent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.upcoming { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.upcoming h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.upcoming button {
  display: flex; width: 100%; gap: 10px; text-align: left; padding: 7px 8px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; align-items: baseline;
}
.upcoming button:hover { background: var(--surface-2); }
.upcoming .d { font: 500 12.5px var(--f-mono); color: var(--accent); min-width: 54px; }
.upcoming .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- день ---------- */
.dayview { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.day-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.day-head .titles { margin-right: auto; min-width: 0; }
.eyebrow { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.day-head h1 { margin: 2px 0 0; font: 400 clamp(28px, 4vw, 40px)/1.1 var(--f-display); text-wrap: balance; }
.day-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.section-title h2 { margin: 0; font-size: 12.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.section-title .rule { flex: 1; height: 1px; background: var(--line); }

/* расписание */
.sched { padding: 6px 0; }
.sched-row {
  display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 12px; align-items: start;
  padding: 10px 16px; border-top: 1px solid var(--line);
}
.sched-row:first-child { border-top: 0; }
.sched-row .time { font: 500 13.5px/1.6 var(--f-mono); color: var(--slate); font-variant-numeric: tabular-nums; }
.sched-row .what b { font-weight: 600; }
.sched-row .meta { color: var(--muted); font-size: 13.5px; }
.sched-empty { padding: 14px 16px; color: var(--muted); }
@media (max-width: 520px) { .sched-row { grid-template-columns: minmax(0, 1fr) auto; } .sched-row .time { grid-column: 1 / -1; } }

/* блоки */
.blocks { display: flex; flex-direction: column; gap: 16px; }
.block { overflow: hidden; }
.block-head {
  display: flex; gap: 10px; align-items: flex-start; padding: 14px 12px 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.block-head .grip { margin-top: 2px; }
.block-head .info { flex: 1; min-width: 0; }
.block-head h3 { margin: 0; font: 400 22px/1.25 var(--f-display); overflow-wrap: anywhere; }
.block-head .sub { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; color: var(--muted); font-size: 13.5px; align-items: center; }
.block-head .sub .tm { font-family: var(--f-mono); color: var(--accent); }
.block-head .desc { margin: 6px 0 0; color: var(--muted); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.block-num { font: 500 12px var(--f-mono); color: var(--muted); }

.etudes { list-style: none; margin: 0; padding: 0; min-height: 8px; }
.etude {
  display: grid; grid-template-columns: 28px 30px minmax(0, 1fr) auto; gap: 8px; align-items: start;
  padding: 10px 12px 10px 8px; border-top: 1px solid var(--line); background: var(--surface);
}
.etudes .etude:first-child { border-top: 0; }
.etude .num { font: 600 15px/34px var(--f-mono); text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.etude .body { min-width: 0; padding-top: 5px; }
.etude .title { font-weight: 600; overflow-wrap: anywhere; }
.etude .note { color: var(--muted); font-size: 13.5px; margin-top: 2px; overflow-wrap: anywhere; }
.people { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.person {
  display: inline-flex; align-items: center; padding: 2px 9px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; border-radius: 999px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.person.me { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.etude .tools { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.grip { cursor: grab; touch-action: none; color: var(--muted); }
.grip:active { cursor: grabbing; }
.etude.mine { box-shadow: inset 3px 0 0 var(--accent); }

.sortable-ghost { opacity: .35; }
.sortable-chosen { background: var(--surface-2); }
.sortable-drag { box-shadow: var(--shadow); }

.add-etude { display: flex; gap: 8px; padding: 12px 12px 12px 16px; border-top: 1px dashed var(--line); background: var(--surface-2); flex-wrap: wrap; }
.add-etude input { flex: 1 1 220px; min-width: 0; }
.empty-list { padding: 14px 16px; color: var(--muted); font-size: 14px; }

.empty-day { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty-day p { max-width: 46ch; margin: 0 auto 14px; }

/* ---------- формы ---------- */
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=email], input[type=url], input[type=tel], input[type=search], textarea, select {
  width: 100%; min-height: 40px; padding: 8px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
}
textarea { min-height: 76px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; min-width: 0; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(14, 16, 22, .45); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog h2 { margin: 0; font: 400 24px/1.2 var(--f-display); }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
dialog .foot .left { margin-right: auto; }
.err { color: var(--accent); font-size: 13.5px; min-height: 1em; }

/* ---------- вход ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px;
}
.login-card { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { margin: 0; font: 400 40px/1 var(--f-display); }
.login-card .sub { color: var(--muted); margin-top: -6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; background: var(--surface-2); }
.seg button { border: 0; background: transparent; border-radius: 7px; min-height: 36px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.curtain { height: 6px; border-radius: 3px; background: repeating-linear-gradient(90deg, var(--accent) 0 14px, transparent 14px 18px); opacity: .85; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

@media (prefers-reduced-motion: no-preference) {
  .etude, .block { transition: background-color .15s; }
}

/* =================== v2 =================== */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.btn.danger { color: var(--accent); }
.linkish { border: 0; background: none; padding: 0; color: var(--slate); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font: inherit; }
.linkish.strong { font-weight: 600; color: var(--ink); }
.pill { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.hw { background: var(--ochre-soft); color: var(--ochre); border-color: transparent; }
.pill.warn { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.empty { padding: 16px; color: var(--muted); font-size: 14px; }
.pad { padding: 16px; }
.flabel { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* шапка с навигацией */
.topbar-in { display: flex; align-items: center; gap: 8px 16px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { border: 0; background: none; cursor: pointer; padding: 0; display: flex; align-items: baseline; gap: 10px; margin: 0; color: var(--ink); }
.brand span { display: none; }
@media (min-width: 1440px) { .brand span { display: inline; } }
.nav { display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-item { border: 0; background: none; padding: 0 12px; min-height: 40px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.who { margin-left: auto; }
@media (max-width: 760px) {
  .nav { order: 3; flex-basis: 100%; }
  #me-label { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* страницы */
.page { padding-block: 24px 64px; display: flex; flex-direction: column; gap: 22px; }
.page.narrow { max-width: 640px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head > div:first-child { margin-right: auto; min-width: 0; }
.page-head h1, .lesson-head h1 { margin: 2px 0 0; font: 400 clamp(28px, 4vw, 40px)/1.12 var(--f-display); text-wrap: balance; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; align-items: start; }
.two-col.wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 900px) { .two-col, .two-col.wide-left { grid-template-columns: minmax(0, 1fr); } }
.back { align-self: flex-start; }
.lesson-head { display: flex; flex-direction: column; gap: 8px; }
.lesson-meta { display: flex; gap: 6px 16px; flex-wrap: wrap; color: var(--muted); align-items: center; }
.lesson-meta .mono { color: var(--slate); font-weight: 600; }
.lesson-note { margin: 0; color: var(--muted); }

/* занятия в карточке дня */
.occ-list { display: flex; flex-direction: column; gap: 10px; }
.occ { display: grid; grid-template-columns: 108px minmax(0, 1fr) auto; gap: 12px; padding: 12px 12px 12px 16px; align-items: start; }
.occ-time { font: 600 14px/1.7 var(--f-mono); color: var(--slate); font-variant-numeric: tabular-nums; }
.occ-kind { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ochre); }
.occ-title { border: 0; background: none; padding: 0; text-align: left; font: 600 16.5px/1.4 var(--f-body); cursor: pointer; color: var(--ink); }
.occ-title:hover { text-decoration: underline; text-underline-offset: 3px; }
.occ .meta, .meta { color: var(--muted); font-size: 13.5px; }
.occ-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.occ.kind-rehearsal, .occ.kind-theatre, .occ.kind-outing { box-shadow: var(--shadow), inset 3px 0 0 var(--ochre); }
.occ.kind-exam { box-shadow: var(--shadow), inset 3px 0 0 var(--accent); }
.occ.kind-exam .occ-kind { color: var(--accent); }
.occ.cancelled { opacity: .6; }
.occ.cancelled .occ-title { text-decoration: line-through; }
@media (max-width: 560px) {
  .occ { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .occ-actions { justify-content: flex-start; }
}
.mark-e { width: 6px; height: 6px; border-radius: 50%; background: var(--ochre); }
.day.sel .mark-e { background: var(--accent-ink); }

/* этюды: комментарии */
.tcomment { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--slate-soft); color: var(--ink); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tcomment .flabel { display: block; color: var(--slate); margin-bottom: 2px; }
.block-summary { padding: 10px 12px 10px 16px; border-top: 1px solid var(--line); background: var(--surface); }
.bs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.comment-text { margin: 6px 0 2px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.etude { grid-template-columns: 28px 30px minmax(0, 1fr) auto; }
@media (max-width: 560px) {
  .etude { grid-template-columns: 28px 26px minmax(0, 1fr); }
  .etude .tools { grid-column: 3; justify-content: flex-start; }
}

/* списки и элементы */
.list { display: flex; flex-direction: column; }
.item { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.list > .item:first-child, .notes > .item:first-child { border-top: 0; }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-head .icon-btn { margin-left: auto; }
.item-head .author { font-weight: 600; }
.item-title { font-weight: 600; font-size: 16px; }
.item-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.notes { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-top: 12px; }
.notes:empty { display: none; }
.soon-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; font-size: 14px; align-items: baseline; padding: 3px 0; }
.soon-main { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.soon-main .linkish { text-align: left; }
.soon-row .mono { color: var(--slate); }
.soon-row.cancelled { opacity: .55; }
.mini { margin: 0; padding-left: 20px; font-size: 14px; }

.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag { border: 1px solid var(--line); background: var(--surface); color: var(--slate); border-radius: 6px; padding: 2px 8px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.tag:hover { border-color: var(--slate); }
.tag.on { background: var(--slate); color: var(--surface); border-color: var(--slate); }
.tag.zero { color: var(--muted); }
.tag span { opacity: .7; font-variant-numeric: tabular-nums; }

/* вложения */
.atts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.att { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); display: flex; flex-direction: column; min-width: 0; }
.att img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.att-file { display: flex; align-items: center; gap: 8px; padding: 18px 12px; color: var(--ink); text-decoration: none; min-height: 80px; }
.att-file svg { width: 24px; height: 24px; flex: none; color: var(--muted); }
.att-file span { overflow-wrap: anywhere; font-size: 13.5px; }
.att figcaption { padding: 6px 8px; font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.att-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att details summary { cursor: pointer; color: var(--slate); font-weight: 500; }
.ai-text { white-space: pre-wrap; font-size: 12.5px; max-height: 220px; overflow: auto; margin-top: 4px; padding: 6px; background: var(--surface); border-radius: 6px; }

/* форма заметки */
.composer { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.composer-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.composer-foot .btn.primary { margin-left: auto; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* поле с фишками */
.field { display: flex; flex-direction: column; gap: 5px; }
.chips-input { display: flex; flex-direction: column; gap: 6px; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; min-height: 24px; }
.chip-x { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13.5px; font-weight: 500; }
.chip-x button { border: 0; background: none; color: inherit; width: 22px; height: 22px; display: grid; place-items: center; cursor: pointer; border-radius: 50%; }
.chip-x button svg { width: 14px; height: 14px; }
.chips-add { display: flex; gap: 6px; }
.chips-add input { flex: 1; min-width: 0; }
.suggest { display: flex; gap: 4px; flex-wrap: wrap; }
.sug { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 2px 9px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.sug:hover { border-color: var(--accent); color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14.5px; }
label.check input { width: 18px; height: 18px; }
dialog.wide { width: min(680px, calc(100vw - 32px)); }
dialog form { max-height: calc(100vh - 40px); overflow: auto; }
.cred { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; padding: 12px; background: var(--surface-2); border-radius: 8px; font-size: 16px; }
.pre { white-space: pre-wrap; font: 13px/1.5 var(--f-mono); background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 50vh; overflow: auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: left; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tr:first-child td { border-top: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
.table tr.muted td { color: var(--muted); }
.actions-cell { white-space: nowrap; text-align: right; }
.backups { margin-top: 12px; }

/* расписание */
.week { display: flex; flex-direction: column; gap: 10px; }
.wk { padding: 4px 0; }
.wk-day { padding: 8px 16px 4px; font: 400 19px var(--f-display); }
.wk-row { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 10px; padding: 8px 12px 8px 16px; align-items: center; border-top: 1px solid var(--line); }
.wk-row .time { color: var(--slate); font-weight: 600; }
@media (max-width: 480px) { .wk-row { grid-template-columns: minmax(0, 1fr) auto; } .wk-row .time { grid-column: 1 / -1; } }

/* преподаватели */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tcard { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.tcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tcard h3 { margin: 0; font: 400 21px/1.25 var(--f-display); }
.tcard.muted { opacity: .6; }

/* база знаний */
.kb { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .kb { grid-template-columns: minmax(0, 1fr); } }
.kb-side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); max-height: calc(100vh - 96px); overflow: auto; padding-right: 4px; }
@media (max-width: 900px) { .kb-side { position: static; max-height: none; } }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 10px; top: 11px; width: 18px; height: 18px; color: var(--muted); }
.search input { padding-left: 36px; width: 100%; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.facet h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; }
.facet h3 .linkish { text-transform: none; letter-spacing: 0; font-weight: 500; }
.facet-list { display: flex; flex-direction: column; }
.facet-item { display: flex; justify-content: space-between; border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.facet-item span { color: var(--muted); font-variant-numeric: tabular-nums; }
.facet-item:hover { background: var(--surface-2); }
.facet-item[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.kb-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.item.row-item { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }

/* v3 */
.day.holiday:not(.sel) { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--surface-2) 6px 8px); color: var(--muted); }
.mark-h { width: 12px; height: 10px; display: inline-block; border-radius: 2px; background: repeating-linear-gradient(135deg, var(--line) 0 2px, transparent 2px 4px); border: 1px solid var(--line); }
.holiday-banner { padding: 10px 14px; border-radius: 10px; background: var(--ochre-soft); color: var(--ochre); font-weight: 500; }
.att-file .ext { font: 600 11px var(--f-mono); padding: 4px 6px; border-radius: 4px; background: var(--slate-soft); color: var(--slate); flex: none; }
.att-media { padding: 16px 8px; }
.att-media audio { width: 100%; }
.att-video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; }
.atts:has(.att-video) { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.item.past { opacity: .55; }
.hol-dates { min-width: 150px; color: var(--ochre); font-weight: 600; }
.item.row-item .icon-btn { margin-left: auto; }
.ai-result { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 14px; margin-top: 12px; align-items: start; }
.ai-result img { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
@media (max-width: 600px) { .ai-result { grid-template-columns: minmax(0, 1fr); } }
.stack-lg { display: flex; flex-direction: column; gap: 22px; }
/* дашборд */
.seg-inline { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; background: var(--surface-2); flex-wrap: wrap; }
.seg-inline button { border: 0; background: transparent; border-radius: 7px; min-height: 34px; padding: 0 12px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg-inline button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.stat b { font: 400 30px/1.1 var(--f-display); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.agenda { display: flex; flex-direction: column; gap: 12px; }
.ag-day { overflow: hidden; }
.ag-date { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.ag-item { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); }
.ag-date + .ag-item { border-top: 0; }
.ag-time { color: var(--slate); font-weight: 600; font-size: 13.5px; line-height: 1.7; }
.ag-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ag-kind { font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ochre); }
.ag-etude .ag-kind { color: var(--accent); }
.ag-exam .ag-kind { color: var(--accent); }
.ag-title { border: 0; background: none; padding: 0; text-align: left; font: 600 15.5px/1.4 var(--f-body); color: var(--ink); cursor: pointer; }
.ag-title:hover { text-decoration: underline; text-underline-offset: 3px; }
.my-etude { margin-top: 4px; padding: 6px 10px; border-radius: 8px; background: var(--accent-soft); }
.my-etude .mono { color: var(--accent); font-weight: 600; }
.ag-hwline { font-size: 14px; margin-top: 2px; }
.ag-item.cancelled { opacity: .55; }
@media (max-width: 520px) { .ag-item { grid-template-columns: minmax(0, 1fr); gap: 2px; } }
.att figcaption { align-items: flex-start; }

/* личные страницы */
.avatar { border-radius: 50%; object-fit: cover; flex: none; display: inline-block; vertical-align: middle; }
.avatar-i { display: inline-grid; place-items: center; background: var(--slate-soft); color: var(--slate); font-weight: 600; letter-spacing: .02em; }
.me-btn { padding-left: 6px; }
.me-btn .avatar { margin-right: 2px; }
button.person { cursor: pointer; font: inherit; font-size: 13px; color: inherit; }
button.person:hover { border-color: var(--muted); }
.person-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.person-head .avatar { box-shadow: var(--shadow); }
.person-head .ph-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.person-head h1 { margin: 0; font: 400 clamp(28px, 4vw, 42px)/1.1 var(--f-display); }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; line-height: 1.6; }
.books, .links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.books li, .links li { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.books li:first-child, .links li:first-child { border-top: 0; }
.books .b-title { font-weight: 600; }
.books .b-title::before { content: "«"; } .books .b-title::after { content: "»"; }
.links a { color: var(--slate); font-weight: 600; overflow-wrap: anywhere; }
.etude-hist li { padding: 8px 16px; border-top: 1px solid var(--line); list-style: none; }
.etude-hist { margin: 0; padding: 0; }
.etude-hist li:first-child { border-top: 0; }
.name-link { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 10px; text-align: left; }
.name-link:hover span { text-decoration: underline; text-underline-offset: 3px; }
.photo-edit { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

/* дни рождения */
.mark-bd { width: 7px; height: 7px; border-radius: 50%; border: 2px solid var(--accent); background: transparent; }
.day.sel .mark-bd { border-color: var(--accent-ink); }
.bday-banner { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; }
.ag-bday .ag-kind { color: var(--accent); }
.ag-bday .ag-main { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.ag-bday .ag-kind { flex-basis: 100%; }
/* бюджет */
.money { font-family: var(--f-mono); font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.money.big { font-size: 20px; }
.neg { color: var(--accent); }
.pos { color: var(--ok); }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: transparent; }
.stat b.money, .stat b { word-break: break-word; }
.debt-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; font-size: 14px; }
.budget-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.budget-filters .search { flex: 1 1 200px; }
.exp-list { display: flex; flex-direction: column; gap: 12px; }
.exp { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.exp.closed { opacity: .85; }
.exp.proposal { box-shadow: var(--shadow), inset 3px 0 0 var(--slate); }
.exp.rejected { opacity: .6; }
.exp-head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.exp-title { min-width: 0; flex: 1 1 240px; }
.exp-title h3 { margin: 0; font: 600 17px/1.35 var(--f-body); overflow-wrap: anywhere; }
.exp-amount { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.exp-desc { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: 14px; }
.exp-url { color: var(--slate); font-size: 14px; overflow-wrap: anywhere; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }
.parts summary { cursor: pointer; color: var(--slate); font-weight: 500; font-size: 14px; }
.part-list { display: flex; flex-direction: column; margin-top: 6px; }
.part-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 8px 12px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.part-row:first-child { border-top: 0; }
.part-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.part-act { min-width: 0; text-align: right; }
@media (max-width: 560px) { .part-row { grid-template-columns: minmax(0, 1fr) auto; } .part-st, .part-act { text-align: left; } }
.exp-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: var(--shadow); } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
.split-tools { font-size: 13px; color: var(--muted); }
.split-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 2px 14px; max-height: 300px; overflow: auto; padding: 4px; border: 1px solid var(--line); border-radius: 8px; }
.split-row { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.split-row label { flex: 1; min-width: 0; }
.share-in { width: 96px !important; flex: none; min-height: 34px !important; }
.split-sum { margin-top: 6px; }
.calc-out { margin-top: -8px; font-family: var(--f-mono); }

/* подсказки */
.help-btn { font-weight: 700; font-size: 16px; border: 1px solid var(--line); }
.tour { position: fixed; inset: 0; z-index: 100; }
.tour-block { position: fixed; inset: 0; }
.tour-spot { position: fixed; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(10, 12, 18, .58); pointer-events: none; outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) { .tour-spot { transition: all .25s ease; } .tour-pop { transition: top .25s ease, left .25s ease; } }
.tour-pop { position: fixed; width: min(380px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.35); border: 1px solid var(--line); }
.tour-pop h3 { margin: 4px 0 6px; font: 400 21px/1.25 var(--f-display); }
.tour-pop p { margin: 0 0 12px; font-size: 14.5px; line-height: 1.5; }
.tour-count { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.tour-btns { display: flex; gap: 6px; align-items: center; }

/* единый вид полей: селекты без системной «пилюли», числа без стрелок */
select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23808690' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=search]::-webkit-search-cancel-button { cursor: pointer; }
input[type=file] { font-size: 14px; max-width: 100%; }
.row > label { justify-content: flex-start; }

/* подписи полей в формах: одна строка «название · подсказка», поля в ряду выровнены по низу */
.lbl { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 13.5px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.lbl .hint { font-weight: 400; }
dialog .row { align-items: flex-end; }
.chips:empty { display: none; }
label.check input { margin: 0; flex: none; }
label.check { padding: 2px 0; }
input[type=file]::file-selector-button { font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; margin-right: 10px; cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: var(--muted); }
.item.row-item:has(.hol-dates) { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr) auto; }
@media (max-width: 520px) { .item.row-item:has(.hol-dates) { grid-template-columns: minmax(0, 1fr) auto; } .item.row-item:has(.hol-dates) .hol-dates { grid-column: 1 / -1; } }
.hol-dates { min-width: 0; }

.linkish { text-align: left; }
.atts { align-items: start; }
#backups td:first-child { white-space: nowrap; }
@media (max-width: 760px) {
  .nav { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); padding-right: 24px; }
}

.admin-toc { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.admin-toc a, .admin-toc .linkish { color: var(--slate); font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
#ai-section, #restore, #admin-dyn { scroll-margin-top: 80px; }

.nav-item { padding: 0 10px; }
@media (min-width: 761px) and (max-width: 1360px) { .nav-item { padding: 0 8px; font-size: 14.5px; } .topbar-in { gap: 8px 10px; } }
@media (min-width: 761px) and (max-width: 1200px) { #me-label { display: none; } }

/* =================== мобильная версия =================== */
html { -webkit-text-size-adjust: 100%; }
/* пока открыто окно, страница под ним не прокручивается */
html:has(dialog[open]), html:has(dialog[open]) body { overflow: hidden; }
dialog form { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
dialog .foot { position: sticky; bottom: -20px; background: var(--surface); padding-block: 12px 0; margin-bottom: -4px; z-index: 1; }

@media (max-width: 640px) {
  /* окна — «шторкой» снизу на всю ширину, прокручиваются внутри себя */
  dialog, dialog.wide {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0;
    max-height: 92dvh; border-left: 0; border-right: 0; border-bottom: 0;
  }
  dialog form { max-height: 92dvh; padding: 18px 16px 0; gap: 14px; }
  dialog h2 { font-size: 22px; padding-right: 8px; }
  dialog .foot { bottom: 0; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
  dialog .foot .btn { flex: 1 1 auto; min-height: 48px; }
  dialog .foot .left { flex-basis: 100%; order: 3; }
  dialog .row > * { flex-basis: 100%; }
  dialog .row:has(> label:nth-child(3)) > * { flex-basis: calc(33% - 8px); }
  dialog::backdrop { background: rgba(14, 16, 22, .5); }
}

@media (max-width: 760px) {
  /* поля не меньше 16px — иначе iPhone приближает страницу при вводе */
  input, select, textarea { font-size: 16px !important; }
  input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select { min-height: 46px; }
  /* удобные для пальца размеры */
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; padding: 0 12px; }
  .icon-btn { width: 44px; height: 44px; }
  .nav-item { min-height: 44px; }
  .sug { min-height: 34px; padding: 4px 12px; font-size: 13.5px; }
  .tag { min-height: 32px; padding: 4px 10px; }
  .chip-x button { width: 32px; height: 32px; }
  label.check { min-height: 40px; }
  label.check input { width: 22px; height: 22px; }
  .linkish { padding-block: 4px; }
  .seg-inline button { min-height: 40px; }
  .facet-item { min-height: 44px; align-items: center; }
  .grip { width: 44px; height: 44px; }
  .day { min-height: 46px; }

  /* шапка компактнее */
  .topbar-in { min-height: 52px; padding-block: 6px; gap: 4px 8px; }
  .brand b { font-size: 21px; }
  .page { padding-block: 16px 72px; gap: 18px; }
  .layout { padding-block: 16px 72px; gap: 16px; }
  .page-head h1, .lesson-head h1, .day-head h1 { font-size: 28px; }
  .page-head .actions, .day-head .actions { width: 100%; }
  .page-head .actions .btn, .day-head .actions .btn { flex: 1 1 auto; }
  .section-title { flex-wrap: wrap; }
  .section-title .rule { min-width: 24px; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 24px; }

  /* карточки и списки */
  .item { padding: 12px 14px; }
  .etude { padding: 10px 8px 10px 4px; gap: 6px; }
  .add-etude .btn { flex: 1 1 auto; }
  .composer-foot .btn.primary { flex: 1 1 100%; margin-left: 0; }
  .debt-row { grid-template-columns: minmax(0, 1fr) auto; }
  .debt-row .btn { grid-column: 1 / -1; }
  .exp-amount { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; }
  .part-act .btn { width: 100%; }
  .tour-pop { left: 8px !important; right: 8px; width: auto; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .tour-btns .btn { min-height: 44px; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: calc(100vw - 32px); text-align: center; }
  .kb-side { gap: 12px; }
  .two-col > aside { order: 0; }
}
.seg-full { display: flex; }
.seg-full button { flex: 1; }
.assignees { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 12px; margin-top: 8px; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
.dups { padding: 10px 12px; border-radius: 8px; background: var(--ochre-soft); color: var(--ink); font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.dup { font-size: 13.5px; }
.pill.personal { background: var(--slate-soft); color: var(--slate); border-color: transparent; }
.hw-personal { box-shadow: inset 3px 0 0 var(--slate); }
.stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) {
  /* шапка: логотип и кнопки профиля в одну строку, разделы — второй строкой */
  .topbar-in { flex-wrap: wrap; }
  .brand { order: 1; }
  .who { order: 2; margin-left: auto; flex-wrap: nowrap; gap: 4px; }
  .nav { order: 3; }
  #me-label { display: none; }
  .me-btn { padding: 0 6px; min-width: 44px; }
}

/* =================== стабильная прокрутка без «болтанки» =================== */
html { overflow-x: hidden; overscroll-behavior-x: none; }
body { overflow-x: hidden; max-width: 100vw; overscroll-behavior-x: none; }
/* пока открыто окно, страница под ним зафиксирована (см. lockScroll в app.js) */
body.scroll-locked { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
dialog { overflow: hidden; overscroll-behavior: contain; }
dialog form { overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
dialog form > * { min-width: 0; max-width: 100%; }
dialog .foot { max-width: none; }
@media (max-width: 640px) { dialog { box-sizing: border-box; inset-inline: 0; } }

/* =================== библиотека =================== */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.lib-card { display: flex; gap: 12px; align-items: center; padding: 10px; text-align: left; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; min-width: 0; }
.lib-card:hover { border-color: var(--muted); }
.lib-thumb { width: 64px; height: 64px; flex: none; border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); color: var(--slate); }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; }
.lib-thumb svg, .lib-icon svg { width: 28px; height: 28px; }
.lib-thumb.kind-book { background: var(--accent-soft); color: var(--accent); }
.lib-thumb.kind-audio { background: var(--ochre-soft); color: var(--ochre); }
.lib-thumb.kind-video { background: var(--slate-soft); color: var(--slate); }
.lib-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lib-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.lib-meta { font-size: 12.5px; color: var(--muted); }
.lib-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .lib-layout { grid-template-columns: minmax(0, 1fr); } }
.viewer-inline { overflow: hidden; min-height: 200px; }

/* ссылки на материалы */
.refs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ref { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer; min-height: 32px; }
.ref:hover { border-color: var(--slate); }
.ref svg { width: 16px; height: 16px; flex: none; color: var(--slate); }
.ref-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ref-pos { font: 600 12.5px var(--f-mono); color: var(--accent); white-space: nowrap; }
.ref-note { color: var(--muted); font-size: 12.5px; }
.refs-picker { display: flex; flex-direction: column; gap: 8px; }
.refs-list { display: flex; flex-direction: column; gap: 4px; }
.refs-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.refs-row svg { width: 16px; height: 16px; flex: none; color: var(--slate); }
.refs-row .ref-t { flex: 1; }
.refs-add { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 6px; }
.refs-add [data-ref-note] { grid-column: 1 / 2; }
@media (max-width: 640px) { .refs-add { grid-template-columns: minmax(0, 1fr); } .refs-add [data-ref-note] { grid-column: auto; } }

/* просмотр */
dialog.viewer-dlg { width: min(1100px, calc(100vw - 32px)); height: min(92vh, 1000px); max-height: none; display: flex; flex-direction: column; padding: 0; }
dialog.viewer-dlg:not([open]) { display: none; }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.viewer-kind svg { width: 22px; height: 22px; color: var(--slate); }
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--surface-2); }
.viewer-body > * { min-height: 0; }
.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.viewer-bar .pg { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.viewer-bar .pg input { width: 72px; min-height: 36px; text-align: center; }
.pdf-stage { flex: 1; overflow: auto; padding: 8px; display: flex; justify-content: center; align-items: flex-start; position: relative; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.viewer-inline .pdf-stage { max-height: 80vh; min-height: 300px; }
.pdf-stage canvas { background: #fff; box-shadow: var(--shadow); max-width: none; }
.viewer-media { display: flex; flex-direction: column; flex: 1; }
.viewer-media video { width: 100%; flex: 1; min-height: 0; max-height: 75vh; background: #000; }
.viewer-media audio { width: calc(100% - 32px); margin: 32px 16px; }
.viewer-media .viewer-bar { border-top: 1px solid var(--line); border-bottom: 0; order: 2; }
.viewer-img { flex: 1; overflow: auto; display: grid; place-items: center; padding: 8px; }
.viewer-img img { max-height: 80vh; object-fit: contain; }
.viewer-text { flex: 1; overflow: auto; margin: 0; padding: 16px; white-space: pre-wrap; font: 14px/1.6 var(--f-mono); background: var(--surface); }
.viewer-empty { padding: 32px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
@media (max-width: 640px) {
  dialog.viewer-dlg { width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  .viewer-head { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .viewer-head [data-open-page] { display: none; }
}
.upload-progress { display: flex; flex-direction: column; gap: 4px; }
.upload-progress .bar { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.upload-progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* видео с хостингов и фрагменты */
.embed-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 75vh; background: #000; flex: none; }
.viewer-dlg .embed-frame { flex: 1; aspect-ratio: auto; min-height: 220px; max-height: none; }
.embed-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.fragment-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: #fff7e6; border-top: 1px solid #f0d9a8; border-bottom: 1px solid #f0d9a8; font-size: 14px; }
.viewer-media .fragment-bar { order: 1; }
.fragment-bar > span { flex: 1; min-width: 180px; }
.fragment-bar[hidden] { display: none; }
.lib-card img { object-fit: cover; }
.lesson-note, .occ-note { white-space: pre-wrap; }

/* выбор файлов и перетаскивание */
.dropzone { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1.5px dashed var(--line); border-radius: 10px; background: var(--surface-2); transition: border-color .15s, background .15s; }
.dz-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dz-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dz-list li { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 2px 2px 2px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.dz-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-over, .dropzone.drop-over, dialog.drop-over form { border-color: var(--accent) !important; background: #fff4f2 !important; }
dialog.drop-over { outline: 3px dashed var(--accent); outline-offset: -6px; }
form.composer.drop-over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.composer-files { flex: 1; min-width: 0; }
.composer-files.dropzone, .composer-files { padding: 0; border: 0; background: none; }
.composer-refs { padding-top: 4px; }
.refs-upload { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px; border: 1.5px dashed var(--line); border-radius: 8px; }
.refs-upload.drop-over { border-color: var(--accent); background: #fff4f2; }

/* документы: Word, PowerPoint, таблицы, TIFF */
.doc-stage { flex: 1; min-height: 0; overflow: auto; padding: 8px; position: relative; -webkit-overflow-scrolling: touch; background: var(--surface-2); }
.viewer-inline .doc-stage { max-height: 80vh; min-height: 320px; }
.doc-stage.pdf-stage { display: flex; justify-content: center; align-items: flex-start; }
.docx-host .docx-wrapper { background: transparent !important; padding: 0 !important; }
.docx-host section.docx { margin: 0 auto 12px !important; box-shadow: var(--shadow) !important; }
.pptx-host { display: flex; flex-direction: column; align-items: center; }
.pptx-host .pptx-preview-wrapper { background: transparent !important; height: auto !important; overflow: visible !important; width: auto !important; }
.pptx-host .pptx-preview-slide-wrapper { margin: 0 auto 12px !important; box-shadow: var(--shadow); }
.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; position: sticky; left: 0; }
.sheet-tabs .seg-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; min-height: 36px; }
.sheet-tabs .seg-btn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.sheet-host table { border-collapse: collapse; background: #fff; font-size: 13px; }
.sheet-host td, .sheet-host th { border: 1px solid #d9dde3; padding: 4px 8px; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.sheet-host tr:first-child td { background: #f3f5f8; font-weight: 600; position: sticky; top: -8px; }
.tiff-canvas { display: block; margin: 0 auto; background: #fff; box-shadow: var(--shadow); height: auto; }
.pg-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
@media (max-width: 640px) { .hide-m { display: none; } }
