/* Цвета берутся из темы Telegram, поэтому приложение выглядит «родным»
   и само переключается между светлой и тёмной темой. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2f7fe0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --overdue: #e5484d;
  --urgent: #f76b15;
  --soon: #e2a100;
  --ok: #2fa36b;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #18181b; --card: #232327; --text: #f2f2f4; --hint: #8e8e96; --accent: #5aa2ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
body { padding: 0 0 96px; -webkit-tap-highlight-color: transparent; }
main { padding: 0 16px; max-width: 560px; margin: 0 auto; }
h3 { font-size: 15px; color: var(--hint); font-weight: 600; margin: 22px 4px 8px;
  text-transform: uppercase; letter-spacing: .03em; }
button { font: inherit; color: inherit; cursor: pointer; }

/* вкладки */
.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; padding: 10px 16px;
  background: var(--bg); max-width: 560px; margin: 0 auto; }
.tabs button { flex: 1; border: 0; border-radius: 12px; padding: 10px; background: var(--card);
  color: var(--hint); font-weight: 600; }
.tabs button.on { background: var(--accent); color: var(--accent-text); }

.card { background: var(--card); border-radius: 16px; padding: 14px 16px; margin: 0 0 10px; }

/* ближайший срок — главный элемент экрана */
.hero { display: flex; gap: 14px; align-items: center; border-left: 6px solid var(--c); }
.hero .num { min-width: 64px; text-align: center; }
.hero .num b { display: block; font-size: 34px; line-height: 1; color: var(--c); }
.hero .num span { font-size: 12px; color: var(--hint); }
.hero .what small { color: var(--hint); display: block; font-size: 13px; }
.hero .what strong { display: block; font-size: 18px; margin: 2px 0; }

/* календарь */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-head strong { font-size: 17px; }
.nav { border: 0; background: none; font-size: 26px; width: 44px; height: 36px; border-radius: 10px; color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
#weekdays div { font-size: 12px; color: var(--hint); padding: 4px 0; }
.day { position: relative; border: 0; background: none; height: 42px; border-radius: 12px; font-size: 15px; }
.day.other { color: var(--hint); opacity: .45; }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); font-weight: 700; }
.day.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.day.has { font-weight: 700; color: #fff; background: var(--c); }
.day.has.sel { box-shadow: inset 0 0 0 3px var(--text); }

/* список сроков */
.dl { display: flex; gap: 12px; align-items: flex-start; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); margin-top: 6px; flex: none; }
.dl strong { display: block; }
.dl .when { color: var(--c); font-weight: 600; font-size: 14px; }
.dl .tip { color: var(--hint); font-size: 14px; margin-top: 2px; }
.empty { color: var(--hint); text-align: center; padding: 18px 8px; }
.note { color: var(--hint); font-size: 12px; text-align: center; margin: 18px 8px; }

/* форма */
label.f { display: block; margin: 0 0 14px; }
label.f > span, .f-title { display: block; font-size: 14px; color: var(--hint); margin: 0 0 6px 4px; }
.hint { font-size: 12px; color: var(--hint); margin: 4px 4px 0; }
input[type=date], input[type=text], select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 48px; appearance: none; }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg button { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px 14px; min-height: 48px; }
.seg button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.seg button.on::before { content: "✓ "; color: var(--accent); }
.trip { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.trip small { display: block; font-size: 12px; color: var(--hint); margin: 0 0 4px 4px; }
.link { border: 0; background: none; color: var(--accent); padding: 12px 4px; font-weight: 600; }
.rm { border: 0; background: none; color: var(--overdue); padding: 12px 6px; font-size: 14px; }
.save { position: fixed; left: 16px; right: 16px; bottom: 16px; max-width: 528px; margin: 0 auto;
  border: 0; border-radius: 14px; padding: 15px; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 17px; }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text);
  color: var(--card); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: opacity .2s;
  pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: .92; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg);
  color: var(--hint); font-size: 28px; }
#loading.gone { display: none; }
.day.has.soon { color: #1c1c1e; }
.day.has.other { opacity: .8; }
.hero .what small.when { color: var(--c); font-weight: 600; }

/* ---------- меню внизу */
.tabs { position: fixed; top: auto; bottom: 0; left: 0; right: 0; max-width: none; gap: 0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--card);
  border-top: 1px solid var(--line); z-index: 1000; }
