/* =========================================
   1. VARIABLES Y CONFIGURACIÓN GLOBAL
   ========================================= */
:root {
    --bg: #f4f4f5;
    --surface: #ffffff;
    --text: #18181b;
    --text-muted: #71717a;
    --accent: #000000;
    --accent-light: #333333;
    --border: #e4e4e7;
    --success: #10b981;
    --danger: #ef4444;
    --offer-color: #facc15; 
    --reco-color: #3b82f6;  
    --combo-color: #a855f7; 
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

/* =========================================
   2. RESET Y ESTILOS BASE
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }

body { background-color: var(--bg); color: var(--text); height: 100dvh; width: 100%; overflow: hidden; position: relative; }
::-webkit-scrollbar { display: none; }

button, .manual-link, .secondary-link, .result-item, .nav-item, .grid-item, .nav-back-btn, .cat-pill, .mini-card, .search-chip, .promo-item label, .menu-card-btn, .tab-btn, .manage-item-row, .btn-tag-action, .btn-delete-trend, .suggestion-chip {
    cursor: pointer; transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s, color 0.2s; touch-action: manipulation;
}
button:active, .manual-link:active, .secondary-link:active, .result-item:active, .grid-item:active, .nav-back-btn:active, .cat-pill:active, .mini-card:active, .search-chip:active, .promo-item label:active, .menu-card-btn:active, .tab-btn:active, .manage-item-row:active, .btn-tag-action:active, .suggestion-chip:active {
    transform: scale(0.96); opacity: 0.9;
}

/* =========================================
   3. SISTEMA DE VISTAS (Navegación SPA)
   ========================================= */
main { height: 100%; width: 100%; position: relative; overflow: hidden; }

.view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow-y: auto; 
    padding: 20px 20px 100px 20px; opacity: 0; pointer-events: none; 
    transform: translateY(15px) scale(0.98); filter: blur(4px);
    transition: opacity 0.35s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.3s;
    background: var(--bg); z-index: 1;
}
.view.active { opacity: 1; pointer-events: all; transform: translateY(0) scale(1); filter: blur(0); z-index: 10; }
.header { text-align: center; margin: 5px; }

/* =========================================
   4. MÓDULO: ESCÁNER
   ========================================= */
#scanner-container {
    width: 100%; border-radius: 24px; overflow: hidden; background: #000; position: relative; box-shadow: 0 8px 30px rgba(0,0,0,0.15); min-height: 250px;
}
.scanner-ui-controls { margin-top: 25px; display: flex; flex-direction: column; align-items: center; gap: 15px; text-align: center; }
.instruction { color: var(--text-muted); font-size: 1rem; font-weight: 500; }
.manual-link {
    background: var(--accent); color: white; border: none; padding: 16px 28px; border-radius: 18px; font-size: 1rem; font-weight: 700; text-decoration: none; box-shadow: 0 4px 15px rgba(0,0,0,0.2); width: 100%; max-width: 280px; display: inline-block;
}
.secondary-link {
    background: transparent; color: var(--accent); border: 2px solid var(--border); padding: 14px 24px; border-radius: 18px; font-size: 0.95rem; font-weight: 700; text-decoration: none; width: 100%; max-width: 280px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; margin-top: 5px;
}

/* =========================================
   5. MÓDULO: TARJETA DE PRODUCTO
   ========================================= */
