/* SEO popover — second sidebar panel that lives immediately right of the
   existing left sidebar (.side, 380 px). Mirrors the design language of
   index.html: same :root tokens, same component patterns (.section-ttl,
   .lr, .badge, .chip, .empty), same shadows/borders.
   On mobile (≤720 px) it transforms into a bottom-sheet. */

#seo-popover {
  position: fixed;
  /* JS syncs top/left/height to .side rect on init + resize. CSS fallbacks below. */
  top: 64px;
  bottom: 0;
  left: 0;            /* overlay the existing .side panel (drill-down view) */
  width: 380px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink-900);
  font-size: 13.5px;
  line-height: 1.5;
  z-index: 800;       /* above Leaflet popups (700) and canvas overlays */
  box-shadow: 1px 0 0 var(--line);
}
#seo-popover[hidden] { display: none !important; }

/* Bottom-sheet for narrow viewports (mobile) */
#seo-popover.seo-popover--bottom-sheet {
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: auto;
  max-height: 78vh;
  border-right: none;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 1200;
  animation: seoSheetSlide 200ms ease-out;
}
@keyframes seoSheetSlide {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Close button (×) — same style as .geo-banner .dismiss */
.seo-popover__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 0;
  color: var(--ink-500);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: grid;
  place-items: center;
  z-index: 3;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.seo-popover__close:hover {
  background: var(--ink-50);
  color: var(--ink-900);
}

.seo-popover__content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.seo-popover__content::-webkit-scrollbar { width: 6px; }
.seo-popover__content::-webkit-scrollbar-thumb { background: var(--ink-150); border-radius: 3px; }

/* ===== Top nav: «← Назад до …» (drill-down back button) ===== */
.seo-popover__content .seo-popover__nav {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 50px 10px 12px;     /* leave room for ✕ on the right */
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.seo-popover__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 8px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-700);
  text-decoration: none;
  transition: background .12s, color .12s;
  max-width: 100%;
}
.seo-popover__back svg {
  flex-shrink: 0;
  color: var(--ink-400);
  transition: transform .15s;
}
.seo-popover__back:hover {
  background: var(--ink-50);
  color: var(--ink-900);
}
.seo-popover__back:hover svg { transform: translateX(-2px); color: var(--brand); }
.seo-popover__back > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Breadcrumbs ===== */
.seo-popover__content .crumbs {
  padding: 14px 44px 0 18px;
}
.seo-popover__content .crumbs ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-500);
}
.seo-popover__content .crumbs li:not(:last-child)::after {
  content: "/";
  margin-left: 4px;
  color: var(--ink-300);
}
.seo-popover__content .crumbs a { color: var(--ink-500); text-decoration: none; }
.seo-popover__content .crumbs a:hover { color: var(--brand); }
.seo-popover__content .crumbs li[aria-current] { color: var(--ink-700); }

/* ===== Hero (panel header) ===== */
.seo-popover__content .hero {
  padding: 8px 44px 14px 18px;
  margin: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}
.seo-popover__content .hero h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-900);
  line-height: 1.3;
  letter-spacing: -.01em;
}
.seo-popover__content .hero .lede {
  font-size: 12px;
  color: var(--ink-500);
  margin: 4px 0 0;
  line-height: 1.45;
}
.seo-popover__content .hero__cta { display: none; }   /* "Подивитися на карті" — карта вже справа */

/* Route hero: badge + title two-column */
.seo-popover__content .hero--route {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: start;
  padding-top: 12px;
}
.seo-popover__content .hero--route .hero__num {
  width: 44px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent, var(--brand));
  color: #fff;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  display: grid;
  place-items: center;
  letter-spacing: -.02em;
}
.seo-popover__content .hero--route .hero__main { min-width: 0; }
.seo-popover__content .hero--route h1 { font-size: 14px; line-height: 1.3; }
.seo-popover__content .hero--route .lede {
  font-size: 11.5px;
  color: var(--ink-500);
  margin-top: 4px;
}

/* Stop hero: just title, slimmer */
.seo-popover__content .hero--stop h1 { font-size: 15px; }

/* Route-as-name (e.g. metro line "Сирецько-Печерська") — no badge */
.seo-popover__content .hero--route--name {
  display: block;
  grid-template-columns: 1fr;
  padding-top: 8px;
}
.seo-popover__content .hero--route--name h1 { font-size: 15px; }

