/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --bg-light: #f8fafc;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --card-bg: #ffffff;
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Inter', system-ui, sans-serif; 
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

body { background-color: var(--bg-light); color: var(--text-dark); height: 100vh; overflow: hidden; display: flex; }

/* LAYOUT PRINCIPAL */
.app-layout { display: flex; width: 100vw; height: 100vh; }

.sidebar { width: 260px; background-color: var(--sidebar-bg); color: white; display: flex; flex-direction: column; z-index: 10; border-right: 1px solid rgba(255,255,255,0.05); }
.brand { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.05); display: flex; align-items: center; gap: 10px; }
.brand i { font-size: 1.8em; color: #38bdf8; }
.brand-text h2 { color: #f8fafc; font-size: 1.2em; font-weight: 700; margin-bottom: 2px; letter-spacing: -0.5px; }
.brand-text p { font-size: 0.75em; color: #94a3b8; font-weight: 500; }

.user-info-sidebar { margin-top: auto; padding: 20px; background: rgba(0,0,0,0.2); border-top: 1px solid rgba(255,255,255,0.05); }
.user-info-sidebar p { margin: 0; font-size: 0.75em; color: #94a3b8; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
.user-info-sidebar strong { color: #f8fafc; display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 0.95em; font-weight: 500; }
.btn-logout { margin-top: 15px; background: transparent; border: 1px solid #ef4444; color: #ef4444; padding: 8px 10px; border-radius: 6px; font-size: 0.85em; cursor: pointer; transition: 0.2s; width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; }
.btn-logout:hover { background: #ef4444; color: white; }

.nav-menu { flex: 1; display: flex; flex-direction: column; padding: 15px 10px; gap: 4px; overflow-y: auto; }
.nav-section-title { color: #64748b; font-size: 0.7em; font-weight: 700; letter-spacing: 1px; padding: 15px 15px 5px 15px; margin-top: 5px; text-transform: uppercase; }
.nav-menu button { background: transparent; color: #cbd5e1; border: none; padding: 10px 15px; border-radius: 6px; text-align: left; font-size: 0.9em; font-weight: 500; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 12px; }
.nav-menu button i { font-size: 1.2em; opacity: 0.7; transition: 0.2s; }
.nav-menu button:hover { background: var(--sidebar-hover); color: white; }
.nav-menu button:hover i { opacity: 1; }
.nav-menu button.active { background: rgba(56, 189, 248, 0.1); color: #38bdf8; font-weight: 600; }
.nav-menu button.active i { opacity: 1; color: #38bdf8; }

.main-content { flex: 1; height: 100vh; overflow: hidden; position: relative; }

/* DASHBOARD ESTRUCTURA AVANZADA */
.dashboard-container { padding: 30px; max-width: 1500px; margin: 0 auto; }
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; }
.dash-header h2 { font-size: 1.6em; color: var(--text-dark); font-weight: 700; letter-spacing: -0.5px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin-bottom: 20px; }
.kpi-card { background: var(--card-bg); padding: 20px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border); display: flex; flex-direction: column; }
.kpi-card .kpi-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.kpi-card h4 { color: var(--text-muted); font-size: 0.8em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin: 0; }
.kpi-card i { font-size: 1.2em; color: var(--primary); opacity: 0.8; }
.kpi-card .value { font-size: 2.2em; font-weight: 700; color: var(--text-dark); letter-spacing: -0.5px; }
.kpi-card .kpi-details { font-size: 0.8em; color: var(--text-muted); margin-top: 15px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; font-weight: 500; }
.kpi-card .kpi-details span { display: inline-flex; align-items: center; gap: 4px; }

.dash-charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(450px, 1fr)); gap: 20px; margin-bottom: 20px; }
.dash-lists-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 20px; align-items: start; }

.dash-panel { background: var(--card-bg); padding: 20px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.dash-panel h3 { margin-top:0; margin-bottom: 15px; color: var(--text-dark); font-size: 1.1em; font-weight: 600; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--bg-light); padding-bottom: 10px; }
.dash-panel h3 i { color: var(--text-muted); }
.top-product-item { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 0.9em; }
.top-product-item:last-child { border-bottom: none; }
.top-product-name { font-weight: 500; color: var(--text-dark); }
.top-product-sales { color: var(--primary); font-weight: 600; }

/* PANTALLA POS */
.pos-layout { display: flex; height: 100%; width: 100%; }
.pos-products-area { flex: 2; display: flex; flex-direction: column; padding: 20px; gap: 15px; height: 100%; }
.pos-search-wrapper { position: relative; flex: 1; }
.pos-search-wrapper input { width: 100%; padding: 12px 15px 12px 40px; font-size: 0.95em; border: 1px solid var(--border); border-radius: 8px; outline: none; transition: 0.2s; }
.pos-search-wrapper input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.pos-search-wrapper i { position: absolute; left: 12px; top: 14px; color: var(--text-muted); font-size: 1.2em; }
.pos-grid-container { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 15px; align-content: start; padding-right: 5px; }
.prod-card { background: var(--card-bg); border-radius: 8px; border: 1px solid var(--border); overflow: hidden; cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.prod-card:active { transform: scale(0.97); }
.prod-card:hover { border-color: #cbd5e1; box-shadow: 0 4px 12px rgba(0,0,0,0.05); transform: translateY(-2px); }
.prod-image { height: 90px; background: #f1f5f9; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--border); overflow: hidden; }
.prod-image img { width: 100%; height: 100%; object-fit: cover; }
.prod-info { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; text-align: center; flex: 1; }
.prod-info.no-img { justify-content: center; padding: 20px 10px; }
.prod-info strong { font-size: 0.85em; font-weight: 600; line-height: 1.3; max-height: 2.6em; overflow: hidden; color: var(--text-dark); }
.prod-info .price { color: var(--primary); font-weight: 700; font-size: 1.05em; margin-top: 2px; }
.prod-info small { font-size: 0.7em; font-weight: 500; }

.subcat-header { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 5px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.btn-subcat { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); cursor: pointer; font-size: 0.8em; font-weight: 600; background: var(--card-bg); color: var(--text-muted); transition: 0.2s; }
.btn-subcat:hover { border-color: #cbd5e1; color: var(--text-dark); }
.btn-subcat.active { background: var(--text-dark); color: white; border-color: var(--text-dark); }

.pos-categories { height: 60px; flex-shrink: 0; display: flex; gap: 10px; overflow-x: auto; padding: 10px 0; border-top: 1px solid var(--border); align-items: center; }
.cat-card { min-width: 100px; height: 100%; background: var(--card-bg); color: var(--text-dark); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 0.85em; padding: 0 15px; transition: 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.cat-card:hover { border-color: #cbd5e1; background: #f8fafc; }
.cat-card.todos { background: var(--text-dark); color: white; border-color: var(--text-dark); }

.pos-cart-area { flex: 1; background: var(--card-bg); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-width: 320px; max-width: 400px; box-shadow: -4px 0 15px rgba(0,0,0,0.02); z-index: 5; }
.cart-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.cart-header h3 { margin: 0; font-size: 1.1em; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cart-header h3 i { color: var(--primary); }
.btn-vaciar { background: transparent; color: var(--text-muted); border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8em; font-weight: 500; transition: 0.2s; display: flex; align-items: center; gap: 5px; }
.btn-vaciar:hover { background: #fee2e2; color: #ef4444; border-color: #fca5a5; }

.cart-items { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.cart-item { display: flex; align-items: center; justify-content: space-between; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.cart-item-qty input { width: 45px; padding: 6px; text-align: center; border: 1px solid var(--border); border-radius: 4px; font-weight: 600; font-size: 0.9em; outline: none; }
.cart-item-qty input:focus { border-color: var(--primary); }
.cart-item-details { flex: 1; padding: 0 12px; }
.cart-item-name { font-weight: 600; font-size: 0.85em; color: var(--text-dark); line-height: 1.2; }
.cart-item-price { font-size: 0.75em; color: var(--text-muted); margin-top: 2px; }
.cart-item-total { font-weight: 700; color: var(--primary); font-size: 0.95em; padding-right: 10px; }
.cart-item-delete { background: none; border: none; color: #ef4444; font-size: 1.2em; cursor: pointer; padding: 4px; opacity: 0.6; transition: 0.2s; }
.cart-item-delete:hover { opacity: 1; }

.cart-footer { padding: 20px; border-top: 1px solid var(--border); background: #f8fafc; }
.cart-total { display: flex; justify-content: space-between; align-items: center; font-size: 1.4em; font-weight: 700; margin-bottom: 15px; color: var(--text-dark); }
.btn-pagar { width: 100%; padding: 14px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 1.1em; font-weight: 600; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 6px rgba(37,99,235,0.2); }
.btn-pagar:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* SECCIONES GENÉRICAS / ADMINISTRACIÓN */
.view-section { display: none; height: 100%; overflow-y: auto; overflow-x: hidden; background: var(--bg-light); }
.admin-container { padding: 25px; max-width: 1200px; margin: 0 auto; }
.admin-sub { background: var(--card-bg); padding: 25px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border); margin-bottom: 20px; }
.admin-sub h3 { margin-top:0; margin-bottom: 20px; font-size: 1.3em; color: var(--text-dark); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.admin-sub h3 i { color: var(--text-muted); }

.admin-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9em; }
.admin-table th, .admin-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table th { background-color: #f1f5f9; color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.75em; letter-spacing: 0.5px; }
.admin-table tr:hover { background-color: #f8fafc; }

.admin-form { display: flex; flex-direction: column; gap: 15px; max-width: 600px; }
.admin-form label { font-size: 0.85em; font-weight: 600; color: var(--text-dark); margin-bottom: -10px; }
.admin-form input, .admin-form select, .admin-form textarea { padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; width: 100%; font-size: 0.95em; outline: none; transition: 0.2s; background: #f8fafc; }
.admin-form input:focus, .admin-form select:focus, .admin-form textarea:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.btn-main { background: var(--text-dark); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.95em; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-main:hover:not(:disabled) { background: #000; transform: translateY(-1px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

button:disabled {
    background-color: #cbd5e1 !important;
    color: #94a3b8 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
    border-color: #cbd5e1 !important;
}

.btn-secondary { background: #f1f5f9; color: var(--text-dark); border: 1px solid var(--border); padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9em; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

/* MODALES */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: white; padding: 30px; border-radius: 12px; width: 90%; max-width: 420px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04); }
.modal-content h3 { margin-top: 0; margin-bottom: 20px; font-size: 1.3em; font-weight: 700; color: var(--text-dark); display: flex; align-items: center; gap: 8px; }
.modal-content h3 i { color: var(--primary); }
.payment-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.payment-row select { padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.95em; outline: none; }
#cashArea input, #voucherCode { width: 100%; padding: 12px 15px; margin-bottom: 15px; border: 1px solid var(--border); border-radius: 8px; font-size: 1em; outline: none; }
#cashArea input:focus, #voucherCode:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; padding: 12px; font-weight: 600; border-radius: 8px; }

.search-item { padding: 12px 15px; border-bottom: 1px solid #f1f5f9; cursor: pointer; font-size: 0.9em; transition: 0.2s; }
.search-item:hover { background: #f8fafc; padding-left: 20px; }

.stock-rojo { color: #ef4444; font-weight: 600; }
.stock-amarillo { color: #eab308; font-weight: 600; }
.stock-verde { color: var(--text-dark); }

/* PANTALLA DE LOGIN */
#login-screen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: #0f172a; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; }
.login-box { background: var(--card-bg); padding: 40px; border-radius: 16px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); text-align: center; width: 90%; max-width: 360px; }
.login-box h2 { color: var(--text-dark); margin-bottom: 5px; font-weight: 700; letter-spacing: -0.5px; }
.login-box p { color: var(--text-muted); margin-bottom: 30px; font-size: 0.9em; }
.pin-display { display: flex; justify-content: center; gap: 15px; margin-bottom: 35px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #cbd5e1; background: transparent; transition: all 0.2s; }
.pin-dot.filled { background: var(--primary); border-color: var(--primary); }
.pin-dot.error { background: #ef4444; border-color: #ef4444; animation: shake 0.3s ease-in-out; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.key-btn { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; width: 65px; height: 65px; margin: 0 auto; font-size: 1.4em; font-weight: 600; color: var(--text-dark); cursor: pointer; transition: 0.1s; display: flex; align-items: center; justify-content: center; }
.key-btn:active { background: #e2e8f0; transform: scale(0.95); }
.key-btn.action { background: transparent; border: none; color: var(--text-muted); font-size: 1.2em; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* RESPONSIVE */
@media (max-width: 1024px) {
    .dash-charts-grid { grid-template-columns: 1fr; }
    .dash-lists-grid { grid-template-columns: 1fr; }
    .pos-layout { flex-direction: column; }
    .pos-products-area { flex: none; height: 55vh; }
    .pos-cart-area { flex: none; height: 45vh; max-width: 100%; border-left: none; border-top: 1px solid var(--border); box-shadow: 0 -4px 15px rgba(0,0,0,0.02); }
}

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; padding: 10px 15px; border-right: none; border-bottom: 1px solid rgba(255,255,255,0.05); }
    .brand { padding: 0; border: none; }
    .brand-text h2 { font-size: 1.2em; display: inline-block; margin-right: 10px; }
    .brand-text p { display: none; }
    .user-info-sidebar { border: none; background: transparent; padding: 0; margin: 0; text-align: right; }
    .user-info-sidebar p { display: none; }
    .user-info-sidebar strong { display: inline-block; margin-right: 10px; font-size: 0.85em; }
    .btn-logout { margin: 0; padding: 6px 10px; font-size: 0.8em; display: inline-block; width: auto; }
    
    .nav-menu { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px 0 0 0; gap: 8px; flex-wrap: nowrap; }
    .nav-section-title { display: none; } 
    .nav-menu button { padding: 8px 12px; font-size: 0.85em; white-space: nowrap; border-radius: 6px; background: rgba(255,255,255,0.05); }
    .nav-menu button.active { background: rgba(56, 189, 248, 0.15); }
    
    .admin-container, .dashboard-container { padding: 15px; }
    #divDatosFactura { grid-template-columns: 1fr; }
    .dash-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}