/* ============================================
   DISTRIBUIDORA - ESTILOS ULTRA RESPONSIVE
   ============================================ */

:root {
    --primary: #25D366;
    --primary-dark: #128C7E;
    --primary-light: #DCF8C6;
    --secondary: #4e73df;
    --secondary-dark: #224abe;
    --danger: #e74a3b;
    --warning: #f6c23e;
    --dark: #1a1a2e;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #6c757d;
    --gray-700: #495057;
    --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --header-height: auto;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: var(--dark);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: calc(80px + var(--safe-bottom));
    min-height: 100vh;
    min-height: 100dvh;
}

/* ==================== HEADER ==================== */
.header {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
    color: var(--white);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.header-logo {
    width: 45px;
    height: 45px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--white);
    padding: 3px;
    flex-shrink: 0;
}

.header-logo-placeholder {
    width: 45px;
    height: 45px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.header-info {
    min-width: 0;
}

.header-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-subtitle {
    font-size: 0.7rem;
    margin: 0;
    opacity: 0.8;
    display: none;
}

.cart-btn {
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    color: var(--white);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    position: relative;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cart-btn:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.3);
}

.cart-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: var(--white);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--secondary);
    transition: transform 0.3s;
}

.cart-count.has-items {
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ==================== BÚSQUEDA ==================== */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i.bi-search {
    position: absolute;
    left: 14px;
    color: rgba(255,255,255,0.6);
    font-size: 1.1rem;
    pointer-events: none;
    z-index: 1;
}

.search-box input {
    width: 100%;
    padding: 10px 40px 10px 40px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius-xl);
    font-size: 0.9rem;
    background: rgba(255,255,255,0.15);
    color: var(--white);
    transition: all 0.3s;
    backdrop-filter: blur(10px);
}

.search-box input::placeholder {
    color: rgba(255,255,255,0.6);
}

.search-box input:focus {
    outline: none;
    background: var(--white);
    color: var(--dark);
    border-color: var(--white);
}

.search-box input:focus::placeholder {
    color: var(--gray-500);
}

.search-box input:focus ~ .search-clear,
.search-box input:focus + .search-clear {
    color: var(--gray-500);
}

.search-clear {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.search-box input:focus ~ .search-clear {
    color: var(--gray-500);
}

/* ==================== FILTROS ==================== */
.filters-wrapper {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: calc(var(--header-height, 0px));
    z-index: 999;
    padding: 8px 0;
}

.filters {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 4px;
}

.filters::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    padding: 7px 16px;
    border: 2px solid var(--gray-200);
    background: var(--white);
    border-radius: var(--radius-xl);
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    transition: all 0.2s;
    flex-shrink: 0;
}

.filter-btn:active {
    transform: scale(0.96);
}

.filter-btn.active {
    background: var(--secondary);
    color: var(--white);
    border-color: var(--secondary);
}

/* ==================== RESULTADOS ==================== */
.results-info {
    padding: 10px 0;
    font-size: 0.8rem;
    color: var(--gray-500);
}

/* ==================== GRID DE PRODUCTOS ==================== */
.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px 0 20px;
}

@media (min-width: 480px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .header-title {
        font-size: 1.2rem;
    }
    
    .header-subtitle {
        display: block;
    }
}

@media (min-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }
    
    .header-logo,
    .header-logo-placeholder {
        width: 55px;
        height: 55px;
    }
}

@media (min-width: 1024px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
    
    .cart-panel {
        width: 420px;
    }
}

@media (min-width: 1280px) {
    .products-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ==================== CARD DE PRODUCTO ==================== */
.product-card {
    background: var(--white);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    position: relative;
    border: 1px solid var(--gray-200);
}

.product-card:active {
    transform: scale(0.98);
}

.product-image-container {
    position: relative;
    width: 100%;
    padding-top: 100%;
    background: var(--gray-100);
    overflow: hidden;
}

.product-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.no-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--gray-300);
    font-size: 2.5rem;
}

.badge-destacado {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--warning);
    color: var(--dark);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.65rem;
    font-weight: 700;
    z-index: 2;
    box-shadow: var(--shadow-sm);
}

.badge-agotado {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: var(--white);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 2;
    white-space: nowrap;
}

