:root {
    --bg: #0f1420;
    --panel: #1a2233;
    --panel-2: #232d42;
    --line: #2c3752;
    --text: #e7ecf5;
    --muted: #8a97b1;
    --accent: #4f8cff;
    --danger: #ef4444;
    --gutter-w: 38px;
    --hour-h: 60px;
    --rows: 15;
    --radius: 12px;
    --scroll-thumb: #3a465f;
    --scroll-thumb-hover: #4d5c7a;
}

/* Светлая тема — меняется только «обвязка»; цвета занятий и детей (inline) не трогаем */
:root[data-theme="light"] {
    --bg: #f3f5fa;
    --panel: #ffffff;
    --panel-2: #eceff5;
    --line: #d9dfea;
    --text: #1b2436;
    --muted: #6b7689;
    --scroll-thumb: #c3ccdb;
    --scroll-thumb-hover: #a7b2c6;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* кастомная полоса прокрутки под тему */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb); border-radius: 8px;
    border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

html { overflow-x: hidden; }   /* без горизонтальной прокрутки страницы */
html.noscroll { overflow: hidden; }   /* блок прокрутки, пока открыт оверлей дня */
html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
/* прокручивается вся страница: шапка уезжает вверх, нативный pull-to-refresh работает */
body { min-height: 100dvh; }

/* ---------- Верхняя панель ---------- */
.topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who { color: var(--muted); font-size: 13px; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--panel-2); color: var(--text); border: none;
    font-size: 18px; text-decoration: none; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
#btnRefresh { font-size: 22px; }
.ref-ico { display: inline-block; line-height: 1; }
.icon-btn.spinning .ref-ico { animation: iconspin .5s linear; }
@keyframes iconspin { to { transform: rotate(360deg); } }

/* ---------- Панель расписаний (чипсы) ---------- */
.schedbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
    display: flex; align-items: center; gap: 10px; justify-content: space-between;
}
.acc-name { font-size: 12px; color: var(--muted); white-space: nowrap; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 20px;
    padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: rgba(79,140,255,.18); }
