:root {
  --bg: #f4f5f9;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --text: #1b1f2a;
  --muted: #6b7280;
  --line: #e5e7ef;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-text: #4338ca;
  --today: #fff7ed;
  --today-line: #fdba74;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 8px 24px -12px rgba(17, 24, 39, 0.18);
  --radius: 14px;
}

[data-theme='dark'] {
  --bg: #0f1117;
  --bg-soft: #161922;
  --card: #171b25;
  --text: #e6e8ef;
  --muted: #9aa1b2;
  --line: #262b39;
  --accent: #818cf8;
  --accent-soft: #1e2333;
  --accent-text: #c7d2fe;
  --today: #221a12;
  --today-line: #b45309;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px clamp(12px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 8px; margin-right: auto; min-width: 0; }
.brandmark {
  width: 24px;
  height: 24px;
  flex: none;
  align-self: center;
  background: var(--accent);
  -webkit-mask: url('/logo-mark.png') center / contain no-repeat;
  mask: url('/logo-mark.png') center / contain no-repeat;
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 14px;
  font-weight: 500;
  max-width: 46vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color .15s, background .15s;
}
.pill:hover { border-color: var(--accent); background: var(--accent-soft); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
}
.icon:hover { border-color: var(--accent); }

/* ---------- неделя ---------- */
.subbar {
  position: sticky;
  top: 56px;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.subbar-inner { display: contents; }

.subbar .weeklabel { font-size: 15px; font-weight: 600; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subbar .weeklabel small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.subbar .spacer { flex: 1; min-width: 0; }

.navbtn {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  display: grid; place-items: center;
  font-size: 16px; line-height: 1;
}
.navbtn:disabled { opacity: .35; cursor: default; }
.navbtn:not(:disabled):hover { border-color: var(--accent); }

.ghostbtn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--muted);
}
.ghostbtn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- сетка дней ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
  padding: 12px clamp(12px, 3vw, 28px) 40px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

.day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  scroll-margin-top: 120px;
}

.day > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.day > header h3 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.day > header span { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.day.weekend > header h3 { color: var(--muted); }

.day.is-today { border-color: var(--today-line); }
.day.is-today > header { background: var(--today); }
.day.is-today > header h3::after {
  content: 'сегодня';
  margin-left: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: 1px;
}

.lessons { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.lesson {
  display: flex;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-soft);
}
.lesson.now { border-color: var(--accent); background: var(--accent-soft); }

.lesson .time {
  flex: none;
  width: 58px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.lesson .time b { display: block; font-size: 13px; }
.lesson .time i { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); }
.lesson .nowtag {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
}

.lesson .body { min-width: 0; flex: 1; }
.lesson h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
  white-space: pre-line;
}
.lesson.open h4 { display: block; -webkit-line-clamp: unset; overflow: visible; }

/* подгруппы: одна карточка на две разные пары */
.subgroups { display: flex; flex-direction: column; gap: 6px; }
.subgroup { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; font-size: 13.5px; }
.subgroup + .subgroup { border-top: 1px dashed var(--line); padding-top: 6px; }
.subgroup-lbl {
  flex: none;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 1px 5px;
  white-space: nowrap;
}

.tags { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 11.5px; color: var(--muted); }
.tag {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 500;
  white-space: nowrap;
}
.tag.room { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.note { background: var(--today); color: var(--today-line); border: 1px solid var(--today-line); }

.practice {
  margin: 10px 10px 0;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px dashed var(--today-line);
  background: var(--today);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.practice b { display: block; margin-bottom: -4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.practice-row {
  line-height: 1.35;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.practice-row.open { display: block; -webkit-line-clamp: unset; }
.practice-row + .practice-row { border-top: 1px solid var(--today-line); padding-top: 7px; }
.practice-time { font-weight: 600; font-variant-numeric: tabular-nums; }

/* практика в общем потоке дня — по времени, как пары */
.lesson.practice-card {
  background: var(--today);
  border-style: dashed;
  border-color: var(--today-line);
}

.empty { margin: 0; padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

.notice {
  grid-column: 1 / -1;
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
}
.notice.error { border-color: #fecaca; color: #b91c1c; background: #fef2f2; }
[data-theme='dark'] .notice.error { background: #2a1315; border-color: #7f1d1d; color: #fca5a5; }

.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.linkbtn:hover { color: var(--accent); }

/* индикатор загрузки */
body.is-loading .subbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: loading-slide 1.1s linear infinite;
}
@keyframes loading-slide {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}
@media (prefers-reduced-motion: reduce) {
  body.is-loading .subbar::after { animation: none; background: var(--accent); opacity: .5; }
}

/* ---------- выбор группы ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  padding: 0;
  width: min(460px, 92vw);
  max-height: 82vh;
  box-shadow: 0 24px 64px -24px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(15, 17, 23, .55); backdrop-filter: blur(2px); }

.dialog-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.dialog-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dialog-title h2 { margin: 0; font-size: 15px; }
.dialog-close {
  width: 32px; height: 32px;
  flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}
.dialog-close:hover { color: var(--text); border-color: var(--accent); }
.dialog-head input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: none;
}
.dialog-head input:focus { border-color: var(--accent); }

.group-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; max-height: 58vh; }
.group-list li button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.group-list li button:hover, .group-list li button:focus-visible { background: var(--accent-soft); outline: none; }
.group-list li button[aria-current='true'] { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.group-list .name { font-weight: 600; font-size: 13.5px; }
.group-list .spec { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-list .empty { padding: 20px; }

@media (max-width: 620px) {
  .brand span { display: none; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .lesson .time { width: 54px; }
  .navbtn { width: 42px; height: 42px; }
}

@media (max-width: 520px) {
  .subbar { gap: 8px; padding: 8px 12px; }
  .subbar .weeklabel { font-size: 14px; }
  .ghostbtn { padding: 6px 9px; font-size: 12px; }
  .pill { max-width: 42vw; padding: 7px 11px; font-size: 13px; }
}
