/**
 * «План поїздки» — printable trip plan (trip-plan). A4 portrait, Inter.
 * Screen: A4-like sheets on a grey desk + a toolbar; print: just the sheets.
 */
:root {
  --tp-ink: #111827;
  --tp-text: #1f2937;
  --tp-muted: #4b5563;
  --tp-line: #e5e7eb;
  --tp-soft: #f5f7fa;
  --tp-accent: #006ce4;
  --tp-car: #1A73E8;
  --tp-foot: #0E9F6E;
  --tp-trail: #E53935;
  --tp-warn-bg: #fffbeb;
  --tp-warn: #92400e;
  --tp-r: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.tp-body {
  margin: 0; background: #e9ecf1; color: var(--tp-text);
  font-family: "Inter", "Inter Fallback", Arial, sans-serif; font-size: 15px; line-height: 1.5;
  font-feature-settings: "tnum" 0; -webkit-font-smoothing: antialiased;
}
.tp-loading { max-width: 640px; margin: 18vh auto; text-align: center; color: var(--tp-muted); font-size: 16px; }
.tp-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tp-ic { width: 1em; height: 1em; vertical-align: -0.14em; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--tp-accent); }

/* ── Toolbar (screen only) ─────────────────────────────────────────── */
.tp-bar {
  position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--tp-line); box-shadow: 0 1px 8px rgba(15,23,42,.06);
}
.tp-bar__in { max-width: 210mm; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.tp-back { display: inline-flex; align-items: center; gap: 6px; color: var(--tp-muted); text-decoration: none; font-size: 14px; margin-right: auto; min-height: 40px; }
.tp-back:hover { color: var(--tp-ink); }
.tp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--tp-line); border-radius: var(--tp-r); background: #fff; color: var(--tp-ink);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.tp-btn:hover, .tp-btn:focus-visible { border-color: var(--tp-accent); color: var(--tp-accent); }
.tp-btn--primary { background: var(--tp-accent); border-color: var(--tp-accent); color: #fff; font-weight: 600; }
.tp-btn--primary:hover, .tp-btn--primary:focus-visible { background: #0059bd; color: #fff; }
.tp-btn:disabled { opacity: .6; cursor: progress; }
.tp-fields { max-width: 210mm; margin: 0 auto; padding: 0 16px 10px; display: flex; flex-wrap: wrap; gap: 10px; }
.tp-field { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--tp-muted); flex: 1 1 220px; }
.tp-field--date { flex: 0 1 190px; }
.tp-field input {
  font: inherit; font-size: 15px; color: var(--tp-ink); padding: 8px 10px; min-height: 40px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
}
.tp-field input:focus { outline: 2px solid var(--tp-accent); outline-offset: 1px; border-color: transparent; }
.tp-hint { max-width: 210mm; margin: 0 auto; padding: 0 16px 10px; font-size: 13px; color: var(--tp-muted); }
.tp-status { max-width: 210mm; margin: 10px auto 0; padding: 0 16px; color: var(--tp-muted); font-size: 14px; }
.tp-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; }
.tp-toast[hidden] { display: none; }

/* ── The document ─────────────────────────────────────────────────── */
.tp-doc { max-width: 210mm; margin: 16px auto 40px; }
.tp-sheet { background: #fff; padding: 14mm 14mm 12mm; margin-bottom: 14px; box-shadow: 0 2px 14px rgba(15,23,42,.08); border-radius: 4px; }
.tp-brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--tp-muted); margin-bottom: 6mm; }
.tp-brand b { color: var(--tp-ink); letter-spacing: .12em; }
.tp-h1 { font-size: 30px; line-height: 1.15; font-weight: 800; color: var(--tp-ink); margin: 0 0 6px; letter-spacing: -.01em; }
.tp-sub { font-size: 15px; color: var(--tp-muted); margin: 0 0 4mm; }
.tp-h2 { font-size: 22px; line-height: 1.2; font-weight: 800; color: var(--tp-ink); margin: 0 0 2px; }
.tp-h2 small { font-size: 15px; font-weight: 500; color: var(--tp-muted); margin-left: 8px; }
.tp-h3 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--tp-muted); font-weight: 700; margin: 5mm 0 2mm; }