.chip i, .ev-sched i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* ---------- Сетка ---------- */
.grid {
    position: relative;   /* не скролл-контейнер: прокручивается страница */
}
.grid-head {
    display: grid;
    grid-template-columns: var(--gutter-w) repeat(7, minmax(0, 1fr));
    position: sticky; top: 0; z-index: 20;   /* строка дней недели «липнет» к верху */
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.corner { z-index: 21; background: var(--panel); }
.dhead {
    text-align: center; padding: 7px 1px; font-size: 12px; font-weight: 600;
    color: var(--muted); border-left: 1px solid var(--line);
    position: relative; cursor: pointer;
}
.dhead:active { background: var(--panel-2); }

/* узкий экран: день на всю ширину на месте, уголок ‹ — назад */
.grid.single .grid-head,
.grid.single .grid-body { grid-template-columns: var(--gutter-w) 1fr; }
.grid.single .corner {
    cursor: pointer; color: var(--text); font-size: 20px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

/* широкий экран: неделя в блюре, выбранный день — панелью по центру */
.grid.blurred { filter: blur(4px); opacity: .55; pointer-events: none; }
.day-overlay {
    position: fixed; inset: 0; z-index: 40;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 12px; background: rgba(5, 8, 15, .35);
    overflow: auto;
}
.day-panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 16px; width: 480px; max-width: calc(100% - 24px);
    margin-top: 64px; max-height: calc(100dvh - 88px); overflow: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
}
.day-panel-head {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 2; background: var(--panel);
    padding: 12px 14px; border-bottom: 1px solid var(--line);
    font-weight: 700; font-size: 16px;
}
.day-close {
    margin-left: auto; width: 34px; height: 34px; border-radius: 9px;
    background: var(--panel-2); color: var(--text); border: none; font-size: 16px; cursor: pointer;
}
.day-grid {
    display: grid; grid-template-columns: var(--gutter-w) 1fr;
    position: relative;
}
.dhead.today { color: var(--text); }
.dhead.today::after {
    content: ''; position: absolute; left: 50%; transform: translateX(-50%);
    bottom: 2px; width: 22px; height: 2px; border-radius: 2px;
    background: #ff3b3b; box-shadow: 0 0 6px 1px rgba(255,59,59,.8);
}

.grid-body {
    display: grid;
    grid-template-columns: var(--gutter-w) repeat(7, minmax(0, 1fr));
    height: calc(var(--rows) * var(--hour-h));
}
.gutter {
    position: sticky; left: 0; z-index: 4;
    background: var(--bg);
    border-right: 1px solid var(--line);
}
.gutter-cell {
    height: var(--hour-h);
    font-size: 10px; color: var(--muted);
    text-align: right; padding: 1px 4px 0 0;
    box-sizing: border-box;
}
.day-col {
    position: relative;
    border-left: 1px solid var(--line);
}
.hour-line {
    height: var(--hour-h);
    border-bottom: 1px solid var(--line);
    pointer-events: none;
}

/* светящаяся полоса текущего времени (на сегодняшней колонке) */
.now-line {
    position: absolute; left: 0; right: 0; height: 0;
    border-top: 2px solid #ff3b3b;
    box-shadow: 0 0 6px 1px rgba(255,59,59,.85), 0 0 14px 4px rgba(255,59,59,.4);
    z-index: 15; pointer-events: none;
}
.now-dot {
    position: absolute; left: -3px; top: -4px;
    width: 8px; height: 8px; border-radius: 50%;
    background: #ff3b3b;
    box-shadow: 0 0 6px 2px rgba(255,59,59,.9);
}

/* ---------- Событие ---------- */
.event {
    position: absolute;
    left: 2px; right: 2px;
    border-radius: 6px;
    padding: 2px 4px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.35);
    display: flex; flex-direction: column; justify-content: center; gap: 0;
    font-size: 10px; line-height: 1.15;
}
.event:active { filter: brightness(1.1); }
.ev-title { font-weight: 700; overflow: hidden; overflow-wrap: anywhere; }
.ev-dur { font-size: 9px; font-weight: 400; opacity: .78; margin-left: 4px; white-space: nowrap; }
.ev-time { font-size: 10px; opacity: .85; }
.ev-sched {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 9px; margin-top: auto; opacity: .9;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- FAB ---------- */
.fab {
    position: fixed;
    right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--accent); color: #fff; border: none;
    font-size: 30px; line-height: 1; cursor: pointer;
    box-shadow: 0 6px 18px rgba(79,140,255,.5);
    z-index: 20;
}
.fab:active { transform: scale(.94); }

