/* Расписание 307 — Apple-стилистика. Light/dark через [data-theme]. */
:root {
  --bg: #ffffff;
  --bg2: #f5f5f7;
  --fg: #1d1d1f;
  --fg2: #86868b;
  --sep: #d2d2d7;
  --card: #ffffff;
  --line: #ececf0;
  --accent: #0071e3;
  --badge-bg: rgba(0, 113, 227, 0.09);
  --btn-bg: rgba(120, 120, 128, 0.12);
  --banner-bg: rgba(250, 250, 252, 0.92);
}
html[data-theme="dark"] {
  --bg: #000000;
  --bg2: #1c1c1e;
  --fg: #f5f5f7;
  --fg2: #86868b;
  --sep: #38383a;
  --card: #1c1c1e;
  --line: #2c2c2e;
  --accent: #0a84ff;
  --badge-bg: rgba(10, 132, 255, 0.16);
  --btn-bg: rgba(120, 120, 128, 0.24);
  --banner-bg: rgba(28, 28, 30, 0.94);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }

/* ---------- Шапка: липкая строка заголовка + уезжающая панель управления ---------- */
.hdr {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 6px;
}
.brand h1 { margin: 0; font-size: 25px; font-weight: 700; letter-spacing: -0.4px; }
.sub { margin: 2px 0 0; font-size: 11.5px; color: var(--fg2); }
.sub b { color: var(--accent); font-weight: 600; }

.iconbtn {
  flex: none; width: 34px; height: 34px; margin-top: 2px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--btn-bg); color: var(--fg);
  cursor: pointer;
}
html[data-theme="light"] .ic-moon { display: none; }
html[data-theme="dark"] .ic-sun { display: none; }

.hdr-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* панель управления: на мобиле сворачивается при скролле, липкой остаётся строка заголовка */
.panel { padding-bottom: 10px; }
@media (min-width: 769px) { .panel { padding-bottom: 0; } }
.panel .controls, .panel .weekrow, .panel .daytabs { margin-top: 10px; }

