:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #19191a;
  --muted: #818c99;
  --border: #e5e7eb;
  --accent: #2688eb;
  --accent-soft: #eaf4ff;
  --green: #2ea043;
  --green-soft: #eaf7ed;
  --orange: #d97706;
  --orange-soft: #fff4df;
  --purple: #7c3aed;
  --purple-soft: #f1eafe;
  --red: #d43c3c;
  --shadow: 0 8px 28px rgba(0, 0, 0, .06);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #191c22;
  --surface-2: #22262e;
  --text: #f4f6f8;
  --muted: #9aa5b1;
  --border: #2d333d;
  --accent: #5aa8ff;
  --accent-soft: #172b42;
  --green: #53c66b;
  --green-soft: #193323;
  --orange: #ffb45a;
  --orange-soft: #3a2b16;
  --purple: #b894ff;
  --purple-soft: #2e2147;
  --red: #ff7a7a;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
body { padding: env(safe-area-inset-top, 0px) 0 calc(78px + var(--safe-bottom)); }
button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { max-width: 760px; margin: 0 auto; min-height: 100%; }
.topbar { padding: 18px 16px 12px; position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); }
.brand-row, .page-heading, .section-head, .date-nav, .setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1, h2 { margin: 2px 0 0; line-height: 1.15; }
h1 { font-size: 28px; }
h2 { font-size: 21px; }
.week-strip { display: flex; align-items: center; gap: 9px; margin-top: 12px; }
.week-pill, .count-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.4; }
.icon-btn, .round-btn { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; font-size: 22px; }
.round-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 25px; line-height: 1; }

