/* ==========================================================================
   Fonts (self-hosted, variable)
   ========================================================================== */

@font-face {
    font-family: 'Roboto';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/roboto-latin-wght-normal-P5vfNz3.woff2") format('woff2');
}

@font-face {
    font-family: 'Source Code Pro';
    font-style: normal;
    font-weight: 200 900;
    font-display: swap;
    src: url("../fonts/source-code-pro-latin-wght-normal-vhAiBSL.woff2") format('woff2');
}

@font-face {
    font-family: 'Source Code Pro';
    font-style: italic;
    font-weight: 200 900;
    font-display: swap;
    src: url("../fonts/source-code-pro-latin-wght-italic-PVtbLdE.woff2") format('woff2');
}

/* ==========================================================================
   Design tokens
   ========================================================================== */

:root {
    --font-heading: 'Roboto', system-ui, sans-serif;
    --font-body: 'Source Code Pro', ui-monospace, monospace;

    /* Palette: light (fondo blanco) */
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f3f2ef;
    --text: #1a1916;
    --text-muted: #6d695f;
    --border: #e5e3dd;
    --border-strong: #c3bfb5;
    --accent: #d8431b;
    --accent-hover: #b93614;
    --accent-contrast: #ffffff;
    --accent-soft: #fbe4dc;
    --success: #2e7d4f;
    --success-soft: #dcefe3;
    --map-fill: #1f8a5b; /* países del mapa: verde para no sumar más naranja */
    --warning: #9a6300;
    --warning-soft: #f6ead0;
    --danger: #b3261e;
    --danger-soft: #f7dcda;
    --focus: #2d5bff;

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;
    --space-9: 6rem;

    /* Type scale */
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;
    --text-3xl: clamp(2.25rem, 5vw, 3.5rem);

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 14px;
    --container: 1120px;
    --container-narrow: 720px;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
    --transition: 150ms ease;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #111110;
    --surface: #191917;
    --surface-2: #22221f;
    --text: #ecebe6;
    --text-muted: #9b978c;
    --border: #2d2c28;
    --border-strong: #45443e;
    --accent: #ff7446;
    --accent-hover: #ff8f68;
    --accent-contrast: #140a06;
    --accent-soft: #3b2017;
    --success: #6fcf97;
    --map-fill: #4cc38a;
    --success-soft: #16301f;
    --warning: #f0b44c;
    --warning-soft: #33280f;
    --danger: #ff8a80;
    --danger-soft: #3a1714;
    --focus: #7c9bff;
    --shadow: none;

    color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color var(--transition), color var(--transition);
}

h1, h2, h3, h4 {
    margin: 0;
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
}

h1 { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.035em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { margin: 0; }

a {
    color: inherit;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
    transition: color var(--transition), text-decoration-color var(--transition);
}

a:hover {
    color: var(--accent);
    text-decoration-color: currentColor;
}

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

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

::selection {
    background: var(--accent);
    color: var(--accent-contrast);
}

/* Que [hidden] gane a cualquier display de componente (.empty-state, .agreement, flex…) */
[hidden] { display: none !important; }

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--space-5);
}

.container--narrow { max-width: var(--container-narrow); }

.site-main {
    flex: 1;
    padding-block: var(--space-7) var(--space-9);
}

.stack > * + * { margin-top: var(--stack-gap, var(--space-4)); }

.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }

.kicker {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.kicker::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 2px;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.flashes {
    display: grid;
    gap: var(--space-2);
    margin-bottom: var(--space-6);
}

/* ==========================================================================
   Header & footer
   ========================================================================== */

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.site-header__inner {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    min-height: 64px;
}

/* Menú centrado en la página, no en el hueco entre logo y botones (que miden distinto) */
@media (min-width: 641px) {
    .site-header__inner:not(.is-collapsed) {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
    }

    .brand { justify-self: start; }
    .header-actions { justify-self: end; }
}

/* Sin sitio para centrar el menú en la fila del logo, se recoge en el botón ☰ de la derecha.
   En móvil siempre; en el resto lo decide header_layout_controller.js midiendo (depende del nombre de usuario) */
.nav-toggle { display: none; }

.site-header__inner.is-collapsed .main-nav { display: none; }
.site-header__inner.is-collapsed .nav-toggle { display: block; }

@media (max-width: 640px) {
    .main-nav { display: none; }
    .nav-toggle { display: block; }

    /* En móvil el botón de usuario es solo icono; el nombre queda para lectores de pantalla */
    .user-menu__name {
        position: absolute;
        width: 1px;
        height: 1px;
        clip: rect(0 0 0 0);
    }
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.375rem;
    letter-spacing: -0.03em;
    text-decoration: none;
}

.brand:hover { color: var(--text); }

.brand__mark {
    display: grid;
    grid-template-columns: repeat(2, 9px);
    gap: 2.5px;
}

.brand__mark span {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    background: var(--text);
}

.brand__mark span:nth-child(2) { background: var(--accent); }


.main-nav {
    display: flex;
    gap: var(--space-4);
    font-size: var(--text-sm);
}

.main-nav a {
    white-space: nowrap; /* "Propose a survey" nunca se parte en dos líneas */
    text-decoration: none;
    color: var(--text-muted);
    padding-block: var(--space-1);
}

.main-nav a:hover,
.main-nav a[aria-current="page"] { color: var(--text); }

.main-nav a[aria-current="page"] {
    box-shadow: inset 0 -2px 0 var(--accent);
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Todos los botones de la cabecera con la misma altura que el botón cuadrado del tema */
.header-actions .btn {
    height: 34px;
    padding-block: 0;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.icon-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.site-footer {
    border-top: 1px solid var(--border);
    padding-block: var(--space-6);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.site-footer__inner {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.site-footer nav {
    display: flex;
    gap: var(--space-4);
}

.icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.6rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:active { transform: translateY(1px); }

.btn--primary {
    background: var(--accent);
    color: var(--accent-contrast);
}

.btn--primary:hover {
    background: var(--accent-hover);
    color: var(--accent-contrast);
}

.btn--secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn--secondary:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.btn--ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn--ghost:hover {
    color: var(--text);
    background: var(--surface-2);
}

.btn--sm { padding: 0.4rem 0.75rem; font-size: var(--text-xs); }
.btn--lg { padding: 0.8rem 1.4rem; font-size: var(--text-base); }
.btn--block { width: 100%; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form { display: grid; gap: var(--space-5); }

.field { display: grid; gap: var(--space-2); }

.field__label {
    font-size: var(--text-sm);
    font-weight: 600;
}

.field__hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.field__error {
    font-size: var(--text-xs);
    color: var(--danger);
}

.input,
.select,
.textarea {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input::placeholder,
.textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--border-strong); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input--invalid { border-color: var(--danger); }

.textarea { min-height: 120px; resize: vertical; }

.select {
    appearance: none;
    padding-right: 2.2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    cursor: pointer;
}

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: var(--text-sm);
    cursor: pointer;
}

.checkbox input {
    margin-top: 3px;
    accent-color: var(--accent);
}

/* Honeypot: fuera de pantalla para humanos */
.hp-field {
    position: absolute;
    left: -9999px;
}

/* ==========================================================================
   Cards, badges, alerts
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--text-muted);
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge--pending_review { background: var(--warning-soft); color: var(--warning); }
.badge--approved { background: var(--success-soft); color: var(--success); }
.badge--rejected { background: var(--danger-soft); color: var(--danger); }
.badge--closed { background: var(--surface-2); color: var(--text-muted); }

.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    background: var(--surface-2);
}

.alert .icon { margin-top: 3px; }
.alert--info { background: var(--accent-soft); }
.alert--success { background: var(--success-soft); color: var(--success); }
.alert--danger { background: var(--danger-soft); color: var(--danger); }

/* ==========================================================================
   Home
   ========================================================================== */

.hero {
    display: grid;
    gap: var(--space-5);
    padding-bottom: var(--space-8);
}

.hero h1 em {
    font-style: normal;
    color: var(--accent);
}

.hero__lead {
    font-size: var(--text-lg);
    color: var(--text-muted);
    max-width: 60ch;
}

.hero__actions {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.hero__bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-5) var(--space-7);
    flex-wrap: wrap;
}

.stats {
    display: flex;
}

.stat {
    padding-inline: var(--space-5);
}

.stat:last-child { padding-right: 0; }

.stat + .stat { border-left: 1px solid var(--border); }

.stat__value {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat__label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.home-surveys {
    padding-top: var(--space-7);
    border-top: 1px solid var(--border);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface-2);
    border-radius: var(--radius);
}

.segmented a,
.segmented button {
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    font-size: var(--text-sm);
    text-decoration: none;
    color: var(--text-muted);
}

.segmented button {
    border: 0;
    background: none;
    font-family: inherit;
    cursor: pointer;
}

.segmented a[aria-current="true"],
.segmented button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.survey-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-5);
}

.survey-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition), transform var(--transition);
}