.tp-map { position: relative; width: 100%; border-radius: var(--tp-r); overflow: hidden; background: #eef1f4; border: 1px solid var(--tp-line); }
.tp-map img { display: block; width: 100%; height: auto; }
.tp-map--cover { aspect-ratio: 16 / 8.6; }
.tp-map--day { aspect-ratio: 16 / 8; }
.tp-map--trail { aspect-ratio: 16 / 7.6; }
.tp-map__wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--tp-muted); font-size: 13px; }
.tp-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--tp-muted); margin: 6px 2px 0; }
.tp-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tp-legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.tp-legend i.tp-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }

/* Stat tiles. */
.tp-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4mm 0 0; }
.tp-stat { border: 1px solid var(--tp-line); border-radius: var(--tp-r); padding: 10px 12px; min-width: 0; }
.tp-stat__l { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--tp-muted); }
.tp-stat__v { font-size: 17px; font-weight: 700; color: var(--tp-ink); font-variant-numeric: tabular-nums; margin-top: 2px; line-height: 1.25; }
.tp-stat__s { font-size: 12px; color: var(--tp-muted); font-variant-numeric: tabular-nums; }

/* Cover: stop list. */
.tp-list { list-style: none; margin: 0; padding: 0; }
.tp-list__day { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--tp-muted); margin: 8px 0 2px; }
.tp-list li.tp-li { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid #f0f2f5; break-inside: avoid; }
.tp-num {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: var(--tp-car); color: #fff;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.tp-li__t { font-weight: 600; color: var(--tp-ink); min-width: 0; }
.tp-li__k { font-size: 12px; color: var(--tp-muted); display: block; font-weight: 400; }
.tp-li__leg { margin-left: auto; font-size: 12px; color: var(--tp-muted); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }

.tp-warn { margin: 4mm 0 0; padding: 8px 12px; border-radius: var(--tp-r); background: var(--tp-warn-bg); color: var(--tp-warn); font-size: 13px; break-inside: avoid; }
.tp-warn b { display: block; margin-bottom: 2px; }
.tp-warn ul { margin: 0; padding-left: 18px; }

.tp-cover-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 4mm; break-inside: avoid; }
.tp-cover-foot p { margin: 0; font-size: 12px; color: var(--tp-muted); max-width: 120mm; }
.tp-qr { display: flex; flex-direction: column; align-items: center; gap: 3px; flex-shrink: 0; text-decoration: none; color: var(--tp-muted); font-size: 10px; text-align: center; }
.tp-qr svg { width: 24mm; height: 24mm; display: block; }
.tp-qr--s svg { width: 20mm; height: 20mm; }

/* Day header. */
.tp-day-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 4mm; }
.tp-day-stats { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; font-size: 13px; color: var(--tp-text); font-variant-numeric: tabular-nums; }
.tp-day-stats span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

