/* Палитра — та же, что у сайта schedule-edu (frontend/app/globals.css):
   холодные сине-серые нейтрали, синий акцент, пастель по видам занятий.
   Тёмная тема — по системной настройке: своей кнопки у мини-приложения нет. */
:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #f0f3fa;
  --line: #e3e8f2;
  --line-strong: #c7d0e4;
  --ink: #151b2b;
  --muted: #5a6480;
  --faint: #8e97ad;
  --accent: #2453d5;
  --accent-soft: #e8edfc;
  --accent-ink: #1a3c9c;
  --on-accent: #ffffff;
  --danger: #c8392f;
  --danger-soft: #fdeceb;
  --warn: #96681c;
  --warn-soft: #fbf1dc;
  --info: #17788a;
  --info-soft: #e2f2f5;
  --skeleton: #eaeef6;
  --shadow: 0 1px 2px rgba(21, 27, 43, 0.05), 0 1px 3px rgba(21, 27, 43, 0.06);
  --shadow-raise: 0 6px 16px -8px rgba(21, 27, 43, 0.18);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --lesson-none-bg: #eef1f6;
  --lesson-none-fg: #5a6480;
  --lesson-lecture-bg: #e9edfb;
  --lesson-lecture-fg: #3a4e9e;
  --lesson-practice-bg: #e0f0f4;
  --lesson-practice-fg: #22697a;
  --lesson-lab-bg: #f0eafa;
  --lesson-lab-fg: #6247a3;
  --lesson-credit-bg: #f7efe0;
  --lesson-credit-fg: #86662d;
  --lesson-credit-diff-bg: #f9ebe0;
  --lesson-credit-diff-fg: #905c34;
  --lesson-exam-bg: #fbe9e7;
  --lesson-exam-fg: #a5453c;
  --lesson-consult-bg: #f6ecf3;
  --lesson-consult-fg: #8d5580;
  --lesson-coursework-bg: #e7f3e6;
  --lesson-coursework-fg: #3d7437;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1219;
    --surface: #161a24;
    --surface-2: #1d2230;
    --line: #272d3b;
    --line-strong: #3a4356;
    --ink: #e5e8f0;
    --muted: #9aa3b8;
    --faint: #6f778c;
    --accent: #5d8bf4;
    --accent-soft: #1a2340;
    --accent-ink: #a8c3ff;
    --on-accent: #0b1224;
    --danger: #ef8a82;
    --danger-soft: #35201e;
    --warn: #d7b46b;
    --warn-soft: #2f2717;
    --info: #6fc0d0;
    --info-soft: #16292f;
    --skeleton: #1f2431;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.25);
    --shadow-raise: 0 8px 18px -8px rgba(0, 0, 0, 0.6);

    --lesson-none-bg: #222838;
    --lesson-none-fg: #9aa3b8;
    --lesson-lecture-bg: #1c2440;
    --lesson-lecture-fg: #a6bcf5;
    --lesson-practice-bg: #122c33;
    --lesson-practice-fg: #86ccdb;
    --lesson-lab-bg: #262040;
    --lesson-lab-fg: #b8a6ee;
    --lesson-credit-bg: #30281a;
    --lesson-credit-fg: #d8b878;
    --lesson-credit-diff-bg: #33261b;
    --lesson-credit-diff-fg: #dfae84;
    --lesson-exam-bg: #37211f;
    --lesson-exam-fg: #e59a92;
    --lesson-consult-bg: #2f1f2b;
    --lesson-consult-fg: #dba6cf;
    --lesson-coursework-bg: #18291a;
    --lesson-coursework-fg: #9fd39a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button:disabled { cursor: default; opacity: 0.35; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3, p { margin: 0; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

[hidden] { display: none !important; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* --- шапка ------------------------------------------------------------------ */

.top {
  padding: calc(12px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--bg);
}
.top.sticky {
  transition: box-shadow 200ms var(--ease-out);
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.top.sticky.scrolled { box-shadow: var(--shadow-raise); }

.app-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 12px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--faint);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* меньше 16px — iOS приближает страницу при фокусе */
  caret-color: var(--accent);
}
.search input::placeholder { color: var(--faint); }