.survey-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.survey-card__media {
    position: relative;
    aspect-ratio: 16 / 12;
    border-bottom: 1px solid var(--border);
}

/* Imagen entera y centrada, dejando ver la rejilla alrededor */
.survey-card__media img {
    position: absolute;
    inset: var(--space-5);
    width: calc(100% - 2 * var(--space-5));
    height: calc(100% - 2 * var(--space-5));
    object-fit: contain;
}

.survey-card__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
    flex: 1;
}

.survey-card__title a {
    text-decoration: none;
}

/* Toda la tarjeta clicable */
.survey-card__title a::after {
    content: '';
    position: absolute;
    inset: 0;
}

.survey-card__meta,
.survey-card__footer {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    margin-top: auto;
    padding-top: var(--space-3);
    border-top: 1px dashed var(--border);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.survey-card__footer span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* Fondo de rejilla: portadas con imagen y fallback sin imagen */
.survey-cover,
.survey-card__media,
.cover-fallback {
    background-color: var(--surface-2);
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
}

/* Fallback visual si la encuesta no tiene imagen */
.cover-fallback {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.cover-fallback__glyph {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    color: var(--accent);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 var(--space-4);
    line-height: 1.3;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-7);
    font-size: var(--text-sm);
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
}

.pagination [aria-current="page"] {
    background: var(--text);
    border-color: var(--text);
    color: var(--bg);
}

/* ==========================================================================
   Survey detail
   ========================================================================== */

/* Breadcrumb: Home / Countries / Spain */
.breadcrumb {
    margin-bottom: var(--space-6);
    font-size: var(--text-sm);
}

.breadcrumb ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.breadcrumb li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.breadcrumb li + li::before {
    content: '/';
    color: var(--border-strong);
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumb a:hover { color: var(--accent); }

/* Página actual: títulos largos de encuesta se cortan con puntos suspensivos */
.breadcrumb [aria-current="page"] {
    max-width: 40ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.survey-header {
    display: grid;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.survey-header h1 { font-size: clamp(1.9rem, 4vw, 2.75rem); }

.survey-header__desc {
    font-size: var(--text-lg);
    color: var(--text-muted);
    max-width: 65ch;
}

.survey-cover {
    aspect-ratio: 21 / 8;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-7);
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    padding: var(--space-5);
}

.survey-cover img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
}

/* El fallback ya pinta su propia rejilla y ocupa todo el espacio */
.survey-cover:has(.cover-fallback) {
    padding: 0;
}

.survey-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--space-7);
    align-items: start;
}

.survey-top {
    align-items: stretch;
    margin-bottom: var(--space-7);
}

/* La portada se estira a la altura de la ficha en vez de guardar su proporción 21:8 */
.survey-top .survey-cover {
    aspect-ratio: auto;
    min-height: 260px;
    margin-bottom: 0;
}

.survey-top .aside-card {
    position: static;
    align-content: start;
}

.vote-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-block: var(--space-5);
    padding: 0;
    border: 0;
}

.vote-option {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.vote-option:hover { border-color: var(--border-strong); }

.vote-option input {
    position: absolute;
    opacity: 0;
}

.vote-option:has(input:checked) {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.vote-option:has(input:focus-visible) {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.vote-option__image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--surface-2);
}

.vote-option__label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
    padding-inline: var(--space-1);
}

