/* =========================================
   1. VARIABLES Y RESET GENERAL
   ========================================= */
:root {
    --primary: #2c3e50;    /* Azul Oscuro (Encabezados) */
    --accent: #3498db;     /* Azul Claro (Botones) */
    --success: #27ae60;    /* Verde (Agregar/Whatsapp) */
    --danger: #e74c3c;     /* Rojo (Eliminar/Cerrar) */
    --light: #f5f6fa;      /* Fondo General */
    --white: #ffffff;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--light);
    color: #333;
    padding-bottom: 80px; /* Espacio para el footer */
}

/* Clase utilitaria vital para el JS */
.hidden {
    display: none !important;
}

/* =========================================
   2. HEADER Y NAVEGACIÓN
   ========================================= */
header {
    background-color: var(--primary);
    color: var(--white);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

h1 {
    font-size: 1.2rem;
    letter-spacing: 1px;
}

.cart-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
}

.cart-btn:hover {
    transform: scale(1.05);
    background-color: #2980b9;
}

.search-container {
    max-width: 1200px;
    margin: 10px auto 0;
}

#searchInput {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    border: none;
    outline: none;
}

/* =========================================
   3. CONTENEDOR PRINCIPAL Y GRID
   ========================================= */
main {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 1rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* Responsivo automático */
    gap: 20px;
}

/* =========================================
   4. TARJETA DE PRODUCTO (CARD)
   ========================================= */
.card {
    background: var(--white);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-5px);
}

/* Imagen y Overlay de Admin */
.img-container {
    position: relative;
    height: 200px;
    background: #eee;
}

.product-img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* O cover, según prefieras */
    padding: 10px;
}

/* El overlay solo se muestra si el body tiene la clase is-admin (controlado por JS) */
.admin-overlay {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(0,0,0,0.5);
    padding: 5px;
    display: none; /* Oculto por defecto */
}

body.is-admin .admin-overlay {
    display: block;
}

/* Cuerpo de la tarjeta */
.card-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Para que los botones se alineen al fondo */
}

.card-body h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--primary);
    height: 40px; /* Altura fija para títulos largos */
    overflow: hidden;
}

/* Tabla de Precios */
.pricing-table {
    display: flex;
    justify-content: space-between;
    background: #f8f9fa;
    border-radius: 5px;
    padding: 8px;
    margin-bottom: 15px;
}

.price-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 48%;
}

.price-lbl {
    font-size: 0.75rem;
    color: #7f8c8d;
    text-transform: uppercase;
}

.price-val {
    font-weight: bold;
    font-size: 1.1rem;
}

.u-val { color: var(--primary); }
.b-val { color: #d35400; } /* Naranja para cajas */

/* Botones de acción */
.actions {
    margin-top: auto; /* Empuja botones al fondo */
    display: flex;
    gap: 5px;
}

.btn-add {
    flex: 1;
    border: none;
    padding: 8px;
    border-radius: 5px;
    color: white;
    cursor: pointer;
    font-weight: bold;
    transition: opacity 0.2s;
}

.btn-add:hover { opacity: 0.9; }
.btn-u { background-color: var(--accent); }
.btn-box { background-color: #d35400; }

/* Botones pequeños (Admin/Carrito) */
.btn-mini {
    border: none;
    padding: 5px 8px;
    border-radius: 3px;
    cursor: pointer;
    color: white;
}

.btn-mini.edit { background-color: #f1c40f; color: #333; }
.btn-mini.del { background-color: var(--danger); }

/* =========================================
   5. PANEL DE ADMINISTRACIÓN
   ========================================= */
.admin-panel {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border-left: 5px solid var(--primary);
    box-shadow: var(--shadow);
}

.admin-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.form-row input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#submitBtn {
    background: var(--success);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
}

#cancelBtn {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    width: 100%;
    margin-top: 5px;
    cursor: pointer;
}

.dashed-line {
    border: 0;
    border-top: 2px dashed #ddd;
    margin: 20px 0;
}

/* CSV Controls */
.csv-section {
    background: #fdfdfd;
    padding: 10px;
    border-radius: 5px;
}
.csv-controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    align-items: center;
}
.btn-csv {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
}

/* =========================================
   6. MODALES (Login y Carrito)
   ========================================= */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px; /* Ancho máximo */
    position: relative;
    max-height: 85vh; /* Evita que sea más alto que la pantalla */
    display: flex;
    flex-direction: column;
}

.cart-items {
    overflow-y: auto; /* Scroll si hay muchos productos */
    flex-grow: 1;
    margin: 15px 0;
    padding-right: 5px;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #777;
}

/* Item dentro del carrito */
.cart-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.cart-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
}

.cart-details h4 {
    font-size: 0.9rem;
    margin-bottom: 3px;
}

.cart-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Footer del carrito */
.cart-total {
    text-align: right;
    font-size: 1.2rem;
    margin-bottom: 15px;
    border-top: 2px solid #eee;
    padding-top: 10px;
}

.whatsapp-btn {
    background: #25D366; /* Verde oficial WhatsApp */
    color: white;
    border: none;
    width: 100%;
    padding: 12px;
    border-radius: 50px; /* Botón redondo */
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.whatsapp-btn:hover {
    background: #1ebc57;
}

/* Login Box específico */
.login-box {
    max-width: 350px;
    text-align: center;
}

.login-box input {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.error-msg {
    color: var(--danger);
    margin-top: 10px;
    font-size: 0.9rem;
}

/* =========================================
   7. FOOTER
   ========================================= */
footer {
    text-align: center;
    padding: 20px;
    color: #777;
    border-top: 1px solid #eee;
    margin-top: 30px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.8rem;
}

/* =========================================
   8. MEDIA QUERIES (Celulares)
   ========================================= */
@media (max-width: 600px) {
    .header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    .pricing-table {
        flex-direction: row; /* Mantenemos fila para que se compare mejor */
    }
}