.product-info {
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-category {
    font-size: 0.6rem;
    color: var(--secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.product-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--dark);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.product-stock {
    font-size: 0.65rem;
    color: var(--gray-500);
    margin-top: auto;
}

.product-stock.low {
    color: var(--danger);
    font-weight: 600;
}

.product-price {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.price-normal {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--dark);
}

.price-mayorista {
    font-size: 0.7rem;
    color: var(--primary-dark);
    font-weight: 600;
    background: var(--primary-light);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}

.btn-add-cart {
    width: 100%;
    background: var(--secondary);
    color: var(--white);
    border: none;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s;
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.btn-add-cart:active {
    transform: scale(0.97);
    background: var(--secondary-dark);
}

.btn-add-cart:disabled {
    background: var(--gray-300);
    color: var(--gray-500);
    cursor: not-allowed;
}

/* ==================== CARRITO ==================== */
.cart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    backdrop-filter: blur(2px);
}

.cart-overlay.show {
    opacity: 1;
    visibility: visible;
}

.cart-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 400px;
    height: 100%;
    height: 100dvh;
    background: var(--white);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
}

.cart-panel.open {
    right: 0;
}

/* Header del carrito */
.cart-header {
    padding: 16px;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.cart-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cart-header-left i {
    font-size: 1.5rem;
}

.cart-header-left h3 {
    font-size: 1rem;
    margin: 0;
    font-weight: 700;
}

.cart-header-left span {
    font-size: 0.75rem;
    opacity: 0.8;
}

.btn-close-cart {
    background: rgba(255,255,255,0.2);
    border: none;
    color: var(--white);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.btn-close-cart:active {
    background: rgba(255,255,255,0.3);
}

/* Body del carrito */
.cart-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Items del carrito */
.cart-items {
    padding: 12px;
}

.cart-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.cart-empty-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.cart-empty h4 {
    margin: 0 0 5px;
    font-size: 1.1rem;
    color: var(--gray-700);
}

.cart-empty p {
    font-size: 0.85rem;
    margin: 0;
}

/* Item individual */
.cart-item {
    display: flex;
    gap: 10px;
    padding: 12px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    align-items: center;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.cart-item-image {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--gray-200);
    flex-shrink: 0;
}

.cart-item-details {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-price {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.cart-item-total {
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.8rem;
    margin-top: 2px;
}

.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.btn-qty {
    width: 32px;
    height: 32px;
    border: 2px solid var(--gray-300);
    background: var(--white);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-700);
    transition: all 0.2s;
}

.btn-qty:active {
    background: var(--gray-200);
    transform: scale(0.9);
}

.cart-item-qty {
    font-weight: 700;
    min-width: 24px;
    text-align: center;
    font-size: 0.9rem;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 4px;
    font-size: 1.1rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-remove:active {
    opacity: 1;
}

/* Sección de datos del cliente */
.cart-section-title {
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0 16px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cart-customer {
    padding: 12px 0;
    border-top: 1px solid var(--gray-200);
    margin: 0 12px;
}

.customer-fields {
    padding: 0 4px;
}

.field-group {
    margin-bottom: 10px;
}

.field-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.field-group input,
.field-group textarea,
.field-group select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: var(--white);
}

.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus {
    outline: none;
    border-color: var(--secondary);
}

.field-group textarea {
    resize: vertical;
    min-height: 60px;
}

/* Footer del carrito */
.cart-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    border-top: 2px solid var(--gray-200);
    background: var(--white);
    flex-shrink: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.cart-total-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cart-total-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cart-total-info span:first-child {
    font-size: 0.9rem;
    color: var(--gray-500);
}

.cart-total-price {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--dark);
}

.btn-whatsapp {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btn-whatsapp:active {
    transform: scale(0.97);
    background: var(--primary-dark);
}

.btn-whatsapp:disabled {
    background: var(--gray-300);
    color: var(--gray-500);
    box-shadow: none;
    cursor: not-allowed;
}

.btn-whatsapp i {
    font-size: 1.3rem;
}

/* ==================== TOAST ==================== */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--dark);
    color: var(--white);
    padding: 12px 20px;
    border-radius: var(--radius-xl);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
    white-space: nowrap;
    pointer-events: auto;
}

.toast.success {
    background: var(--primary-dark);
}

.toast.error {
    background: var(--danger);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ==================== LOADING ==================== */
.loading-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

.spinner {
    display: inline-block;
    margin-bottom: 15px;
}

.spinner-icon {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

.no-results i {
    font-size: 4rem;
    display: block;
    margin-bottom: 15px;
    opacity: 0.5;
}

.no-results h4 {
    margin: 0 0 5px;
    color: var(--gray-700);
}

.no-results p {
    font-size: 0.9rem;
    margin: 0;
}

/* ==================== FOOTER ==================== */
.footer {
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 20px 0;
    margin-top: 20px;
    text-align: center;
}

.footer-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.footer-info {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.footer-info p {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.footer-copy {
    font-size: 0.7rem;
    color: var(--gray-500);
    margin: 0;
}

/* ==================== UTILIDADES ==================== */
.container {
    padding-left: 12px;
    padding-right: 12px;
    max-width: 1400px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .container {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* ==================== ACCESIBILIDAD ==================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    .product-card {
        border: 2px solid var(--dark);
    }
    
    .btn-add-cart {
        border: 2px solid var(--dark);
    }
}