/* ==========================================================================
   PSPRadar — visual system inspired by Cars.com's marketplace look & feel:
   bold red brand accent, clean white/light-gray surfaces, confident sans-
   serif type, rounded pill controls, card-based results grid.
   ========================================================================== */

:root {
  --red: #C8102E;
  --red-dark: #9E0B24;
  --ink: #1B1F24;
  --ink-soft: #4B5563;
  --gray-50: #F7F8FA;
  --gray-100: #F0F2F5;
  --gray-200: #E4E7EB;
  --gray-300: #D1D5DB;
  --white: #FFFFFF;
  --amber: #F5A623;
  --green: #1E8E3E;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10), 0 2px 4px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --container: 1160px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; margin: 0; }

img { max-width: 100%; display: block; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-pill);
  padding: 10px 20px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--red);
  color: var(--white);
}
.btn-primary:hover { background: var(--red-dark); }

.btn-secondary {
  background: var(--white);
  color: var(--ink);
  border-color: var(--gray-300);
}
.btn-secondary:hover { border-color: var(--ink); }

.btn-text {
  background: transparent;
  color: var(--ink-soft);
  padding: 6px 10px;
}
.btn-text:hover { color: var(--ink); }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}

.header-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand .logo {
  height: 32px;
  width: 32px;
  object-fit: contain;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }

.brand-name {
  font-weight: 800;
  font-size: 20px;
  color: var(--red);
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
}

.site-nav {
  display: flex;
  gap: 24px;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover { border-bottom-color: var(--red); }

/* ---------- Hero / search-filters ---------- */
#search-filters {
  background: linear-gradient(180deg, var(--gray-50) 0%, var(--white) 100%);
  border-bottom: 1px solid var(--gray-200);
  padding: 28px 24px;
}

/* Search (left) + compact coverage map (right). Kept deliberately compact
   top-to-bottom so the results section starts near the fold — see #results
   below, where padding is tightened to match. */
.hero-grid {
  max-width: var(--container);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: start;
}

.hero-inner { min-width: 0; }

#search-filters h1 {
  font-size: 27px;
  max-width: 560px;
}

.hero-sub {
  margin: 8px 0 18px;
  color: var(--ink-soft);
  font-size: 15px;
  max-width: 560px;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.select-wrap select {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234B5563'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 32px;
}

.select-wrap select:hover { border-color: var(--ink); }

/* ---------- Features dropdown (button + checkbox panel) ---------- */
.features-wrap { position: relative; }

.dropdown-toggle {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-pill);
  padding: 10px 32px 10px 16px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234B5563'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.dropdown-toggle:hover { border-color: var(--ink); }
.dropdown-toggle[aria-expanded="true"] { border-color: var(--ink); }

.features-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.features-panel.hidden { display: none; }

/* ---------- PSP Name dropdown (button + logo/name row panel) ----------
   A native <select> can't render an image inside its <option>s, so this is
   a custom button + panel, built the same way as the Features dropdown
   above, but listing one row per PSP with a small logo/initials avatar. */
.psp-name-wrap { position: relative; }

.psp-picker-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.psp-name-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 260px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.psp-name-panel.hidden { display: none; }

.psp-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.psp-name-row:hover { background: var(--gray-100); }
.psp-name-row.active { background: #FBEAEC; color: var(--red); }

.psp-name-row-all {
  border-bottom: 1px solid var(--gray-200);
  border-radius: 0;
  margin-bottom: 4px;
  padding-bottom: 10px;
}

/* Shared small avatar used in the PSP Name toggle button and its dropdown
   rows — logo image with a colored-initials fallback layered underneath,
   same pattern (and same tiny-placeholder-image heuristic) as .psp-logo /
   .psp-logo-fallback on the result cards below. */
.psp-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  overflow: hidden;
  flex-shrink: 0;
}

.psp-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.psp-avatar-img.hidden { display: none; }

.psp-avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.psp-avatar-fallback.hidden { display: none; }

.features-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.features-panel input[type="checkbox"] {
  accent-color: var(--red);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.filter-group {
  border: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.filter-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
}

.filter-group input[type="checkbox"] {
  accent-color: var(--red);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ---------- Generic section shell ---------- */
.section-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 40px 24px;
}

#results h2 { font-size: 24px; }

.section-sub {
  margin: 6px 0 20px;
  color: var(--ink-soft);
  font-size: 14px;
}

/* ---------- Coverage map panel (compact, beside search on desktop) ---------- */
.map-panel {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.map-panel-head h2 { font-size: 15px; }

.map-panel .section-sub { margin: 2px 0 10px; font-size: 12px; }

.map-card {
  position: relative;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 12px;
}

#africa-map {
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* Anchored so it grows from the cursor toward the LEFT and stays clear of
   it vertically — with the map now docked to the right edge of the page,
   the old "offset right and down" positioning routinely pushed the tooltip
   off-screen. translateX(-100%) makes the tooltip's own width irrelevant:
   its right edge always lands a fixed gap to the left of the pointer. */
#map-tooltip {
  position: absolute;
  background: var(--ink);
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 5;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  transform: translate(-100%, -50%);
}

#map-tooltip.hidden { display: none; }

/* ---------- Results ---------- */
#results { background: var(--gray-50); border-top: 1px solid var(--gray-200); border-bottom: 1px solid var(--gray-200); }

/* Tightened so results land as close to the fold as possible, right under
   the (now more compact) search + map section above. */
#results .section-inner { padding-top: 22px; }

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

#results-count {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

#results-list {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 18px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-soft);
  padding: 32px 0;
}

.psp-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 150ms ease, transform 150ms ease;
  display: flex;
  flex-direction: column;
}