.vote-option__radio {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border-strong);
    border-radius: 50%;
    flex-shrink: 0;
    transition: border var(--transition);
}

.vote-option:has(input:checked) .vote-option__radio {
    border: 5px solid var(--accent);
}

.vote-option__letter {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Wireframes de ejemplo para opciones visuales */
.wireframe {
    aspect-ratio: 4 / 3;
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 10px;
    display: grid;
    gap: 6px;
}

.wireframe i {
    display: block;
    border-radius: 3px;
    background: var(--border-strong);
    opacity: 0.55;
}

.wireframe i.is-accent { background: var(--accent); opacity: 1; }

.wireframe--top { grid-template-rows: 14px 1fr; }
.wireframe--top i:first-child { display: flex; justify-content: flex-end; }
.wireframe--side { grid-template-columns: 34px 1fr; }
.wireframe--bottom { grid-template-rows: 1fr 16px; }

.vote-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.voted-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.voted-banner__edit {
    font-weight: 600;
    color: inherit;
    text-underline-offset: 3px;
}

.results { display: grid; gap: var(--space-4); }

.result-row { display: grid; gap: 6px; }

.result-row__head {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: var(--text-sm);
}

.result-row__pct {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.result-bar {
    height: 10px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.result-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--border-strong);
}

.result-row--winner .result-bar span { background: var(--accent); }
.result-row--mine .result-row__label::after {
    content: ' ← ' attr(data-mine-label);
    color: var(--accent);
    font-size: var(--text-xs);
}

.country-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.country-table th {
    text-align: left;
    font-weight: 500;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
}

.country-table td {
    padding: var(--space-3);
    border-bottom: 1px dashed var(--border);
    vertical-align: middle;
}

.country-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.flag {
    display: inline-block;
    width: 20px;
    height: 15px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px var(--border);
}

.country {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

a.country { color: inherit; text-decoration: none; }
a.country:hover { color: var(--accent); }

/* Split se lleva todo el ancho sobrante; el resto de columnas se ajusta a su contenido */
.country-table th,
.country-table td { white-space: nowrap; }

.country-table .col-split {
    width: 100%;
    padding-right: var(--space-6);
}

.stacked-bar {
    display: flex;
    height: 8px;
    min-width: 140px;
    gap: 2px;
}

.stacked-bar span {
    position: relative;
    cursor: default;
    transition: box-shadow var(--transition);
}

.stacked-bar span:first-child { border-radius: 999px 0 0 999px; }
.stacked-bar span:last-child { border-radius: 0 999px 999px 0; }

.stacked-bar span:nth-child(1) { background: var(--accent); }
.stacked-bar span:nth-child(2) { background: color-mix(in srgb, var(--text) 55%, var(--bg)); }
.stacked-bar span:nth-child(3) { background: var(--border-strong); }
.stacked-bar span:nth-child(4) { background: var(--border); }
.stacked-bar span:nth-child(5) { background: color-mix(in srgb, var(--accent) 45%, var(--bg)); }
.stacked-bar span:nth-child(6) { background: color-mix(in srgb, var(--text) 25%, var(--bg)); }

.stacked-bar span:hover { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--border-strong); }

/* Tooltip con el porcentaje del tramo */
.stacked-bar span[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: var(--text-xs);
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
}

.legend {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend i {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legend span:nth-child(1) i { background: var(--accent); }
.legend span:nth-child(2) i { background: var(--text); opacity: 0.55; }
.legend span:nth-child(3) i { background: var(--border-strong); }
.legend span:nth-child(4) i { background: var(--border); }
.legend span:nth-child(5) i { background: color-mix(in srgb, var(--accent) 45%, var(--bg)); }
.legend span:nth-child(6) i { background: color-mix(in srgb, var(--text) 25%, var(--bg)); }

.locked-results {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.locked-results__preview {
    filter: blur(5px);
    opacity: 0.55;
    user-select: none;
    pointer-events: none;
}

.locked-results__overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-4);
    text-align: center;
    font-size: var(--text-sm);
    background: color-mix(in srgb, var(--bg) 35%, transparent);
}

.locked-results__overlay .icon {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

.survey-results {
    margin-top: var(--space-8);
}

.vote-options:disabled .vote-option { cursor: default; }
.vote-options:disabled .vote-option:not(:has(input:checked)) { opacity: 0.55; }

.aside-card {
    position: sticky;
    top: 88px;
    display: grid;
    gap: var(--space-5);
}

.meta-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    font-size: var(--text-sm);
}

.meta-list div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
}

.meta-list dt { flex-shrink: 0; color: var(--text-muted); }
/* Valores largos (p. ej. el email) se parten en vez de salirse de la tarjeta */
.meta-list dd { min-width: 0; margin: 0; font-weight: 500; text-align: right; overflow-wrap: anywhere; }

.share {
    display: flex;
    gap: var(--space-2);
}

.share .input { font-size: var(--text-xs); }

/* ==========================================================================
   Propose
   ========================================================================== */

.page-head {
    display: grid;
    gap: var(--space-3);
    margin-bottom: var(--space-7);
}

.page-head h1 { font-size: clamp(1.9rem, 4vw, 2.75rem); }

.option-list {
    display: grid;
    gap: var(--space-2);
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: option;
}

.option-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    counter-increment: option;
}

