/* Минималистичный интерфейс: цвета берутся из темы Telegram, чтобы приложение
   выглядело родным и в светлой, и в тёмной. Значения после запятой — запас
   на случай, если Telegram переменную не передал (например, в браузере). */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f4f4f7);
  --ink: var(--tg-theme-text-color, #16181c);
  --mut: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f7fed);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--mut) 22%, transparent);

  --full: #34a853;
  --half: #f2a33c;
  --pending: #e5484d;
  --planned: #4b9bff;
  --vacation: #12b3a8;
  --cancelled: #9aa0a8;

  --r: 14px;
  --pad: 16px;
}

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

/* Селектор по классу перебивает браузерное [hidden]{display:none}, поэтому
   любой блок с собственным display (.boot, .tabs, .seg) продолжал бы
   показываться после hidden = true. Правило ниже это закрывает. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

/* --- загрузка --- */
.boot {
  min-height: 70vh; display: grid; place-content: center;
  justify-items: center; gap: 14px; color: var(--mut);
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.view { padding: 6px var(--pad) 0; }

/* --- заголовки --- */
.bar, .monthbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0 14px;
}
.monthbar { justify-content: space-between; }
h1 {
  font-size: 19px; font-weight: 650; margin: 0;
  letter-spacing: -.01em; text-align: center; flex: 1;
}
.bar h1 { text-align: left; }
h2 {
  font-size: 13px; font-weight: 600; margin: 0 0 12px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--mut);
}

/* --- кнопки --- */
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.ghost {
  min-width: 40px; height: 40px; border-radius: 12px;
  font-size: 22px; line-height: 1; color: var(--mut);
  transition: background .15s;
}
.ghost:active { background: var(--card); }
.ghost.wide { width: 100%; height: 44px; font-size: 15px; background: var(--card); }
.primary {
  width: 100%; height: 46px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 16px; font-weight: 600; margin-top: 4px;
}
.primary:active { opacity: .85; }
.primary[disabled] { opacity: .4; }

/* --- сетка календаря --- */
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays span {
  text-align: center; font-size: 11px; color: var(--mut);
  padding-bottom: 6px; letter-spacing: .04em;
}
.weekdays .dim { color: color-mix(in srgb, var(--pending) 55%, var(--mut)); }

.days button {
  position: relative; aspect-ratio: 1; border-radius: 12px;
  display: grid; place-content: center; gap: 0;
  font-size: 16px; font-variant-numeric: tabular-nums;
  transition: background .15s, transform .1s;
}
.days button:active { transform: scale(.93); }
.days .empty { visibility: hidden; }
.days .out { color: var(--mut); opacity: .45; }
.days .today { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Заливка дня по состоянию: цвет мягкий, текст остаётся читаемым. */
.days .s-full     { background: color-mix(in srgb, var(--full) 20%, transparent); }
.days .s-half     { background: color-mix(in srgb, var(--half) 22%, transparent); }
.days .s-pending  { background: color-mix(in srgb, var(--pending) 20%, transparent); }
.days .s-planned  { background: color-mix(in srgb, var(--planned) 16%, transparent); }
.days .s-vacation { background: color-mix(in srgb, var(--vacation) 20%, transparent); }
.days .s-cancelled{ background: var(--card); color: var(--mut); text-decoration: line-through; }

.days .mark {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
}
.mark.full { background: var(--full); }
.mark.half { background: var(--half); }
.mark.pending { background: var(--pending); }
.mark.planned { background: var(--planned); }
.mark.vacation { background: var(--vacation); }
.mark.cancelled { background: var(--cancelled); }

/* --- легенда --- */
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  padding: 16px 2px 4px; font-size: 12px; color: var(--mut);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.full { background: var(--full); }
.dot.half { background: var(--half); }
.dot.pending { background: var(--pending); }
.dot.planned { background: var(--planned); }
.dot.vacation { background: var(--vacation); }
.dot.cancelled { background: var(--cancelled); }

/* --- карточки --- */
.card {
  background: var(--card); border-radius: var(--r);
  padding: var(--pad); margin: 14px 0;
}
.row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; padding: 9px 0;
}
.row + .row { border-top: 1px solid var(--line); }
.row .k { color: var(--mut); font-size: 14px; }
.row .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.big .v { font-size: 19px; }
.row.sub .k, .row.sub .v { font-size: 13px; color: var(--mut); font-weight: 500; }

.hint { color: var(--mut); font-size: 13px; margin: 8px 0 0; }
.note { color: var(--mut); font-size: 12.5px; line-height: 1.5; margin: 6px 2px 20px; }
.warn {
  background: color-mix(in srgb, var(--half) 16%, transparent);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 12px;
}

/* --- поля --- */
.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 13px; color: var(--mut); margin-bottom: 6px; }
input, select {
  width: 100%; height: 44px; padding: 0 12px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* --- сегментированный переключатель --- */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 44px; height: 42px; border-radius: 11px;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 14px; color: var(--mut);
}
.seg button.on {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}

/* --- список отпусков и рейсов --- */
.item {
  background: var(--card); border-radius: var(--r);
  padding: 14px var(--pad); margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.item .t { font-weight: 600; }
.item .s { color: var(--mut); font-size: 13px; margin-top: 3px; }
.del {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  color: var(--pending); font-size: 18px;
}
.del:active { background: color-mix(in srgb, var(--pending) 14%, transparent); }

.train { display: flex; align-items: baseline; gap: 10px; }

/* Заголовок маршрута: обе станции одним начертанием, стрелка приглушена. */
.routehead {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  font-size: 16px; font-weight: 600; padding: 2px 0 10px;
}
.routehead .sep { color: var(--mut); font-weight: 400; }
.routehead .meta {
  width: 100%; font-size: 13px; font-weight: 400; color: var(--mut);
}
.train .time { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.train .arrow { color: var(--mut); }
.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent); font-weight: 600;
}

/* --- нижняя навигация --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  padding: 8px 0 9px; font-size: 10.5px; color: var(--mut);
  display: grid; gap: 2px; justify-items: center;
}
.tabs button span { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .6; }
.tabs button.on { color: var(--accent); }
.tabs button.on span { filter: none; opacity: 1; }

/* --- лист действий --- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.42); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 20px var(--pad) calc(16px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-body h2 {
  text-transform: none; letter-spacing: 0; font-size: 17px;
  color: var(--ink); margin-bottom: 4px;
}
.opt {
  width: 100%; height: 48px; border-radius: 12px; margin-bottom: 8px;
  background: var(--card); font-size: 15.5px; text-align: left; padding: 0 14px;
  display: flex; align-items: center; gap: 10px;
}
.opt::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--mut); }
.opt.full::before { background: var(--full); }
.opt.half::before { background: var(--half); }
.opt.cancelled::before { background: var(--cancelled); }
.opt.pending::before { background: var(--pending); }
.opt:active { opacity: .7; }
.opt.move::before { background: var(--accent); }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

/* Перенесённые дни: исходный приглушён и перечёркнут, целевой — с уголком. */
.days .moved-from { opacity: .5; text-decoration: line-through; }
.days .moved-to::after {
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 0; height: 0; border-top: 6px solid var(--accent);
  border-left: 6px solid transparent;
}

/* --- всплывающее сообщение --- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 20px; font-size: 13.5px;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; transform: translate(-50%, 6px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