main { padding: 0 14px 22px; }
.view { display: none; animation: fade .16s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .45; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.date-nav { margin: 8px 0 12px; }
.date-title-wrap { text-align: center; min-width: 0; }
.date-title { font-size: 20px; font-weight: 800; }
.day-chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.day-chip { border: 0; background: transparent; border-radius: 14px; padding: 8px 2px; cursor: pointer; min-width: 0; }
.day-chip span, .day-chip strong { display: block; }
.day-chip span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.day-chip strong { font-size: 15px; margin-top: 3px; }
.day-chip.active { background: var(--accent); color: white; }
.day-chip.active span { color: rgba(255,255,255,.78); }
.day-chip.today:not(.active) { background: var(--accent-soft); color: var(--accent); }

.next-card { border-radius: 20px; padding: 16px; margin: 8px 0 18px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, #7657ff)); color: white; box-shadow: var(--shadow); }
.next-card.hidden, .hidden { display: none !important; }
.next-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; opacity: .86; text-transform: uppercase; letter-spacing: .05em; }
.next-subject { font-size: 20px; font-weight: 800; margin-top: 7px; }
.next-meta { margin-top: 6px; font-size: 14px; opacity: .9; }

.section-head { margin: 16px 2px 10px; align-items: flex-end; }
.segmented { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }
.segmented.wide { width: 100%; }
.seg { border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 7px 9px; font-size: 12px; font-weight: 700; cursor: pointer; flex: 1; white-space: nowrap; }
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.lesson-list, .homework-list, .homework-groups { display: grid; gap: 9px; }
.lesson-card { display: grid; grid-template-columns: 88px minmax(0, 1fr); border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.lesson-time { padding: 15px 12px; background: var(--surface-2); border-right: 1px solid var(--border); font-size: 12px; font-weight: 800; white-space: pre-line; line-height: 1.5; }
.lesson-body { padding: 14px; min-width: 0; }
.lesson-subject { font-size: 16px; font-weight: 800; overflow-wrap: anywhere; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.lesson-card.current { border-color: color-mix(in srgb, var(--green) 55%, var(--border)); }
.lesson-card.next { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.lesson-card.past { opacity: .62; }
.type-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 7px; font-size: 11px; font-weight: 800; }
.type-lecture { color: var(--purple); background: var(--purple-soft); }
.type-seminar { color: var(--orange); background: var(--orange-soft); }
.type-other { color: var(--muted); background: var(--surface-2); }

.empty-card { border: 1px dashed var(--border); border-radius: var(--radius); padding: 26px 18px; text-align: center; color: var(--muted); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.empty-icon { font-size: 26px; margin-bottom: 6px; }

.homework-head { margin-top: 22px; }
.text-btn { border: 0; background: transparent; color: var(--accent); font-weight: 700; cursor: pointer; padding: 6px; }
.hw-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 11px; padding: 14px; border: 1px solid var(--border); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.hw-check { width: 24px; height: 24px; margin: 1px 0 0; accent-color: var(--green); cursor: pointer; }
.hw-check:disabled { cursor: default; opacity: .65; }
.hw-title { font-weight: 800; font-size: 14px; }
.hw-text { margin-top: 5px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.hw-meta { margin-top: 7px; color: var(--muted); font-size: 11px; }
.hw-card.done .hw-title, .hw-card.done .hw-text { text-decoration: line-through; opacity: .6; }

.page-heading { margin: 12px 2px 14px; }
.week-controls { display: flex; gap: 7px; }
.week-list { display: grid; gap: 10px; }
.week-day { border: 1px solid var(--border); background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.week-day-header { width: 100%; border: 0; background: transparent; padding: 14px 15px; display: flex; justify-content: space-between; gap: 12px; align-items: center; text-align: left; cursor: pointer; }
.week-day-title { font-weight: 800; }
.week-day-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.week-day-count { font-size: 12px; color: var(--muted); text-align: right; }
.week-day-body { padding: 0 14px 14px; display: grid; gap: 7px; }
.week-mini-lesson { border-left: 3px solid var(--accent); padding: 5px 0 5px 10px; }
.week-mini-lesson b { display: block; font-size: 13px; }
.week-mini-lesson span { color: var(--muted); font-size: 11px; }

.homework-toolbar { display: grid; gap: 9px; margin-bottom: 14px; }
.search-input, .select-input { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 13px; padding: 12px 13px; outline: none; }
.search-input:focus, .select-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hw-group { margin-bottom: 16px; }
.hw-group-title { display: flex; justify-content: space-between; margin: 0 3px 8px; font-weight: 800; font-size: 13px; }

.settings-card, .about-card { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 12px; }
.setting-row { padding: 15px; }
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-title { font-weight: 800; font-size: 14px; margin-bottom: 3px; }
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; top: 3px; left: 3px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.select-input { width: auto; min-width: 120px; padding: 9px 10px; }
.about-card { padding: 16px; }
.about-title { font-weight: 900; font-size: 18px; margin-bottom: 5px; }
.connection-state { margin-top: 12px; font-size: 12px; color: var(--green); }
.notice { padding: 13px 14px; background: var(--orange-soft); color: var(--orange); border-radius: 14px; font-size: 12px; margin-bottom: 12px; }

.bottom-nav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 760px; display: grid; grid-template-columns: repeat(4, 1fr); padding: 7px 8px calc(7px + var(--safe-bottom)); background: color-mix(in srgb, var(--surface) 93%, transparent); border-top: 1px solid var(--border); backdrop-filter: blur(20px); }
.nav-item { border: 0; background: transparent; min-height: 52px; border-radius: 14px; color: var(--muted); cursor: pointer; display: grid; place-items: center; align-content: center; gap: 2px; }
.nav-item span { font-size: 20px; line-height: 1; }
.nav-item small { font-size: 10px; font-weight: 700; }
.nav-item.active { color: var(--accent); background: var(--accent-soft); }

.toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-bottom)); transform: translate(-50%, 14px); opacity: 0; pointer-events: none; background: #222; color: #fff; padding: 10px 14px; border-radius: 999px; font-size: 12px; transition: .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 620px) {
  main { padding-left: 22px; padding-right: 22px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .week-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .lesson-card { grid-template-columns: 76px minmax(0, 1fr); }
  .lesson-time { padding-left: 10px; padding-right: 8px; }
  .seg { padding-left: 7px; padding-right: 7px; }
}

/* v4.1 — admin homework + realtime */
.section-actions, .page-actions, .modal-actions, .modal-actions-right, .hw-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-actions { justify-content: flex-end; flex-wrap: wrap; }
.primary-mini-btn, .primary-btn, .secondary-btn, .danger-btn, .hw-edit-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}
.primary-mini-btn {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  font-size: 12px;
}
.hw-main { min-width: 0; }
.hw-title-row { justify-content: space-between; align-items: flex-start; }
.hw-edit-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 17px;
  margin: -5px -4px 0 4px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  padding-bottom: calc(18px + var(--safe-bottom));
  background: rgba(0,0,0,.42);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(100%, 620px);
  max-height: calc(100vh - 34px);
  overflow: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 24px;
  padding: 17px;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
}
.modal-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom: 14px; }
.hw-form { display: grid; gap: 12px; }
.hw-form label { display:grid; gap:6px; color:var(--muted); font-size:12px; font-weight:700; }
.textarea-input { resize: vertical; min-height: 112px; font-family: inherit; }
.form-grid { display:grid; grid-template-columns: 1fr 1fr; gap:10px; }
.modal-actions { justify-content: space-between; margin-top: 4px; flex-wrap: wrap; }
.modal-actions-right { margin-left: auto; }
.primary-btn, .secondary-btn, .danger-btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 13px;
}
.primary-btn { background: var(--accent); color: white; }
.secondary-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.danger-btn { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.primary-btn:disabled { opacity: .55; cursor: wait; }
@media (min-width: 620px) {
  .modal-backdrop { align-items: center; }
}
@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
  .section-actions { gap: 3px; }
  .primary-mini-btn { padding-left: 9px; padding-right: 9px; }
}