/* ---------- Модалки ---------- */
.modal {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(5,8,15,.65);
    display: flex; align-items: flex-end; justify-content: center;
    padding: 0;
}
.modal.hidden, .hidden { display: none; }
.modal-card {
    background: var(--panel);
    width: 100%; max-width: 460px;
    border-radius: 18px 18px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    max-height: 90dvh; overflow-y: auto;
    animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-card h2 { margin: 0 0 14px; font-size: 18px; }
.modal-card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
input[type=text], input[type=password], input[type=time], select, input[type=color] {
    width: 100%; margin-top: 5px;
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 10px;
    padding: 11px 12px; font-size: 15px;
}
input[type=color] { height: 46px; padding: 4px; }
input[type=checkbox] { width: auto; margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.icon-search { width: 100%; margin: 0 0 8px; }
.emoji-palette { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; max-height: 168px; overflow-y: auto; }
.emoji {
    width: 40px; height: 40px; border-radius: 10px;
    border: 2px solid transparent; background: var(--panel-2);
    font-size: 20px; line-height: 1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.emoji.active { border-color: var(--accent); }
.emoji-none { color: var(--muted); font-size: 16px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.spacer { flex: 1; }
button.btn-primary, button.btn-ghost, button.btn-danger {
    border: none; border-radius: 10px; padding: 11px 16px;
    font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--panel-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger.small { padding: 6px 10px; font-size: 13px; }

.alert {
    background: rgba(239,68,68,.15); color: #fca5a5;
    border: 1px solid rgba(239,68,68,.4);
    padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 12px;
}

/* ---------- Карточка просмотра занятия ---------- */
.view-tile {
    position: relative;
    border-radius: 14px;
    padding: 22px 18px;
    min-height: 120px;
    display: flex; flex-direction: column; justify-content: center; gap: 8px;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.view-edit {
    position: absolute; top: 10px; right: 10px;
    width: 42px; height: 42px; border-radius: 11px;
    background: rgba(0,0,0,.28); border: none;
    font-size: 20px; line-height: 1; cursor: pointer;
}
.view-edit:active { background: rgba(0,0,0,.45); }
.view-name { font-size: 26px; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.view-time { font-size: 20px; font-weight: 600; opacity: .92; }
.view-info {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
    margin: 16px 2px 4px; font-size: 16px; color: var(--text);
}
.vinfo-day { color: var(--muted); }
.vinfo-child { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.vinfo-child i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ---------- Список пользователей ---------- */
.users-list { list-style: none; margin: 0; padding: 0; }
.users-list li {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.tag { font-size: 10px; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 6px; font-weight: 700; }
.tag.off { background: #ef4444; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--panel-2); border: 1px solid var(--line);
    padding: 1px 6px; border-radius: 6px; font-weight: 700; letter-spacing: 1px; }

/* редактор расписаний */
.sched-item { display: flex; align-items: center; gap: 8px; flex: 1; }
.mini-color { width: 36px !important; height: 36px; padding: 3px; margin: 0; flex-shrink: 0; }
.mini-icon { width: 44px !important; margin: 0 !important; padding: 8px 6px; text-align: center; flex-shrink: 0; }
.mini-name { margin: 0 !important; padding: 8px 10px; }
.sched-acts { display: flex; gap: 6px; flex-shrink: 0; margin-left: 8px; }

.alert.ok { background: rgba(34,197,94,.15); color: #86efac; border-color: rgba(34,197,94,.4); }

/* ---------- Вход ---------- */
.login-body { display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 18px; padding: 28px 22px; width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.login-card .muted { color: var(--muted); text-align: center; margin: 0 0 18px; font-size: 14px; }
.login-card button { width: 100%; background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 13px; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 6px; }
.muted { color: var(--muted); }

@media (min-width: 560px) {
    .modal { align-items: center; }
    .modal-card { border-radius: 18px; }
}

/* ---------- Печать / PDF ---------- */
.print-head { display: none; }
@media print {
    @page { size: landscape; margin: 6mm; }
    html, body { background: #fff !important; color: #000 !important; }
    .topbar, .schedbar, .fab, .now-line, .modal, .day-overlay { display: none !important; }
    .grid.blurred { filter: none !important; opacity: 1 !important; }

    .print-head { display: block; margin: 0 0 6px; }
    .print-title { font-size: 16px; font-weight: 800; color: #000; }
    .print-sub { font-size: 12px; color: #333; margin-top: 2px; }

    .grid { overflow: visible !important; }
    .grid-head { position: static !important; box-shadow: none !important; background: #fff !important; }
    .corner, .gutter { background: #fff !important; }
    .dhead, .gutter-cell { color: #000 !important; }
    .day-col, .hour-line, .grid-head, .dhead { border-color: #bbb !important; }

    /* без указателя текущего дня */
    .dhead.today { color: #000 !important; }
    .dhead.today::after { display: none !important; }

    /* чёрно-белые плитки: без заливки и цветной полосы ребёнка */
    .event {
        background: #fff !important;
        color: #000 !important;
        border: 1px solid #555 !important;
        box-shadow: none !important;
    }

    /* уместить неделю на одной странице (без разрыва между шапкой и телом) */
    .grid, .grid-head, .grid-body { page-break-inside: avoid; break-inside: avoid; }
}