.chips {
  display: flex;
  gap: 6px;
  margin: 10px calc(-1 * var(--gutter)) 0;
  padding: 0 var(--gutter);
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips.dim { opacity: 0.45; }

.chip {
  flex: none;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.chip,
.icon-btn,
.empty .retry {
  transition:
    transform 120ms var(--ease-out),
    background-color 200ms var(--ease-out),
    border-color 200ms var(--ease-out),
    color 200ms var(--ease-out),
    opacity 200ms var(--ease-out);
}
.chip:active,
.icon-btn:not(:disabled):active,
.empty .retry:active { transform: scale(0.95); }

.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* --- список групп ----------------------------------------------------------- */

.groups { padding: 4px var(--gutter) 24px; }

.section-title {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.recent { display: flex; flex-wrap: wrap; gap: 6px; }
.recent .chip { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; }

.group-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.group {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px 8px 14px;
  text-align: left;
}
.group + .group { border-top: 1px solid var(--line); }
.group { transition: background-color 150ms var(--ease-out); }
.group:active { background: var(--surface-2); transition-duration: 0ms; }
.group-text { flex: 1; min-width: 0; }
.group-name { display: block; font-weight: 650; font-size: 16px; }
.group-spec { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group svg { color: var(--faint); }

/* --- неделя ----------------------------------------------------------------- */

.bar { display: flex; align-items: center; gap: 6px; margin-left: -8px; }
.bar-title { min-width: 0; }
.bar-title h1 { font-size: 20px; font-weight: 700; line-height: 1.2; }
.bar-title p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--ink);
  flex: none;
}
.icon-btn:not(:disabled):active { background: var(--surface-2); }

.week-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.week-label {
  transition: opacity 150ms var(--ease-out);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
  padding: 4px 0;
}
.week-label.stale,
.days.stale { opacity: 0.45; }
.days.stale { pointer-events: none; }

#week-dates { font-weight: 650; font-variant-numeric: tabular-nums; }
#week-tag { font-size: 12px; color: var(--muted); }
#week-tag.away { color: var(--accent); }

.days {
  position: relative;
  min-height: 52px; /* пока неделя не пришла, шапка не схлопывается */
  transition: opacity 150ms var(--ease-out);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  margin-top: 8px;
}
.day-thumb {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  transition: transform 340ms var(--ease-out);
}
.day-thumb.instant { transition: none; }

.day-tab {
  transition: color 200ms var(--ease-out), transform 120ms var(--ease-out);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0 9px;
  border-radius: var(--radius-md);
  color: var(--muted);
  line-height: 1.15;
}
.day-tab b { font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; transition: color 200ms var(--ease-out); }
.day-tab small { font-size: 12px; transition: color 200ms var(--ease-out); }
.day-tab:active { transform: scale(0.94); }
.day-tab.free b { color: var(--faint); }
/* точка — в этот день есть пары */
.day-tab.busy::after {
  content: "";
  position: absolute;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--faint);
}
.day-tab.today small { color: var(--accent); font-weight: 700; }
.day-tab[aria-selected="true"] { color: var(--on-accent); }
.day-tab[aria-selected="true"] b,
.day-tab[aria-selected="true"] small { color: var(--on-accent); }
.day-tab[aria-selected="true"]::after { background: var(--on-accent); }

.day { padding: 14px var(--gutter) 32px; touch-action: pan-y; }

.day-title { display: flex; align-items: baseline; gap: 8px; font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.day-title span { font-size: 13px; font-weight: 600; color: var(--accent); }

.banner {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  background: var(--warn-soft);
  color: var(--warn);
}
.banner.practice { background: var(--info-soft); color: var(--info); }
.banner b { display: block; }
.banner p { color: var(--ink); }

.lesson {
  --tone-bg: var(--lesson-none-bg);
  --tone-fg: var(--lesson-none-fg);
  display: flex;
  gap: 12px;
  padding: 12px 14px 12px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.lesson[data-tone="lecture"] { --tone-bg: var(--lesson-lecture-bg); --tone-fg: var(--lesson-lecture-fg); }
.lesson[data-tone="practice"] { --tone-bg: var(--lesson-practice-bg); --tone-fg: var(--lesson-practice-fg); }
.lesson[data-tone="lab"] { --tone-bg: var(--lesson-lab-bg); --tone-fg: var(--lesson-lab-fg); }
.lesson[data-tone="credit"] { --tone-bg: var(--lesson-credit-bg); --tone-fg: var(--lesson-credit-fg); }
.lesson[data-tone="credit-diff"] { --tone-bg: var(--lesson-credit-diff-bg); --tone-fg: var(--lesson-credit-diff-fg); }
.lesson[data-tone="exam"] { --tone-bg: var(--lesson-exam-bg); --tone-fg: var(--lesson-exam-fg); }
.lesson[data-tone="consult"] { --tone-bg: var(--lesson-consult-bg); --tone-fg: var(--lesson-consult-fg); }
.lesson[data-tone="coursework"] { --tone-bg: var(--lesson-coursework-bg); --tone-fg: var(--lesson-coursework-fg); }

.lesson.now { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.lesson.cancelled { opacity: 0.7; }
.lesson.cancelled h3 { text-decoration: line-through; color: var(--muted); }

.when {
  flex: none;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}
.when b { font-size: 20px; line-height: 1.1; color: var(--ink); }
.when .pair-word { margin-bottom: 4px; }

.what { flex: 1; min-width: 0; }
.what h3 { font-size: 16px; font-weight: 650; line-height: 1.25; margin-bottom: 4px; overflow-wrap: anywhere; }
.what p { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.what .note { margin-top: 4px; color: var(--ink); font-style: italic; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tag {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--tone-bg);
  color: var(--tone-fg);
}
.tag.plain { background: var(--surface-2); color: var(--muted); }
.tag.now {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--on-accent);
}
.tag.now::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: live 1.8s var(--ease-out) infinite;
}
@keyframes live {
  0% { box-shadow: 0 0 0 0 currentColor; }
  70%, 100% { box-shadow: 0 0 0 5px transparent; }
}
.tag.cancel { background: var(--danger-soft); color: var(--danger); }
.tag.remote { background: var(--info-soft); color: var(--info); }

.gap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 4px 10px;
  color: var(--faint);
  font-size: 13px;
}
.gap::before, .gap::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }

/* --- пустые, ошибки, загрузка ------------------------------------------------ */

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty .retry {
  margin-top: 14px;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.skeleton {
  height: 84px;
  margin-bottom: 8px;
  border-radius: var(--radius-lg);
  background: var(--skeleton);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.skeleton.row { height: 56px; }
@keyframes pulse { to { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .tag.now::before { animation: none; }
  .day-thumb { transition: none; }
  .chip:active,
  .icon-btn:not(:disabled):active,
  .empty .retry:active,
  .day-tab:active { transform: none; }
}