/* Timeline: legs and stops. */
.tp-leg { display: flex; align-items: center; gap: 10px; margin: 4mm 0; padding: 8px 12px; border-radius: var(--tp-r); background: var(--tp-soft); font-size: 14px; break-inside: avoid; break-after: avoid; }
.tp-leg__ic { display: inline-flex; width: 30px; height: 30px; border-radius: 50%; align-items: center; justify-content: center; background: #fff; color: var(--tp-car); flex-shrink: 0; font-size: 16px; }
.tp-leg--foot .tp-leg__ic { color: var(--tp-foot); }
.tp-leg__t { min-width: 0; }
.tp-leg__t b { color: var(--tp-ink); }
.tp-leg__m { display: block; font-size: 12px; color: var(--tp-muted); }
.tp-leg__v { margin-left: auto; font-weight: 700; color: var(--tp-ink); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.tp-leg__v a { display: block; font-size: 12px; font-weight: 500; text-decoration: none; }

.tp-stop { border: 1px solid var(--tp-line); border-radius: 12px; padding: 12px; margin: 4mm 0; break-inside: avoid; }
.tp-stop--trail { break-inside: auto; }
.tp-stop__top, .tp-trail-stats, .tp-map, .tp-hl, .tp-facts { break-inside: avoid; }
.tp-stop__top { break-after: avoid; }
.tp-stop__top { display: flex; gap: 12px; align-items: flex-start; }
.tp-stop__img { width: 34mm; height: 34mm; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: #eef1f4; }
.tp-stop__body { flex: 1; min-width: 0; }
.tp-stop__k { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--tp-muted); }
.tp-stop__t { font-size: 18px; line-height: 1.25; font-weight: 700; color: var(--tp-ink); margin: 2px 0 4px; }
.tp-stop__t a { color: inherit; text-decoration: none; }
.tp-meta { margin: 0; font-size: 13px; color: var(--tp-text); }
.tp-meta div { display: flex; gap: 6px; align-items: baseline; }
.tp-meta dt { color: var(--tp-muted); flex-shrink: 0; }
.tp-meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.tp-text { font-size: 14px; line-height: 1.55; color: var(--tp-text); margin: 6px 0 0; }
.tp-night { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: #374151; background: var(--tp-soft); border-radius: 10px; padding: 2px 9px; margin-top: 4px; }

/* Trail block. */
.tp-trail-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 0; }
.tp-trail-stats .tp-stat { padding: 7px 10px; }
.tp-trail-stats .tp-stat__v { font-size: 15px; }
.tp-trail-extra { margin-top: 3mm; break-inside: auto; }
.tp-profile { margin-top: 3mm; break-inside: avoid; }
.tp-profile svg { display: block; width: 100%; height: auto; }
.tp-profile .tp-pa { fill: rgba(229,57,53,.12); }
.tp-profile .tp-pl { fill: none; stroke: var(--tp-trail); stroke-width: 1.6; stroke-linejoin: round; }
.tp-profile .tp-pg { stroke: #eef0f3; }
.tp-profile text { font-family: "Inter", Arial, sans-serif; font-size: 10px; fill: var(--tp-muted); }
.tp-hl { font-size: 13px; margin: 3mm 0 0; }
.tp-hl b { color: var(--tp-ink); }
.tp-facts { list-style: none; margin: 2mm 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; font-size: 13px; }
.tp-facts li { display: flex; gap: 6px; align-items: baseline; }
.tp-facts .tp-ic { color: var(--tp-muted); }
.tp-about { display: grid; grid-template-columns: 1fr 1fr; gap: 3mm 6mm; margin-top: 3mm; }
.tp-about section { break-inside: avoid; }
.tp-about h4 { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 0 0 2px; color: var(--tp-ink); }
.tp-about p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--tp-text); white-space: pre-line; }
.tp-note { font-size: 12.5px; color: var(--tp-muted); margin: 3mm 0 0; }

/* Safety page. */
.tp-safety { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4mm 0; }
.tp-sos { border: 1.5px solid #fecaca; background: #fff5f5; border-radius: 12px; padding: 10px 12px; break-inside: avoid; }
.tp-sos b { display: block; font-size: 30px; line-height: 1.1; color: #b91c1c; font-weight: 800; font-variant-numeric: tabular-nums; }
.tp-sos span { font-size: 12.5px; color: var(--tp-text); }
.tp-tips { margin: 0; padding-left: 18px; font-size: 14px; }
.tp-tips li { margin: 3px 0; }
.tp-credits { font-size: 11px; color: var(--tp-muted); margin-top: 6mm; border-top: 1px solid var(--tp-line); padding-top: 3mm; }

.tp-empty { background: #fff; border-radius: 8px; padding: 40px 24px; text-align: center; color: var(--tp-muted); }

/* ── Phones ───────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  body.tp-body { font-size: 15px; }
  .tp-doc { margin: 8px 0 24px; }
  .tp-sheet { padding: 18px 16px; border-radius: 0; margin-bottom: 8px; }
  .tp-h1 { font-size: 26px; }
  .tp-stats, .tp-trail-stats { grid-template-columns: 1fr 1fr; }
  .tp-safety, .tp-about, .tp-facts { grid-template-columns: 1fr; }
  .tp-stop__img { width: 76px; height: 76px; }
  .tp-qr--s { display: none; }
  .tp-day-head { flex-direction: column; align-items: flex-start; }
  .tp-day-stats { justify-content: flex-start; }
  .tp-back span { display: none; }
  .tp-bar__in { padding: 8px 12px; }
  .tp-btn { padding: 8px 11px; }
}

/* ── Print ────────────────────────────────────────────────────────── */
@page { size: A4 portrait; margin: 11mm 12mm 12mm; }
@media print {
  body.tp-body { background: #fff; font-size: 10.5pt; }
  .tp-bar, .tp-fields, .tp-hint, .tp-status, .tp-toast, .tp-noprint { display: none !important; }
  .tp-doc { max-width: none; margin: 0; }
  .tp-sheet { box-shadow: none; padding: 0; margin: 0; border-radius: 0; }
  .tp-sheet + .tp-sheet { break-before: page; }
  .tp-map, .tp-stop, .tp-leg, .tp-stat, .tp-sos { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tp-num, .tp-leg, .tp-legend i, .tp-warn, .tp-night, .tp-sos, .tp-profile { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
  .tp-h1 { font-size: 24pt; }
  .tp-h2 { font-size: 17pt; }
  .tp-text { font-size: 10pt; }
  .tp-stop__t { font-size: 13.5pt; }
}

.tp-cover-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tp-qr--cover { margin-top: -2mm; }
.tp-qr--cover svg { width: 21mm; height: 21mm; }
@media (max-width: 720px) { .tp-qr--cover { display: none; } }

/* Toolbar v2: [back] [secondary…] [primary]; fields below, not sticky. */
.tp-bar__in { max-width: 1040px; flex-wrap: nowrap; }
.tp-bar__sec { display: flex; gap: 8px; margin-left: auto; }
.tp-fields { max-width: 210mm; padding: 12px 16px 0; align-items: flex-end; }
.tp-fields .tp-hint { flex-basis: 100%; padding: 0; margin: 0; display: flex; align-items: center; gap: 6px; }
@media (max-width: 960px) {
  .tp-bar__in { flex-wrap: wrap; }
  .tp-bar__sec { order: 3; flex-basis: 100%; margin-left: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
  .tp-bar__sec .tp-btn { min-width: 0; padding: 8px 6px; }
  .tp-bar__sec .tp-btn span { overflow: hidden; text-overflow: ellipsis; }
  .tp-print { margin-left: auto; }
}
@media (max-width: 720px) {
  .tp-bar__sec .tp-btn { font-size: 13px; gap: 5px; }
  .tp-fields { padding: 10px 12px 0; gap: 8px; }
  .tp-field { flex: 1 1 100%; }
  .tp-field--date { flex: 1 1 100%; }
}
@media print { .tp-fields { display: none !important; } }
.tp-s { display: none; }
@media (max-width: 720px) { .tp-bar__sec .tp-l { display: none; } .tp-bar__sec .tp-s { display: inline; } }
.tp-leg--ap { background: #f1faf6; }
.tp-leg--ap .tp-leg__ic { color: var(--tp-foot); }
.tp-leg--dash { background: #fff; border: 1.5px dashed #9fd8c2; }
.tp-legend i.tp-dash { background: repeating-linear-gradient(90deg, var(--tp-foot) 0 5px, transparent 5px 9px) !important; }
@media print { .tp-leg--ap, .tp-leg--dash { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ── Cover fit (print.js fitCover sets data-fit 0…4) ──────────────────
   The cover must stay one A4 page whatever the title / number of stops. */
.tp-li__leg2 { display: none; }
.tp-map--cover img { height: 100%; object-fit: cover; }
.tp-cover[data-fit="1"] .tp-map--cover { aspect-ratio: 16 / 7.6; }
.tp-cover[data-fit="2"] .tp-map--cover { aspect-ratio: 16 / 7.6; }
.tp-cover[data-fit="3"] .tp-map--cover { aspect-ratio: 16 / 6.4; }
.tp-cover[data-fit="4"] .tp-map--cover { aspect-ratio: 16 / 5.2; }
/* ≥1: compact rows. */
.tp-cover:not([data-fit="0"]) .tp-li { padding: 2px 0; gap: 8px; line-height: 1.3; }
.tp-cover:not([data-fit="0"]) .tp-num { min-width: 20px; height: 20px; font-size: 11px; }
.tp-cover:not([data-fit="0"]) .tp-list__day { margin: 5px 0 1px; }
.tp-cover:not([data-fit="0"]) .tp-h3 { margin: 4mm 0 1mm; }
.tp-cover:not([data-fit="0"]) .tp-stats { margin-top: 3mm; }
.tp-cover:not([data-fit="0"]) .tp-stat { padding: 7px 10px; }
.tp-cover:not([data-fit="0"]) .tp-warn { margin-top: 3mm; padding: 6px 10px; font-size: 12px; }
/* ≥2: the stop list in two columns, the leg joins the kind line. */
.tp-cover[data-fit="2"] .tp-list, .tp-cover[data-fit="3"] .tp-list, .tp-cover[data-fit="4"] .tp-list { columns: 2; column-gap: 7mm; }
.tp-cover[data-fit="2"] .tp-list__day, .tp-cover[data-fit="3"] .tp-list__day, .tp-cover[data-fit="4"] .tp-list__day { break-after: avoid; break-inside: avoid; }
.tp-cover[data-fit="2"] .tp-list__day:first-child, .tp-cover[data-fit="3"] .tp-list__day:first-child, .tp-cover[data-fit="4"] .tp-list__day:first-child { margin-top: 0; }
.tp-cover[data-fit="2"] .tp-li, .tp-cover[data-fit="3"] .tp-li, .tp-cover[data-fit="4"] .tp-li { align-items: flex-start; }
.tp-cover[data-fit="2"] .tp-li__t, .tp-cover[data-fit="3"] .tp-li__t, .tp-cover[data-fit="4"] .tp-li__t { font-size: 13px; }
.tp-cover[data-fit="2"] .tp-li__leg, .tp-cover[data-fit="3"] .tp-li__leg, .tp-cover[data-fit="4"] .tp-li__leg { display: none; }
.tp-cover[data-fit="2"] .tp-li__leg2, .tp-cover[data-fit="3"] .tp-li__leg2, .tp-cover[data-fit="4"] .tp-li__leg2 { display: inline; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* ≥3: smaller title, tighter head. */
.tp-cover[data-fit="3"] .tp-brand, .tp-cover[data-fit="4"] .tp-brand { margin-bottom: 3mm; }
.tp-cover[data-fit="3"] .tp-h1, .tp-cover[data-fit="4"] .tp-h1 { font-size: 24px; }
.tp-cover[data-fit="3"] .tp-sub, .tp-cover[data-fit="4"] .tp-sub { margin-bottom: 2.5mm; }
@media (max-width: 720px) {
  .tp-cover[data-fit="2"] .tp-list, .tp-cover[data-fit="3"] .tp-list, .tp-cover[data-fit="4"] .tp-list { columns: 1; }
}
@media print {
  .tp-cover[data-fit="3"] .tp-h1, .tp-cover[data-fit="4"] .tp-h1 { font-size: 19pt; }
  .tp-cover[data-fit="2"] .tp-list, .tp-cover[data-fit="3"] .tp-list, .tp-cover[data-fit="4"] .tp-list { columns: 2; }
  /* Even level 4 overflows: let day 1 continue on the spill-over page. */
  .tp-sheet.tp-cover--flow + .tp-sheet { break-before: auto; margin-top: 8mm; }
}
/* Measuring pass (fitCover): the cover as it prints — 186 mm wide (A4 −
   @page side margins), print type sizes, desktop grids even on a phone. */
body.tp-measure .tp-cover { width: 186mm; max-width: none; padding: 0; font-size: 10.5pt; }
body.tp-measure .tp-cover .tp-h1 { font-size: 24pt; }
body.tp-measure .tp-cover[data-fit="3"] .tp-h1, body.tp-measure .tp-cover[data-fit="4"] .tp-h1 { font-size: 19pt; }
body.tp-measure .tp-cover .tp-stats { grid-template-columns: repeat(4, 1fr); }
body.tp-measure .tp-cover .tp-qr--cover { display: flex; }
body.tp-measure .tp-cover .tp-noprint { display: none; }
body.tp-measure .tp-cover[data-fit="2"] .tp-list, body.tp-measure .tp-cover[data-fit="3"] .tp-list, body.tp-measure .tp-cover[data-fit="4"] .tp-list { columns: 2; }
