:root {
    --max-red: #E30613;
    --max-black: #1A1A1A;
    --bg-gray: #F5F7FA;
    --white: #FFFFFF;
    --border: #E1E8ED;
    --text-muted: #7F8C8D;
    --whatsapp-green: #25D366;
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg-gray);
    color: var(--max-black);
    font-family: 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
}

/* --- HEADER / NAVBAR --- */
.navbar {
    background-color: var(--max-black);
    padding: 12px 5%;
    border-bottom: 4px solid var(--max-red);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-container {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.logo-container img { 
    height: 45px; 
    display: block;
}

.search-bar {
    flex: 1;
    max-width: 500px;
    margin: 0 30px;
}

.search-bar input {
    width: 100%;
    padding: 10px 15px;
    border-radius: 4px;
    border: none;
    font-size: 0.9rem;
    outline: none;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-admin, .btn-cart {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.3s;
}

.btn-admin:hover, .btn-cart:hover {
    background-color: white;
    color: var(--max-black);
}

#cart-count {
    background-color: var(--max-red);
    color: white;
    padding: 2px 7px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: bold;
}

/* --- FILTROS --- */
.filters {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 15px 5%;
    background-color: var(--white);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    white-space: nowrap;
}

.filter-btn {
    background-color: #F8F9FA;
    color: var(--max-black);
    border: 1px solid var(--border);
    padding: 8px 18px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: 0.2s;
}

.filter-btn:hover { background-color: #EDF0F2; }

.filter-btn.active {
    background-color: var(--max-red) !important;
    color: white !important;
    border-color: var(--max-red) !important;
    box-shadow: 0 4px 10px rgba(227, 6, 19, 0.2);
}

/* --- GRID DE PRODUCTOS --- */
.grid-catalogo {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 25px;
    padding: 30px 5%;
    max-width: 1400px;
    margin: 0 auto;
}

.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: 0.3s;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
}

.img-container {
    height: 240px;
    padding: 15px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.card-info {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.brand-tag {
    color: var(--max-red);
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.card-info h3 {
    font-size: 1rem;
    margin-bottom: 6px;
    color: var(--max-black);
    height: 2.4em; /* Asegura alineación si el nombre es largo */
    overflow: hidden;
}

.sku-text {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 12px;
}

/* --- BOTONES DE LA TARJETA --- */
.card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.btn-add-item {
    flex: 1;
    background-color: var(--max-red);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    cursor: pointer;
    transition: 0.3s;
}

.btn-add-item:hover { background-color: #C20510; }

.btn-pdf-link {
    width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F8F9FA;
    color: #E74C3C;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    transition: 0.3s;
}

.btn-pdf-link:hover {
    background: #E74C3C;
    color: white;
}

/* --- MODAL DE COTIZACIÓN --- */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0; top: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    margin: 5% auto;
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-header {
    background: var(--max-black);
    color: white;
    padding: 15px 20px;
    border-bottom: 3px solid var(--max-red);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-footer {
    padding: 20px;
    background: #F8F9FA;
}

.btn-whatsapp {
    width: 100%;
    background-color: var(--whatsapp-green);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* --- PANEL ADMIN --- */
.admin-panel {
    background: white;
    padding: 20px 5%;
    border-bottom: 2px solid var(--max-red);
    box-shadow: inset 0 -5px 10px rgba(0,0,0,0.05);
}

.admin-form {
    max-width: 1000px;
    margin: 0 auto;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

/* --- ESTILOS DEL PANEL ADMIN --- */
.admin-panel {
    background-color: #ffffff;
    padding: 30px 5%;
    border-bottom: 3px solid var(--max-red);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    animation: slideDown 0.4s ease-out;
}

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

.admin-container {
    max-width: 1100px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

.admin-header h3 {
    font-size: 1.5rem;
    color: var(--max-black);
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-header h3 i { color: var(--max-red); }

.btn-close-admin {
    background: #f8f9fa;
    border: none;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
}

.btn-close-admin:hover { background: var(--max-red); color: white; }

/* Formulario en Grilla */
.admin-form .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group-full {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #444;
}

.form-group input, .form-group select {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fbfbfb;
    font-size: 0.9rem;
    outline: none;
    transition: 0.3s;
}

.form-group input:focus {
    border-color: var(--max-red);
    background: white;
    box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

/* Estilo para los selectores de archivos (File Inputs) */
.file-group .file-select {
    position: relative;
    border: 2px dashed #ddd;
    padding: 15px;
    text-align: center;
    border-radius: 6px;
    background: #fafafa;
    cursor: pointer;
    transition: 0.3s;
}

.file-group .file-select:hover {
    border-color: var(--max-black);
    background: #f0f0f0;
}

.file-group input[type="file"] {
    position: absolute;
    width: 100%; height: 100%;
    top: 0; left: 0;
    opacity: 0;
    cursor: pointer;
}

.file-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Botones de acción */
.admin-actions {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 15px;
    justify-content: flex-end;
}

.admin-controls-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 10;
}

.btn-edit-small, .btn-delete-small {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: 0.2s;
}

.btn-edit-small { background-color: #3498db; }
.btn-edit-small:hover { background-color: #2980b9; }

.btn-delete-small { background-color: #e74c3c; }
.btn-delete-small:hover { background-color: #c0392b; }

/* Asegurar que la card sea relativa para posicionar el overlay */
.card { position: relative; }

.btn-save {
    background: #27ae60;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Badge de SKU Flotante */
.sku-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 8px;
    font-size: 0.65rem;
    font-weight: bold;
    border-radius: 3px;
    z-index: 5;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Espaciado para el nombre */
.product-title {
    min-height: 45px; /* Reserva espacio para 2 líneas de texto */
    margin-bottom: 10px;
    font-size: 1rem;
    line-height: 1.2;
}

/* Contenedor de Certificaciones */
.cert-wrapper {
    margin-bottom: 15px;
    position: relative;
    display: inline-block;
}

.cert-badge-trigger {
    background: #f0f4f8;
    color: #2c3e50;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: help;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #d1d9e0;
    transition: 0.3s;
}

.cert-badge-trigger i {
    color: var(--max-red);
}

.cert-badge-trigger:hover {
    background: #e2e8f0;
}

/* Tooltip (El texto que aparece al hacer hover) */
.cert-tooltip {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 100;
    bottom: 125%; /* Aparece arriba del badge */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.7rem;
    line-height: 1.4;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.card {
    position: relative; /* Para que el SKU se ubique bien */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
/* Flechita del tooltip */
.cert-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.cert-badge-trigger:hover .cert-tooltip {
    visibility: visible;
    opacity: 1;
}

.btn-save:hover { background: #219150; transform: translateY(-2px); }

.btn-cancel {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 4px;
    cursor: pointer;
}
.admin-form input, .admin-form select {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    outline: none;
}

.admin-form input:focus { border-color: var(--max-red); }

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .nav-container { flex-direction: column; gap: 15px; }
    .search-bar { margin: 0; width: 100%; max-width: 100%; }
    .filters { justify-content: flex-start; }
}
/* --- AJUSTES JULIO 2026: ORDENAMIENTO + MODAL SCROLLABLE --- */
.card {
    position: relative;
    overflow: visible;
    display: flex;
    flex-direction: column;
    background: white;
    border: 1px solid #eee;
    border-radius: 8px;
}

.img-container {
    position: relative;
    background: white;
    cursor: pointer;
    height: 280px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 8px 8px 0 0;
}

.img-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: all 0.3s ease;
    display: block;
}

.overlay-ficha {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    background: rgba(255,255,255,0.4);
}

.img-container:hover .overlay-ficha { opacity: 1; }
.img-container:hover img { opacity: 0.7; }

.btn-ficha-hover {
    background: #333;
    color: white;
    padding: 10px 18px;
    border-radius: 50px;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    pointer-events: auto;
}

.qty-control {
    display: flex;
    align-items: center;
    gap: 5px;
}

.qty-control span {
    font-size: 0.75rem;
    font-weight: bold;
    color: #888;
}

.qty-control input {
    width: 54px;
    padding: 7px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    outline: none;
}

.card-actions {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-add-item {
    flex-grow: 1;
    background: var(--max-red);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

/* Modal centrado con scroll interno. Mantiene siempre visible el botón de WhatsApp. */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    padding: 20px;
}

.modal.is-open {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    margin: 0 auto;
    width: min(92vw, 560px);
    max-height: calc(100vh - 40px);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

.modal-header,
.modal-footer {
    flex: 0 0 auto;
}

.cart-items-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 15px;
}

.client-data-box {
    padding: 15px;
    background: #f4f4f4;
    border-bottom: 2px solid #ddd;
    margin-bottom: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.client-data-box label {
    display: block;
    font-weight: bold;
    margin-bottom: 3px;
    color: #333;
    font-size: 0.85rem;
}

.client-data-box input {
    width: 100%;
    padding: 8px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 0.95rem;
}

.cart-item-row {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid #eee;
    align-items: center;
    gap: 12px;
}

.cart-item-name {
    font-weight: bold;
    color: #222;
}

.cart-item-qty {
    color: var(--max-red);
    font-weight: bold;
    font-size: 0.85rem;
}

.btn-remove-cart {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.1rem;
}

.cart-empty {
    text-align: center;
    padding: 20px;
}

/* Admin organizer */
.admin-organizer {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.admin-organizer-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
}

.admin-organizer h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.admin-organizer h4 i { color: var(--max-red); }

.admin-organizer p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.btn-save-order {
    background: var(--max-black);
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-save-order:hover { background: var(--max-red); }

.organizer-grid {
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
    gap: 18px;
}

.organizer-box {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fbfbfb;
    overflow: hidden;
}

.organizer-box h5 {
    padding: 12px 14px;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.order-list {
    padding: 10px;
    max-height: 340px;
    overflow-y: auto;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 20px;
}

.order-row {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid #e7ebef;
    background: white;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
}

.order-row.selected {
    border-color: var(--max-red);
    box-shadow: 0 0 0 2px rgba(227, 6, 19, 0.08);
}

.order-index {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--max-black);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
}

.order-name {
    font-weight: 700;
    color: #222;
    min-width: 0;
}

.order-name small {
    display: block;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 2px;
}

.order-actions {
    display: flex;
    gap: 5px;
}

.order-actions button {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: #f8f9fa;
    cursor: pointer;
}

.order-actions button:hover:not(:disabled) {
    background: var(--max-red);
    color: white;
}

.order-actions button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .modal { padding: 10px; }
    .modal-content { width: 96vw; max-height: calc(100vh - 20px); }
    .organizer-grid { grid-template-columns: 1fr; }
    .admin-organizer-header { flex-direction: column; align-items: stretch; }
    .btn-save-order { justify-content: center; }
    .admin-actions { flex-direction: column; }
}

/* --- MEJORAS JULIO 2026: CATEGORÍAS, COTIZACIÓN Y PDF --- */
.admin-category-manager {
    margin: 28px 0;
    padding: 20px;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.category-manager-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-bottom: 16px;
}

.category-manager-row input,
.category-manager-item input,
.client-data-box input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.9rem;
    outline: none;
}

.category-manager-row input:focus,
.category-manager-item input:focus,
.client-data-box input:focus {
    border-color: var(--max-red);
    box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

.category-manager-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-manager-item {
    display: grid;
    grid-template-columns: 34px 1fr auto auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.category-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.btn-category-action,
.btn-category-danger,
.btn-pdf,
.btn-clear-cart {
    border: none;
    padding: 10px 12px;
    border-radius: 5px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.btn-category-action { background: #1f78d1; color: white; }
.btn-category-danger { background: #E30613; color: white; }
.btn-category-danger:disabled { background: #ddd; color: #999; cursor: not-allowed; }

.modal.is-open { display: block; }

.modal-content {
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}

.cart-items-list {
    overflow-y: auto;
    max-height: calc(88vh - 175px);
    padding: 18px 20px;
}

.client-data-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.client-data-box label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 5px;
    color: #444;
}

.quote-actions-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 10px;
}

.btn-pdf {
    background: var(--max-black);
    color: white;
    width: 100%;
}

.btn-clear-cart {
    background: #f1f1f1;
    color: var(--max-black);
}

.cart-item-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.cart-item-name { font-weight: 700; }
.cart-item-qty { color: var(--text-muted); font-size: 0.82rem; margin-top: 3px; }

.btn-remove-cart {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #ffe8e8;
    color: #E30613;
    cursor: pointer;
}

.cart-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
}

@media (max-width: 720px) {
    .category-manager-row,
    .category-manager-item,
    .client-data-box,
    .quote-actions-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 96%;
        margin: 2% auto;
        max-height: 96vh;
    }

    .cart-items-list {
        max-height: calc(96vh - 190px);
    }
}
