/* Дизайн-система Timora — те же токены, что в iOS-приложении. */
:root {
  --bg: #F6F6F7;
  --surface: #FFFFFF;
  --surface-muted: #F2F2F3;
  --ink: #141414;
  --ink-secondary: #808080;
  --ink-tertiary: #A0A0A4;
  --border: #E2E2E4;
  --positive: #2E7D5B;
  --warning: #B07B26;
  --critical: #B3261E;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 22px;
  --radius-card: 24px;
  --radius-hero: 28px;
  --on-ink: #FFFFFF;
  /* Приглушённый текст НА акцентной подложке (--ink). В тёмной теме --ink светлый,
     поэтому белый здесь стал бы невидимым. */
  --on-ink-muted: rgba(255, 255, 255, 0.7);
  /* Полупрозрачные панели поверх контента: таббар и элементы карты. */
  --panel-bg: rgba(255, 255, 255, 0.94);
  --skeleton-highlight: #E8E8EC;
  --shadow-card: 0 9px 14px rgba(0, 0, 0, 0.085);
  --tabbar-height: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 12px);
}

.screen { display: none; padding: 12px 20px 24px; }
.screen.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: .4 } to { opacity: 1 } }

.wordmark { font-size: 18px; font-weight: 700; letter-spacing: -0.2px; margin: 8px 0 0; }
h1.title { font-size: 30px; font-weight: 700; letter-spacing: -0.6px; margin: 14px 0 2px; }
p.subtitle { color: var(--ink-secondary); margin: 0 0 4px; font-size: 15px; }
h2.section { font-size: 21px; font-weight: 700; margin: 30px 0 12px; letter-spacing: -0.3px; }
.overline { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--ink-secondary); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 12px;
}
.card.shadow { box-shadow: var(--shadow-card); }
.card.ink { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.card.ink .overline, .card.ink .muted { color: var(--on-ink-muted); }
.card.compact { padding: 14px 16px; border-radius: var(--radius-md); }

.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-secondary); font-size: 12px; }
.tertiary { color: var(--ink-tertiary); font-size: 11px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.metric { font-size: 37px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.metric-lg { font-size: 44px; font-weight: 700; letter-spacing: -1.2px; line-height: 1; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 12px;
  border-radius: 999px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-secondary);
}
.badge.ink { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.badge.warn { background: rgba(176,123,38,.14); color: var(--warning); border-color: transparent; }
.badge.ok { background: rgba(46,125,91,.12); color: var(--positive); border-color: transparent; }

button, .btn {
  font: inherit; cursor: pointer; border: none;
  border-radius: 17px; height: 52px; padding: 0 20px;
  background: var(--ink); color: var(--on-ink); font-weight: 700; font-size: 16px;
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:disabled { background: var(--ink-tertiary); cursor: default; }
button.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border); font-weight: 600; }
button.danger { background: var(--surface); color: var(--critical); border: 1px solid var(--border); font-weight: 600; }
button.small { height: 40px; font-size: 14px; width: auto; padding: 0 16px; border-radius: 13px; }

input, textarea {
  font: inherit; width: 100%; height: 52px; padding: 0 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  color: var(--ink); outline: none;
}
input:focus, textarea:focus { border-color: var(--ink); }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--ink-secondary); margin: 0 0 7px 2px; }

/* Полоса дней недели */
.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 20px; }
.day {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.day .dow { font-size: 10px; font-weight: 600; color: var(--ink-secondary); text-transform: uppercase; }
.day .num { font-size: 18px; font-weight: 700; }
.day.selected { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.day.selected .dow { color: var(--on-ink-muted); }
.weeknav { display: flex; justify-content: space-between; margin-top: 12px; font-size: 12px; font-weight: 600; color: var(--ink-secondary); }
.weeknav button { background: none; color: inherit; width: auto; height: auto; padding: 4px; font-size: 12px; font-weight: 600; }

/* Пары */
.lesson { display: flex; gap: 16px; align-items: flex-start; }
.lesson .time { width: 52px; flex: none; }
.lesson .time .start { font-weight: 600; font-size: 14px; }
.lesson .time .end { color: var(--ink-tertiary); font-size: 12px; }
.lesson .name { font-weight: 600; font-size: 16px; }

/* Состояния */
.state { text-align: center; padding: 28px 20px; }
.state .glyph { font-size: 26px; margin-bottom: 12px; }
.state .head { font-weight: 700; font-size: 18px; margin-bottom: 8px; }
.skeleton { background: var(--surface-muted); border-radius: 8px; height: 14px; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

/* Чат */
.bubble { max-width: 86%; padding: 12px 15px; border-radius: var(--radius-md); margin-bottom: 10px; font-size: 14px; white-space: pre-wrap; }
.bubble.me { background: var(--ink); color: var(--on-ink); margin-left: auto; }
.bubble.ai { background: var(--surface); border: 1px solid var(--border); }
.composer { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 10px 0; background: var(--bg); }
.composer input { height: 52px; }
.composer button { width: 52px; height: 52px; flex: none; border-radius: 15px; padding: 0; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chips button { width: auto; height: 40px; font-size: 13px; font-weight: 600; border-radius: 13px; background: var(--surface); color: var(--ink); border: 1px solid var(--border); }

/* Карта */
.map { position: relative; height: 240px; border-radius: var(--radius-card); border: 1px solid var(--border); background: var(--surface-muted); overflow: hidden; }
.pin { position: absolute; width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: var(--on-ink); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; transform: translate(-50%, -50%); }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; font-size: 13px; }
.legend .k { display: inline-flex; width: 18px; font-weight: 700; }

/* Таб-бар */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--panel-bg); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
  background: none; color: var(--ink-tertiary); height: var(--tabbar-height);
  border-radius: 0; font-size: 10px; font-weight: 600; flex-direction: column; gap: 4px; padding: 0;
}
.tabbar button .ic { font-size: 19px; line-height: 1; }
.tabbar button.active { color: var(--ink); }

.code {
  font-size: 30px; font-weight: 700; letter-spacing: 6px;
  background: var(--surface-muted); border-radius: var(--radius-md);
  padding: 16px; text-align: center; user-select: all;
}
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-height) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--on-ink); padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.hidden { display: none !important; }

