:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #f1f5f9;
    --secondary-hover: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --bg-main: #f8fafc;
    --border-color: #cbd5e1;
    --danger: #ef4444;
    --success: #10b981;
    --radius-sm: 6px;
    --radius-md: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg-main); color: var(--text-main); }

/* Vistas de la aplicación garantizando que solo 1 se vea a la vez */
.view-wrapper { display: none !important; }
.view-wrapper.active { display: block !important; }
.hidden { display: none !important; }

/* Global Utilities */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.5rem 1rem; border-radius: var(--radius-sm); border: none; cursor: pointer; font-weight: 500; font-size: 0.875rem; font-family: inherit; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-block { width: 100%; padding: 0.75rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.4rem; border-radius: 4px; }
.btn-icon:hover { background: var(--secondary); color: var(--text-main); }
.btn-dashed { border: 1px dashed var(--border-color); background: transparent; color: var(--text-muted); padding: 0.5rem; font-weight: 600; }
.btn-dashed:hover { background: var(--secondary); color: var(--text-main); border-color: #94a3b8; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.text-white { color: white !important; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; } .mt-2 { margin-top: 0.5rem; } .mt-3 { margin-top: 1rem; } .mt-4 { margin-top: 1.5rem; } .mb-3 { margin-bottom: 1rem; } .mb-4 { margin-bottom: 1.5rem; }
.p-0 { padding: 0 !important; } .p-4 { padding: 1.5rem; }
.w-100 { width: 100%; }
.d-flex { display: flex; } .justify-between { justify-content: space-between; } .align-center { align-items: center; }

/* Login */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
.login-box { background: white; padding: 2.5rem; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); width: 90%; max-width: 400px; text-align: center; }
.logo-icon-large { font-size: 3rem; color: var(--primary); margin-bottom: 1rem; }
.login-header h2 { font-size: 1.25rem; font-weight: 800; color: #1e293b; letter-spacing: -0.02em; }
.login-header p { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.2rem; margin-bottom: 1.5rem; }
.input-group label { display: block; text-align: left; font-size: 0.875rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; }
.input-group select, .input-group input, .std-input { width: 100%; padding: 0.75rem; border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-family: inherit; }
.input-group select:focus, .input-group input:focus, .std-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

/* Header app */
.app-header { background: white; border-bottom: 1px solid var(--border-color); padding: 1rem 2rem; position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow-sm); }
.header-container { max-width: 1300px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.logo-area { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; font-size: 1.125rem;}
.logo-icon { color: var(--primary); font-size: 1.25rem; }
.badge { background: #dbeafe; color: #1e40af; padding: 0.25rem 0.75rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; }
.nav-tabs { display: flex; gap: 0.5rem; }
.tab-btn { background: transparent; border: none; padding: 0.5rem 1rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Layout App */
.app-main { max-width: 1300px; margin: 2rem auto; padding: 0 1.5rem; padding-bottom: 4rem;}
.card { background: white; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); }
.date-row { background: var(--secondary); padding: 1rem; border-radius: var(--radius-sm); font-weight: 600; color: #334155; }
.date-input { border: 1px solid var(--border-color); padding: 0.5rem; border-radius: 4px; font-family: inherit; margin-left: 1rem; outline: none; background: white; font-weight: bold; }

/* Grid 2 Columnas */
.sides-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
@media (max-width: 1024px) { .sides-grid { grid-template-columns: 1fr; } }
.side-col { background: #ffffff; padding: 1.5rem; border-radius: var(--radius-md); border: 1px solid #e2e8f0; }
.z-report-col { background: #f8fafc; border-color: #cbd5e1; }
.col-title { font-size: 1.1rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; color: #0f172a; border-bottom: 3px solid var(--text-main); padding-bottom: 0.75rem; margin-bottom: 1.5rem; display: flex; justify-content: space-between; align-items: baseline; }
.col-title small { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); text-transform: none; letter-spacing: 0; }

/* Filas Formulario Grouped */
.fp-group { display: flex; flex-direction: column; width: 100%; margin-bottom: 0.25rem; }
.sub-rows-container { display: flex; flex-direction: column; gap: 0.25rem; width: 100%; }
.sub-row-item { padding-left: 1.5rem !important; margin-top: 0 !important; background: transparent;}
.sub-row-item .notes-input { width: 160px; border-style: dashed; }
.sub-row-item:hover { background: #f8fafc; }

.fixed-inputs-list { display: flex; flex-direction: column; gap: 0.25rem; }
.fp-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; padding: 0.4rem 0.5rem; border-radius: 6px; }
.fp-row:hover { background: #f1f5f9; }
.highlight-row { background: #f0fdf4 !important; border: 1px solid #bbf7d0; }
.lbl-main { flex: 1; color: #334155; font-weight: 600; padding-right: 1rem;}
.row-inputs { display: flex; gap: 0.5rem; align-items: center; }

/* Campos */
.notes-input { width: 140px; padding: 0.45rem 0.5rem; border: 1px dashed #cbd5e1; border-radius: 4px; font-size: 0.8rem; font-family: inherit; background: transparent; transition: all 0.2s; }
.notes-input:focus { border-style: solid; border-color: var(--primary); outline: none; background: white; }
.input-icon { position: relative; width: 120px; }
.input-icon span { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: 600; }
.input-icon input { width: 100%; padding: 0.45rem 0.5rem 0.45rem 1.6rem; border: 1px solid var(--border-color); border-radius: 4px; text-align: right; font-family: inherit; font-size: 0.95rem; font-weight: 600; color: #0f172a; }
.input-icon input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
.val-w-btn { display: flex; align-items: center; gap: 0.25rem; }

/* Informe Z Especiales */
.sales-banner-z { display: flex; justify-content: center; align-items: center; gap: 0.5rem; padding: 1.25rem 1rem; border: 1px solid #bae6fd; background: #e0f2fe; border-radius: var(--radius-sm); margin-bottom: 1rem; flex-wrap: wrap; }
.calc-box-z { display: flex; flex-direction: column; gap: 0.25rem; width: 130px; }
.calc-box-z label { font-size: 0.7rem; font-weight: 700; color: #0369a1; text-transform: uppercase; }
.calc-box-z.highlight-z { width: 160px; }
.calc-box-z.highlight-z .input-icon input { background: #0284c7; color: white; border-color: #0369a1; font-size: 1.2rem; }
.calc-box-z.highlight-z .input-icon span { color: #bae6fd; }
.calc-operator-z { font-size: 1.25rem; font-weight: 800; color: #0369a1; margin-top: 1rem; }
.z-separator { margin: 1.5rem 0 1rem 0; text-align: center; position: relative; }
.z-separator::before { content: ''; position: absolute; left: 0; top: 50%; width: 100%; height: 1px; background: #cbd5e1; z-index: 1; }
.z-separator span { position: relative; z-index: 2; background: #f8fafc; padding: 0 1rem; font-size: 0.8rem; font-weight: 700; color: #475569; letter-spacing: 0.05em; text-transform: uppercase; }

/* Footers Columna */
.col-footer { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; background: white; padding: 0.75rem 1rem; border-radius: var(--radius-sm); border: 2px solid var(--border-color); }
.big-val { font-size: 1.25rem; font-weight: 800; color: var(--primary); }

/* Resumen Global */
.balance-tray { background: #fff; border: 2px dashed #cbd5e1; padding: 1.25rem; border-radius: var(--radius-sm); }
.pt-compact { padding-top: 1rem; }
.diff-box { font-size: 1.1rem; background: #f1f5f9; padding: 0.5rem 1rem; border-radius: 6px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.05); }
.diff-val.err { color: var(--danger); }

/* Firmas */
.signatures-area { display: flex; justify-content: space-around; margin-top: 2rem; padding-top: 1rem; }
.signature-box { text-align: center; width: 40%; }
.signature-box input { border: none; border-bottom: 1px solid #000; font-family: inherit; width: 100%; text-align: center; font-size: 1rem; background: transparent; padding-bottom: 0.25rem;}
.signature-box input:focus { outline: none; border-bottom-color: var(--primary); }
.signature-box label { display: block; font-weight: 600; font-size: 0.85rem; color: #475569; margin-top: 0.5rem; text-transform: uppercase;}

/* Admin Panels */
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-filters { display: flex; gap: 0.5rem; align-items: center; }
.table-responsive { overflow-x: auto; background: white; border: 1px solid var(--border-color); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
.data-table th { background: #f8fafc; padding: 0.85rem 1rem; border-bottom: 2px solid var(--border-color); color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.data-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color); color: #334155; }
.data-table tr:hover { background: #f0fdf4; }
.empty-state { padding: 4rem; text-align: center; color: var(--text-muted); font-size: 1.1rem; border: 1px dashed var(--border-color); border-radius: var(--radius-sm); background: #f8fafc; }

/* Modales */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.7); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 999; }
.modal { background: white; width: 90%; max-width: 550px; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.modal.large { max-width: 800px; }
@keyframes modalPop { 0% { opacity: 0; transform: scale(0.95) translateY(10px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; }
.modal-header h2 { font-size: 1.25rem; color: var(--text-main); font-weight: 800; display: flex; align-items: center; gap: 0.5rem;}
.modal-body { padding: 1.5rem; overflow-y: auto; max-height: 70vh; font-size: 0.95rem; color: #334155; line-height: 1.5; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-color); background: #f1f5f9; display: flex; justify-content: flex-end; gap: 0.75rem; }

/* Modal Resumen */
.summary-box { background: white; border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.sum-row { display: flex; justify-content: space-between; font-size: 1rem; }
.sum-row span:last-child { font-weight: 700; color: #0f172a; }

/* Detalle Avanzado Admin */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 650px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-box { border: 1px solid var(--border-color); border-radius: 6px; padding: 1rem; }
.detail-box h4 { font-size: 0.85rem; text-transform: uppercase; font-weight: 700; color: var(--text-muted); margin-bottom: 0.5rem; border-bottom: 1px solid #e2e8f0; padding-bottom: 0.25rem; }
.detail-line { display: flex; justify-content: space-between; font-size: 0.9rem; padding: 0.2rem 0; }
.detail-line small { color: #64748b; font-style: italic; }
.detail-header { background: #f1f5f9; padding: 1rem; border-radius: 6px; margin-bottom: 1.5rem; font-weight: 600; display:flex; flex-direction: column; gap: 0.25rem; }

/* Tabla Calculadora */
.calc-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.calc-table th { text-align: left; padding: 0.5rem; border-bottom: 2px solid var(--border-color); color: #475569; }
.calc-table td { padding: 0.5rem; border-bottom: 1px solid var(--border-color); }
.calc-table input { width: 80px; padding: 0.35rem; text-align: center; border: 1px solid #94a3b8; border-radius: 4px; font-weight: bold; }
.calc-table input:focus { border-color: var(--primary); outline: none; }
.total-cell { font-size: 1.25rem; color: var(--success); }

/* Responsive tweaks */
@media (max-width: 650px) {
    .wrap-mobile { flex-direction: column; align-items: stretch !important; gap: 1rem; }
    .admin-filters { flex-direction: column; }
    .row-inputs { flex-direction: column; align-items: flex-end; gap: 0.25rem;}
    .notes-input { width: 120px; text-align: right; }
}

/* PRINT STYLES - SINGLE PAGE OPTIMIZED */
@media print {
    body { background: white !important; font-size: 9pt; color: black; }
    .no-print, .btn, .app-header { display: none !important; }
    .hidden-screen { display: block !important; }
    .view-wrapper { display: block !important; }
    #admin-wrapper, #login-wrapper { display: none !important; }
    .card { border: none !important; box-shadow: none !important; padding: 0 !important; }
    .app-main { margin: 0; padding: 0; width: 100%; max-width: 100%;}
    
    .store-layout { zoom: 0.85; }

    /* LAYOUT OPTIMIZATION (GRID DE LISTAS COLABORATIVAS) */
    .sides-grid { grid-template-columns: 1fr; gap: 0rem; }
    .side-col { padding: 0; border: none; background: transparent; }
    .z-report-col { background: transparent; margin-top: 0.5rem;}
    
    /* MULTICOLUMNS (GRID) PARA FILAS EN IMPRESION */
    .fixed-inputs-list { display: grid !important; grid-template-columns: 1fr 1fr; column-gap: 1.5rem; row-gap: 0.15rem; width: 100%; }
    
    .col-title { font-size: 11pt; border-bottom: 2px solid black; padding-bottom: 0.1rem; margin-bottom: 0.25rem; margin-top: 0.1rem; }
    
    .signature-box input { border-bottom: 1px solid black; color: black; }
    .input-icon input { border: none !important; background: transparent !important; padding: 0 !important; text-align: left; font-size: 9pt; }
    .input-icon span { display: none; }
    .input-icon { width: auto; }
    .notes-input { border: none; padding: 0; color: #444; font-style: italic; text-align:left; width: auto; min-width: 60px; }
    .notes-input::placeholder { color: transparent; }
    
    .fp-row { padding: 0; margin-bottom: 0px !important; line-height: 1.1; break-inside: avoid; }
    .lbl-main { font-weight: bold; font-size: 8.5pt;}
    
    /* ESTILOS DE LISTAS DINAMICAS - DEBEN IMPRIMIRSE */
    .fp-group { display: flex; flex-direction: column; width: 100%; margin-bottom: 0px !important; break-inside: avoid;}
    .sub-rows-container { display: flex; flex-direction: column; width: 100%; gap: 0px;}
    .sub-row-item { padding-left: 1rem !important; margin-bottom: 0px !important; }
    .sub-row-item .notes-input { font-size: 8.5pt; max-width: 80px; text-align: right; margin-right: 0.5rem;}
    
    .btn-rem-sub, .btn-add-sub, .btn-calc { display: none !important; }
    
    .sales-banner-z { border: 1px solid black !important; background: transparent !important; padding: 0.2rem !important; margin-bottom:0.2rem; gap: 0.25rem;}
    .calc-box-z label { color: black; font-size: 0.65rem; }
    .calc-box-z.highlight-z .input-icon input { color: black; background: transparent; font-weight: bold; font-size: 10pt; }
    .calc-operator-z { margin-top: 0.5rem; font-size: 1rem; color: black; }
    
    .z-separator { margin: 0.2rem 0; grid-column: 1 / -1;}
    .z-separator span { background: white; font-size: 0.7rem; color: #444; border: 1px dashed #444; border-radius: 4px;}
    .z-separator::before { display: none; }
    
    .col-footer { padding: 0.2rem; border: 1px dotted black; border-radius: 0; margin-top: 0.1rem; justify-content: flex-end; }
    .big-val { font-size: 10pt; color: black; }
    
    .balance-tray { border: 1px solid black; padding: 0.5rem; margin-top: 0.25rem; page-break-inside: avoid; }
    .diff-box { border: 1px solid black; background: transparent !important; padding: 0.25rem 0.5rem; font-size: 9pt;}
    
    .global-obs-area textarea { border: 1px solid #ccc; background: transparent; width: 100%; font-size: 8pt; box-shadow: none; resize: none; overflow: hidden;}
    
    @page { margin: 1cm; size: A4 portrait; }
}