.card {
    background: var(--surface); border-radius: 26px; margin-top: 20px; box-shadow: 0 15px 40px rgba(0,0,0,0.08); overflow: hidden; position: relative; animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.card-image { background: #f8f8f8; display: flex; align-items: center; justify-content: center; position: relative; }
.card-image img { width: 100%; height: 200px; object-fit: contain; padding: 20px; mix-blend-mode: multiply; }
.card-badges { position: absolute; bottom: 15px; left: 15px; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.badge-promo { background: var(--offer-color); color: #000; font-size: 0.75rem; font-weight: 800; padding: 6px 12px; border-radius: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.badge-promo.blue { background: var(--reco-color); color: white; }
.card-info { padding: 0 24px 24px 24px; }
.price-container { display: flex; align-items: center; justify-content: space-between; margin: 5px 0; }
.price-wrap { display: flex; align-items: baseline; gap: 8px; }
.price { font-size: 2.2rem; font-weight: 800; letter-spacing: -1px; }
.unit-tag { font-size: 0.95rem; color: var(--text-muted); font-weight: 600; }
.status-pill { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.5px; padding: 6px 12px; border-radius: 20px; background: #fef2f2; color: var(--danger); border: 1px solid var(--danger); text-transform: uppercase; }
.wholesale-container { display: flex; align-items: baseline; gap: 8px; margin-top: -5px; margin-bottom: 15px; background: #f0fdf4; padding: 8px 12px; border-radius: 10px; display: inline-flex; }
.wholesale-price { font-size: 1.1rem; font-weight: 700; color: #15803d; }
.wholesale-unit { font-size: 0.85rem; color: #166534; font-weight: 600; }
.desc { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 15px; line-height: 1.5; }
.meta-code { font-size: 0.75rem; background: #f4f4f5; padding: 6px 10px; border-radius: 8px; font-weight: 700; color: var(--text-muted); }
.icon-btn, .icon-btn-left { position: absolute; top: 15px; border: none; background: rgba(255,255,255,0.8); backdrop-filter: blur(4px); border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,0.05); z-index: 5; }
.icon-btn { right: 15px; }
.icon-btn-left { left: 15px; }

/* =========================================
   6. MÓDULO: TIENDA
   ========================================= */
.store-header-sticky { position: sticky; top: -20px; background: var(--bg); z-index: 50; padding-bottom: 10px; padding-top: 5px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; }
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.store-search { position: relative; background: white; border: 1px solid var(--border); border-radius: 16px; padding: 0 12px; height: 50px; display: flex; align-items: center; gap: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.03); margin-bottom: 15px; transition: all 0.2s; }
.store-search:focus-within { border-color: var(--accent); box-shadow: 0 4px 12px rgba(0,0,0,0.08); transform: translateY(-1px); }
.store-search input { border: none; padding: 0; height: 100%; font-weight: 500; font-size: 1rem; flex: 1; outline: none; }
.search-icon { color: var(--text-muted); width: 20px; }
#btn-clear-search { background: #f4f4f5; border: none; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }

.category-scroll-container { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 5px; scrollbar-width: none; }
.cat-pill { flex-shrink: 0; background: white; border: 1px solid transparent; border-radius: 50px; padding: 8px 18px; font-size: 0.9rem; font-weight: 600; color: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.cat-pill.active { background: var(--accent); color: white; box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.store-section { margin-top: 30px; margin-bottom: 10px; }
.section-title h3 { font-size: 1.2rem; margin-bottom: 15px; font-weight: 800; letter-spacing: -0.5px; }
.horizontal-products-scroll { display: flex; gap: 15px; overflow-x: auto; padding-bottom: 20px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.mini-card { min-width: 140px; width: 140px; flex-shrink: 0; display: flex; flex-direction: column; padding: 5px; scroll-snap-align: start; }
.mini-card img { width: 100%; height: 120px; object-fit: contain; background: white; border-radius: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.06); margin-bottom: 10px; }
.mini-card h4 { font-size: 0.9rem; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.mini-card .price { font-size: 1rem; font-weight: 800; }
.results-list { margin-top: 10px; }
.result-item { display: flex; align-items: center; gap: 15px; padding: 15px; background: white; border-radius: 18px; margin-bottom: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.03); }
.result-info { flex: 1; }
.thumb { width: 55px; height: 55px; border-radius: 12px; object-fit: cover; background: #f4f4f5; }
.result-item.agotado { border-right: 5px solid var(--danger); }
.tag-agotado-list { background: #fef2f2; color: var(--danger); font-size: 0.65rem; padding: 4px 8px; border-radius: 8px; font-weight: 800; border: 1px solid var(--danger); }

/* Estados Vacíos */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; margin-top: 60px; padding: 20px; color: var(--text-muted); }
.empty-icon { width: 60px; height: 60px; background: #e4e4e7; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text); margin-bottom: 15px; }
.empty-state p { font-weight: 500; font-size: 1.1rem; }

/* =========================================
   7. MÓDULO: CATÁLOGO
   ========================================= */
.catalog-grid { 
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; 
    padding-top: 20px; padding-bottom: 100px; 
}
.grid-item { background: white; border-radius: 20px; padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; box-shadow: 0 4px 10px rgba(0,0,0,0.03); border: 2px solid transparent; position: relative; overflow: hidden; }
.grid-item img { width: 80px; height: 80px; object-fit: contain; margin-bottom: 10px; mix-blend-mode: multiply; }
.grid-item h4 { font-size: 0.9rem; margin-bottom: 4px; line-height: 1.2; }
.grid-item p { font-size: 0.8rem; color: var(--text-muted); font-weight: 700; }
.grid-item.agotado { border-color: var(--danger); background: #fef2f2; opacity: 0.8; }
.grid-item.offer { border-color: var(--offer-color); background: #fefce8; }
.grid-item.reco { border-color: var(--reco-color); background: #eff6ff; }
.grid-item.combo { border-color: var(--combo-color); background: #faf5ff; }

/* =========================================
   8. MENÚ DE GESTIÓN
   ========================================= */
.manage-menu { display: grid; grid-template-columns: 1fr; gap: 15px; margin-top: 20px; }
.menu-card-btn { background: white; border: none; border-radius: 20px; padding: 20px; display: flex; align-items: center; gap: 20px; text-align: left; box-shadow: 0 4px 15px rgba(0,0,0,0.03); }
.menu-card-btn .icon-box { width: 50px; height: 50px; border-radius: 14px; background: #f4f4f5; display: flex; align-items: center; justify-content: center; color: var(--text); }
.menu-card-btn .icon-box.purple { background: #faf5ff; color: var(--combo-color); }
.menu-card-btn .icon-box.blue { background: #eff6ff; color: var(--reco-color); }

/* =========================================
   9. CONFIGURADOR DE VITRINAS
   ========================================= */
.tabs-container { display: flex; background: white; padding: 5px; border-radius: 16px; margin-bottom: 20px; border: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab-btn { flex: 1; border: none; background: transparent; padding: 10px; border-radius: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tab-btn.active { background: var(--bg); color: var(--text); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }

.active-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.mini-active-item { background: white; border-radius: 12px; padding: 8px; position: relative; text-align: center; border: 1px solid var(--border); }
.mini-active-item img { width: 100%; height: 60px; object-fit: contain; }
.btn-remove-item { position: absolute; top: -5px; right: -5px; background: var(--danger); color: white; border: none; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.input-row-add { display: flex; gap: 10px; margin-bottom: 20px; padding: 0 5px; }
.input-row-add input { flex: 1; }
.action-btn-small { width: auto; margin: 0; padding: 0 20px; background: var(--accent); color: white; border: none; border-radius: 14px; }
.manage-instruction { padding: 12px; background: #f4f4f5; border-radius: 12px; margin-bottom: 15px; font-size: 0.9rem; color: #71717a; border: 1px dashed var(--border); }

/* CORRECCIÓN: Estilos para la lista de productos disponibles en Vitrinas */
.manage-item-row { display: flex; align-items: center; justify-content: space-between; background: white; padding: 10px; margin-bottom: 8px; border-radius: 12px; border: 1px solid var(--border); }
.manage-item-row img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; margin-right: 12px; }
.manage-info { flex: 1; }
.manage-info h4 { font-size: 0.9rem; margin: 0; }
.btn-add-item { width: 32px; height: 32px; border-radius: 8px; border: none; background: #eff6ff; color: var(--reco-color); display: flex; align-items: center; justify-content: center; }

/* =========================================
   10. FORMULARIO Y NAVS
   ========================================= */
.header-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.nav-back-btn { background: transparent; border: none; color: var(--text); padding: 8px; border-radius: 50%; }
.form-body { display: flex; flex-direction: column; gap: 18px; }
.form-row { display: flex; gap: 12px; width: 100%; margin: 0; padding: 0; }
.input-group { flex: 1; display: flex; flex-direction: column; align-items: flex-start; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; color: var(--text-muted); }
input, select, textarea { width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 14px; font-size: 1rem; outline: none; background: white; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.action-btn { width: 100%; padding: 18px; background: var(--accent); color: white; border: none; border-radius: 18px; font-weight: 700; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.status-toggle-container { background: white; padding: 15px; border-radius: 18px; border: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--danger); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(22px); }

/* Navbar */
.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; height: calc(70px + var(--safe-bottom)); background: rgba(255,255,255,0.95); backdrop-filter: blur(12px); display: flex; justify-content: space-around; align-items: center; border-top: 1px solid rgba(0,0,0,0.05); z-index: 100; padding-bottom: var(--safe-bottom); }
.nav-item { background: none; border: none; color: #d4d4d8; display: flex; flex-direction: column; align-items: center; }
.nav-item.active { color: var(--accent); transform: translateY(-6px) scale(1.25); }
.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: rgba(20, 20, 20, 0.95); color: #fff; padding: 12px 24px; border-radius: 30px; z-index: 2000; transition: all 0.4s; font-size: 0.9rem; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,0.2); pointer-events: none; }
.hidden { display: none !important; }

/* =========================================
   13. TARJETA GLOBAL
   ========================================= */
.card-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 2000; display: flex; align-items: flex-end; backdrop-filter: blur(2px); }
.card-modal { width: 100%; height: 85vh; background: var(--surface); border-top-left-radius: 26px; border-top-right-radius: 26px; overflow-y: auto; position: relative; animation: slideUpModal 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes slideUpModal { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* =========================================
   14. ESCÁNER GESTIÓN Y CAJA MAYORISTA
   ========================================= */
.manage-scanner-wrapper { background: #000; border-radius: 20px; overflow: hidden; margin-bottom: 20px; min-height: 200px; }
.wholesale-box-edit { width: 100%; margin-top: 5px; margin-bottom: 5px; display: flex; flex-direction: column; gap: 18px; }
.instruction-small { text-align: center; color: var(--text-muted); font-size: 0.8rem; margin-top: 8px; }

/* =========================================
   15. GESTIÓN DE ETIQUETAS
   ========================================= */
.tags-list-vertical { display: flex; flex-direction: column; gap: 8px; }
.manage-tag-row { display: flex; align-items: center; justify-content: space-between; background: white; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--border); }
.manage-tag-row.is-hidden { opacity: 0.6; background: #f4f4f5; border-style: dashed; }
.btn-tag-action { width: 32px; height: 32px; border-radius: 8px; border: none; background: #f4f4f5; display: flex; align-items: center; justify-content: center; }
.btn-tag-action.active { background: var(--accent); color: white; }

/* =========================================
   16. TENDENCIAS (Formulario)
   ========================================= */
.trend-chip-edit { display: flex; align-items: center; gap: 8px; background: white; border: 1px solid var(--border); padding: 8px 12px 8px 16px; border-radius: 20px; font-weight: 600; }
.btn-delete-trend { background: #fef2f2; color: var(--danger); border: none; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

/* =========================================
   17. SUGERENCIAS ACORDEÓN (Formulario)
   ========================================= */
.tag-suggestions-wrapper { background: #fff; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; margin-top: 10px; width: 100%; }
.toggle-tags-btn { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: transparent; border: none; font-size: 0.9rem; font-weight: 600; color: var(--text-muted); }
.toggle-tags-btn.open { color: var(--accent); border-bottom: 1px solid var(--border); }
.toggle-tags-btn.open i { transform: rotate(180deg); }

/* CORRECCIÓN: !important para ganar a cualquier otro estilo */
.hidden-content { display: none !important; padding: 12px; background: #fafafa; max-height: 200px; overflow-y: auto; flex-wrap: wrap; gap: 8px; }
.hidden-content.show { display: flex !important; animation: slideDown 0.2s ease; }

.suggestion-chip { background: white; border: 1px solid var(--accent); color: var(--accent); padding: 6px 12px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   18. ESTILOS FALTANTES (Chips y Tendencias)
   ========================================= */
.suggestions-panel { margin-top: 10px; margin-bottom: 20px; padding: 0 5px; }
.chips-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.search-chip { background: white; border: 1px solid var(--border); padding: 10px 18px; border-radius: 50px; font-size: 0.9rem; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.03); transition: all 0.2s ease; }
.search-chip:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.08); }
.search-chip:active { background: var(--bg); transform: scale(0.96); }
.search-chip i { width: 16px; height: 16px; color: var(--text-muted); }