* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background-color: #f4f6f9;
    color: #333;
    font-size: 16px;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
}

/* =====================
   CABECERA
   ===================== */
header {
    background-color: #1a3a5c;
    color: white;
    padding: 0 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 300;
    width: 100%;
}

header nav a {
    color: white;
    text-decoration: none;
    font-size: 17px;
    font-weight: 500;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

header nav a:hover {
    opacity: 1;
}

/* Botón hamburguesa — oculto en escritorio */
.nav-hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.nav-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.25s;
}

/* Menú móvil desplegable */
.nav-mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 400;
    opacity: 0;
    transition: opacity 0.3s;
}

.nav-mobile-overlay.visible { opacity: 1; }

.nav-mobile-panel {
    position: fixed;
    top: 0; right: -100%;
    visibility: hidden;
    width: min(320px, 85vw);
    height: 100%;
    background: #0d1f35;
    z-index: 500;
    transition: right 0.3s ease;
    overflow-y: auto;
    padding: 20px 0 40px;
}

.nav-mobile-panel.visible { right: 0; }

.nav-mobile-panel a,
.nav-mobile-panel button.nav-mobile-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: none;
    border-left: none;
    border-right: none;
    border-top: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.nav-mobile-panel a:hover,
.nav-mobile-panel button.nav-mobile-item:hover {
    background: rgba(255,255,255,0.07);
    color: white;
}

.nav-mobile-section-title {
    padding: 16px 20px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.3);
}

.nav-mobile-close {
    display: flex;
    justify-content: flex-end;
    padding: 10px 16px 20px;
}

