/* Оформление letim.
   Мобильный экран — основной: маршрут ищут с телефона, часто на ходу,
   поэтому крупная цена, крупные кнопки и ни одной горизонтальной прокрутки.
   Тема следует системной, светлая задаётся только там, где это уместно. */

:root {
  --bg: #0b1220;
  --bg-soft: #131c2f;
  --card: #18233a;
  --line: #243149;
  --text: #e8edf7;
  --muted: #94a3bb;
  --accent: #4ea1ff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-soft: #ffffff;
    --card: #ffffff;
    --line: #e2e8f0;
    --text: #17202f;
    --muted: #64748b;
    --accent: #1d6fe0;
    --shadow: 0 8px 24px rgba(15, 23, 42, .08);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }

/* ───────── Вход ───────── */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(78, 161, 255, .18), transparent), var(--bg);
  z-index: 50;
}
/* Атрибут hidden должен действительно скрывать: правило display у класса
   перебивает его молча, и форма входа остаётся поверх приложения. */
.login-screen[hidden] { display: none; }

.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 2.4rem; line-height: 1; margin-bottom: 6px; }
.login-card h1 { font-size: 1.6rem; margin-bottom: 2px; }
.login-card input { margin: 18px 0 12px; }

/* ───────── Каркас ───────── */
.app[hidden] { display: none; }
.app { max-width: 920px; margin: 0 auto; padding: 0 16px 48px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -.02em; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  font: inherit;
  font-size: .92rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab.is-active { background: var(--bg-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.panel { display: none; padding-top: 16px; }
.panel.is-active { display: block; }

.banner {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 18%, var(--card));
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  font-size: .9rem;
}
.banner[hidden] { display: none; }

/* ───────── Формы ───────── */
.search-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row.route { align-items: flex-end; }
.row.dates .field { flex: 1 1 140px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; min-width: 0; position: relative; }
.field.narrow { flex: 0 1 130px; }
.field > span { font-size: .78rem; color: var(--muted); padding-left: 2px; }

input, select, button {
  font: inherit;
  color: var(--text);
}
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  min-height: 44px; /* палец, а не курсор */
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
/* На тёмной теме системный date-picker рисует чёрную иконку на тёмном фоне. */
@media (prefers-color-scheme: dark) {
  input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.7); }
}

button { cursor: pointer; border-radius: 12px; min-height: 44px; padding: 10px 16px; }
.primary { background: var(--accent); color: #fff; border: 0; font-weight: 600; }
.primary:disabled { opacity: .55; cursor: progress; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.swap {
  align-self: flex-end;
  flex: 0 0 auto;
  width: 44px;
  padding: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
}
.checkbox { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.checkbox input { width: 18px; height: 18px; min-height: 0; }

/* ───────── Подсказки городов ───────── */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
}
.suggestions[hidden] { display: none; }
.suggestion { padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.suggestion:hover, .suggestion.is-active { background: var(--bg-soft); }
.suggestion .code { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.suggestion .where { color: var(--muted); font-size: .8rem; }

/* ───────── Календарь дешёвых дат ───────── */
.calendar-strip { margin-top: 18px; }
.calendar-strip[hidden] { display: none; }
.strip-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 10px; scrollbar-width: thin; }
.day {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  text-align: center;
  cursor: pointer;
}
.day .date { font-size: .78rem; color: var(--muted); }
.day .price { font-weight: 650; font-variant-numeric: tabular-nums; }
.day.is-cheapest { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.day.is-selected { background: color-mix(in srgb, var(--accent) 22%, var(--card)); border-color: var(--accent); }

/* ───────── Результаты ───────── */
.results { display: grid; gap: 10px; margin-top: 18px; }
.offer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 14px;
  /* Выравнивание по верху, а не по центру: у карточки с ценами других
     агентств правая колонка выше левой, и при центрировании рейс уезжал
     на середину карточки, ломая ритм списка. */
  align-items: start;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.offer .when { font-weight: 600; }
.offer .meta { grid-column: 1; color: var(--muted); font-size: .86rem; }
.offer .price-col { grid-row: 1 / span 2; grid-column: 2; text-align: right; display: grid; gap: 4px; justify-items: end; align-content: start; }
.offer .price { font-size: 1.32rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.offer .buy {
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 600;
}
.offer.is-best { border-color: var(--good); }
.badge {
  display: inline-block;
  font-size: .72rem;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  margin-left: 6px;
  vertical-align: middle;
}
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.sources-line { margin-top: 12px; font-size: .82rem; }
.sources-line[hidden] { display: none; }

/* ───────── Слежение ───────── */
.watch-intro { margin-bottom: 12px; }
.watch-new { margin-bottom: 16px; }
.watch-new summary {
  cursor: pointer;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
}
.watch-new[open] summary { border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; }
.watch-new .search-form { border-radius: 0 0 var(--radius) var(--radius); }

.watch-list { display: grid; gap: 12px; }
.watch {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 10px;
}
.watch.is-paused { opacity: .6; }
.watch-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.watch-route { font-weight: 650; font-size: 1.05rem; }
.watch-best { margin-left: auto; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.watch-meta { color: var(--muted); font-size: .85rem; }
.watch-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.watch-actions button { min-height: 38px; padding: 6px 12px; font-size: .88rem; }
.spark { display: block; width: 100%; height: 44px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark .area { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: none; }

/* ───────── Состояние ───────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card .label { font-size: .78rem; color: var(--muted); }
.card .value { font-size: 1.2rem; font-weight: 650; }
.table-wrap { overflow-x: auto; margin-bottom: 18px; }
table.log { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.log th, table.log td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.log th { color: var(--muted); font-weight: 500; }
table.log td.detail { white-space: normal; color: var(--muted); max-width: 420px; }
.state-ok { color: var(--good); }
.state-bad { color: var(--bad); }

/* ───────── Мелочи ───────── */
.error { color: var(--bad); font-size: .88rem; margin: 8px 0 0; }
.error[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 60;
  font-size: .9rem;
}
.toast[hidden] { display: none; }

@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .brand { flex: 1 1 100%; }
  .offer { grid-template-columns: 1fr auto; }
  .row.route .field { flex: 1 1 100%; }
  .swap { order: 3; width: 100%; }
}

/* Тот же рейс у другого агентства: мелко, но кликабельно — разница в цене
   между продавцами бывает в сотни рублей. */
.offer .also { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.offer .also a { font-size: .78rem; color: var(--muted); text-decoration: none; }
.offer .also a:hover { color: var(--accent); text-decoration: underline; }

/* Кнопка «показать ещё» — во всю ширину списка, чтобы попадать пальцем. */
.results .more { width: 100%; }

/* Когда пассажиров несколько, крупная цена — за одно место: без подписи её
   читают как сумму поездки и удивляются на кассе. */
.offer .per-seat { font-size: .75rem; color: var(--muted); }
