:root {
  --primary-50:  #F5F3FF;
  --primary-100: #EDE9FE;
  --primary-200: #DDD6FE;
  --primary-300: #C4B5FD;
  --primary-400: #A78BFA;
  --primary-500: #8B5CF6;
  --primary-600: #667EEA;
  --primary-700: #764BA2;
  --primary-800: #5B21B6;
  --primary-900: #4C1D95;

  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm:   0 1px 4px rgba(0, 0, 0, 0.05);
  --shadow-card: 0 2px 8px rgba(17, 24, 39, 0.08);
  --shadow-lg:   0 4px 10px rgba(17, 24, 39, 0.10);

  --brand-gradient: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--gray-900);
  background: #fff;
  line-height: 1.5;
  font-weight: 400;
  /* Match Flutter Web rendering: don't force antialiased smoothing.
     macOS's default subpixel-antialiased makes Poppins-Black weights
     render visibly heavier — the previous -webkit-font-smoothing:
     antialiased was thinning out the .price text vs the same w900 in
     the Flutter app. */
  -webkit-font-smoothing: subpixel-antialiased;
  -moz-osx-font-smoothing: auto;
  /* Bring the HTML rasterizer closer to Flutter's CanvasKit/Skia output:
     enable kerning + standard ligatures and ask for legibility-optimised
     glyph rendering. Reduces the perceptual gap between the two engines. */
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}

a { color: var(--primary-700); text-decoration: none; }
a:hover { color: var(--primary-900); }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== Header ===== */
.site-header {
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 64px;
  padding: 0 16px;
}
.site-header .brand { display: inline-flex; align-items: center; }
.site-header .brand-logo { height: 40px; width: auto; }
.site-header nav { display: flex; gap: 24px; align-items: center; }
.site-header nav a {
  color: var(--gray-700);
  font-weight: 500;
  font-size: 14px;
}
.site-header nav a:hover { color: var(--primary-600); }
.site-header nav .btn-gradient {
  background: var(--brand-gradient);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.site-header nav .btn-gradient:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

@media (max-width: 640px) {
  .header-inner { height: 48px; padding: 0 12px; }
  .site-header .brand-logo { height: 28px; }
  .site-header nav { gap: 12px; }
  .site-header nav a { font-size: 13px; }
  .site-header nav .btn-gradient { padding: 6px 12px; font-size: 13px; }
}

/* ===== Breadcrumbs ===== */
.breadcrumbs {
  font-size: 13px;
  color: var(--gray-500);
  padding: 16px 0 8px;
}
.breadcrumbs a { color: var(--gray-500); }
.breadcrumbs a:hover { color: var(--primary-600); }
.breadcrumbs .sep { margin: 0 8px; }

/* ===== Hero ===== */
.hero {
  position: relative;
  padding: 40px 0 32px;
  background:
    linear-gradient(to right, rgba(102,126,234,0.03) 1px, transparent 1px) 0 0/50px 50px,
    linear-gradient(to bottom, rgba(102,126,234,0.03) 1px, transparent 1px) 0 0/50px 50px,
    linear-gradient(180deg, #EEF2FF 0%, #ffffff 40%, #F5F3FF 80%, #FEF2F2 100%);
  margin-bottom: 8px;
}
.hero h1 {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p.subtitle {
  font-size: 17px;
  color: var(--gray-600);
  margin: 0;
  max-width: 640px;
}
@media (max-width: 640px) {
  .hero { padding: 24px 0 20px; }
  .hero h1 { font-size: 28px; }
  .hero p.subtitle { font-size: 15px; }
}

/* ===== Stats strip ===== */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}
.stat-card--accent {
  border-color: var(--primary-600);
  background: linear-gradient(135deg, rgba(102,126,234,0.04), rgba(118,75,162,0.04));
}
.stat-card--accent .value {
  color: var(--primary-600);
}
@media (max-width: 640px) {
  .stats-strip { grid-template-columns: 1fr 1fr; }
  .stat-card:last-child { grid-column: span 2; }
}

/* ===== AI summary block ===== */
.summary {
  background: linear-gradient(135deg, rgba(102,126,234,0.06), rgba(118,75,162,0.06));
  border-left: 4px solid var(--primary-600);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin: 16px 0 24px;
  font-size: 16px;
  color: var(--gray-700);
  line-height: 1.6;
}

/* ===== Charts (price histogram, condition vs price) ===== */
.chart-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 20px 0;
  box-shadow: var(--shadow-card);
}
.chart-header {
  margin: 0 0 16px;
}
.chart-card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}
.chart-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--gray-500);
}
.y-axis-label {
  fill: var(--gray-500);
  font-size: 11px;
  font-weight: 500;
}
.seo-chart { width: 100%; height: auto; display: block; }
.chart-grid-line { stroke: var(--gray-200); stroke-width: 1; }
.chart-bar { transition: opacity .15s ease; }
.chart-bar:hover { opacity: 0.85; }
.tick-label { fill: var(--gray-400); font-size: 10px; }
.bar-pct,
.bar-avg { fill: var(--gray-600); font-size: 10px; font-weight: 600; }
.range-label { fill: var(--gray-600); font-size: 10px; font-weight: 500; }

/* ===== Listings ===== */
.listings h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 32px 0 16px;
  letter-spacing: -0.01em;
}

.listing-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 640px) {
  .listing-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 220px));
    gap: 10px;
    justify-content: center;
  }
}

/* ===== Listing card (vertical grid card matching Flutter _ResultGridItem) ===== */
.listing-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--radius-md);
  /* Material elevation 1 (key + ambient drop shadow) — closer to the
     Flutter Card(elevation: 1) than the previous --shadow-card, which
     was longer and softer than the Material spec. */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  overflow: hidden;
  transition: transform 120ms ease, box-shadow 120ms ease;
  /* Fixed card aspect mirrors Flutter SliverGrid aspectRatio: 0.75
     (line 1556 of search_results_view.dart). Without a fixed aspect,
     CSS Grid stretches each card to the tallest in its row, which
     leaves visible empty space inside cards that have shorter meta
     content (no condition badge, etc.). */
  aspect-ratio: 3 / 4;
}
.listing-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) {
  .listing-card { border-radius: var(--radius-lg); }
}

/* Image area — 60% of card */
.listing-photo {
  position: relative;
  /* Photo + info share the card's fixed height with the same 60/40 split
     as Flutter (Expanded(flex: 60) image + remaining info). Using flex
     here instead of aspect-ratio on the photo means all cards in a row
     are identically sized and the photo always fills its slot. */
  flex: 60;
  min-height: 0; /* allow flex to compress without expanding the image */
  padding: 4px;
  background: #fff;
}
.listing-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
@media (min-width: 640px) {
  .listing-photo { padding: 6px; }
  /* Flutter uses borderRadius - 2 = 12 - 2 = 10 on the inner ClipRRect. */
  .listing-photo img { border-radius: 10px; }
}

/* Placeholder when no image */
.listing-photo--empty,
.listing-photo:not(:has(img)) {
  background: var(--gray-200);
}
.listing-photo--empty::after,
.listing-photo:not(:has(img))::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='1.5'><rect x='3' y='5' width='18' height='14' rx='2'/><circle cx='9' cy='10.5' r='1.5'/><path d='M3 16l5-4 4 3 3-2 6 5'/></svg>") no-repeat center;
  background-size: 36px;
}

/* Info area */
.listing-body {
  padding: 6px;
  display: flex;
  flex-direction: column;
  /* Takes the remaining 40% of the fixed-aspect card. min-height: 0
     prevents content from blowing out the card height. */
  flex: 40;
  min-height: 0;
}
@media (min-width: 640px) {
  .listing-body { padding: 8px; }
}

/* Vertical rhythm matches Flutter's explicit SizedBox separators between
   rows: 4px before the price row, 2px before the meta row. */
.listing-body .price-row { margin-top: 4px; }
.listing-body .listing-meta { margin-top: 2px; }