.option-row::before {
    content: counter(option, upper-alpha);
    display: grid;
    place-items: center;
    width: 32px;
    height: 38px;
    flex-shrink: 0;
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.option-row { flex-wrap: wrap; }
.option-row .input { flex: 1; width: auto; }
.option-row .icon-button { flex-shrink: 0; }
.option-row .icon-button:disabled { opacity: 0.35; cursor: not-allowed; }
.option-row .field__error { flex-basis: 100%; padding-left: 40px; }

.form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding-top: var(--space-5);
    border-top: 1px solid var(--border);
}

.confirmation {
    display: grid;
    justify-items: start;
    gap: var(--space-4);
}

.confirmation__icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--success-soft);
    color: var(--success);
    font-size: 1.4rem;
}

/* ==========================================================================
   Auth
   ========================================================================== */

.auth {
    display: grid;
    place-items: center;
    padding-block: var(--space-5);
}

.auth__card {
    width: 100%;
    max-width: 420px;
    display: grid;
    gap: var(--space-6);
}

.auth__head { display: grid; gap: var(--space-2); }
.auth__head h1 { font-size: var(--text-2xl); }

.auth__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
}

.auth__footer {
    text-align: center;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ==========================================================================
   Profile
   ========================================================================== */

.profile-head {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    flex-wrap: wrap;
    margin-bottom: var(--space-7);
}

.avatar {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-lg);
    background: var(--accent-soft);
    color: var(--accent);
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 700;
}

.profile-head__actions { margin-left: auto; }

.profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--space-6);
    align-items: start;
}

.proposal-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.proposal-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-block: var(--space-4);
    border-bottom: 1px dashed var(--border);
}

.proposal-item:last-child { border-bottom: 0; }

.proposal-item__main {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}

.proposal-item__title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-state {
    display: grid;
    justify-items: center;
    gap: var(--space-3);
    padding: var(--space-7) var(--space-4);
    text-align: center;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
}

/* ==========================================================================
   Countries
   ========================================================================== */

.country-title {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.flag--lg {
    width: 40px;
    height: 30px;
    border-radius: 4px;
}

.country-survey .survey-card__body { gap: var(--space-4); }

/* Una columna: tarjetas horizontales con la portada a la derecha */
.country-surveys {
    display: grid;
    gap: var(--space-5);
}

.country-survey {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 34%);
}

.country-survey .survey-card__media {
    order: 2;
    aspect-ratio: auto;
    min-height: 220px;
    border-bottom: 0;
    border-left: 1px solid var(--border);
}

.country-survey .survey-card__body { padding: var(--space-6); }