/* v4.2 — мастер добавления ДЗ */
.wizard-modal { max-width: 620px; }
.wizard-progress { display:flex; align-items:center; gap:8px; margin: 2px 0 18px; }
.wizard-progress-item { display:grid; justify-items:center; gap:5px; min-width:62px; color:var(--muted); font-size:11px; font-weight:800; }
.wizard-progress-item span { display:grid; place-items:center; width:30px; height:30px; border-radius:50%; border:1px solid var(--border); background:var(--surface); color:var(--muted); }
.wizard-progress-item.active span { background:var(--accent); border-color:var(--accent); color:white; }
.wizard-progress-item.done span { background:var(--accent-soft); border-color:transparent; color:var(--accent); }
.wizard-progress-item.done span::before { content:'✓'; font-size:14px; }
.wizard-progress-item.done span { font-size:0; }
.wizard-progress-line { height:1px; background:var(--border); flex:1; min-width:12px; margin-top:-18px; }
.wizard-copy { margin-bottom:12px; }
.wizard-copy h3 { margin:0 0 4px; font-size:18px; }
.wizard-copy p { margin:0; color:var(--muted); font-size:13px; line-height:1.45; }
.subject-picker, .occurrence-picker { display:grid; gap:9px; }
.subject-option, .occurrence-option { width:100%; display:flex; align-items:center; gap:12px; border:1px solid var(--border); background:var(--surface); color:var(--text); border-radius:16px; padding:13px 14px; text-align:left; min-height:64px; cursor:pointer; }
.subject-option:active, .occurrence-option:active { transform:scale(.995); }
.subject-option-icon { display:grid; place-items:center; width:38px; height:38px; border-radius:12px; background:var(--accent-soft); flex:0 0 auto; font-size:18px; }
.subject-option-copy, .occurrence-date { display:grid; gap:3px; min-width:0; flex:1; }
.subject-option-copy strong, .occurrence-date strong { font-size:14px; overflow-wrap:anywhere; }
.subject-option-copy small, .occurrence-date small { font-size:12px; color:var(--muted); }
.subject-option-arrow { color:var(--muted); font-size:24px; line-height:1; }
.occurrence-room { color:var(--muted); font-size:12px; text-align:right; }
.selected-subject-card, .selected-lesson-card { border:1px solid var(--border); background:var(--accent-soft); border-radius:16px; padding:12px 14px; margin-bottom:14px; }
.selected-subject-card { display:flex; align-items:center; gap:10px; }
.selected-subject-card > span { font-size:20px; }
.selected-subject-card div { display:grid; gap:2px; }
.selected-subject-card small { color:var(--muted); }
.selected-lesson-card { display:grid; gap:4px; }
.selected-lesson-card strong { font-size:16px; }
.selected-lesson-card > div:last-child { color:var(--muted); font-size:13px; }
.selected-lesson-date { color:var(--accent)!important; font-size:12px!important; font-weight:800; text-transform:uppercase; letter-spacing:.03em; }
.wizard-back { border:0; background:transparent; color:var(--accent); padding:0 0 12px; font:inherit; font-size:13px; font-weight:800; cursor:pointer; }
.wide-btn { width:100%; justify-content:center; margin-top:10px; }
.picker-loading { padding:18px; text-align:center; color:var(--muted); }
.extra-toggle { border:0; background:transparent; color:var(--accent); padding:4px 0; text-align:left; font:inherit; font-size:13px; font-weight:800; cursor:pointer; }
.extra-fields { display:grid; gap:12px; padding:13px; border:1px solid var(--border); background:var(--surface-2); border-radius:16px; }
.edit-lock-note { margin:-4px 0 14px; padding:10px 12px; border-radius:12px; background:var(--surface-2); color:var(--muted); font-size:12px; line-height:1.4; }
.hw-extras { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.hw-extra { display:inline-flex; align-items:center; min-height:24px; padding:3px 8px; border-radius:999px; background:var(--surface-2); color:var(--muted); font-size:11px; font-weight:700; text-decoration:none; }
.hw-extra.important { color:var(--red); background:color-mix(in srgb, var(--red) 10%, transparent); }
.hw-link { color:var(--accent); }
.hw-note { margin-top:7px; color:var(--muted); font-size:12px; line-height:1.45; }
.important-hw { border-color:color-mix(in srgb, var(--red) 35%, var(--border)); }

@media (max-width: 520px) {
  .wizard-progress-item { min-width:54px; }
  .wizard-progress-item small { font-size:10px; }
  .occurrence-option { align-items:flex-start; }
  .occurrence-room { max-width:90px; }
}