/* ---------- Сегментированные переключатели ---------- */
.seg {
  display: flex; width: 100%;
  background: var(--btn-bg); border-radius: 9px; padding: 2px;
}
.seg button {
  flex: 1; min-height: 32px;
  border: none; border-radius: 7px;
  background: transparent; color: var(--fg);
  font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; padding: 4px 8px;
}
.seg button[aria-pressed="true"] {
  background: var(--card); color: var(--fg); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
html[data-theme="dark"] .seg button[aria-pressed="true"] { background: #5a5a5e; box-shadow: none; }
.controls { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.lab { font-size: 13px; font-weight: 600; color: var(--fg2); }
.groupseg { width: auto; }
.groupseg button { flex: none; min-width: 48px; padding: 6px 16px; }
.weekrow { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.wk-step {
  flex: none; width: 30px; height: 30px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--btn-bg); color: var(--fg); cursor: pointer;
}
.wk-step:disabled { opacity: 0.35; cursor: default; }
.weekseg { flex: 1 1 auto; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.weekseg::-webkit-scrollbar { display: none; }
.weekseg button { flex: 1 0 auto; min-width: 34px; }
.weekseg button.istoday { color: var(--accent); font-weight: 600; }

/* ---------- Табы дней: пилюли с датами + «Вся неделя» ---------- */
.daytabs {
  display: flex; gap: 4px; margin-top: 12px;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.daytabs::-webkit-scrollbar { display: none; }
.daytabs button {
  flex: 1 0 0; min-width: 0; min-height: 46px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: none; border-radius: 10px; background: transparent; cursor: pointer;
  color: var(--fg2); padding: 5px 0; position: relative;
}
.daytabs button.allweek { flex: 1.45 0 0; }
.daytabs button.allweek .dname { font-size: 11px; white-space: nowrap; }
.daytabs .dname { font-size: 12px; font-weight: 600; line-height: 1.25; }
.daytabs .ddate { font-size: 9px; line-height: 1.25; opacity: 0.85; font-variant-numeric: tabular-nums; }
.daytabs button[aria-selected="true"] {
  background: var(--accent); color: #fff; font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.daytabs button[aria-selected="true"] .ddate { opacity: 0.8; }
.backtoday {
  display: flex; align-items: center; gap: 5px;
  margin: 8px 0 0; padding: 0;
  border: none; background: none; cursor: pointer;
  color: var(--accent); font-size: 12.5px; font-weight: 500;
  min-height: 32px;
}
.backtoday[hidden] { display: none; }

/* ---------- Контент ---------- */
main { padding: 12px 16px calc(40px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.empty { color: var(--fg2); text-align: center; padding: 48px 0; font-size: 14px; }

section.day h2 {
  font-size: 14.5px; font-weight: 700; letter-spacing: 0.1px;
  margin: 20px 0 2px; padding-bottom: 6px;
  border-bottom: 1px solid var(--sep);
}
section.day:first-of-type h2 { margin-top: 4px; }
.dayempty { color: var(--fg2); font-size: 12px; padding: 10px 0 2px; }

/* мобильная карточка дня (вид «Неделя» ≤768px) */
.mday { display: none; }
.mday h2 {
  font-size: 14px; font-weight: 700; letter-spacing: 0.1px;
  margin: 14px 0 2px; padding-bottom: 6px;
  border-bottom: 1px solid var(--sep);
}
.mday .slot:last-child { border-bottom: none; }
.mday .slot { padding: 7px 0; }

.slot {
  display: grid; grid-template-columns: max-content 1fr; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--line);
}
.slot.last { border-bottom: none; padding-bottom: 2px; }
.slot .t { font-weight: 600; font-size: 11.5px; white-space: nowrap; padding-left: 5px; padding-top: 2px; }
.slot.win .wtxt { font-size: 12px; color: var(--fg2); }

.it + .it { margin-top: 7px; }
.it .name { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.badge {
  display: inline-block; font-size: 9px; font-weight: 600;
  color: var(--accent); background: var(--badge-bg);
  border-radius: 4px; padding: 1px 5px; margin-left: 6px;
  letter-spacing: 0.2px; vertical-align: 1px;
}
.it .meta { font-size: 11px; color: var(--fg2); margin-top: 1px; line-height: 1.35; overflow-wrap: anywhere; }
.it .meta a { color: var(--accent); }

/* ---------- Вид «Неделя» (десктоп) ---------- */
.table { display: none; }
.wk-day { min-width: 0; }
.wk-day .cell, .wk-day .wcell {
  border-radius: 6px; padding: 4px 7px 5px; font-size: 9px; line-height: 1.3;
}
.wk-day .cell { background: var(--bg2); }
.wk-day .cell + .cell, .wk-day .cell + .wcell { margin-top: 3px; }
.wk-day .cell .name { font-weight: 600; display: block; }
.wk-day .cell .meta { color: var(--fg2); display: block; }
.wk-day .badge { font-size: 7px; padding: 0 4px; margin-left: 3px; }
.wk-day .wcell { background: var(--bg2); color: var(--fg2); font-size: 8.5px; padding-top: 5px; padding-bottom: 5px; }
.wk-day .wcell.nowin { background: transparent; }
.wk-day .dayh {
  font-size: 10.5px; font-weight: 700; text-align: center;
  padding-bottom: 4px; border-bottom: 1px solid var(--sep); margin-bottom: 4px;
}
.wk-day .dayh span { display: block; font-weight: 400; font-size: 8.5px; color: var(--fg2); }
.wk-day.is-today .dayh { color: var(--accent); }
.wk-grid { display: grid; grid-template-columns: 64px repeat(6, 1fr); gap: 4px; }
.wk-grid .time { font-size: 8.5px; font-weight: 600; color: var(--fg2); padding-top: 2px; }
.wk-grid .time + .wk-day, .wk-day + .time { border-top: none; }
.wk-grid > div { min-width: 0; }

/* ---------- Подвал ---------- */
.ftr { padding: 8px 16px calc(28px + env(safe-area-inset-bottom)); color: var(--fg2); font-size: 11.5px; max-width: 760px; margin: 0 auto; }
.legend { margin: 3px 0; }
.legend b { color: var(--accent); font-weight: 600; }
.ftr-row { margin-top: 14px; }
.linkbtn {
  border: none; background: none; padding: 0; cursor: pointer;
  color: var(--fg2); font-size: 11.5px; text-decoration: underline;
}

/* ---------- Баннер ---------- */
.banner {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--banner-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-radius: 14px; padding: 12px 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}
.banner[hidden] { display: none; }
.banner-title { margin: 0; font-size: 13px; font-weight: 700; }
.banner-text { margin: 1px 0 0; font-size: 12px; color: var(--fg2); }
.banner-no {
  border: none; background: none; padding: 0; margin-top: 5px; cursor: pointer;
  color: var(--accent); font-size: 11.5px; font-weight: 500;
}
.banner-body { flex: 1; min-width: 0; }
.banner-x {
  flex: none; width: 30px; height: 30px; margin-top: -5px; display: grid; place-items: center;
  border: none; border-radius: 50%; background: var(--btn-bg); color: var(--fg2); cursor: pointer;
}

/* ---------- Адаптив ---------- */
@media (min-width: 769px) {
  .hdr { padding-left: 24px; padding-right: 24px; }
  main, .ftr { padding-left: 24px; padding-right: 24px; }
  .topbar, .panel, .backtoday { max-width: 760px; margin-left: auto; margin-right: auto; }
  .daytabs { margin-top: 10px; }
  /* на десктопе неделя = сетка */
  body[data-view="week"] #content .day { display: none; }
  body[data-view="week"] .table { display: grid; }
}
@media (max-width: 768px) {
  /* на мобиле шапка уезжает, липкой остаётся строка заголовка */
  .hdr { position: static; border-bottom: none; }
  .topbar { box-shadow: 0 1px 0 var(--line); }
  .brand h1 { font-size: 20px; }
  .iconbtn { margin-top: -2px; }
  .daytabs .allweek { min-width: 74px; padding-left: 7px; padding-right: 7px; }
  /* на мобиле неделя = компактные карточки дней */
  .table { display: none; }
  body[data-view="week"] .day { display: none; }
  body[data-view="week"] .mday { display: block; }
  .slot { gap: 10px; }
  .it .name { font-size: 13px; }
  .it .meta { font-size: 11.5px; }
}
@media (max-width: 380px) {
  .brand h1 { font-size: 19px; }
  .lab { font-size: 12px; }
  .groupseg button { min-width: 40px; padding: 6px 10px; }
  .weekseg button { min-width: 30px; }
  .wk-step { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
.seg button, .daytabs button, .iconbtn, .banner { transition: background 0.18s, color 0.18s, box-shadow 0.18s; }