/* Etiqueta sobre la portada, para no competir con el título */
.country-survey .badge--differs {
    position: absolute;
    top: var(--space-3);
    left: var(--space-3);
    box-shadow: var(--shadow);
}

.country-survey__title {
    font-size: var(--text-lg);
    margin: 0;
}

.country-survey__title a {
    color: inherit;
    text-decoration: none;
}

.country-survey__title a:hover { color: var(--accent); }

.country-survey__pick {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-block: var(--space-1) var(--space-2);
}

.country-survey__answer {
    display: grid;
    gap: 2px;
    padding-left: var(--space-4);
    border-left: 1px solid var(--border);
}

.country-survey__pct {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}

.country-survey__label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
}

/* Muestra de color de una opción, mismos colores que .stacked-bar y .legend */
.swatch {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    border-radius: 2px;
}

.swatch--1 { background: var(--accent); }
.swatch--2 { background: color-mix(in srgb, var(--text) 55%, var(--bg)); }
.swatch--3 { background: var(--border-strong); }
.swatch--4 { background: var(--border); }
.swatch--5 { background: color-mix(in srgb, var(--accent) 45%, var(--bg)); }
.swatch--6 { background: color-mix(in srgb, var(--text) 25%, var(--bg)); }

.country-survey .legend .is-top {
    color: var(--text);
    font-weight: 600;
}

.country-survey__foot {
    display: grid;
    gap: var(--space-3);
}

/* Leyenda en 2 columnas que se leen de arriba abajo (1 y 2 a la izquierda, 3 y 4 a la derecha) */
.legend--columns {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--legend-rows, 2), 1.5em);
    grid-auto-columns: minmax(0, 1fr);
    column-gap: var(--space-5);
    row-gap: var(--space-1);
}

.legend--columns > span { min-width: 0; }

