/* ==========================================================================
   1. VARIABLES Y BASE
   ========================================================================== */
:root { 
    --rojo: #d32f2f; 
    --teal: #009688; 
    --gris: #f4f4f4; 
    --blanco: #ffffff;
}

body { 
    margin: 0; 
    background: var(--gris); 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    min-height: 100vh;
}

/* ==========================================================================
   2. CABECERA (HEADER)
   ========================================================================== */
header { 
    background: var(--rojo); 
    color: white; 
    padding: 0.8rem 2rem; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.2); 
    position: sticky; 
    top: 0; 
    z-index: 1000; 
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-img {
    height: auto;
    max-height: 50px; 
    width: auto;
    display: block;
    object-fit: contain;
}

.logo-texto {
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 1px;
    line-height: 1.2;
    text-transform: uppercase;
}

/* ==========================================================================
   3. BOTONES Y COMPONENTES
   ========================================================================== */
.btn { 
    padding: 0.8rem 1.5rem; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: 0.3s; 
    text-decoration: none;
    display: inline-block;
}

.btn-teal { background: var(--teal); color: white; }
.btn-teal:hover { background: #00796b; }
.btn-rojo { background: var(--rojo); color: white; }
.btn-rojo:hover { background: #b71c1c; }

.btn-salir {
    margin-left: 15px;
    color: white;
    text-decoration: none;
    border: 1px solid white;
    padding: 6px 15px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
    transition: 0.3s;
}

.btn-salir:hover {
    background: white;
    color: var(--rojo);
}

/* ==========================================================================
   4. PESTAÑAS (TABS)
   ========================================================================== */
.filtros-container { 
    display: flex !important; 
    flex-wrap: wrap !important; 
    align-items: flex-end !important; 
    margin-bottom: 25px !important; 
    border-bottom: 3px solid var(--teal) !important;
    gap: 0 !important; 
    padding: 2 !important;
    list-style: none !important; 
}

.filtros-container li {
    list-style: none !important;
    margin: 2 !important;
    padding: 2 !important;
}

.tab-btn-cli { 
    display: inline-block !important; 
    border: 1px solid #ccc !important; 
    border-bottom: none !important; 
    background: #e0e0e0 !important; 
    padding: 10px 25px !important; 
    border-radius: 8px 8px 0 0 !important; 
    cursor: pointer !important; 
    font-weight: bold !important; 
    color: #555 !important; 
    margin-right: -1px !important; 
    text-align: center;
    transition: 0.2s;
}

.tab-btn-cli.active { 
    background: var(--teal) !important; 
    color: white !important; 
    border-color: var(--teal) !important;
    z-index: 2;
    padding-top: 12px !important; 
}

/* ==========================================================================
   5. TIENDA Y CARRITO
   ========================================================================== */
.main-wrapper { 
    max-width: 1400px; 
    margin: 2rem auto; 
    padding: 0 1rem; 
}

.tienda-container { display: grid; grid-template-columns: 3fr 1fr; gap: 2rem; }

.productos-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); 
    gap: 1.5rem; 
}

.producto-card { 
    background: white; 
    border-radius: 12px; 
    padding: 1rem; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.1); 
    transition: 0.3s; 
    border: 1px solid #eee;
}

.producto-card:hover { transform: translateY(-5px); box-shadow: 0 5px 15px rgba(0,0,0,0.15); }

.img-container { 
    display: flex; 
    gap: 5px; 
    height: 180px; 
    width: 100%; 
    margin-bottom: 1rem; 
}

.img-container img { 
    flex: 1; 
    height: 100%; 
    object-fit: cover; 
    border-radius: 6px; 
}

.carrito-lateral { 
    background: white; 
    padding: 1.5rem; 
    border-radius: 12px; 
    position: sticky; 
    top: 100px; 
    box-shadow: 0 5px 20px rgba(0,0,0,0.1); 
    border: 1px solid #ddd;
}

/* ==========================================================================
   6. MODALES (UNIFICADOS)
   ========================================================================== */

/* REPARADO: Se añade fixed y z-index alto para que flote sobre la web */
.modal-bg, .modal-cli { 
    display: none; /* Se activa con 'flex' desde JS */
    position: fixed !important; 
    top:0 !important; 
    left:0 !important; 
    width:100% !important; 
    height:100% !important; 
    background:rgba(0,0,0,0.85) !important; 
    z-index:5000 !important; 
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
}

.modal-content-cli {
    background-color: #fff;
    padding: 25px;
    width: 90%;
    max-width: 900px;
    border-radius: 15px;
    position: relative;
    animation: slideDown 0.3s ease-out;
    margin: auto; /* Asegura centrado */
}

