:root {
  --bg: var(--tg-bg, #ffffff);
  --surface: var(--tg-secondary-bg, #f7f9f9);
  --text: var(--tg-text, #0f1419);
  --hint: var(--tg-hint, #536471);
  --accent: var(--tg-button, #1d9bf0);
  --accent-text: var(--tg-button-text, #ffffff);
  --link: var(--tg-link, #1d9bf0);
  --border: rgba(15, 20, 25, 0.1);
  --red: #f4212e;
  --blue: #1d9bf0;
  --green: #00ba7c;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 20, 25, 0.06), 0 8px 24px rgba(15, 20, 25, 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-bg, #000000);
    --surface: var(--tg-secondary-bg, #16181c);
    --text: var(--tg-text, #e7e9ea);
    --hint: var(--tg-hint, #71767b);
    --border: rgba(239, 243, 244, 0.15);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-bg, #000000);
  --surface: var(--tg-secondary-bg, #16181c);
  --text: var(--tg-text, #e7e9ea);
  --hint: var(--tg-hint, #71767b);
  --border: rgba(239, 243, 244, 0.15);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; background: none; border: none; padding: 0; margin: 0; cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
input { font-family: inherit; }

#app { min-height: 100vh; padding-bottom: 88px; }

.screen { animation: fadeIn 0.2s ease forwards; }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

svg.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Hero / role picker ---------- */
.hero { padding: 40px 24px 12px; text-align: center; }
.hero-badge {
  width: 64px; height: 64px; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
}
.hero h1 { font-size: 24px; margin: 0 0 6px; font-weight: 800; letter-spacing: -0.01em; }
.hero-sub { margin: 0; color: var(--hint); font-size: 15px; }

.role-cards { display: flex; flex-direction: column; gap: 12px; padding: 24px 20px; }
.role-card {
  display: flex; align-items: center; gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: left;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.role-card:active { transform: scale(0.98); border-color: var(--accent); }
.role-icon {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: var(--bg);
  color: var(--accent);
  font-size: 24px;
}
.role-title { display: block; font-size: 16px; font-weight: 800; color: var(--text); }
.role-sub { display: block; font-size: 13px; color: var(--hint); margin-top: 2px; }
.role-card { flex-direction: row; flex-wrap: wrap; }
.role-card .role-title, .role-card .role-sub { flex-basis: 100%; }

.link-btn {
  display: block;
  margin: 4px auto 24px;
  color: var(--link);
  font-size: 14.5px;
  font-weight: 700;
  text-align: center;
  width: 100%;
}
.link-btn:active { opacity: 0.6; }

/* ---------- Picker headers ---------- */
.picker-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 12px 8px;
}
.picker-header h1 { flex: 1; text-align: center; font-size: 17px; font-weight: 800; margin: 0; }
.icon-btn-spacer { width: 38px; height: 38px; flex: 0 0 auto; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 18px;
  flex: 0 0 auto;
}
.icon-btn.bell.subscribed { background: var(--accent); color: #fff; border-color: transparent; }
.icon-btn:active { transform: scale(0.92); }

/* ---------- Course tabs + group grid ---------- */
.course-tabs {
  display: flex; gap: 8px;
  padding: 12px 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.course-tabs::-webkit-scrollbar { display: none; }
.course-chip {
  flex: 0 0 auto;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.course-chip.active { background: var(--accent); color: #fff; border-color: transparent; }

.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  padding: 14px 16px 8px;
}
.group-card {
  padding: 16px 8px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 15px;
  border: 1px solid var(--border);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.group-card:active { transform: scale(0.95); border-color: var(--accent); }

/* ---------- Search + teacher list ---------- */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 16px 12px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.search-icon { color: var(--hint); font-size: 16px; flex: 0 0 auto; display: flex; }
.search-bar input {
  border: none; outline: none; background: transparent;
  font-size: 15px; color: var(--text); width: 100%;
}
.search-bar input::placeholder { color: var(--hint); }

.teacher-list { padding: 0 16px 8px; display: flex; flex-direction: column; }
.teacher-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.teacher-row:active { background: var(--surface); }
.teacher-row:last-child { border-bottom: none; }
.teacher-name { font-size: 15px; font-weight: 700; }
.empty-note { color: var(--hint); font-size: 13.5px; padding: 24px 20px; text-align: center; }

.avatar {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

/* ---------- Main screen ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px;
  background: var(--bg);
}
.topbar-title { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.topbar-text { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.group-name { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.course-name { font-size: 11.5px; color: var(--hint); }

.week-bar { margin: 0 16px 8px; display: flex; align-items: center; gap: 8px; }
.week-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--hint);
}
.week-pill.is-red { color: var(--red); border-color: rgba(244,33,46,0.3); background: rgba(244,33,46,0.08); }
.week-pill.is-blue { color: var(--blue); border-color: rgba(29,155,240,0.3); background: rgba(29,155,240,0.08); }

.week-switch { display: flex; gap: 6px; padding: 3px; background: var(--surface); border-radius: 999px; border: 1px solid var(--border); }
.week-switch button { padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: var(--hint); }
.week-switch button.active.red { background: var(--red); color: #fff; }
.week-switch button.active.blue { background: var(--blue); color: #fff; }

.week-tag { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.week-tag.red { background: var(--red); }
.week-tag.blue { background: var(--blue); }

.live-banner {
  margin: 8px 16px 8px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}
.live-banner.is-current { border-color: rgba(0,186,124,0.35); background: rgba(0,186,124,0.08); }

.live-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.live-label { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: var(--hint); flex: 1; }
.live-banner.is-current .live-label { color: #00925f; }
@media (prefers-color-scheme: dark) { .live-banner.is-current .live-label { color: var(--green); } }
.live-time { font-size: 12px; font-weight: 700; color: var(--hint); white-space: nowrap; }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: 0 0 auto; position: relative; }
.live-dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; background: var(--green);
  opacity: 0.35; animation: livePulse 1.8s ease-out infinite;
}
.live-dot.next { background: var(--accent); }
.live-dot.next::after { display: none; }
@keyframes livePulse { 0% { transform: scale(0.4); opacity: 0.5; } 100% { transform: scale(1.7); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .live-dot::after { animation: none; opacity: 0; } }

.live-subject { font-size: 15px; font-weight: 800; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.live-change-tag { background: rgba(255,159,10,0.18); color: #b36200; border-color: transparent; }
@media (prefers-color-scheme: dark) { .live-change-tag { color: #ff9f0a; } }

.live-progress { margin-top: 10px; height: 4px; border-radius: 3px; background: var(--border); overflow: hidden; }
.live-progress-fill { height: 100%; background: var(--green); border-radius: 3px; }

.changes-banner {
  margin: 0 16px 8px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255,159,10,0.1);
  border: 1px solid rgba(255,159,10,0.3);
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.changes-banner .banner-icon { color: #ff9f0a; flex: 0 0 auto; font-size: 18px; display: flex; }

/* ---------- View toggle (День / Неделя) ---------- */
.view-toggle {
  position: sticky; top: 66px; z-index: 4;
  display: flex; gap: 22px;
  padding: 2px 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.view-tab {
  position: relative;
  padding: 10px 2px 12px;
  font-size: 14.5px; font-weight: 700;
  color: var(--hint);
}
.view-tab.active { color: var(--text); }
.view-tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 3px; border-radius: 3px 3px 0 0; background: var(--accent);
}

/* ---------- Date strip (день view) ---------- */
.date-strip {
  position: sticky; top: 108px; z-index: 4;
  display: flex; gap: 4px;
  padding: 10px 12px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg);
}
.date-strip::-webkit-scrollbar { display: none; }
.date-cell {
  flex: 0 0 auto;
  width: 46px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 6px 0 8px;
  position: relative;
}
.date-cell .dow { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: var(--hint); }
.date-cell.is-today .dow { color: var(--accent); }
.date-cell .dnum {
  width: 32px; height: 32px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800; color: var(--text);
}
.date-cell.active .dnum { background: var(--text); color: var(--bg); }
.date-cell.is-today:not(.active) .dnum { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
.date-cell .change-dot { position: absolute; top: 4px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: #ff9f0a; }

.day-heading {
  padding: 10px 16px 6px;
  font-size: 19px; font-weight: 800; letter-spacing: -0.01em;
}
.day-heading .day-heading-date { font-weight: 600; color: var(--hint); font-size: 14px; margin-left: 6px; }

/* ---------- Week view sections ---------- */
.day-section { padding: 0 16px; margin-bottom: 22px; }
.day-section-header { display: flex; align-items: baseline; gap: 8px; padding: 2px 0 10px; }
.day-section-name { font-size: 16px; font-weight: 800; }
.day-section-date { font-size: 13px; color: var(--hint); font-weight: 600; }
.day-section-header.is-today .day-section-name { color: var(--accent); }
.day-section-list { display: flex; flex-direction: column; gap: 8px; }

.slots { padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.slots.is-week { padding-left: 0; padding-right: 0; }

.slot-card {
  display: flex; gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: 14px;
  border-left: 3px solid var(--border);
}
.slot-card.has-change { border-left-color: #ff9f0a; background: rgba(255,159,10,0.07); }
.slot-card.is-break { opacity: 0.6; }
.slot-card.is-empty { opacity: 0.5; }
.slot-card.is-cancelled { opacity: 0.6; }
.slot-card.compact { padding: 10px 12px; border-radius: 12px; }
.slot-card.is-live { border-left-color: var(--green); background: rgba(0,186,124,0.07); }
.live-tag { margin-top: 3px; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; color: var(--green); }

.slot-time { flex: 0 0 60px; display: flex; flex-direction: column; align-items: center; padding-top: 2px; }
.slot-pair-num { font-weight: 800; font-size: 15px; color: var(--accent); }
.slot-time-range { font-size: 10.5px; color: var(--hint); text-align: center; margin-top: 2px; line-height: 1.3; }

.slot-body { flex: 1; min-width: 0; }
.lesson-block + .lesson-block { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.lesson-subject { font-weight: 700; font-size: 14.5px; line-height: 1.35; display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.lesson-group-tag {
  font-size: 11px; font-weight: 800;
  padding: 1px 7px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); color: var(--hint);
}
.lesson-meta { font-size: 12.5px; color: var(--hint); margin-top: 3px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lesson-meta .meta-item { display: inline-flex; align-items: center; gap: 4px; }
.lesson-meta .meta-item svg { color: var(--hint); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.02em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px;
  margin-bottom: 6px;
  background: rgba(255,159,10,0.18); color: #b36200;
}
@media (prefers-color-scheme: dark) { .badge { color: #ff9f0a; } }
.badge.cancelled { background: rgba(244,33,46,0.16); color: var(--red); }

.original-lesson {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--hint);
  text-decoration: line-through;
  opacity: 0.8;
}
.original-lesson span { display: block; }

.reassigned-note { font-size: 12px; color: var(--red); margin-top: 4px; font-weight: 600; }

.empty-note.tiny { padding: 0; text-align: left; }

/* ---------- Subscriptions ---------- */
.sub-list { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.sub-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.sub-row .sub-icon {
  width: 38px; height: 38px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--accent); font-size: 17px; flex: 0 0 auto;
}
.sub-row .sub-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sub-row .sub-name { font-weight: 800; font-size: 14.5px; }
.sub-row .sub-type { font-size: 12px; color: var(--hint); }
.sub-row .sub-remove {
  width: 32px; height: 32px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  color: var(--hint); background: var(--bg); border: 1px solid var(--border); flex: 0 0 auto;
}
.sub-row .sub-remove:active { color: var(--red); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  color: var(--hint);
  font-size: 11px; font-weight: 700;
}
.nav-item svg { font-size: 21px; }
.nav-item.active { color: var(--accent); }
.nav-item::after { content: attr(data-label); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 20;
  animation: toastIn 0.2s ease;
  max-width: calc(100% - 48px);
  text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 60px 0; color: var(--hint); font-size: 14px; }