/* ===== Block (section with H2 + content) ===== */
.seo-popover__content .block {
  padding: 14px 18px 14px;
  margin: 0;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
}
.seo-popover__content .block:first-of-type { border-top: 0; }
.seo-popover__content .block h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-500);
  letter-spacing: .1em;
  text-transform: uppercase;
}
.seo-popover__content .block h3 {
  margin: 10px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-700);
}
.seo-popover__content .block p {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--ink-700);
  line-height: 1.5;
}
.seo-popover__content .block p:last-child { margin-bottom: 0; }
.seo-popover__content .muted { color: var(--ink-500); }

/* ===== Live counter block (route / stop) ===== */
.seo-popover__content .live-block {
  text-align: center;
  padding: 14px 18px;
}
.seo-popover__content .live-block h2 { margin-bottom: 8px; }
.seo-popover__content .live-stat__num {
  font-size: 36px;
  font-weight: 800;
  font-family: "JetBrains Mono", monospace;
  color: var(--brand);
  letter-spacing: -.04em;
  line-height: 1;
}
.seo-popover__content .live-stat__lbl {
  font-size: 11.5px;
  color: var(--ink-500);
  margin: 4px 0 8px;
}
.seo-popover__content .live-stat__sub {
  font-size: 10.5px;
  color: var(--ink-400);
  line-height: 1.4;
}
.seo-popover__content .live-stat__cta { display: none; }

/* ===== Stops list (timeline, mirrors sidebar item rhythm) ===== */
.seo-popover__content .stops-list {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.seo-popover__content .stops-list::before {
  content: "";
  position: absolute;
  left: 24px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--ink-200);
}
.seo-popover__content .stops-list li {
  position: relative;
  padding: 0;
  border-bottom: 1px solid var(--line-soft);
}
.seo-popover__content .stops-list li:last-child { border-bottom: 0; }
.seo-popover__content .stops-list li > a,
.seo-popover__content .stops-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px 10px 44px;
  text-decoration: none;
  color: inherit;
  position: relative;
}
.seo-popover__content .stops-list li > a:hover { background: var(--ink-50); }
.seo-popover__content .stops-list .dot {
  position: absolute;
  left: 19px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--accent, var(--brand));
  z-index: 1;
}
.seo-popover__content .stops-list .stop-name {
  font-size: 12.5px;
  color: var(--ink-900);
  line-height: 1.3;
}
.seo-popover__content .stops-list a:hover .stop-name { color: var(--brand); }

/* ===== Route chips (stop page) ===== */
.seo-popover__content .routes-group {
  margin-bottom: 14px;
}
.seo-popover__content .routes-group:last-child { margin-bottom: 0; }
.seo-popover__content .routes-group__title {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-500);
  letter-spacing: .1em;
  text-transform: uppercase;
}
.seo-popover__content .route-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.seo-popover__content .route-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-900);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .1s;
}
.seo-popover__content .route-chip:hover {
  background: var(--ink-50);
  border-color: var(--ink-200);
  transform: translateY(-1px);
}
.seo-popover__content .route-chip--metro       { border-left: 3px solid var(--brand); }
.seo-popover__content .route-chip--tram        { border-left: 3px solid var(--tram); }
.seo-popover__content .route-chip--trolleybus  { border-left: 3px solid var(--trol); }
.seo-popover__content .route-chip--bus         { border-left: 3px solid var(--bus); }
.seo-popover__content .route-chip--marshrutka  { border-left: 3px solid var(--bus); }
.seo-popover__content .route-chip--electrichka { border-left: 3px solid #5e8a3a; }
.seo-popover__content .route-chip--funicular   { border-left: 3px solid #8b5a2b; }

/* ===== Tag list (reachable destinations) ===== */
.seo-popover__content .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.seo-popover__content .tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ink-50);
  color: var(--ink-700);
  border: 1px solid var(--line);
  font-size: 11px;
}