.psp-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.psp-logo-wrap {
  height: 36px;
  margin-bottom: 10px;
}

.psp-logo {
  height: 36px;
  max-width: 120px;
  object-fit: contain;
}

.psp-logo.hidden { display: none; }

/* Shown instead of .psp-logo when a PSP has no logo_url, its image fails to
   load, or a favicon lookup silently succeeds with a tiny generic
   placeholder icon (see the load-handler check in main.js). */
.psp-logo-fallback {
  height: 36px;
  width: 36px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.psp-logo-fallback.hidden { display: none; }

.psp-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 2px;
}

.psp-subtitle {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.psp-products {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  background: var(--gray-100);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.psp-methods {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.4;
}

.psp-methods-label { font-weight: 700; color: var(--ink); }

.psp-pricing {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--ink);
}

.psp-meta {
  font-size: 12.5px;
  color: var(--amber);
  font-weight: 700;
  margin: 0 0 14px;
}

.psp-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
}

.psp-actions .btn { flex: 1; padding: 9px 14px; font-size: 13px; }

/* ---------- Compare drawer ----------
   A normal in-flow section (not fixed/sticky) so it can never sit on top of
   and block the results grid's buttons — it just sits above the footer and
   fills in once PSPs are added to the comparison. */
#compare-drawer {
  background: var(--white);
  border-top: 1px solid var(--gray-200);
}

.compare-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 14px 24px;
}

.compare-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.compare-head h2 { font-size: 15px; }

#compare-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  margin-top: 10px;
}

#compare-drawer:not(.has-items) #compare-list { display: none; margin: 0; }
#compare-drawer:not(.has-items) .compare-head h2::after {
  content: ' — add up to 4 PSPs from the list above';
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 13px;
}
#compare-drawer:not(.has-items) #clear-compare { display: none; }

.compare-item {
  flex: 0 0 220px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- Footer ---------- */
.site-footer {
  background: var(--ink);
  color: var(--gray-200);
  padding: 32px 24px;
}

.footer-inner {
  max-width: var(--container);
  margin: 0 auto;
}

.site-footer .brand-name {
  color: var(--white);
  font-size: 16px;
  font-weight: 800;
}

.site-footer p {
  color: var(--gray-300);
  font-size: 13px;
  margin: 6px 0 0;
}

.footer-legal {
  margin-top: 16px !important;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 12px !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  /* Not enough width for search + map side-by-side — stack, map second. */
  .hero-grid { grid-template-columns: 1fr; gap: 20px; }
  .map-panel { max-width: 420px; margin: 0 auto; width: 100%; }
}

@media (max-width: 720px) {
  .header-inner { padding: 10px 16px; }
  .site-nav { gap: 14px; }
  .site-nav a { font-size: 13px; }
  .brand-tag { display: none; }

  #search-filters { padding: 24px 16px 20px; }
  #search-filters h1 { font-size: 24px; }

  .section-inner { padding: 24px 16px; }
  #results .section-inner { padding-top: 18px; }
  #results-list { grid-template-columns: 1fr; }

  .compare-inner { padding: 12px 16px; }
}

@media (max-width: 480px) {
  .site-nav a:nth-child(3) { display: none; }
}
