/* Цвета берутся из темы Telegram (--tg-theme-*), вне Telegram — запасные значения */
:root[data-theme="light"], :root {
  --fb-bg: #F1F3F7;
  --fb-card: #FFFFFF;
  --fb-text: #0F172A;
  --fb-hint: #6B7280;
  --line: rgba(15, 23, 42, .08);
  --skeleton: rgba(15, 23, 42, .07);
}
:root[data-theme="dark"] {
  --fb-bg: #0F1115;
  --fb-card: #1A1D24;
  --fb-text: #F3F4F6;
  --fb-hint: #9CA3AF;
  --line: rgba(255, 255, 255, .08);
  --skeleton: rgba(255, 255, 255, .07);
}
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: #1565FF;
  --accent-soft: rgba(21, 101, 255, .12);
  --green: #16A34A;
  --orange: #EA580C;
  --red: #DC2626;
  --radius: 16px;
  color-scheme: light dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
a { color: inherit; text-decoration: none; }
b { font-weight: 600; }
.hint { color: var(--hint); font-size: 13px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }

#app { max-width: 560px; margin: 0 auto; }
.screen { padding: 8px 16px 24px; }
body.has-main .screen { padding-bottom: 96px; }
body.has-tabs .screen { padding-bottom: 88px; }
body.has-main.has-tabs .screen { padding-bottom: 160px; }