.nav-mobile-close button {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =====================
   CONTENEDOR PRINCIPAL
   ===================== */
.contenedor {
    max-width: 1600px;
    margin: 30px auto;
    padding: 0 40px;
}

/* =====================
   TARJETAS DE EJERCICIO
   ===================== */
.grid-ejercicios {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 20px;
}

.tarjeta {
    background: white;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e0e0e0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tarjeta:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

.tarjeta h3 {
    font-size: 16px;
    color: #1a3a5c;
    margin-bottom: 8px;
}

.tarjeta p {
    font-size: 13px;
    color: #777;
    margin-bottom: 12px;
}

/* =====================
   ETIQUETAS
   ===================== */
.etiqueta {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 5px;
    margin-bottom: 5px;
}

.etiqueta-nivel-1 { background: #e8f5e9; color: #2e7d32; }
.etiqueta-nivel-2 { background: #fff8e1; color: #f57f17; }
.etiqueta-nivel-3 { background: #fce4ec; color: #c62828; }
.etiqueta-edad    { background: #e3f2fd; color: #1565c0; }
.etiqueta-tiempo  { background: #f3e5f5; color: #6a1b9a; }

/* =====================
   FILTROS
   ===================== */
.filtros {
    background: white;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 20px;
}

.filtros label {
    font-size: 12px;
    color: #555;
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.filtros select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: 14px;
    color: #333;
    background: white;
    min-width: 150px;
}

/* =====================
   BOTONES
   ===================== */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-primario    { background: #1a3a5c; color: white; }
.btn-primario:hover  { background: #14304d; }
.btn-secundario  { background: #e8edf2; color: #1a3a5c; }
.btn-secundario:hover { background: #d5dde6; }
.btn-verde       { background: #2e7d32; color: white; }
.btn-verde:hover { background: #1b5e20; }

/* =====================
   FORMULARIOS
   ===================== */
.formulario {
    background: white;
    padding: 30px;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    max-width: 450px;
    margin: 40px auto;
}

.formulario h2 {
    color: #1a3a5c;
    margin-bottom: 25px;
    font-size: 20px;
}

.campo { margin-bottom: 18px; }

.campo label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.campo input,
.campo select,
.campo textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px; /* ≥16px evita zoom en iOS */
    color: #333;
    background: white;
    font-family: inherit;
    transition: border-color 0.2s;
}

.campo input:focus,
.campo select:focus,
.campo textarea:focus {
    outline: none;
    border-color: #1a3a5c;
}

/* =====================
   MENSAJES
   ===================== */
.mensaje-error {
    background: #fce4ec;
    color: #c62828;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 15px;
}

.mensaje-ok {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 15px;
}

/* =====================
   FICHA EJERCICIO
   ===================== */
.ficha-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 28px;
    align-items: start;
    margin-top: 24px;
}

.ficha-col-izq {
    position: sticky;
    top: 80px;
}

.ficha-col-der {
    /* fluye normalmente */
}

@media (max-width: 768px) {

    .ficha-layout {
        grid-template-columns: 1fr;
        gap: 14px;
        margin-top: 16px;
    }

    /* En móvil: textos primero, imagen+info después */
    .ficha-col-izq  { order: 2; position: static; top: auto; }
    .ficha-col-der  { order: 1; }

    /* Banner ficha */
    .ficha-banner {
        padding: 18px 14px 22px !important;
    }

    .ficha-banner-inner {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 14px !important;
    }

    .ficha-banner-inner > button,
    .ficha-banner-inner > a {
        width: 100% !important;
        text-align: center !important;
        justify-content: center !important;
    }
}
/* =====================
   GRIDS ADMIN (usuarios, organizaciones)
   ===================== */
.admin-sidebar-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 24px;
    align-items: start;
}

.admin-sidebar-layout.narrow {
    grid-template-columns: 360px 1fr;
}

.admin-sidebar-form {
    position: sticky;
    top: 20px;
    background: white;
    border-radius: 14px;
    border: 1px solid #e8edf2;
    padding: 24px;
}

@media (max-width: 768px) {

    .admin-sidebar-layout,
    .admin-sidebar-layout.narrow {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Formulario lateral: deja de ser sticky */
    .admin-sidebar-form {
        position: static;
    }

    /* En móvil el formulario va debajo de la lista */
    .admin-sidebar-form   { order: 2; }
    .admin-sidebar-list   { order: 1; }

    /* Grids internos de formulario 2 col → 1 col */
    .admin-sidebar-form .campo-grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* Tabla importar: scroll horizontal */
    .importar-tabla-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Preview importar: ocultar columnas menos importantes */
    .preview-col-opc { display: none !important; }
}
/* =====================
   TABLAS ADMIN
   ===================== */
.tabla-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}
footer {
    margin-top: 60px;
}

/* =====================
   VARIOS
   ===================== */
.contenido-bloqueado { position: relative; overflow: hidden; }

.overlay-registro {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 120px;
    background: linear-gradient(transparent, white);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 15px;
}

/* =====================
   BARRA DE FILTROS sticky
   (ejercicios.php)
   ===================== */
.barra-filtros-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.barra-filtros-scroll::-webkit-scrollbar { display: none; }

/* =====================
   CARRITO FLOTANTE
   ===================== */
#carrito {
    max-width: calc(100vw - 48px);
    z-index: 600;
}

/* ================================================
   RESPONSIVE — TABLET  (≤ 900px)
   ================================================ */
@media (max-width: 900px) {

    .grid-ejercicios {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
}

/* ================================================
   RESPONSIVE — LAPTOP  (901px – 1399px)
   ================================================ */
@media (min-width: 901px) and (max-width: 1399px) {

    .grid-ejercicios {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

/* ================================================
   PANTALLAS GRANDES  (≥ 1400px)
   ================================================ */
@media (min-width: 1400px) {

    .grid-ejercicios {
        grid-template-columns: repeat(4, 1fr);
        gap: 24px;
    }

    .contenedor {
        padding: 0 60px;
    }
}

/* ================================================
   RESPONSIVE — MÓVIL  (≤ 768px)
   ================================================ */
@media (max-width: 768px) {

    /* --- Header --- */
    header {
        padding: 0 16px;
        height: 60px;
    }

    header > div {
        height: 60px;
    }

    header img {
        height: 44px !important;
    }

    /* Ocultar nav de escritorio en móvil */
    header nav {
        display: none !important;
    }

    /* Mostrar hamburguesa */
    .nav-hamburger {
        display: flex;
    }

    /* --- Contenedor --- */
    .contenedor {
        margin: 16px auto;
        padding: 0 12px;
    }

    /* --- Grid ejercicios: 1 columna --- */
    .grid-ejercicios {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* --- Tarjeta ejercicio en lista: imagen más pequeña --- */
    .tarjeta-ejercicio > div:first-child {
        height: 140px !important;
    }

    /* --- Formularios admin: grid 2 col → 1 col --- */
    .admin-grid-2col {
        grid-template-columns: 1fr !important;
    }

    /* Forzar full-width en campos con grid-column:1/-1 */
    .campo[style*="grid-column"] {
        grid-column: 1 / -1 !important;
    }

    /* --- Botones de acción en cabecera admin --- */
    .admin-header-actions {
        width: 100%;
        justify-content: flex-start !important;
    }

    .admin-header-actions a,
    .admin-header-actions button {
        flex: 1;
        justify-content: center;
        text-align: center;
    }

    /* --- Filtros barra --- */
    .filtros select {
        min-width: 100%;
    }

    /* --- Formulario login/registro --- */
    .formulario {
        margin: 16px auto;
        padding: 20px 16px;
        border-radius: 8px;
    }

    /* --- Visibilidad: 2 col → 1 col --- */
    #vis-opciones {
        grid-template-columns: 1fr !important;
    }

    /* --- Footer: reducir padding --- */
    footer > div {
        padding: 30px 16px 16px !important;
    }

    /* --- Stats y franja: reducir padding lateral --- */
    #stats-bar {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    #franja-bar {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* --- Barra de filtros: padding reducido en móvil --- */
    .barra-filtros-sticky {
        padding: 10px 12px !important;
    }

    /* --- Banners interiores en móvil --- */
    .ficha-banner,
    #banner-perfil,
    [style*="padding:40px 60px"],
    [style*="padding:36px 60px"],
    [style*="padding:28px 60px"],
    [style*="padding:50px 60px"],
    [style*="padding:60px 60px"],
    [style*="padding:14px 60px"] {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* --- Menús de filtros: posición fixed en móvil para evitar clipping del sticky bar --- */
    .filtro-menu {
        position: fixed !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        max-width: none !important;
        max-height: 60vh;
        overflow-y: auto !important;
    }

    /* --- CTA box dentro de home-características --- */
    .home-caracteristicas > div:last-child {
        padding: 28px 20px !important;
    }

    /* --- Banner cookies: apilar botones --- */
    #banner-cookies > div {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px !important;
    }

    #banner-cookies > div > div:last-child {
        flex-direction: column;
    }

    #banner-cookies button {
        width: 100%;
        text-align: center;
    }

    /* --- Carrito flotante compacto --- */
    #carrito {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        min-width: unset !important;
        max-width: 100% !important;
    }

    /* --- Barra contador+buscador: columna --- */
    .buscador-contador-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .buscador-contador-row input {
        width: 100% !important;
    }

    /* --- Página ficha: grid → columna --- */
    .ficha-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- home características --- */
    .home-caracteristicas {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    /* --- Tabla admin: scroll horizontal --- */
    .tabla-responsive {
        margin: 0 -12px;
        border-radius: 0;
    }

    /* --- Filtros dropdown: z-index alto para superar sticky bar --- */
    .filtro-dropdown { position: relative; }
    .filtro-menu { z-index: 9000 !important; }

    /* --- Acciones header admin: columna --- */
    .admin-top-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }

    .admin-top-bar > div:last-child {
        width: 100%;
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }

    .admin-top-bar > div:last-child a {
        flex: 1;
        text-align: center;
        justify-content: center;
    }

    /* --- Buscador en editar-ejercicios: columna --- */
    .buscador-tabla-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .buscador-tabla-row input,
    .buscador-tabla-row select {
        width: 100% !important;
    }
}

@media (max-width: 768px) {

    /* ── HOME: above-fold en móvil ── */
    #above-fold {
        height: auto !important;
        display: block !important;
    }
    #hero-wrap {
        height: auto !important;
        min-height: 55vh;
        flex: none !important;
    }
    #hero-wrap > div:last-of-type {
        padding: 32px 20px 28px !important;
    }
    #hero-wrap h1 {
        font-size: 36px !important;
        margin-bottom: 4px !important;
    }
    #hero-wrap h2 {
        font-size: 30px !important;
        margin-bottom: 12px !important;
    }
    #hero-wrap p {
        font-size: 14px !important;
        margin-bottom: 18px !important;
        max-width: 100% !important;
    }

    /* Stats: 2x2 en móvil */
    #stats-bar > div,
    #stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    #stats-bar .stats-cell {
        padding: 20px 12px !important;
        gap: 4px !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255,255,255,0.08) !important;
    }
    #stats-bar .stats-cell:nth-child(1),
    #stats-bar .stats-cell:nth-child(3) {
        border-right: 1px solid rgba(255,255,255,0.08) !important;
    }
    #stats-bar .stats-cell:nth-child(3),
    #stats-bar .stats-cell:nth-child(4) {
        border-bottom: none !important;
    }
    #stats-bar .stats-cell p:first-child {
        font-size: 32px !important;
        margin-bottom: 2px !important;
    }
    #stats-bar .stats-cell p:last-child {
        font-size: 10px !important;
        letter-spacing: 1px !important;
    }

    /* Franja inferior: 1 columna */
    #franja-bar > div {
        grid-template-columns: 1fr !important;
    }
    #franja-bar .franja-cell {
        border-right: none !important;
        border-bottom: 1px solid #e8edf2;
        padding: 18px 20px !important;
    }
    #franja-bar .franja-cell:last-child {
        border-bottom: none;
    }

    /* Buscador y filtros */
    .buscador-contador-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .buscador-contador-row input[type="text"] {
        width: 100% !important;
    }
    /* Barra filtros en móvil: wrap en varias líneas (evita que overflow-x corte los menús desplegables) */
    .barra-filtros-sticky > div {
        flex-wrap: wrap !important;
        overflow-x: visible;
        padding-bottom: 4px;
    }
}

