
/* ---------- базовые ---------- */
:root {
  --ink: #1E2235; --navy: #27367A; --muted: #4A5170; --line: #D5D9E6; --bg: #EEF0F6; --panel: #ffffff;
  --accent: #1F63C9; --accent-soft: #E3EFFF; --warn: #B45309; --warn-soft: #FEF3C7; --err: #B91C1C; --err-soft: #FEE2E2;
  --ok: #1E6B27; --ok-soft: #E1F6E3; --focus: #1F63C9; --topbar-h: 56px; --panel-w: 400px;
}
@page { size: A4 landscape; margin: 0; }
* { box-sizing: border-box; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Nunito', 'Trebuchet MS', 'Segoe UI', sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; font-weight: 700; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h2 { font-size: 17px; font-weight: 900; margin: 0 0 4px; color: var(--navy); }
h3 { font-size: 14px; font-weight: 900; margin: 18px 0 8px; color: var(--navy); text-transform: uppercase; letter-spacing: .3px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 700; line-height: 1.4; margin: 0 0 10px; }
.note { font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: #174C99; line-height: 1.4; margin: 0 0 10px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.err { background: var(--err-soft); color: var(--err); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
code { font-family: Consolas, 'Courier New', monospace; font-size: 13px; }

/* ---------- кнопки, поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 800; white-space: nowrap; }
.btn:hover { background: #F5F6FA; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: #1B2660; }
.btn.danger { border-color: #E5B2B2; color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #EEF0F6; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: 14px; border-radius: 8px; }
.btn.lg { min-height: 52px; font-size: 17px; padding: 8px 20px; border-radius: 14px; }
.btn.icon { width: 36px; min-width: 36px; padding: 0; }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label, .field > .lbl { font-size: 13px; color: var(--muted); font-weight: 800; }
.inp { min-height: 40px; padding: 6px 10px; border: 2px solid var(--line); border-radius: 10px; background: #fff; width: 100%; }
.inp:focus-visible { border-color: var(--focus); outline: none; }
.inp.sm { min-height: 34px; padding: 3px 8px; border-radius: 8px; font-size: 14px; }
input[type="number"].inp { width: 80px; }
input[type="time"].inp { width: 118px; }
input[type="color"] { width: 44px; height: 40px; padding: 2px; border: 2px solid var(--line); border-radius: 10px; background: #fff; }
.row-h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 36px; min-width: 40px; padding: 4px 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-weight: 800; }
.chips button[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chips button:hover { border-color: var(--navy); }
fieldset { border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px 12px; margin: 0 0 12px; }
legend { font-size: 13px; font-weight: 900; color: var(--navy); padding: 0 6px; }
details.fine { border: 2px dashed var(--line); border-radius: 10px; padding: 6px 10px; margin: 8px 0; }
details.fine summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 800; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--navy); }

/* ---------- верхняя панель ---------- */
#topbar { height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; padding: 0 12px; flex: 0 0 auto; }
#topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 900; color: var(--navy); white-space: nowrap; }
#topbar .brand svg { width: 28px; height: 28px; }
#proj-name { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; max-width: 260px; padding: 4px 10px; border: 2px solid transparent; border-radius: 8px; background: transparent; font-weight: 900; overflow: hidden; }
#proj-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#proj-name:hover { border-color: var(--line); background: #F5F6FA; }
#proj-name-input { max-width: 260px; min-height: 36px; }
.save-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: #9CA3AF; }
.save-state.ok::before { background: #2E9A3A; }
.save-state.dirty::before { background: #F59E0B; }
.save-state.err::before { background: #DC2626; }
.tb-spacer { flex: 1; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 6px; z-index: 50; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; font-weight: 800; }
.menu button:hover, .menu button:focus-visible { background: #EEF0F6; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 14px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #F6D28B; flex: 0 0 auto; flex-wrap: wrap; }
.bar.info { background: var(--accent-soft); color: #174C99; border-color: #BFD4F5; }
.bar .grow { flex: 1; min-width: 200px; }
#mobile-switch { display: none; }

/* ---------- каркас ---------- */
#app { display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr); flex: 1 1 auto; min-height: 0; }
#panel { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
#tabs button { flex: 1; min-height: 46px; border: 0; background: transparent; font-weight: 800; color: var(--muted); border-bottom: 3px solid transparent; display: flex; align-items: center; justify-content: center; gap: 6px; }
#tabs button .n { width: 22px; height: 22px; border-radius: 50%; background: #E3E7F0; color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
#tabs button[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); }
#tabs button[aria-selected="true"] .n { background: var(--navy); color: #fff; }
#tabs button:hover { background: #F5F6FA; }
.tab { display: none; padding: 14px 14px 28px; overflow: auto; flex: 1; min-height: 0; }
.tab[data-active] { display: block; }
#preview-wrap { min-width: 0; overflow: auto; padding: 14px 18px 18px; position: relative; }
#preview-scaler { transform-origin: top left; }
#sheet-host > div { box-shadow: 0 2px 14px rgba(0,0,0,.18); }
#statusbar { position: sticky; top: 0; z-index: 2; margin: -14px -18px 12px; padding: 8px 18px; background: rgba(238,240,246,.95); display: flex; gap: 10px; align-items: center; }
#status-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 800; color: var(--ok); }
#status-pill.warn { color: var(--warn); background: var(--warn-soft); border-color: #F6D28B; }
#status-pill.err { color: var(--err); background: var(--err-soft); border-color: #F5B5B5; }
#status-details { position: absolute; top: 44px; left: 18px; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 8px 12px; max-width: 520px; font-size: 13px; }
#status-details li { margin: 4px 0; }
#status-details .err { color: var(--err); } #status-details .warn { color: var(--warn); }
#status-info { font-size: 13px; color: var(--muted); }

/* ---------- звонки ---------- */
#bells { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
#bells th { font-size: 12px; color: var(--muted); font-weight: 800; text-align: left; padding: 0 4px; }
#bells td { padding: 0 3px; vertical-align: middle; }
#bells tr.lesson td:first-child .num { width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
#bells tr.break td { background: #F3FAFF; }
#bells tr.break td:first-child { border-radius: 10px 0 0 10px; } #bells tr.break td:last-child { border-radius: 0 10px 10px 0; }
#bells tr.break .num { font-size: 11px; background: #F2A900; color: #3A2E00; padding: 2px 7px; border-radius: 999px; font-weight: 900; white-space: nowrap; }
#bells .inp.sm { width: 100%; min-width: 0; }
#bells input[type="time"].inp.sm { width: 100%; }
#bells .end { font-size: 12px; color: var(--muted); white-space: nowrap; }
#bells .acts { white-space: nowrap; }
#bells .acts button { width: 30px; min-width: 30px; min-height: 30px; padding: 0; font-size: 13px; }
#bells tr.flash td { box-shadow: inset 0 0 0 2px var(--accent); }
#bells tr.qa-err td:nth-child(2) .inp { border-color: #DC2626; }
.bells-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tcard { border: 2px solid var(--line); border-radius: 12px; padding: 6px; background: #fff; text-align: left; }
.tcard:hover { border-color: var(--navy); }
.tcard[aria-pressed="true"] { border-color: var(--navy); box-shadow: 0 0 0 3px var(--accent-soft); }
.tcard .mini { height: 62px; border-radius: 8px; position: relative; overflow: hidden; margin-bottom: 6px; border: 1px solid #E3E6EF; }
.tcard .mini .bar { position: absolute; left: 8%; right: 30%; top: 12%; height: 14%; border-radius: 3px; }
.tcard .mini .pill { position: absolute; right: 8%; top: 12%; width: 16%; height: 14%; border-radius: 999px; }
.tcard .mini .blk { position: absolute; top: 40%; height: 42%; width: 26%; border-radius: 5px; border: 2px solid; }
.tcard .tname { font-weight: 800; font-size: 14px; }
.tcard .twho { font-size: 11px; color: var(--muted); line-height: 1.25; }
/* ---------- дни ---------- */
.days-list { display: flex; flex-direction: column; gap: 6px; }
.days-list .row-h .inp { flex: 1; }

/* ---------- предметы ---------- */
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: stretch; border-radius: 999px; border: 2px solid var(--c, var(--line)); background: var(--t, #fff); min-height: 38px; overflow: hidden; }
.chip { max-width: 100%; }
.chip .pick { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 5px; border: 0; background: transparent; font-size: 13px; font-weight: 800; cursor: grab; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chip .edit { border: 0; border-left: 2px solid var(--c); background: rgba(255,255,255,.55); padding: 0 8px; font-size: 13px; }
.chip .edit:hover { background: #fff; }
.chip .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--c); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.chip[data-brush="true"] { box-shadow: 0 0 0 3px var(--navy); }
.chip.dragging { opacity: .5; }
.chip.editing .edit { background: var(--navy); color: #fff; }
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.icon-grid button { aspect-ratio: 1; border: 2px solid var(--line); border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.icon-grid button[aria-pressed="true"] { border-color: var(--navy); background: var(--accent-soft); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.presets button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--navy); }
.swatch .sample { width: 120px; min-height: 40px; border-radius: 10px; border: 2px solid var(--a); background: var(--t); color: var(--s); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; }
body[data-brush] #sheet-host .cell { cursor: crosshair; }

/* ---------- всплывающий выбор предмета ---------- */
.pop { position: absolute; z-index: 20; width: 340px; max-width: calc(100% - 24px); background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); padding: 10px 12px 12px; }
.pop h4 { margin: 0 0 8px; font-size: 14px; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.pop h4 .x { margin-left: auto; }
.pop .pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 300px; overflow: auto; padding: 2px; }
.pcard { display: flex; align-items: center; gap: 7px; min-height: 42px; padding: 4px 8px 4px 5px; border-radius: 11px; border: 2px solid var(--c, var(--line)); background: var(--t, #fff); text-align: left; font-size: 13px; font-weight: 800; line-height: 1.1; }
.pcard .dot { width: 26px; height: 26px; border-radius: 50%; background: var(--c); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.pcard[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--navy); }
.pcard.empty { border-style: dashed; color: var(--muted); justify-content: center; }
.pop .pfoot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- диалоги ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); color: var(--ink); }
dialog::backdrop { background: rgba(20,24,48,.5); }
dialog form, dialog .dlg { padding: 18px 20px 20px; }
dialog h3 { margin: 0 0 12px; font-size: 20px; font-weight: 900; color: var(--navy); text-transform: none; letter-spacing: 0; }
dialog p { line-height: 1.45; margin: 0 0 10px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; font-weight: 800; color: var(--muted); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--navy); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
#welcome { width: min(640px, 94vw); }
#welcome .big { display: grid; gap: 10px; margin-top: 14px; }
#welcome .big .btn { justify-content: flex-start; text-align: left; gap: 12px; }
#welcome .big .btn small { font-weight: 700; color: var(--muted); display: block; font-size: 13px; }
#welcome .big .btn.primary small { color: #D6DCF5; }
.plist { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; }
.pitem { border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pitem.current { border-color: var(--navy); background: #F5F7FF; }
.pitem .pname { font-weight: 900; flex: 1; min-width: 140px; }
.pitem .pdate { font-size: 12px; color: var(--muted); }
.pitem .pacts { display: flex; gap: 4px; flex-wrap: wrap; }
.tips li { margin: 6px 0; line-height: 1.4; }

/* ---------- QA на экране ---------- */
.cell { cursor: pointer; position: relative; }
.cell:hover { filter: brightness(.97); }
@media screen { .cell[data-ghost] { border-color: #E6E9F2 !important; } }
.cell.is-empty::after { content: '+'; position: absolute; right: 6px; top: 2px; font-size: 18px; font-weight: 900; color: #B9BFD0; opacity: 0; transition: opacity .15s; }
.cell.is-empty:hover::after { opacity: 1; }
.cell.qa-overflow { box-shadow: 0 0 0 3px #F59E0B, 0 0 0 6px #FEF3C7 !important; }
.cell.drop-target, .cell.pop-target { box-shadow: 0 0 0 3px var(--navy) !important; }
.tcell.qa-overlap { box-shadow: 0 0 0 3px #DC2626 !important; }
.tcell.qa-gap { box-shadow: 0 0 0 3px #F59E0B !important; }
.tcell, .dhead { cursor: pointer; }
.row-qa-count { box-shadow: 0 0 0 3px #DC2626 !important; }
.cell:focus-visible, .tcell:focus-visible, .dhead:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.sheet-hint { position: absolute; left: 50%; top: 42%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 3; text-align: center; max-width: 420px; }

/* ---------- печать ---------- */
@media print {
  html, body { height: auto; background: #fff; display: block; }
  #topbar, #savebar, #conflictbar, #mobile-switch, #panel, #statusbar, dialog, .pop, .sheet-hint { display: none !important; }
  #app { display: block; }
  #preview-wrap { overflow: visible; padding: 0; }
  #preview-scaler { transform: none !important; width: auto !important; height: auto !important; margin: 0 !important; }
  #sheet-host > div { box-shadow: none; }
  .cell, .tcell, .dhead { box-shadow: none !important; filter: none !important; outline: none !important; }
  .cell.is-empty::after { display: none; }
  html, body { width: 297mm; height: 210mm; overflow: hidden; }
}
/* ---------- узкие экраны ---------- */
@media (max-width: 900px) {
  :root { --topbar-h: auto; }
  #topbar { flex-wrap: nowrap; overflow-x: auto; padding: 6px 8px; gap: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #topbar::-webkit-scrollbar { display: none; }
  #topbar .brand { display: none; }
  #proj-name { max-width: 150px; flex: 0 0 auto; }
  #topbar .tb-spacer { display: none; }
  #topbar .btn { flex: 0 0 auto; }
  .save-state { font-size: 0; gap: 0; flex: 0 0 auto; }
  .save-state::before { width: 12px; height: 12px; }
  #mobile-switch button { min-height: 34px; }
  #mobile-switch { display: flex; gap: 4px; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--line); }
  #mobile-switch button { flex: 1; min-height: 38px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-weight: 800; }
  #mobile-switch button[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
  #app { grid-template-columns: 1fr; }
  body[data-view="sheet"] #panel { display: none; }
  body[data-view="panel"] #preview-wrap { display: none; }
  #preview-wrap { padding: 10px; }
  #statusbar { margin: -10px -10px 10px; padding: 6px 10px; }
  .pop { width: calc(100% - 20px); }
}

.site-return { color: var(--muted); text-decoration: none; white-space: nowrap; padding: 6px; }
.site-return:hover { color: var(--accent); }
.site-release { color: var(--muted); font-size: 10px; white-space: nowrap; }