.tabs button { background: none; padding: 4px 2px; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 12px; font-weight: 600; min-height: 52px; justify-content: center; }
.tabs button i { font-style: normal; font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .6; }
.tabs button.on { background: none; color: var(--accent); }
.tabs button.on i { filter: none; opacity: 1; }
main { padding-top: 12px; }
body { padding-bottom: 150px; }
.save { bottom: calc(76px + env(safe-area-inset-bottom)); }
#toast { bottom: 150px; }

/* ---------- билеты */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.go { width: 100%; border: 0; border-radius: 14px; padding: 15px; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 17px; margin: 4px 0 12px; }
.leave { border-left: 6px solid var(--urgent); }
.price { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; }
.price .d { min-width: 74px; }
.price .d b { display: block; font-size: 17px; }
.price .d small, .price .info small { color: var(--hint); font-size: 13px; }
.price .info { flex: 1; }
.price .rub { font-weight: 800; font-size: 18px; color: var(--ok); white-space: nowrap; }
.price.best { box-shadow: inset 0 0 0 2px var(--ok); }
.months { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.months button, .chips button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.months button.on, .chips button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ---------- карта */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 10px; scrollbar-width: none; }
#mapbox { height: 46vh; min-height: 260px; border-radius: 16px; overflow: hidden; background: var(--card); z-index: 0; }
.map-tools { display: flex; gap: 8px; margin: 10px 0; }
.pill { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px; font-weight: 600; }
.place { display: flex; gap: 12px; align-items: center; }
.place .n { flex: 1; min-width: 0; }
.place .n strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place .n small { color: var(--hint); font-size: 13px; display: block; }
.place .km { color: var(--accent); font-weight: 700; font-size: 14px; white-space: nowrap; }
.place .route { border: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
  border-radius: 10px; padding: 9px 10px; font-weight: 600; font-size: 14px; }