.legend--columns .legend__label {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge--differs { background: var(--accent-soft); color: var(--accent); }

/* Buscador del índice de países, a la derecha de los botones de orden */
.search {
    flex: 0 1 280px;
}

.country-count { margin: 0 0 var(--space-3); }

/* ==========================================================================
   User menu (cabecera)
   ========================================================================== */

.user-menu { position: relative; }

.user-menu__toggle { gap: var(--space-2); }

/* Nombres largos (hasta 30 caracteres) no ensanchan la cabecera */
.user-menu__name {
    max-width: 16ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-menu__toggle[aria-expanded="true"] .icon:last-child { transform: rotate(180deg); }

.user-menu__panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    z-index: 50;
    display: grid;
    min-width: 220px;
    padding: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.user-menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.user-menu__item:hover,
.user-menu__item[aria-current="page"] { background: var(--surface-2); }
.user-menu__item .icon { color: var(--text-muted); }

.user-menu__sep {
    margin: var(--space-2) 0;
    border: 0;
    border-top: 1px solid var(--border);
}

/* ==========================================================================
   World map (Leaflet sin tiles)
   ========================================================================== */

.world-map {
    position: relative;
    z-index: 0; /* los paneles de Leaflet (z-index 400+) no pisan la cabecera fija */
    height: 380px;
    margin-bottom: var(--space-5);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.world-map.leaflet-container {
    background: var(--surface);
    font: inherit;
}

/* Sin anillo de foco al pinchar un país: el mapa es decorativo (la tabla es la versión accesible) */
.world-map path:focus,
.world-map.leaflet-container:focus { outline: none; }

.world-map .world-map__country { cursor: default; }
.world-map .world-map__country--link { cursor: pointer; }

/* Muestras que el controlador lee para pintar con los colores del tema */
.world-map__probe-fill { background: var(--map-fill); }
.world-map__probe-empty { background: var(--surface-2); }
.world-map__probe-stroke { background: var(--surface); }
.world-map__probe-text { background: var(--text); }

/* Botones + / − con los colores del tema (Leaflet trae blanco y grises fijos, que en oscuro desentonan).
   Selectores con .world-map.leaflet-container porque la CSS de Leaflet se carga después de app.css */
.world-map.leaflet-container .leaflet-bar {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.world-map.leaflet-container .leaflet-bar a {
    background: var(--surface);
    color: var(--text);
    border-bottom-color: var(--border);
    transition: background var(--transition);
}

.world-map.leaflet-container .leaflet-bar a:last-child { border-bottom: 0; }

.world-map.leaflet-container .leaflet-bar a:hover,
.world-map.leaflet-container .leaflet-bar a:focus-visible { background: var(--surface-2); }

/* Zoom al tope: mismo fondo, solo el signo atenuado */
.world-map.leaflet-container .leaflet-bar a.leaflet-disabled {
    background: var(--surface);
    color: var(--border-strong);
}

.world-map__tip.leaflet-tooltip {
    padding: 4px 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: var(--text-xs);
    box-shadow: none;
}

.world-map__tip.leaflet-tooltip-top::before { border-top-color: var(--text); }

.world-map__tip-title {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

.world-map__tip-lines {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: var(--space-2);
    row-gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.world-map__tip-lines li { display: contents; }
.world-map__tip-lines .swatch { box-shadow: 0 0 0 1px color-mix(in srgb, var(--bg) 40%, transparent); }
.world-map__tip-pct { text-align: right; font-variant-numeric: tabular-nums; }

.world-map__tip-footer {
    display: block;
    margin-top: 4px;
    opacity: 0.7;
}

.section-head__title {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.country-map { margin: 0 0 var(--space-6); }
.country-map .world-map { margin-bottom: var(--space-2); }

/* Fila del país del visitante, primera en el índice */
.country-table tr.is-mine td { background: var(--accent-soft); }
.country-table tr.is-mine td:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.country-table tr.is-mine td:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* Coincidencia con el global en el índice de países: ocupa el ancho sobrante */
.country-table .col-agreement {
    width: 100%;
    padding-right: var(--space-6);
}

.agreement {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.meter {
    flex: 1;
    max-width: 320px;
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.agreement__value {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    min-width: 3.5em;
}

/* ==========================================================================
   Prose (privacy)
   ========================================================================== */

.prose { max-width: 68ch; }
.prose h2 { margin-top: var(--space-7); margin-bottom: var(--space-3); }
.prose p,
.prose ul { margin-bottom: var(--space-4); color: var(--text-muted); }
.prose ul { padding-left: var(--space-5); }
.prose li + li { margin-top: var(--space-2); }
.prose strong { color: var(--text); }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 860px) {
    .survey-layout,
    .profile-layout { grid-template-columns: 1fr; }
    .aside-card { position: static; }
    .survey-top .survey-cover { min-height: 200px; }
}

@media (max-width: 640px) {
    .container { padding-inline: var(--space-4); }
    .site-main { padding-block: var(--space-6) var(--space-8); }
    .header-actions .btn--ghost { display: none; }
    .hero__bar { flex-direction: column; align-items: stretch; }
    .hero__actions .btn { flex: 1 1 auto; }
    .search { flex-basis: 100%; }
    .world-map { height: 240px; }
    .stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        padding-top: var(--space-5);
        border-top: 1px solid var(--border);
    }
    .stat { padding-inline: var(--space-4); }
    .stat:first-child { padding-left: 0; }
    .survey-grid { grid-template-columns: 1fr; }
    .country-survey { grid-template-columns: minmax(0, 1fr); }
    .country-survey .survey-card__media {
        order: 0;
        aspect-ratio: 16 / 9;
        min-height: 0;
        border-left: 0;
        border-bottom: 1px solid var(--border);
    }
    .country-survey .survey-card__body { padding: var(--space-5); }
    /* La portada crece con la imagen en vez de encogerla a 21:8 */
    .survey-cover:has(img) { aspect-ratio: auto; padding: var(--space-4); }
    .survey-cover img { width: 100%; max-height: 70vh; }
    .vote-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
    .card { padding: var(--space-5); }
    .country-table .hide-sm { display: none; }
    .country-table td:first-child { white-space: normal; }
    .country-table .col-split,
    .country-table .col-agreement { padding-right: var(--space-3); }
    .meter { min-width: 48px; }
    .stacked-bar { min-width: 80px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
