/* Identidad visual: colores y tipografía */
:root {
  color-scheme: dark;
  /* Fondo, superficies, bordes, texto y acento */
  --bg: #0B0B0D; --surface: #151519; --line: #26262E; --code-bg: #151519;
  --heading: #FAFAFA; --fg: #C9C9D1; --muted: #8A8A96;
  --accent: #FFD231; --accent-soft: rgba(255, 210, 49, .12);
  --radius: 12px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
/* hidden siempre oculta, aunque el componente defina su propio display */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 16px/1.65 var(--sans); }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
header { padding: 40px 0 32px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; color: var(--heading); text-wrap: balance; }
p, li, summary { text-wrap: pretty; }
.nw { white-space: nowrap; }
h1 { font-size: clamp(2rem, 5.5vw, 2.9rem); line-height: 1.12; margin: 0 0 14px; letter-spacing: -0.015em; }
h2 { font-size: 1.5rem; line-height: 1.25; margin: 56px 0 14px; }
h3 { font-size: 1.2rem; line-height: 1.3; margin: 36px 0 10px; }
h2 a, h3 a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 4px; }
p { margin: 0 0 12px; }
b, strong { color: var(--heading); font-weight: 500; }
.lede { color: var(--muted); font-size: 1.1rem; max-width: 40rem; }
a { color: var(--accent); text-underline-offset: 3px; }
code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); color: var(--heading); padding: 1px 5px; border-radius: 4px; }
pre { font-family: var(--mono); font-size: .85rem; background: var(--code-bg); border: 1px solid var(--line);
      border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; margin: 0 0 12px; line-height: 1.55; color: var(--fg);
      white-space: pre-wrap; overflow-wrap: anywhere; }
pre code { background: none; padding: 0; color: inherit; }

.acciones { margin-top: 22px; }
.boton { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; color: var(--heading); text-decoration: none;
         background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 15px; }
.boton:hover { border-color: var(--accent); }
.boton:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.boton svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 32px 0 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-family: var(--mono); font-size: 1.9rem; line-height: 1.1; font-weight: 500; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-family: var(--mono); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.source { color: var(--muted); font-size: .9rem; }