/* Карта студента */
.mapwrap {
  position: relative; margin-top: 12px; height: 58vh; min-height: 320px;
  border-radius: var(--radius-card); border: 1px solid var(--border);
  overflow: hidden; background: var(--bg); touch-action: none;
}
.mapwrap canvas { width: 100%; height: 100%; display: block; }
.mapzoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.mapzoom button {
  width: 40px; height: 40px; padding: 0; border-radius: 12px; font-size: 20px; font-weight: 600;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
}
.mapattr {
  position: absolute; left: 12px; bottom: 12px; font-size: 10px; color: var(--ink-tertiary);
  background: rgba(255,255,255,.8); padding: 4px 8px; border-radius: 8px;
}
select {
  font: inherit; width: 100%; height: 46px; padding: 0 12px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  appearance: none; -webkit-appearance: none;
}
.chips button.mode { height: 36px; }
.chips button.mode.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.routeline { display: flex; gap: 10px; align-items: baseline; margin-top: 14px; }
.routeline .big { font-size: 24px; font-weight: 700; }
.applinks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.applinks a {
  display: flex; align-items: center; justify-content: center; height: 44px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  color: var(--ink); font-size: 13px; font-weight: 600;
}

/* Фрагмент карты в профиле */
.mapwrap.preview { height: 190px; min-height: 0; margin-top: 12px; }
.mapexpand {
  position: absolute; right: 10px; top: 10px; width: auto; height: 34px; padding: 0 14px;
  border-radius: 12px; font-size: 12px; font-weight: 600;
  background: var(--panel-bg); color: var(--ink); border: 1px solid var(--border);
}
.screen.fullmap { padding-top: 0; }