/* ---------- Шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--bg);
}
.top h1 { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 30px; line-height: 1; width: 32px; height: 32px; margin-left: -6px; color: var(--accent); }

/* ---------- Карточки ---------- */
.card { display: block; width: 100%; background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.section-title { font-size: 16px; font-weight: 700; margin: 20px 2px 10px; }

/* ---------- Главная ---------- */
.hero {
  margin: 0 -16px 0; padding: 22px 20px 64px;
  background: linear-gradient(135deg, #1565FF 0%, #3B8BFF 60%, #6BB0FF 100%);
  color: #fff; border-radius: 0 0 28px 28px;
}
.hero .hello { opacity: .9; font-size: 15px; }
.hero h1 { margin: 4px 0 0; font-size: 28px; font-weight: 800; letter-spacing: -.3px; }
.screen-home { padding-top: 0; }
.search { margin-top: -44px; box-shadow: 0 8px 24px rgba(15, 23, 42, .12); position: relative; }

.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg > button { flex: 1; text-align: center; padding: 8px 6px; border-radius: 10px; font-size: 14px; color: var(--hint); }
.seg > button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.big > button { padding: 12px; font-size: 15px; }

.field {
  display: flex; flex-direction: column; width: 100%;
  background: var(--bg); border-radius: 12px; padding: 9px 12px; margin-bottom: 8px; position: relative;
}
.field .lbl { font-size: 12px; color: var(--hint); }
.field .val { font-size: 16px; font-weight: 600; }
.field .val.add { color: var(--accent); }
.field .code { position: absolute; right: 52px; top: 50%; transform: translateY(-50%); color: var(--hint); font-weight: 600; }
.field input[type="date"] {
  border: 0; background: transparent; font-size: 16px; font-weight: 600; padding: 0; width: 100%; min-height: 22px;
  -webkit-appearance: none; appearance: none;
}
.route { position: relative; }
.swap {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); z-index: 1;
  width: 36px; height: 36px; border-radius: 50%; text-align: center;
  background: var(--card); color: var(--accent); font-size: 18px; box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 .field { margin-bottom: 8px; }

.popular { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pop { margin: 0; display: flex; flex-direction: column; gap: 2px; min-height: 92px; }
.pop-city { font-weight: 700; font-size: 16px; }
.pop-country { color: var(--hint); font-size: 12px; }
.pop-price { margin-top: auto; color: var(--accent); font-weight: 600; font-size: 14px; }

.benefits { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 20px; }
.benefits div { background: var(--card); border-radius: 14px; padding: 12px 8px; text-align: center; font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.benefits b { font-size: 20px; }
.demo-note { text-align: center; color: var(--hint); font-size: 12px; margin: 20px 0 4px; }

/* ---------- Списки ---------- */
.search-box input {
  width: 100%; border: 0; border-radius: 12px; background: var(--card); padding: 12px 14px; font-size: 16px; margin-bottom: 10px;
  outline: none;
}
.list { padding: 4px 0; }
.list-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.li-title { font-weight: 600; }
.code-badge { margin-left: auto; color: var(--hint); font-weight: 600; font-size: 13px; }
.icon-btn { color: var(--hint); width: 32px; height: 32px; text-align: center; border-radius: 50%; }
.plain { text-align: left; }
.empty { text-align: center; color: var(--hint); padding: 32px 12px; }
.empty.small { padding: 14px; font-size: 13px; }
.empty.big { padding: 64px 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text); }
.empty-ico { font-size: 48px; }

/* ---------- Пассажиры: степперы ---------- */
.stepper-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.stepper-row + .stepper-row { border-top: 1px solid var(--line); }
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 20px; text-align: center; }
.stepper button:disabled { opacity: .35; }
.stepper span { min-width: 16px; text-align: center; font-weight: 600; font-size: 17px; }

/* ---------- Результаты ---------- */
.res-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dates { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px; scrollbar-width: none; }
.dates::-webkit-scrollbar { display: none; }
.date { flex: 0 0 auto; background: var(--card); border-radius: 12px; padding: 7px 10px; text-align: center; display: flex; flex-direction: column; min-width: 66px; }
.date span { font-size: 12px; color: var(--hint); }
.date b { font-size: 13px; }
.date.on { background: var(--accent); color: #fff; }
.date.on span { color: rgba(255, 255, 255, .8); }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 8px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.small { margin: 0 0 10px; padding: 0; flex-wrap: wrap; }
.chip { flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 13px; font-weight: 500; white-space: nowrap; }
.chips.small .chip { background: var(--accent-soft); color: var(--accent); }
.chip.on { background: var(--accent); color: #fff; }
.count { margin: 4px 2px 10px; }

.offer { text-align: left; }
.offer:active, .pop:active, .order-card:active { transform: scale(.985); }
.offer-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.price { font-size: 20px; font-weight: 800; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 7px; border-radius: 6px; }
.badge.green { background: rgba(22, 163, 74, .12); color: var(--green); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.al-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; font-size: 13px; color: var(--hint); }
.al-logo {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 7px; color: #fff; font-size: 10px; font-weight: 800; letter-spacing: .2px;
}

.leg { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 8px 0 2px; }
.leg + .leg { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 10px; }
.leg-t { display: flex; flex-direction: column; }
.leg-t b { font-size: 18px; }
.leg-t span { color: var(--hint); font-size: 12px; font-weight: 600; }
.leg-t.r { text-align: right; }
.leg-t sup { color: var(--orange); font-size: 10px; margin-left: 1px; }
.leg-mid { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.leg-dur { font-size: 12px; color: var(--hint); }
.leg-line { position: relative; width: 100%; height: 2px; background: var(--line); border-radius: 2px; }
.leg-line::before, .leg-line::after { content: ""; position: absolute; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--hint); }
.leg-line::before { left: 0; }
.leg-line::after { right: 0; }
.leg-line i { position: absolute; left: 50%; top: -3px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--orange); }
.leg-stops { font-size: 12px; color: var(--green); }
.leg-stops.warn { color: var(--orange); }
.seats { margin-top: 8px; font-size: 12px; color: var(--red); }

.skeleton { height: 132px; display: flex; flex-direction: column; gap: 12px; }
.skeleton i { display: block; height: 16px; border-radius: 6px; background: var(--skeleton); animation: pulse 1.2s ease-in-out infinite; }
.skeleton i:nth-child(1) { width: 40%; height: 22px; }
.skeleton i:nth-child(2) { width: 90%; }
.skeleton i:nth-child(3) { width: 70%; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- Детали перелёта ---------- */
.leg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.segment { display: grid; grid-template-columns: 48px 14px 1fr; gap: 10px; }
.seg-times, .seg-info { display: flex; flex-direction: column; justify-content: space-between; min-height: 96px; }
.seg-times { align-items: flex-start; }
.seg-rail { display: flex; flex-direction: column; align-items: center; padding: 6px 0; }
.seg-rail i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); flex: 0 0 auto; }
.seg-rail span { flex: 1; width: 2px; background: var(--accent-soft); margin: 2px 0; }
.seg-al { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--hint); }
.seg-al .al-logo { width: 20px; height: 20px; font-size: 8px; border-radius: 5px; }
.layover { margin: 10px 0 10px 72px; padding: 8px 10px; border-radius: 10px; background: rgba(234, 88, 12, .1); color: var(--orange); font-size: 13px; }

.fares { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.fares::-webkit-scrollbar { display: none; }
.fare { flex: 0 0 auto; width: 168px; margin: 0; border: 2px solid transparent; text-align: left; }
.fare.on { border-color: var(--accent); }
.fare-head { display: flex; flex-direction: column; gap: 2px; }
.fare-head span { color: var(--accent); font-weight: 700; }
.fare ul { margin: 8px 0 0; padding-left: 16px; font-size: 13px; color: var(--hint); }
.fare li { margin-bottom: 2px; }

/* ---------- Формы ---------- */
.demo-fill {
  display: block; width: 100%; text-align: center; padding: 10px; margin-bottom: 10px; border-radius: 12px;
  border: 1.5px dashed var(--accent); color: var(--accent); font-weight: 600; font-size: 14px;
}
.form-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 360px) { .grid2 { grid-template-columns: 1fr; } }
.inp { display: flex; flex-direction: column; background: var(--bg); border-radius: 10px; padding: 7px 10px; border: 1.5px solid transparent; min-width: 0; }
.inp span { font-size: 11px; color: var(--hint); }
.inp input, .inp select {
  border: 0; background: transparent; padding: 2px 0 0; font-size: 15px; outline: none; width: 100%; min-height: 22px;
  -webkit-appearance: none; appearance: none;
}
.inp.upper input { text-transform: uppercase; }
.inp.err { border-color: var(--red); }
.inp:focus-within { border-color: var(--accent); }
.link-btn { margin-top: 10px; color: var(--accent); font-weight: 600; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 2px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Оплата ---------- */
.sum-row + .sum-row { margin-top: 10px; }
.sum-route { display: flex; gap: 10px; align-items: center; }
.sum-lines { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.sum-lines div { display: flex; justify-content: space-between; gap: 12px; }
.sum-lines div span:first-child { color: var(--hint); }
.sum-lines div span:last-child { text-align: right; }
.sum-lines .total { font-size: 17px; font-weight: 700; margin-top: 4px; }
.sum-lines .total span:first-child { color: var(--text); }
.pay-badge { width: 38px; height: 38px; border-radius: 10px; color: #fff; font-weight: 800; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: 0 0 auto; }
.pay.on .radio { border: 7px solid var(--accent); }

/* ---------- Успех ---------- */
.success { text-align: center; padding: 20px 8px 12px; }
.success h1 { margin: 12px 0 14px; font-size: 24px; }
.success-ico {
  width: 76px; height: 76px; margin: 0 auto; border-radius: 50%; background: var(--green); color: #fff;
  font-size: 40px; line-height: 76px; animation: pop .4s ease-out;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.pnr { font-size: 30px; font-weight: 800; letter-spacing: 4px; margin: 2px 0 12px; color: var(--accent); }
.btn-row { display: flex; gap: 8px; margin-top: 6px; }
.btn {
  flex: 1; display: block; text-align: center; padding: 13px 14px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { color: var(--red); background: rgba(220, 38, 38, .1); }
.btn.full { width: 100%; margin-top: 20px; }
.empty .btn { flex: 0 0 auto; margin-top: 12px; padding: 12px 28px; }

/* ---------- Мои билеты ---------- */
.order-card { text-align: left; }
.order-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.status { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.status.paid { background: rgba(22, 163, 74, .12); color: var(--green); }
.status.refund { background: rgba(234, 88, 12, .12); color: var(--orange); }
.order-route { display: flex; gap: 10px; align-items: center; }
.order-total { margin-top: 10px; font-weight: 700; text-align: right; }

/* ---------- Посадочный / электронный билет ---------- */
.pass { background: var(--card); border-radius: 20px; margin-bottom: 14px; overflow: hidden; }
.pass-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 0; }
.pass-al { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pass-route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px; }
.pass-route div { display: flex; flex-direction: column; }
.pass-route .r { text-align: right; }
.pass-route b { font-size: 32px; font-weight: 800; letter-spacing: 1px; }
.pass-route span { color: var(--hint); font-size: 13px; }
.plane { color: var(--accent); font-size: 22px; }
.pass-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 16px 14px; }
.pass-grid.two { grid-template-columns: 1fr 1fr; padding: 0; flex: 1; }
.pass-grid div { display: flex; flex-direction: column; min-width: 0; }
.pass-grid .wide { grid-column: 1 / -1; }
.pass-grid span { font-size: 11px; color: var(--hint); }
.pass-grid b { font-size: 14px; overflow-wrap: anywhere; }
.pass-cut { position: relative; border-top: 2px dashed var(--line); margin: 0 14px; }
.pass-cut::before, .pass-cut::after { content: ""; position: absolute; top: -12px; width: 22px; height: 22px; border-radius: 50%; background: var(--bg); }
.pass-cut::before { left: -26px; }
.pass-cut::after { right: -26px; }
.pass-bottom { display: flex; gap: 12px; align-items: center; padding: 14px 16px 16px; }
.qr { width: 96px; height: 96px; flex: 0 0 auto; border-radius: 8px; }

/* ---------- Профиль ---------- */
.user { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto; object-fit: cover;
  background: linear-gradient(135deg, #1565FF, #6BB0FF); color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Таббар и нижняя кнопка ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
#tabbar[hidden] { display: none; }
#tabbar button { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--hint); padding: 4px 0; }
#tabbar button .ico { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
#tabbar button.on { color: var(--accent); }
#tabbar button.on .ico { filter: none; opacity: 1; }

#fallback-main {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg);
}
#fallback-main[hidden] { display: none; }
body.has-tabs #fallback-main { bottom: 60px; background: transparent; }
#fallback-main button {
  display: block; width: 100%; max-width: 528px; margin: 0 auto; padding: 15px; border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; text-align: center;
  box-shadow: 0 6px 18px rgba(21, 101, 255, .3);
}
#fallback-main button:disabled { opacity: .6; }

#toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 20;
  background: rgba(17, 24, 39, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); text-align: center; animation: drop .25s ease-out;
}
#toast[hidden] { display: none; }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } }
