/* ProteRadar: estilos propios, fuentes del sistema y ningún recurso externo. */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #4b5563;
  --accent: #1d4ed8;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.wrap { max-width: 1200px; margin-inline: auto; padding-inline: 16px; }

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

.skip-link {
  position: absolute; left: 16px; top: -100px; z-index: 10; background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: 0 0 8px 8px; font-weight: 600;
}
.skip-link:focus { top: 0; }

/* Cabecera y pie */
.site-header { background: #fff; border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; min-height: 60px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.logo-icon { flex: none; }
.site-header nav { display: flex; gap: 20px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); text-decoration: none; padding: 18px 0 14px; border-bottom: 3px solid transparent; font-weight: 500; }
.site-header nav a:hover { color: var(--text); }
.site-header nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.site-footer { margin-top: 48px; padding: 24px 0; border-top: 1px solid var(--border); background: #fff; color: var(--muted); font-size: 0.9rem; }

main { padding-top: 32px; }
main:focus { outline: none; }
h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 20px 0 8px; }
h4 { font-size: 1rem; margin: 20px 0 6px; }
.intro h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); max-width: 19em; letter-spacing: -0.015em; }
.intro p { margin: 4px 0; }
.lead { color: var(--muted); font-size: 1.1rem; max-width: 46rem; }
.updated { color: var(--muted); font-size: 0.9rem; }
.muted { color: var(--muted); font-size: 0.9em; }
.crumbs { margin: 0 0 8px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 20px 0; }
.table-card { padding: 0; overflow: hidden; }
.note { color: var(--muted); font-size: 0.9rem; margin: 8px 0 0; }
.empty { color: var(--muted); padding: 12px 0; margin: 0; }
.table-card .empty { padding: 20px; }
.prose ul { padding-left: 20px; }
.prose li { margin: 6px 0; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }

/* Filtros */
.filters { display: flex; gap: 16px; flex-wrap: wrap; align-items: end; }
.filters[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 200px; flex: 1 1 200px; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
select {
  font: inherit; color: var(--text); background: #fff; padding: 8px 10px;
  border: 1px solid #9ca3af; border-radius: 8px; min-height: 40px;
}

/* Tablas */
/* position: relative contiene los .sr-only (absolute) de las celdas; si no, ensanchan la página. */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap:focus-visible, .chart-wrap:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
thead th { background: #f9fafb; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.offers { min-width: 640px; }
table.breakdown, table.criteria { min-width: 560px; }
table.criteria ul { margin: 0; padding-left: 18px; }
table.criteria li { margin: 4px 0; }
tbody th { font-weight: 600; }
.product-link { font-weight: 600; }
.mark { cursor: help; }

/* Estados de oferta */
.badge { display: inline-block; padding: 1px 10px; border: 1px solid transparent; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.deal-real { background: #dbeafe; color: #1e3a8a; }
.deal-inflated { background: #ffedd5; color: #9a3412; }
.deal-unknown { background: #f3f4f6; color: #374151; }
.deal-normal { background: #fff; color: #374151; border-color: #9ca3af; }
.deal-both { border-color: #b91c1c; }

/* Leyenda */
.legend dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.legend dt { font-weight: 600; }
.legend dd { margin: 0; }
@media (max-width: 640px) { .legend dl { grid-template-columns: 1fr; gap: 2px; } .legend dd { margin-bottom: 10px; } }

/* Ficha */
.best-price strong { font-size: 1.6rem; }
.best p { margin: 6px 0; }
.button {
  display: inline-block; background: var(--accent); color: #fff; padding: 10px 18px;
  border-radius: 8px; text-decoration: none; font-weight: 600;
}
.button:hover { background: #1e40af; }
.button-secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); font: inherit; font-weight: 600; cursor: pointer; margin-left: 8px; }
.button-secondary:hover { background: #eff6ff; }
.chart-wrap { position: relative; overflow-x: auto; }
.chart { width: 100%; min-width: 520px; max-width: 760px; height: auto; display: block; }
.score { font-size: 1.1rem; margin: 8px 0 0; }
.score-value { font-size: 2rem; font-weight: 700; }
.warning { background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; padding: 10px 14px; border-radius: 8px; margin: 12px 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 20px; margin: 8px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.label-block h3 { margin-top: 0; }

/* Ranking (escritorio) */
table.ranking th, table.ranking td { padding: 12px 10px; vertical-align: middle; }
table.ranking .sub { display: block; color: var(--muted); font-size: 0.86rem; font-weight: 400; }
table.ranking .product-link { display: block; }
table.ranking .store { display: block; font-weight: 600; }
table.ranking .c-prod { min-width: 200px; }
table.ranking .c-perkg strong { font-size: 1.05rem; }
.score-pill { display: inline-block; min-width: 3em; text-align: center; padding: 2px 10px; border-radius: 8px; font-weight: 700; }
.score-hi { background: #dbeafe; color: #1e3a8a; }
.score-mid { background: #eef2f7; color: #1f2937; }
.score-low { background: #f3f4f6; color: #4b5563; }
.deal-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.deal-legend li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.legend-sub { margin: 20px 0 8px; }

/* Ranking en tarjetas (móvil y tablet): la misma tabla, solo con CSS */
@media (max-width: 900px) {
  .table-card { background: none; border: 0; border-radius: 0; overflow: visible; margin: 16px 0; }
  .table-card .table-wrap { overflow: visible; }
  table.ranking, table.ranking tbody { display: block; }
  table.ranking thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .ranking-row {
    display: grid; grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas: "pos prod score" "perkg perkg p25" "offer offer price" "deal deal deal";
    gap: 8px 10px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px;
  }
  .ranking-row[hidden] { display: none; }
  table.ranking td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; }
  table.ranking .num { text-align: left; }
  .c-pos { grid-area: pos; color: var(--muted); }
  .c-prod { grid-area: prod; min-width: 0; }
  .c-score { grid-area: score; text-align: right !important; }
  .c-score .muted { display: none; }
  .c-perkg { grid-area: perkg; }
  .c-perkg strong { font-size: 1.6rem; line-height: 1.1; }
  .c-perkg strong::after { content: " /kg prot."; font-size: 0.85rem; font-weight: 400; color: var(--muted); }
  .c-25g { grid-area: p25; align-self: end; text-align: right !important; color: var(--muted); }
  .c-25g::after { content: " / 25 g"; }
  .c-offer { grid-area: offer; }
  .c-price { grid-area: price; text-align: right !important; }
  .c-deal { grid-area: deal; }
}

/* Tablas apiladas en móvil: cada fila es un bloque con las etiquetas de sus celdas */
@media (max-width: 640px) { .card { padding: 16px; } }
@media (max-width: 900px) {
  .table-wrap { overflow: visible; }
  table.stack, table.offers, table.breakdown, table.criteria { min-width: 0; }
  .stack, .stack tbody, .stack tr, .stack th, .stack td { display: block; }
  .stack thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .stack tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
  .stack tbody tr:last-child { border-bottom: 0; }
  .stack th, .stack td {
    position: relative; padding: 3px 0 3px 8.5rem; border: 0; text-align: left; white-space: normal;
  }
  .stack th[scope="row"] { padding-left: 0; font-size: 1rem; }
  .stack td::before {
    content: attr(data-label); position: absolute; left: 0; top: 3px; width: 8rem;
    font-weight: 600; font-size: 0.85rem; color: var(--muted);
  }
  .stack td[data-label="Detalle"], .stack td[data-label="Reglas"] { padding-left: 0; }
  .stack td[data-label="Detalle"]::before, .stack td[data-label="Reglas"]::before {
    position: static; display: block; width: auto;
  }
}