.place.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.pin { width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--accent);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); display: grid; place-items: center; }
.pin span { transform: rotate(45deg); font-size: 13px; }
.me { width: 16px; height: 16px; border-radius: 50%; background: #2f7fe0; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(47,127,224,.25); }
.leaflet-container { font: inherit; }

/* ---------- главная и помощь */
.top { display: flex; justify-content: flex-end; margin: 0 0 10px; }
.pill.edit { flex: none; padding: 8px 14px; font-size: 14px; }
.hero .tip { color: var(--hint); font-size: 14px; margin-top: 4px; }
details.card { padding: 0; }
details.card summary { list-style: none; padding: 14px 40px 14px 16px; font-weight: 600; position: relative; cursor: pointer; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "›"; position: absolute; right: 16px; top: 10px; font-size: 22px; color: var(--hint); transition: transform .15s; }
details.card[open] summary::after { transform: rotate(90deg); }
details.card .body { padding: 0 16px 14px; white-space: pre-line; color: var(--text); font-size: 15px; }
details.card .body code { font-size: 16px; font-weight: 700; }
.tobot { width: 100%; border: 1px solid var(--accent); color: var(--accent); background: none; border-radius: 14px; padding: 13px; font-weight: 700; }

/* путь после въезда */
.path-head { display: block; width: 100%; text-align: left; border: 0; }
.path-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.path-top small, .path-head .hint { color: var(--hint); }
.path-head .hint { display: block; margin-top: 6px; font-size: 13px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); margin: 10px 0; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.path-now { display: flex; flex-direction: column; gap: 2px; }
.path-now small { color: var(--hint); font-size: 13px; }
.late { color: var(--overdue) !important; font-weight: 600; }
.step summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.step summary::-webkit-details-marker { display: none; }
.step .mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--line); color: var(--hint); }
.step.done .mark { background: var(--ok); color: #fff; }
.step.cur .mark { background: var(--accent); color: var(--accent-text); }
.step.done .st { color: var(--hint); }
.step .st { flex: 1; font-weight: 600; }
.step .body p { margin: 10px 0 0; }
.step .body .hint { color: var(--hint); font-size: 13px; }
.step .body .pill { margin-top: 12px; }

/* чьи сроки: я и близкие */
.top { display: flex; gap: 8px; align-items: center; }
.chips.people { flex: 1; min-width: 0; padding: 0; }
.chips.people button { display: inline-flex; align-items: center; gap: 6px; }
.chips.people .pdot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chips.people .add { color: var(--accent); border-style: dashed; }
.link.danger { color: var(--overdue); display: block; margin: 18px auto 0; }

/* сверка патента */
.pc-head { display: block; width: 100%; text-align: left; border: 0; border-left: 6px solid var(--c); }
.pc-title { font-weight: 700; margin: 6px 0 4px; }
.pc-item { display: flex; gap: 8px; margin: 6px 0; line-height: 1.35; }
.pc-item span:first-child { flex: none; }
.pc-body .pc-item + .pc-item { border-top: 1px solid var(--line); padding-top: 8px; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.pill.wide { display: block; width: 100%; margin: 0 0 10px; }

/* инструменты в «Помощи»: тест, письмо в банк, памятка */
.tool summary { font-weight: 700; }
.tool .seg { margin: 6px 0 12px; }
.tool .f-title { display: block; margin-top: 10px; }
.tool pre.letter { white-space: pre-wrap; font: 14px/1.45 ui-monospace, Menlo, Consolas, monospace; background: var(--bg);
  border-radius: 12px; padding: 12px; margin: 10px 0; user-select: text; }
.tool .pre { white-space: pre-line; }
.tool .warn { color: var(--urgent); }
.pill.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); margin-top: 14px; }
.pill[disabled] { opacity: .45; }
.stay small { display: block; margin-top: 8px; color: var(--hint); }
.ics { margin: 12px 0 4px; }
.ics small { display: block; margin-top: 6px; color: var(--hint); text-align: center; }
.ex-opts { display: grid; gap: 8px; margin: 8px 0; }
.ex-opts .pill { text-align: left; white-space: normal; }
.ex-opts .pill.right { background: var(--ok); color: #fff; border-color: var(--ok); }
.ex-opts .pill.wrong { background: var(--overdue); color: #fff; border-color: var(--overdue); }
.tool .ok { color: var(--ok); }
.consent { position: fixed; inset: 0; z-index: 2000; background: var(--bg); overflow-y: auto; padding: 16px 16px 32px; }
.consent .card { max-width: 560px; margin: 0 auto; }
.consent .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.consent .doc { font-size: 14px; line-height: 1.45; margin-bottom: 12px; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px; font-size: 15px; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.review { font-size: 13px; color: var(--hint); background: var(--card); border-left: 3px solid var(--soon); border-radius: 8px; padding: 8px 10px; margin: 4px 0 10px; }
.tool textarea { margin: 6px 0 10px; resize: vertical; }
.note.ad { font-size: 12px; }

/* действие в главной карточке и вступление к анкете */
.hero .hero-act { margin-top: 10px; }
.hero .row { display: flex; gap: 8px; flex-wrap: wrap; }
.intro { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; background: var(--card, rgba(127,127,127,.08)); line-height: 1.4; }
#cal-toggle { margin: 4px 0 10px; }
.hero .row .pill { flex: 1; white-space: nowrap; font-size: 15px; }

/* проверки и разговорник */
.card.check, .card.phrase { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.card.check small, .card.phrase small { display: block; color: var(--hint); margin-top: 4px; }
.big { position: fixed; inset: 0; z-index: 3000; background: var(--card); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; text-align: center; }
.big div { font-size: 30px; font-weight: 700; line-height: 1.3; }
.big small { margin-top: 24px; color: var(--hint); }

/* ---------- помощник: кнопка посередине меню и переписка */
.tabs button.mid i { font-size: 24px; }
#chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 70px; }
.msg { max-width: 88%; border-radius: 18px; padding: 10px 14px; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.msg .pre { white-space: pre-line; }
.msg .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.msg .acts .pill { flex: 1 1 auto; padding: 9px 12px; font-size: 14px; color: var(--accent); }
.msg .f-title { margin: 10px 0 2px; }
.msg .link.art { display: block; text-align: left; padding: 6px 0; }
.msg.typing { color: var(--hint); letter-spacing: 3px; }
#chat > .f-title { margin-top: 8px; }
.ai-chips { flex-wrap: wrap; overflow: visible; }
.ask { position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 999;
  display: flex; gap: 8px; padding: 8px 16px; background: var(--bg); max-width: 560px; margin: 0 auto; }
.ask input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 11px 16px;
  background: var(--card); color: var(--text); font: inherit; }
.ask button { border: 0; border-radius: 999px; padding: 0 16px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
#ai[hidden] .ask { display: none; }
.row.quick { margin: 0 0 6px; }
.back-to { padding: 4px 4px 10px; }

/* значки вкладок — линии (svg в index.html) */
.tabs button i svg { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