/* Вложения и режим разбора в чате */
.filestrip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chipfile {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.chipfile span { color: var(--ink-tertiary); }
.attach {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 52px; font-size: 18px; cursor: pointer; flex: none;
}
#ai-reasoning.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.bubble { animation: bubbleIn .25s ease; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ── Иконки таб-бара ─────────────────────────────────────────────────────── */
.tabbar button .ic { width: 22px; height: 22px; display: block; }
.tabbar button .ic svg { width: 100%; height: 100%; display: block; }
.tabbar button { transition: color .18s ease; }
.tabbar button .ic { transition: transform .22s cubic-bezier(.2,.9,.3,1.2); }
.tabbar button.active .ic { transform: translateY(-2px) scale(1.06); }

/* ── Тумблер режима ассистента ───────────────────────────────────────────── */
.switchrow { cursor: pointer; user-select: none; }
.switch {
  width: 50px; height: 30px; border-radius: 999px; background: var(--surface-muted);
  border: 1px solid var(--border); position: relative; flex: none;
  transition: background .22s ease, border-color .22s ease;
}
.switch i {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .24s cubic-bezier(.2,.9,.3,1.2);
}
.switch.on { background: var(--ink); border-color: var(--ink); }
.switch.on i { transform: translateX(20px); }
.modeicon {
  width: 38px; height: 38px; border-radius: 12px; background: var(--surface-muted);
  display: flex; align-items: center; justify-content: center; font-size: 17px;
  transition: background .22s ease, transform .3s cubic-bezier(.2,.9,.3,1.2);
}
.switchrow.on .modeicon { background: var(--ink); transform: rotate(-8deg) scale(1.05); }

/* ── Анимации появления ──────────────────────────────────────────────────── */
.screen.active { animation: screenIn .26s cubic-bezier(.2,.8,.3,1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

/* Карточки въезжают по очереди — экран собирается, а не появляется рывком. */
.screen.active .card, .screen.active .day, .screen.active .mapwrap {
  animation: cardIn .32s cubic-bezier(.2,.8,.3,1) backwards;
}
.screen.active .card:nth-child(1) { animation-delay: .02s }
.screen.active .card:nth-child(2) { animation-delay: .05s }
.screen.active .card:nth-child(3) { animation-delay: .08s }
.screen.active .card:nth-child(4) { animation-delay: .11s }
.screen.active .card:nth-child(n+5) { animation-delay: .14s }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(.99) } to { opacity: 1; transform: none } }

/* Нажатия: лёгкое сжатие вместо мгновенной смены цвета. */
button, .card.compact[data-place], .card.compact[data-group], .switchrow, .day {
  transition: transform .12s ease, background .18s ease, border-color .18s ease, color .18s ease;
}
button:active, .card.compact[data-place]:active, .card.compact[data-group]:active,
.switchrow:active, .day:active { transform: scale(.97); }

/* Метрики «набегают» при появлении. */
.metric, .metric-lg { animation: metricIn .45s cubic-bezier(.2,.8,.3,1) backwards; animation-delay: .1s; }
@keyframes metricIn { from { opacity: 0; transform: translateY(6px) scale(.96) } to { opacity: 1; transform: none } }

/* Скелетоны переливаются, а не просто мигают. */
.skeleton {
  background: linear-gradient(90deg, var(--surface-muted) 25%, var(--skeleton-highlight) 37%, var(--surface-muted) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0 } to { background-position: 0 0 } }

/* Тост выезжает снизу. */
.toast { transform: translateX(-50%) translateY(12px); transition: opacity .22s ease, transform .28s cubic-bezier(.2,.9,.3,1.2); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Выбранный день недели «подпрыгивает». */
.day.selected { animation: dayPop .28s cubic-bezier(.2,.9,.3,1.3); }
@keyframes dayPop { 0% { transform: scale(.94) } 60% { transform: scale(1.04) } 100% { transform: scale(1) } }

/* Уважение к системной настройке «уменьшить движение». */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* «Окно» — свободный промежуток между парами. Оформлено легче карточки пары:
   это отсутствие занятия, оно не должно спорить по весу с реальными парами. */
.window {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; margin-bottom: 10px;
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  background: transparent;
}
.window .glyph { font-size: 18px; opacity: .75; }
.window .ttl { font-weight: 600; font-size: 15px; }

/* Экран выбора вуза занимает всё окно: пока вуз не выбран, вкладки бессмысленны —
   расписание и оценки без него загрузить всё равно нельзя. */
body.choosing-institution .tabbar { display: none; }
body.choosing-institution { padding-bottom: 24px; }

/* ── Тёмная тема ────────────────────────────────────────────────────────────
   Два источника: настройка системы (prefers-color-scheme) и тема мессенджера —
   Telegram и ВК сообщают её через SDK, и app.js проставляет data-theme на <html>.
   Явный data-theme всегда важнее системного: внутри мессенджера студент видит
   ровно ту тему, что и в самом мессенджере. */
:root[data-theme="dark"] {
  --bg: #101012;
  --surface: #17171A;
  --surface-muted: #212127;
  --ink: #F2F2F4;
  --ink-secondary: #9A9AA2;
  --ink-tertiary: #6E6E78;
  --border: #2B2B32;
  --on-ink: #101012;
  --on-ink-muted: rgba(16, 16, 18, 0.66);
  --panel-bg: rgba(23, 23, 26, 0.94);
  --positive: #4FB088;
  --warning: #D9A441;
  --critical: #E5645C;
  --skeleton-highlight: #2A2A31;
  --shadow-card: 0 9px 18px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101012;
    --surface: #17171A;
    --surface-muted: #212127;
    --ink: #F2F2F4;
    --ink-secondary: #9A9AA2;
    --ink-tertiary: #6E6E78;
    --border: #2B2B32;
    --on-ink: #101012;
    --positive: #4FB088;
    --warning: #D9A441;
    --critical: #E5645C;
    --skeleton-highlight: #2A2A31;
    --shadow-card: 0 9px 18px rgba(0, 0, 0, 0.5);
  }
}


/* Баннер технических работ — над содержимым, не поверх него. */
/* Оформлен как обычная карточка Timora: та же подложка, радиус и обводка —
   сообщение не должно выглядеть чужеродной наклейкой поверх интерфейса. */
.maintenance {
  display: flex; gap: 12px; align-items: flex-start;
  margin: 8px 20px 0; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-card);
}
.maintenance-icon {
  flex: none; width: 28px; height: 28px; display: flex;
  align-items: center; justify-content: center; font-size: 14px;
  background: var(--surface-muted); border-radius: var(--radius-sm);
}
.maintenance .muted { margin-top: 2px; }
.maintenance-close {
  flex: none; width: 28px; height: 28px; padding: 0; border: 0;
  background: none; color: var(--ink-tertiary); font-size: 13px; line-height: 1;
  border-radius: var(--radius-sm); cursor: pointer;
}