/* Title row: title + platform badge */
.listing-title-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  /* Fixed height — same as Flutter SizedBox(height: 28/32), guarantees
     2 lines of room for the title regardless of length. */
  height: 28px;
}
.listing-body h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.2;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
@media (min-width: 640px) {
  .listing-title-row { height: 32px; }
  .listing-body h3 { font-size: 12px; }
}

/* Platform badge with country flag */
.platform-badge {
  position: relative;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}
.platform-badge > img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.country-flag {
  position: absolute;
  right: -15%;
  bottom: -15%;
  width: 45%;
  height: 45%;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
@media (min-width: 640px) {
  .platform-badge { width: 24px; height: 24px; }
}

/* Country flag CSS gradients */
.flag-ES { background: linear-gradient(to bottom, #C60B1E 25%, #FFC400 25% 75%, #C60B1E 75%); }
.flag-DE { background: linear-gradient(to bottom, #000 33%, #DD0000 33% 66%, #FFCC00 66%); }
.flag-FR { background: linear-gradient(to right, #002395 33%, #FFF 33% 66%, #ED2939 66%); }
.flag-IT { background: linear-gradient(to right, #009246 33%, #FFF 33% 66%, #CE2B37 66%); }
.flag-PT { background: linear-gradient(to right, #006600 40%, #FF0000 40%); }
.flag-GB { background: linear-gradient(to bottom, #012169 33%, #FFF 33% 66%, #CE1124 66%); }

/* Price row: price + label pill */
.price-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.listing-body .price {
  font-size: 16px;
  /* Flutter's textTheme only loads Poppins weights 400/500/600/700 via
     GoogleFonts.poppinsTextTheme; FontWeight.w900 is rendered on top of
     the already-loaded Poppins-Bold (700) face, only marginally heavier
     than real Bold. Match Flutter by using real Bold (700) here.
     line-height intentionally NOT set — Flutter's grid card price has no
     `height` in its TextStyle, so the renderer uses Poppins's natural
     metrics. The body's 1.5 inheritance is the closest we can get. */
  font-weight: 700;
  color: var(--primary-600);
}
@media (min-width: 640px) {
  .listing-body .price { font-size: 18px; }
}

/* Price label pill (match Flutter _PriceLabelPill) */
.price-label {
  font-size: 8px;
  font-weight: 700;
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
  line-height: 1.2;
  white-space: nowrap;
}
@media (min-width: 640px) {
  .price-label { font-size: 9px; }
}
.price-label--bargain { background: #22C55E; }
.price-label--good_price { background: #3B82F6; }
.price-label--fair_price { background: #F97316; }
.price-label--expensive { background: #EF4444; }

/* Condition badge (chip) */
.condition-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.condition-new { background: #22C55E; }
.condition-like_new { background: #14B8A6; }
.condition-good { background: #3B82F6; }
.condition-used { background: #F97316; }
.condition-acceptable { background: #EF4444; }
.condition-for_parts { background: #374151; }

/* Meta row: shipping + (optional) condition badge.
   Flutter's equivalent Row never wraps and doesn't override line-height,
   so we leave both as default and inherit the body's 1.5. */
.listing-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--gray-600);
}
@media (min-width: 640px) {
  .listing-meta { font-size: 11px; }
}
@media (min-width: 640px) {
  .listing-meta { font-size: 11px; }
}

/* Shipping indicator */
.shipping-icon {
  display: inline-flex;
  align-items: center;
  width: 10px;
  height: 10px;
  color: var(--gray-500);
  flex-shrink: 0;
}
.shipping-icon svg { width: 100%; height: 100%; }
.shipping-no {
  color: var(--gray-300);
  position: relative;
}
.shipping-no::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 141%;
  height: 0;
  border-top: 1.5px solid var(--gray-400);
  transform: rotate(-45deg);
  transform-origin: top left;
}
@media (min-width: 640px) {
  .shipping-icon { width: 12px; height: 12px; }
}

/* ===== CTA ===== */
.cta-wrap {
  background: var(--brand-gradient);
  border-radius: var(--radius-xl);
  padding: 32px;
  margin: 32px 0;
  text-align: center;
  color: #fff;
  box-shadow: var(--shadow-lg);
}
.cta-wrap p {
  margin: 0 0 16px;
  font-size: 15px;
  opacity: 0.95;
}
.cta {
  display: inline-block;
  background: #fff;
  color: var(--primary-700);
  font-weight: 700;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  font-size: 16px;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.15);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.22);
  color: var(--primary-700);
}

/* ===== FAQ ===== */
.faq {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 24px 0;
  box-shadow: var(--shadow-card);
}
.faq h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}
.faq-list { display: flex; flex-direction: column; }
.faq-item {
  border-top: 1px solid var(--gray-100);
  padding: 14px 0;
}
.faq-item:first-child { border-top: 0; padding-top: 0; }
.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  color: var(--gray-900);
  list-style: none;
  padding-right: 24px;
  position: relative;
  outline: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  color: var(--primary-700);
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
}
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p {
  margin: 10px 0 0;
  color: var(--gray-700);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== Guides ===== */
.guide {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 40px;
  margin: 24px auto;
  box-shadow: var(--shadow-card);
  max-width: 760px;
}
.guide h1 {
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 20px;
  color: var(--gray-900);
  letter-spacing: -0.02em;
}
.guide h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--gray-900);
}
.guide h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--gray-900);
}
.guide p { line-height: 1.7; color: var(--gray-700); margin: 0 0 16px; }
.guide a { color: var(--primary-700); text-decoration: underline; }
.guide ul, .guide ol { line-height: 1.7; color: var(--gray-700); padding-left: 24px; }
.guide li { margin-bottom: 6px; }
.guide table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0 24px;
  font-size: 14px;
}
.guide th, .guide td {
  border: 1px solid var(--gray-200);
  padding: 10px 12px;
  text-align: left;
}
.guide th { background: var(--gray-50); font-weight: 600; }

/* ===== Related / interlinking ===== */
.related { margin: 24px 0; }
.related h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--gray-700);
}
.related a {
  display: inline-block;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  padding: 8px 16px;
  margin: 0 8px 8px 0;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 500;
  transition: all 120ms ease;
}
.related a:hover {
  border-color: var(--primary-600);
  color: var(--primary-700);
  background: var(--primary-50);
}

/* ===== Hub cards (category/brand pages) ===== */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0 32px;
}
@media (min-width: 640px) {
  .hub-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 280px));
    justify-content: center;
  }
}
.hub-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-card);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.hub-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-200);
}
.hub-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}
.hub-card-price {
  font-size: 24px;
  font-weight: 900;
  color: var(--primary-600);
  line-height: 1.1;
}
.hub-card-range {
  font-size: 12px;
  color: var(--gray-500);
}
.hub-card-cta {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-700);
  margin-top: 4px;
}

/* ===== Footer (4-column matching Flutter) ===== */
.site-footer {
  background: linear-gradient(135deg, var(--gray-900) 0%, var(--gray-900) 50%, var(--primary-900) 100%);
  color: var(--gray-300);
  padding: 48px 0;
  margin-top: 48px;
  font-size: 14px;
}
.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}
.footer-columns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 32px;
}
.footer-col a {
  display: block;
  color: var(--gray-300);
  font-size: 14px;
  margin-bottom: 8px;
}
.footer-col a:hover { color: #fff; }
.footer-col-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 16px;
}
.footer-brand-name {
  display: block;
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, #A78BFA, #667EEA);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 12px;
}
.footer-desc {
  color: var(--gray-300);
  font-size: 14px;
  margin: 0;
  line-height: 1.5;
}
.footer-divider {
  height: 1px;
  background: var(--gray-800);
  margin: 32px 0;
}
.footer-copyright {
  text-align: center;
  font-size: 14px;
  color: var(--gray-300);
  margin: 0;
}
@media (max-width: 768px) {
  .footer-columns {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
}
@media (max-width: 480px) {
  .footer-columns {
    grid-template-columns: 1fr;
    gap: 28px;
  }
}