@keyframes slideDown {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close-modal {
    position: absolute;
    right: 20px; top: 10px;
    font-size: 40px;
    cursor: pointer;
    color: #333;
    z-index: 10;
}

.modal-body-cli { display: flex; gap: 24px; flex-wrap: nowrap; align-items: flex-start; overflow: hidden; }
.modal-img-container { flex: 0 0 auto; width: 45%; display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.modal-thumbs { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.modal-thumbs img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 2px solid #ddd; cursor: pointer; transition: border-color .2s; }
.modal-thumbs img.active, .modal-thumbs img:hover { border-color: #1a3c8c; }
.modal-img-main { flex: 1; max-height: 420px; object-fit: contain; width: 100%; border-radius: 8px; }
.modal-img-container img#modalImg { flex: 1; min-width: 0; width: 100%; max-height: 420px; object-fit: contain; }
.modal-info-cli { flex: 1 1 0; min-width: 0; overflow: hidden; }
@media (max-width: 600px) {
    .modal-body-cli { flex-wrap: wrap; }
    .modal-img-container { width: 100%; }
}

/* ==========================================================================
   7. PANEL DE ACCESO (LOGIN)
   ========================================================================== */
.login-container {
    background: #ffffff !important;
    width: 90% !important;
    max-width: 380px !important; 
    padding: 40px !important;
    border-radius: 20px !important;
    border: 3px solid var(--rojo) !important;
    box-shadow: 0 15px 35px rgba(0,0,0,0.5) !important;
    text-align: center;
    box-sizing: border-box !important;
    position: relative; /* Para que la X de cierre se ubique bien */
}

.logo-real {
    width: 120px;
    height: 120px;
    margin: 0 auto 10px auto;
    background: url('../img/logo-descenso.png') no-repeat center;
    background-size: contain;
    display: block;
}

/* Aseguramos que el login-container no se rompa */
.login-container h1 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.6rem;
    color: #333;
}

/* ==========================================================================
   8. TABLAS Y RESPONSIVE
   ========================================================================== */
table { width: 100%; border-collapse: collapse; margin-top: 2rem; background: white; }
th { background: #f8f8f8; padding: 1rem; text-align: left; border-bottom: 2px solid #eee; }
td { padding: 1rem; border-bottom: 1px solid #eee; }

@media (max-width: 800px) {
    .tienda-container { grid-template-columns: 1fr; }
    .carrito-lateral { position: static; margin-top: 20px; }
    .modal-content-cli { width: 95%; padding: 15px; }
}

@media (max-width: 600px) {
    .logo-texto { font-size: 1rem; }
    .logo-img { max-height: 35px; }
    header { padding: 0.8rem 1rem; }
}

/* ==========================================================================
   REPARACIÓN PANEL ADMINISTRACIÓN (AÑADIR AL FINAL)
   ========================================================================== */

/* Restablece las pestañas de admin (PRODUCTOS, PEDIDOS, DESCUENTOS) en horizontal */
.tabs-header {
    display: flex !important;
    flex-direction: row !important;
    gap: 10px !important;
    margin-bottom: 20px !important;
    border-bottom: 2px solid #ccc;
    padding-bottom: 10px;
}

.tab-trigger {
    padding: 10px 20px !important;
    cursor: pointer !important;
    background: #e0e0e0 !important;
    border: none !important;
    border-radius: 4px !important;
    font-weight: bold !important;
    color: #555 !important;
}

.tab-trigger.active {
    background: var(--teal) !important;
    color: white !important;
}

/* Control de visibilidad de los paneles */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Restaura la rejilla (GRID) de los formularios de admin */
.grid-form {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 15px !important;
    margin-bottom: 15px !important;
}

/* Estilos específicos para los inputs dentro del admin para que no se amontonen */
#main-admin-form input, 
#main-admin-form select, 
#main-admin-form textarea {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#main-admin-form textarea {
    grid-column: 1 / -1; /* Ocupa todo el ancho */
}

/* Estilos para controles de cantidad */
.btn-cantidad {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    transition: background-color 0.2s;
}

.btn-cantidad:hover {
    background-color: #e0e0e0 !important;
}

.btn-cantidad:active {
    background-color: #d0d0d0 !important;
}

.input-cantidad {
    -moz-appearance: textfield;
    appearance: textfield;
    width: 40px;
    text-align: center;
    font-weight: bold;
}

.input-cantidad::-webkit-inner-spin-button,
.input-cantidad::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Mejora para el botón comprar */
.btn-rojo {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-rojo:hover {
    background-color: #c82333;
}

.btn-teal {
    background-color: #20c997;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-teal:hover {
    background-color: #17a2b8;
}