/* ===== Info-stat (metro hours, etc.) ===== */
.seo-popover__content .info-stat {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.seo-popover__content .info-stat:last-child { border-bottom: 0; }
.seo-popover__content .info-stat__lbl { color: var(--ink-500); min-width: 110px; }
.seo-popover__content .info-stat__val { font-weight: 600; color: var(--ink-900); }

/* ===== Routes table (type pages) — mirrors index.html .lr rows: 44px
   colored badge + endpoint name. Badge color is driven by the popover's
   data-url-type attribute (set by seo-nav.js). ===== */
.seo-popover__content .routes-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 -18px;             /* extend to container edges */
  width: calc(100% + 36px);
}
.seo-popover__content .routes-table thead { display: none; }
.seo-popover__content .routes-table tbody { display: block; }
.seo-popover__content .routes-table tr {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 12px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.seo-popover__content .routes-table tr:last-child { border-bottom: 0; }
.seo-popover__content .routes-table tr:hover { background: var(--ink-50); }
.seo-popover__content .routes-table td { display: block; padding: 0; border: 0; }
.seo-popover__content .routes-table td.t-label {
  width: 44px;
  height: 32px;
  border-radius: 8px;
  background: var(--ink-300);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.seo-popover__content .routes-table td.t-label a {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
}
.seo-popover__content .routes-table td.t-name {
  font-size: 12px;
  color: var(--ink-700);
  line-height: 1.3;
  white-space: normal;
  overflow: hidden;
  min-width: 0;
}
.seo-popover__content .routes-table td.t-name a {
  color: inherit;
  text-decoration: none;
  display: block;
}
.seo-popover__content .routes-table tr:hover td.t-name { color: var(--ink-900); }
/* Per-row badge color — each tr carries a tt-${type} class so stop pages
   (which mix types) and type pages (uniform) both render correctly. */
.seo-popover__content .routes-table tr.tt-tram        .t-label { background: var(--tram); }
.seo-popover__content .routes-table tr.tt-trolleybus  .t-label { background: var(--trol); color: var(--ink-900); }
.seo-popover__content .routes-table tr.tt-bus         .t-label { background: var(--bus); }
.seo-popover__content .routes-table tr.tt-marshrutka  .t-label { background: var(--marshrutka); }
.seo-popover__content .routes-table tr.tt-metro       .t-label { background: var(--metro-red); }
.seo-popover__content .routes-table tr.tt-electrichka .t-label { background: var(--express); }
.seo-popover__content .routes-table tr.tt-funicular   .t-label { background: var(--funicular); color: var(--ink-900); }

/* ===== Routes group (stop pages) — section-ttl rhythm with right-aligned
   count, mirrors index.html's .section-ttl. ===== */
.seo-popover__content .routes-group { margin: 0 -18px 14px; }
.seo-popover__content .routes-group:last-child { margin-bottom: 0; }
.seo-popover__content .routes-group__title {
  margin: 0;
  padding: 12px 18px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-500);
  letter-spacing: .1em;
  text-transform: uppercase;
}
.seo-popover__content .routes-group__count {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  color: var(--ink-400);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
/* Override default routes-table outer margin when nested inside a group */
.seo-popover__content .routes-group .routes-table { margin: 0; width: 100%; }

/* ===== Nearby stops list (single-column .lr rows) ===== */
.seo-popover__content .nb-list {
  display: block;
  margin: 0 -18px;
  width: calc(100% + 36px);
}
.seo-popover__content .nb-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  column-gap: 12px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none;
  color: inherit;
}
.seo-popover__content .nb-row:last-child { border-bottom: 0; }
.seo-popover__content .nb-row:hover { background: var(--ink-50); }
.seo-popover__content .nb-badge {
  width: 44px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink-200);
  color: var(--ink-700);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 700;
}
.seo-popover__content .nb-row--metro     .nb-badge { background: var(--metro-red); color: #fff; }
.seo-popover__content .nb-row--funicular .nb-badge { background: var(--funicular); color: var(--ink-900); }
.seo-popover__content .nb-row--express   .nb-badge { background: var(--express); color: #fff; }
.seo-popover__content .nb-main { min-width: 0; }
.seo-popover__content .nb-name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-900);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seo-popover__content .nb-row:hover .nb-name { color: var(--brand); }
.seo-popover__content .nb-sub {
  display: block;
  font-size: 11.5px;
  color: var(--ink-500);
  margin-top: 3px;
}
.seo-popover__content .nb-dist {
  text-align: right;
  font-family: "JetBrains Mono", monospace;
}
.seo-popover__content .nb-dist-n { font-size: 15px; font-weight: 700; color: var(--ink-900); letter-spacing: -.02em; }
.seo-popover__content .nb-dist-u { font-size: 9.5px; color: var(--ink-500); margin-left: 2px; }

/* ===== City hub: tiles rendered as .lr-style rows (mirrors index.html
   sidebar: 44px badge + main(title/sub stacked) + auto arrow). The render
   inserts 4 children + ::before, so we pin each to an explicit grid cell
   to keep title/sub on their own rows under the badge column. */
.seo-popover__content .tiles {
  display: block;
  margin: 0 -18px;
  width: calc(100% + 36px);
}
.seo-popover__content .tile {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 3px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none;
  color: inherit;
  border-radius: 0;
  background: transparent;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  min-height: auto;
  position: relative;
}
.seo-popover__content .tile:hover { background: var(--ink-50); transform: none; box-shadow: none; }
.seo-popover__content .tile:last-child { border-bottom: 0; }
.seo-popover__content .tile::before {
  content: "";
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 44px;
  height: 32px;
  border-radius: 8px;
  background: var(--ink-300);
  align-self: center;
  justify-self: stretch;
}
.seo-popover__content .tile--metro::before       { background: var(--metro-red); }
.seo-popover__content .tile--tram::before        { background: var(--tram); }
.seo-popover__content .tile--trolleybus::before  { background: var(--trol); }
.seo-popover__content .tile--bus::before         { background: var(--bus); }
.seo-popover__content .tile--marshrutka::before  { background: var(--marshrutka); }
.seo-popover__content .tile--electrichka::before { background: var(--express); }
.seo-popover__content .tile--funicular::before   { background: var(--funicular); }
.seo-popover__content .tile__title {
  grid-column: 2;
  grid-row: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-900);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.seo-popover__content .tile__sub {
  grid-column: 2;
  grid-row: 2;
  font-size: 11.5px;
  color: var(--ink-500);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  margin-top: 0;
}
.seo-popover__content .tile__arrow {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--ink-300);
  font-size: 14px;
  position: static;
}

