/* =========================================
   Variables de color (Inspiración Renault)
   ========================================= */
:root {
    --amarillo-renault: #FFCC00; 
    --gris-oscuro: #1A1A1A;      
    --gris-medio: #4A4A4A;       
    --gris-claro: #F4F4F4;       
    --blanco: #FFFFFF;
}

/* =========================================
   Reset básico y configuración general
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%;
    min-width: 0;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--gris-oscuro);
    background-color: var(--blanco);
    display: flex;
    flex-direction: column;
    min-height: 100vh; 
}

img {
    max-width: 100%;
    height: auto;
}

/* =========================================
   Cabecera (Header) y Navegación
   ========================================= */
header {
    background-color: var(--blanco);
    padding: 1rem 2rem;
    border-bottom: 4px solid var(--amarillo-renault);
    display: flex;
    justify-content: space-between;
    align-items: center; 
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gris-oscuro);
}

.header-derecha {
    display: flex;
    align-items: center;
    gap: 2rem; 
}

nav ul {
    list-style: none;
    display: flex;
    align-items: center;
}

nav li {
    margin: 0 5px;
}

nav a {
    color: var(--gris-oscuro);
    text-decoration: none;
    padding: 0.5rem 1rem;
    display: block;
    font-weight: 600;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

nav a:hover, 
nav a:focus {
    background-color: var(--amarillo-renault);
    outline: none;
}

nav a.activo {
    border-bottom: 3px solid var(--amarillo-renault);
    border-radius: 4px 4px 0 0;
}

/* =========================================
   Botón Menú Hamburguesa (Oculto en PC)
   ========================================= */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--gris-oscuro);
    cursor: pointer;
}

/* =========================================
   Icono de Usuario y Menú Desplegable
   ========================================= */
.perfil-usuario {
    color: var(--gris-medio);
    cursor: pointer;
    transition: color 0.2s ease;
    border-radius: 50%;
    display: inline-block; 
}

.perfil-usuario:hover,
.perfil-usuario:focus {
    color: var(--amarillo-renault);
    outline: none;
}

.dropdown-usuario {
    position: relative;
    display: inline-block;
}

.dropdown-usuario::after {
    content: "";
    position: absolute;
    bottom: -15px;
    left: 0;
    width: 100%;
    height: 15px;
    background: transparent;
}

.dropdown-contenido {
    display: none; 
    position: absolute;
    right: 0;
    top: calc(100% + 10px); 
    background-color: var(--blanco);
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.15);
    border-radius: 6px;
    border: 1px solid #E0E0E0;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-contenido a {
    color: var(--gris-oscuro) !important;
    padding: 12px 16px;
    display: block; 
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    border-radius: 0; 
    border-bottom: none !important; 
}

.dropdown-contenido a:hover,
.dropdown-contenido a:focus {
    background-color: var(--gris-claro);
}

.dropdown-usuario:hover .dropdown-contenido,
.dropdown-usuario:focus-within .dropdown-contenido {
    display: block;
}

.dropdown-contenido a.cerrar-sesion {
    color: #dc3545 !important;
    font-weight: 600;
}

.dropdown-contenido a.cerrar-sesion:hover,
.dropdown-contenido a.cerrar-sesion:focus {
    background-color: #f8d7da !important; 
    color: #721c24 !important; 
}

/* =========================================
   Contenido Principal (Main)
   ========================================= */