.demo { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.selects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
label { display: block; font-family: var(--mono); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
select, input { width: 100%; font: inherit; color: var(--heading); background: var(--bg); border: 1px solid var(--line);
                border-radius: 8px; padding: 9px 10px; line-height: 1.625; }
select { appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
         background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238A8A96' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
         background-repeat: no-repeat; background-position: right 14px center; background-size: 12px 8px; }
select:disabled { cursor: default; }
select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select:disabled { opacity: .5; }
.result { margin-top: 16px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-height: 2.6rem; }
.result:has(#cp:empty) { min-height: 0; margin-top: 0; }
.cp { font-family: var(--mono); font-size: 2rem; font-weight: 500; color: var(--accent); letter-spacing: .04em; }
.result small { color: var(--muted); font-family: var(--mono); }
#cp-enlace { align-self: center; font-size: .95rem; }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-family: var(--mono); font-weight: 400; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
td code { white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.tag { display: inline-block; font-family: var(--mono); font-size: .7rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em;
       background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 2px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details:last-child { border-bottom: 0; }
.faq summary { cursor: pointer; padding: 14px 0; font-weight: 500; color: var(--heading); }
.faq summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.faq details p { color: var(--muted); }
footer { margin: 72px 0 32px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
footer a { white-space: nowrap; }
/* Listas separadas por «·»: el punto vive en el hueco entre elementos y se recorta al inicio de cada línea,
   así nunca queda colgando al final ni abriendo un renglón */
.puntos { display: flex; flex-wrap: wrap; column-gap: 1.1em; clip-path: inset(-12px -12px -12px 0); }
.puntos > * { position: relative; }
.puntos > * + *::before { content: '·'; position: absolute; left: -.72em; color: var(--muted); pointer-events: none; }
.puntos a:focus-visible { outline-offset: -2px; }

.explorar-lede { color: var(--muted); max-width: 40rem; margin-bottom: 18px; }
.lista-controles { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 10px; }
.lista-controles input[type="search"] { flex: 1 1 240px; width: auto; }
.lista-total { margin: 0 0 8px; font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.tabla-gam { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tabla-gam table { font-size: .9rem; }
.tabla-gam thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tabla-gam th, .tabla-gam td { padding: 8px 12px; }
.tabla-gam tbody tr:last-child td { border-bottom: 0; }
.tabla-gam .etiqueta-gam { display: inline-block; white-space: nowrap; }
.tabla-gam .sub { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.filtro-gam { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border: 0; margin: 0; padding: 0; }
.filtro-gam legend { float: left; margin-right: 6px; font-family: var(--mono); font-size: .75rem; text-transform: uppercase;
                     letter-spacing: .08em; color: var(--muted); }
.filtro-gam label { position: relative; cursor: pointer; font-size: .9rem; color: var(--fg); border: 1px solid var(--line);
                    border-radius: 999px; padding: 0 14px; height: 40px; display: inline-flex; align-items: center; }
.lista-controles input[type="search"] { height: 40px; padding-top: 0; padding-bottom: 0; }
.filtro-gam input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.filtro-gam label:hover { border-color: var(--accent); }
.filtro-gam label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.filtro-gam label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.etiqueta-gam { align-self: center; font-family: var(--mono); font-size: .75rem; font-weight: 500; text-transform: uppercase;
                letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; }
.etiqueta-gam { white-space: nowrap; display: inline-block; }
.etiqueta-gam.sub-gam, .tabla-distritos .sub { display: none; }
p code, li code, summary code, .faq code { overflow-wrap: anywhere; }
.etiqueta-gam.si { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.copiar { font: inherit; font-size: .85rem; font-weight: 500; color: var(--heading); background: var(--bg); border: 1px solid var(--line);
          border-radius: 8px; padding: 6px 12px; cursor: pointer; align-self: center; }
.copiar:hover { border-color: var(--accent); }
.copiar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.copiar.listo { color: var(--accent); border-color: var(--accent); }

/* Buscador principal */
header.inicio { padding-bottom: 8px; }
.resultados:not(:empty) { margin-bottom: 24px; }
.buscador input { font-size: 1.15rem; padding: 15px 18px; border-radius: var(--radius); border-color: var(--accent); background: var(--surface); }
.buscador input:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 0; }
.ayuda { margin: 8px 2px 0; font-size: .9rem; color: var(--muted); }
.resultados { list-style: none; margin: 14px 0 0; padding: 0; }
.resultados:not(:empty) { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.resultados li { display: grid; grid-template-columns: minmax(0, 1fr) auto 9.5rem auto; align-items: center; gap: 8px 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.resultados li.sin-resultados { display: block; }
.resultados li:last-child { border-bottom: 0; }
.resultados li > a { text-decoration: none; min-width: 0; }
.resultados .lugar { display: block; font-family: var(--serif); font-weight: 500; font-size: 1.3rem; color: var(--heading); }
.resultados li > a:hover .lugar { color: var(--accent); }
.resultados .lugar-ruta { display: block; font-size: .9rem; color: var(--muted); }
.resultados .cp { font-size: 1.45rem; }
.resultados .etiqueta-gam, .resultados .copiar { justify-self: start; }
.resultados .sin-resultados { color: var(--muted); }
.resultados-total { margin: 14px 2px 0; font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.resultados-total:empty { display: none; }
.resultados-total + .resultados { margin-top: 8px; }
.resultados li.mas { display: block; text-align: center; padding: 10px 16px; }
.boton-mas { font: inherit; font-size: .9rem; font-weight: 500; color: var(--accent); background: none; border: 1px solid var(--line);
             border-radius: 999px; padding: 7px 16px; cursor: pointer; }
.boton-mas:hover { border-color: var(--accent); }
.boton-mas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Provincias y cantones */
.provincias { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-top: 18px; }
.provincia { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.provincia h3 { margin: 0 0 6px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.provincia p { margin: 0; font-size: .9rem; line-height: 1.75; color: var(--muted); }
.provincia p a { color: var(--fg); text-decoration: none; }
/* Los nombres de cantones en listas no se parten al final de la línea */
.provincia p a, .indice-cantones a { white-space: nowrap; }
.provincia p a:hover { color: var(--accent); text-decoration: underline; }
.ver-listas { margin-top: 14px; }

/* Sección de la API */
.api { margin-top: 72px; padding-top: 8px; border-top: 1px solid var(--line); }

/* Páginas de provincia, cantón y distrito */
header.pagina { padding: 40px 0 8px; }
header.pagina .idiomas { margin-bottom: 18px; }
.migas { display: flex; flex-wrap: wrap; gap: 6px; font-size: .9rem; color: var(--muted); }
.migas [aria-current] { color: var(--heading); }
.miga { display: inline-flex; gap: 6px; }
main h1 { margin-top: 18px; }
.cp-ficha { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 4px 0 18px; }
.cp-ficha .cp { font-size: 3rem; line-height: 1; }
table.ficha { max-width: 520px; margin: 18px 0 8px; }
table.ficha th { width: 1%; white-space: nowrap; padding-right: 24px; color: var(--muted); font-family: var(--mono); font-weight: 400; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.direccion { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.direccion code { font-size: .95rem; padding: 8px 12px; }
.enlaces { columns: 2 220px; padding: 0; list-style: none; margin: 0; }
.enlaces li { padding: 4px 0; break-inside: avoid; }
.enlaces code { margin-left: 6px; color: var(--muted); }
.nota-api { margin-top: 40px; font-size: .9rem; color: var(--muted); }
.buscar-otro { margin-top: 32px; }
.indice-cantones { font-size: .9rem; line-height: 1.8; color: var(--muted); }
.tabla-distritos { font-size: .95rem; }
/* La columna del código postal se ajusta a su contenido y deja el resto del ancho al nombre */
.tabla-gam td:first-child { width: 1%; white-space: nowrap; }
/* Dentro de tarjetas (fondo de superficie) la pastilla del código usa el fondo de la página para distinguirse */
.tabla-gam code, .demo code, .resultados code, .provincia code { background: var(--bg); }
/* Las tablas de distritos usan anchos fijos de columna: así las tablas de cada cantón en una misma página
   quedan alineadas entre sí, sin importar el largo de los nombres */
.tabla-distritos.con-zona { table-layout: fixed; }
.tabla-distritos.con-zona th:first-child { width: 8.5rem; }
.tabla-distritos.con-zona th:last-child { width: 11.5rem; }
.tabla-distritos.con-zona td:first-child { white-space: nowrap; }
.tabla-distritos.tabla-lista { table-layout: auto; }
.tabla-distritos.tabla-lista th:first-child, .tabla-distritos.tabla-lista th:last-child { width: 1%; white-space: nowrap; }

@media (max-width: 640px) {
  header { padding-top: 40px; }
  .selects { grid-template-columns: 1fr; }
  .stat b { font-size: 1.45rem; }
  .cp-ficha .cp { font-size: 2.4rem; }
  /* Con el nombre del distrito en dos renglones, cada celda se alinea con el primero */
  .tabla-distritos td { vertical-align: baseline; }
  .resultados .cp { font-size: 1.2rem; }
  .resultados li { grid-template-columns: auto auto 1fr; }
  .resultados li > a { grid-column: 1 / -1; }
  /* En la lista de distritos, cantón y provincia pasan debajo del distrito para que la zona quepa */
  .tabla-gam th:nth-child(3), .tabla-gam td:nth-child(3), .tabla-gam th:nth-child(4), .tabla-gam td:nth-child(4) { display: none; }
  .tabla-gam .sub { display: block; font-size: .8rem; color: var(--muted); }
  .tabla-gam th, .tabla-gam td { padding: 8px 9px; }
  .tabla-gam .etiqueta-gam { font-size: .7rem; padding: 3px 8px; }
  /* Listas de cantones y distritos: provincia, cantón y cantidad pasan debajo del nombre */
  .tabla-lista th:nth-child(3), .tabla-lista td:nth-child(3), .tabla-lista th:nth-child(4), .tabla-lista td:nth-child(4),
  .tabla-cantones th:nth-child(2), .tabla-cantones td:nth-child(2), .tabla-cantones th:nth-child(3), .tabla-cantones td:nth-child(3) { display: none; }
  .tabla-distritos .sub { display: block; font-size: .8rem; color: var(--muted); }
  .tabla-distritos th, .tabla-distritos td { padding: 8px 9px; }
  /* Endpoints de la API: cada fila pasa a ser un bloque, con la ruta arriba y la descripción debajo */
  .api table thead { display: none; }
  .api table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .api table td { display: block; padding: 2px 0; border: 0; }
  .api td code { white-space: normal; overflow-wrap: anywhere; font-size: .8em; }
}

/* Teléfonos: la zona pasa debajo del nombre del distrito para que ninguna tabla necesite scroll lateral */
@media (max-width: 480px) {
  /* Ficha del distrito: código y Copiar en la primera fila, la zona debajo, sea GAM o no */
  .cp-ficha { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "cp copiar" "zona zona"; gap: 10px 14px; }
  .cp-ficha .cp { grid-area: cp; }
  .cp-ficha .copiar { grid-area: copiar; justify-self: start; }
  .cp-ficha .etiqueta-gam { grid-area: zona; justify-self: start; }
  .con-zona th:last-child, .con-zona td:last-child, .tabla-gam th:nth-child(5), .tabla-gam td:nth-child(5) { display: none; }
  .tabla-distritos.con-zona th:first-child { width: 5.25rem; }
  .con-zona .etiqueta-gam.sub-gam, .tabla-gam .etiqueta-gam.sub-gam { display: block; width: fit-content; margin-top: 6px; font-size: .7rem; padding: 2px 9px; }
  .stats { grid-template-columns: 1fr; gap: 8px; }
  .stat { display: flex; align-items: baseline; gap: 12px; padding: 10px 14px; }
  .stat b { display: inline; }
  /* Resultados del buscador: código, zona y botón bajan de línea si no caben */
  .resultados li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  .resultados li > a { flex-basis: 100%; }
  .resultados .copiar { margin-left: auto; }
}

.idiomas { display: flex; justify-content: flex-end; gap: 16px; margin-bottom: 28px; font-family: var(--mono); font-size: .8rem;
           text-transform: uppercase; letter-spacing: .08em; }
.idiomas a { color: var(--muted); text-decoration: none; padding: 6px 2px; }
.idiomas a:hover { color: var(--heading); }
.idiomas a[aria-current="page"] { color: var(--accent); }
.idiomas a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