/* ===== Popular list (city hub) ===== */
.seo-popover__content .popular-list {
  list-style: none;
  margin: 0 -18px;
  padding: 0;
  width: calc(100% + 36px);
  display: block;
}
.seo-popover__content .popular-list li {
  border-bottom: 1px solid var(--line-soft);
}
.seo-popover__content .popular-list li:last-child { border-bottom: 0; }
.seo-popover__content .popular-list a {
  display: block;
  padding: 8px 18px;
  font-size: 12.5px;
  color: var(--ink-700);
  text-decoration: none;
  border: 0;
  background: transparent;
  border-radius: 0;
}
.seo-popover__content .popular-list a:hover { background: var(--ink-50); color: var(--ink-900); border: 0; }
.seo-popover__content .popular-list a b { color: var(--ink-900); margin-right: 6px; font-weight: 700; }

/* ===== Similar grid (related routes) — render as compact list ===== */
.seo-popover__content .similar-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.seo-popover__content .similar-card {
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: 11.5px;
  transition: border-color .12s, background .12s, transform .1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.seo-popover__content .similar-card:hover {
  border-color: var(--ink-300);
  background: var(--ink-50);
  transform: translateY(-1px);
}
.seo-popover__content .similar-card__num {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-900);
}
.seo-popover__content .similar-card__ep {
  color: var(--ink-500);
  font-size: 11px;
  line-height: 1.3;
}

/* ===== FAQ ===== */
.seo-popover__content .faq__item {
  border-top: 1px solid var(--line-soft);
  padding: 8px 0;
}
.seo-popover__content .faq__item:first-child { border-top: 0; padding-top: 0; }
.seo-popover__content .faq__item summary {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink-900);
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-right: 22px;
}
.seo-popover__content .faq__item summary::-webkit-details-marker { display: none; }
.seo-popover__content .faq__item summary::after {
  content: "+";
  position: absolute;
  right: 0;
  top: 0;
  font-size: 16px;
  color: var(--ink-400);
  transition: transform .15s;
}
.seo-popover__content .faq__item[open] summary::after { transform: rotate(45deg); }
.seo-popover__content .faq__item p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-700);
}

/* Hide buttons that don't make sense in side-panel layout */
.seo-popover__content .btn { display: none; }

/* Hide site chrome that would have appeared in old standalone layout */
.seo-popover__content .site-header,
.seo-popover__content .site-footer { display: none; }

/* ===== Mobile bottom-sheet content tweaks ===== */
@media (max-width: 720px) {
  #seo-popover {
    /* JS adds .seo-popover--bottom-sheet; this media query is a fallback if
       JS hasn't run yet or class wasn't applied. */
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 78vh;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    z-index: 1200;
    box-shadow: var(--shadow-lg);
  }
  .seo-popover__content .crumbs { padding-top: 18px; }
  .seo-popover__content .similar-grid { grid-template-columns: 1fr; }
}