/* ================================================
   ================================================ */
@media (max-width: 480px) {

    .btn {
        padding: 9px 14px;
        font-size: 13px;
    }

    .grid-ejercicios {
        gap: 10px;
    }

    /* Ajustar etiquetas en tarjetas */
    .etiqueta {
        font-size: 10px;
        padding: 2px 8px;
    }

    /* Tarjeta ejercicio: imagen aún más compacta */
    .tarjeta-ejercicio > div:first-child {
        height: 120px !important;
    }

    /* Banner de bienvenida/librería: reducir padding */
    .banner-hero {
        padding: 28px 16px 32px !important;
    }

    .banner-hero h1 {
        font-size: clamp(22px, 6vw, 32px) !important;
    }

    /* Sticky filtros: reducir padding */
    .barra-filtros-sticky {
        padding: 10px 12px !important;
    }

    /* Formulario: reducir padding interior de campos */
    .campo input,
    .campo select,
    .campo textarea {
        padding: 9px 12px;
        font-size: 16px; /* evitar zoom automático iOS */
    }

    /* Checkboxes edad/material: texto más pequeño */
    .checkbox-pill {
        font-size: 13px !important;
        padding: 7px 12px !important;
    }

    /* Footer: ocultar columna legal en muy pequeño */
    footer .footer-col-legal {
        display: none;
    }
}