main {
    flex: 1; 
    padding: 3rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

main section {
    background-color: var(--gris-claro);
    padding: 2.5rem;
    border-radius: 8px;
    border-left: 5px solid var(--amarillo-renault); 
}

main h2 { margin-bottom: 1rem; font-size: 1.8rem; }
main p { color: var(--gris-medio); font-size: 1.1rem; }

/* =========================================
   Estilos para Formularios
   ========================================= */
.contenedor-formulario {
    max-width: 800px;
    margin: 0 auto;
}

.formulario-registro fieldset {
    border: 1px solid #E0E0E0;
    padding: 1.5rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
    background-color: var(--blanco);
}

.formulario-registro legend {
    font-weight: 700;
    padding: 0 0.5rem;
    color: var(--gris-oscuro);
    font-size: 1.05rem;
}

.grupo-campo {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.2rem;
    width: 100%;
}

.grupo-campo label {
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.95rem;
}

.grupo-campo input,
.grupo-campo select,
.grupo-campo textarea {
    padding: 0.75rem;
    border: 1px solid #CCC;
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.grupo-campo input:focus,
.grupo-campo select:focus,
.grupo-campo textarea:focus {
    outline: none;
    border-color: var(--gris-oscuro);
    box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.4); 
}

.fila-formulario {
    display: flex;
    gap: 1.5rem;
}
.fila-formulario .grupo-campo { flex: 1; }

/* REGLA AÑADIDA PARA SOLUCIONAR EL DISEÑO */
.grid-servicios {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 20px;
    margin-top: 2rem;
}

.boton-primario {
    background-color: var(--gris-oscuro);
    color: var(--blanco);
    border: 2px solid var(--gris-oscuro);
    padding: 0.85rem 2rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s ease;
    text-align: center;
}

.boton-primario:hover,
.boton-primario:focus {
    background-color: var(--amarillo-renault);
    color: var(--gris-oscuro);
    border-color: var(--amarillo-renault);
}

/* =========================================
   Sección Transparente y Tarjetas
   ========================================= */
main section.seccion-transparente {
    background-color: transparent;
    border-left: none;
    padding: 1rem 0;
}

.tarjeta-servicio {
    position: relative;
    display: block;
    border-radius: 8px;
    overflow: hidden; 
    text-decoration: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.tarjeta-servicio img {
    width: 100%;
    height: 300px;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease; 
}

.capa-descripcion {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(26, 26, 26, 0.85); 
    color: var(--blanco);
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
    padding: 2rem;
    opacity: 0; 
    transition: opacity 0.4s ease;
}

.capa-descripcion h3, .capa-descripcion p {
    transform: translateY(20px); 
    transition: transform 0.4s ease;
}
.capa-descripcion h3 { color: var(--amarillo-renault); margin-bottom: 1rem; font-size: 1.5rem; }

.tarjeta-servicio:hover img { transform: scale(1.05); }
.tarjeta-servicio:hover .capa-descripcion { opacity: 1; }
.tarjeta-servicio:hover .capa-descripcion h3,
.tarjeta-servicio:hover .capa-descripcion p { transform: translateY(0); }

/* =========================================
   Pie de página (Footer)
   ========================================= */
footer {
    background-color: var(--gris-oscuro);
    color: var(--blanco);
    text-align: center;
    padding: 1.5rem;
    font-size: 0.9rem;
    border-top: 4px solid var(--amarillo-renault);
}


/* =======================================================
   ADAPTACIÓN PARA MÓVILES (DISEÑO 100% APP NATIVA)
   ======================================================= */
@media screen and (max-width: 900px) {

    /* Mantiene la cabecera y el pie a todo el ancho del dispositivo aunque
       una tabla o un cuadro de torneo necesiten desplazamiento interno. */
    body > header,
    body > footer {
        width: 100%;
        max-width: 100%;
        flex: 0 0 auto;
    }

    body > main,
    body > main > * {
        min-width: 0;
        max-width: 100%;
    }
    
    /* --- 1. CABECERA Y MENÚ HAMBURGUESA --- */
    header {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
        position: relative;
    }
    
    header h1 {
        font-size: 1.1rem; /* Logo más compacto en móvil */
    }

    .menu-toggle {
        display: block;
        flex: 0 0 auto;
    }

    .logo,
    .logo > a,
    .logo > a > div {
        min-width: 0;
        max-width: 100%;
    }

    .logo > a { gap: 10px !important; }
    .logo img { flex: 0 0 auto; }
    .logo h1 { font-size: clamp(1rem, 4.5vw, 1.25rem) !important; overflow-wrap: anywhere; }
    .header-derecha { min-width: 0; flex: 0 0 auto; }

    .nav-links {
        display: none;
        width: 100%;
        background: var(--blanco);
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 1000;
        border-bottom: 2px solid #ddd;
        box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    }

    .nav-links.activo {
        display: block;
    }

    .nav-links ul {
        flex-direction: column;
        padding: 1rem 0;
    }

    .nav-links li {
        width: 100%;
        text-align: center;
        margin: 5px 0;
    }

    /* --- 2. ESPACIOS GENERALES --- */
    main { padding: 15px !important; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.2rem; }

    .contenedor-formulario, .contenedor-login {
        width: 100%;
        padding: 1.2rem !important;
        margin: 1rem auto !important;
        box-shadow: none; 
        border-radius: 0;
    }

    .fila-formulario {
        flex-direction: column;
        gap: 1rem;
    }

    .grupo-campo input, .grupo-campo select, .grupo-campo textarea {
        font-size: 16px; /* Vital para que los iPhone/Android no hagan zoom al escribir */
    }

    /* --- 3. TABLAS: mantener legibles los campos al convertirlas en tarjetas --- */
    .tabla-reservas, .tabla-admin, 
    .tabla-reservas tbody, .tabla-admin tbody, 
    .tabla-reservas tr, .tabla-admin tr, 
    .tabla-reservas td, .tabla-admin td {
        display: block !important;
        width: 100% !important;
        white-space: normal !important; /* El texto baja a la siguiente línea */
        box-sizing: border-box;
    }

    .tabla-reservas thead, .tabla-admin thead {
        display: none !important; /* Ocultamos las cabeceras en móvil */
    }

    .tabla-reservas tr, .tabla-admin tr {
        margin-bottom: 1.5rem;
        border: 1px solid #ddd;
        border-radius: 12px;
        padding: 15px;
        background: #fff;
        box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    }

    .tabla-reservas td, .tabla-admin td {
        text-align: left !important;
        padding: 0.6rem 0 !important;
        border: none !important;
        border-bottom: 1px dashed #eee !important;
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .tabla-reservas td::before,
    .tabla-admin td::before {
        content: attr(data-label);
        display: block;
        color: #4a4a4a;
        font-size: 0.78rem;
        font-weight: 700;
        line-height: 1.3;
        letter-spacing: 0.02em;
    }

    .tabla-reservas td:last-child, .tabla-admin td:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    /* --- 4. OTROS AJUSTES --- */
    .dashboard-grid { grid-template-columns: 1fr; }
    .tarjeta-anuncio { width: 100% !important; margin-bottom: 20px; }
    .contenedor-tablon { padding: 10px; }
    
   /* --- 5. BOTONES DE ACCIÓN CENTRADOS EN MÓVIL --- */
    .tabla-reservas td:last-child, .tabla-admin td:last-child {
        align-items: center; /* Centra todo el bloque de botones */
        padding-top: 15px !important; /* Da un poco de aire respecto al texto de arriba */
        padding-bottom: 10px !important;
    }

    /* Evita que los formularios que envuelven los botones rompan el centrado */
    .tabla-reservas td:last-child form, 
    .tabla-admin td:last-child form {
        width: 100%;
        display: flex;
        justify-content: center;
        margin: 0 !important;
    }

    /* Ajuste de ancho y centrado para que respiren por los lados */
    .tabla-reservas td:last-child button, 
    .tabla-reservas td:last-child a,
    .tabla-admin td:last-child button, 
    .tabla-admin td:last-child a {
        width: 85% !important; /* El margen mágico para que no toquen el borde */
        max-width: 250px; /* Evita que se estiren en tablets */
        margin: 5px auto !important;
        display: block;
        text-align: center;
        border-radius: 8px !important; /* Toque redondeado estilo App */
    }

    /* =========================================
   FOTO DE PERFIL Y NOTIFICACIONES
   ========================================= */
.img-perfil-menu {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--amarillo-renault);
}

.contenedor-icono-perfil {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.burbuja-notificacion {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: #dc3545;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 50%;
    display: none; /* Oculto hasta que el JS encuentre mensajes */
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
}

/* Estilos para el panel de subir foto */
.upload-foto-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border: 1px dashed #ccc;
}
.img-perfil-preview {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #ddd;
}

/* =========================================
   FOTO DE PERFIL EN LA CABECERA (CORRECCIÓN)
   ========================================= */
.img-perfil-menu {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important; /* Evita que el menú lo aplaste */
    min-height: 40px !important; /* Evita que el menú lo estire */
    border-radius: 50%;
    object-fit: cover; /* Recorta la foto para que encaje en el círculo sin deformarse */
    border: 2px solid var(--amarillo-renault);
    display: block;
}

.contenedor-icono-perfil {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: 10px;
}

    /* Las tablas de auditoría pueden desplazarse dentro de su propio bloque. */
    .log-table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Bandejas de mensajes: apilar asunto y fecha para que quepan en el móvil. */
    .tabla-historial,
    .tabla-historial tbody {
        display: block;
        width: 100%;
    }

    .tabla-historial tr {
        display: block;
        width: 100%;
        margin-bottom: 0.75rem;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        background: #fff;
    }

    .tabla-historial td {
        display: block;
        width: 100% !important;
        padding: 0.8rem !important;
        text-align: left !important;
        overflow-wrap: anywhere;
    }

    .tabla-historial td:first-child::before,
    .tabla-historial td:nth-child(2)::before {
        display: block;
        margin-bottom: 0.35rem;
        color: #4a4a4a;
        font-size: 0.78rem;
        font-weight: 700;
    }

    .tabla-historial td:first-child::before { content: 'Conversación'; }
    .tabla-historial td:nth-child(2)::before { content: 'Fecha y estado'; }

    /* El aviso de cookies ocupa el ancho disponible sin forzar el scroll de página. */
    #banner-cookies { padding: 1rem !important; }
    #banner-cookies > div { align-items: stretch !important; gap: 10px !important; }
    #banner-cookies > div > div:first-child { min-width: 0 !important; flex: 1 1 100% !important; }
    #banner-cookies > div > div:last-child { width: 100%; }
    #banner-cookies button { width: 100%; }
}

@media screen and (max-width: 380px) {
    header { padding: 0.75rem !important; }
    .logo > a { gap: 7px !important; }
    .logo img { max-width: 42px; }
    .logo h1 { font-size: 1rem !important; }
}

/* Correcciones comunes para tablet y móvil: conservan el diseño de escritorio
   y evitan que estilos propios de cada página desplacen el contenido. */
@media screen and (max-width: 1024px) {
    html,
    body {
        width: 100%;
        min-width: 0;
    }

    body {
        overflow-x: clip;
    }

    body > header,
    body > main,
    body > footer {
        min-width: 0;
        box-sizing: border-box;
    }

    body > main {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    body > main > * {
        min-width: 0;
    }

    img,
    video,
    iframe,
    canvas,
    svg {
        max-width: 100%;
    }
}

@media screen and (max-width: 900px) {
    body {
        align-items: stretch;
    }

    body > header,
    body > footer {
        align-self: stretch;
        width: 100%;
        max-width: 100%;
    }

    body > main {
        width: calc(100% - 32px) !important;
        max-width: 1200px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding: clamp(16px, 3vw, 24px) !important;
    }

    body > main > * {
        min-width: 0;
        max-width: 100%;
    }

    main section {
        padding: clamp(1rem, 3vw, 2rem);
    }

    main input,
    main select,
    main textarea,
    main button {
        max-width: 100%;
        box-sizing: border-box;
    }

    main button,
    main a {
        overflow-wrap: anywhere;
    }
}

@media screen and (max-width: 640px) {
    body > main {
        width: calc(100% - 24px) !important;
        padding: 14px !important;
    }

    main h1,
    main h2,
    main h3 {
        overflow-wrap: anywhere;
    }

    main [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    main [style*="min-width: 200px"] {
        min-width: 0 !important;
        width: 100% !important;
    }

    main form[style*="display: flex"],
    main div[style*="display: flex"] {
        flex-wrap: wrap;
    }

    .contenedor-formulario,
    .contenedor-login,
    .panel-contenedor,
    .modulo-comunicacion,
    .dossier-container {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding: 1rem !important;
    }

    .formulario-registro fieldset,
    main fieldset {
        min-width: 0;
        padding: 1rem;
    }

    main table {
        max-width: 100%;
    }
}
