:root {
    --primary-color: #2c3e50;
    --accent-color: #f8f9fa;
    --success-color: #27ae60;
    --danger-color: #c0392b;
    --bg-light: #f8f9fa;
    --border-color: #ddd;
}
* { box-sizing: border-box; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
body { margin: 0; padding: 20px; background-color: #e9ecef; }
.main-container { max-width: 1400px; margin: 0 auto; background: white; padding: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); border-radius: 8px; display: flex; flex-direction: column; min-height: 95vh; margin-bottom: 40px;}

.btn { padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; color: white; transition: background 0.2s; text-decoration: none; text-align: center; display: inline-block; }
.btn-primary { background-color: var(--primary-color); }
.btn-primary:hover { background-color: #1a252f; }
.btn-success { background-color: var(--success-color); }
.btn-success:hover { background-color: #219150; }
.btn-danger { background-color: var(--danger-color); }
.readonly-input { background-color: #e0e0e0; cursor: not-allowed; color: #555; }

/* =========================================
   EDITOR DE NOTAS (index.php)
   ========================================= */
.invoice-header { background-color: white; border: 1px solid var(--border-color); padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.header-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; }
.input-group { display: flex; flex-direction: column; position: relative;}
.input-group label { font-size: 0.75rem; font-weight: bold; margin-bottom: 4px; color: #555; text-transform: uppercase;}
.input-group input, .input-group select { padding: 8px 10px; border: 1px solid #ccc; border-radius: 4px; width: 100%; font-size: 0.9rem;}
.input-group input:focus, .input-group select:focus { border-color: var(--primary-color); outline: none; }

.autocomplete-list { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid #ccc; border-radius: 4px; max-height: 200px; overflow-y: auto; z-index: 1000; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.autocomplete-list div { padding: 10px; cursor: pointer; border-bottom: 1px solid #eee; font-size: 0.85rem;}
.autocomplete-list div:hover { background: #eaf8ff; }

.workspace-container { display: flex; flex-direction: row; align-items: stretch; gap: 15px; margin-bottom: 15px; height: 450px; }
.grid-section { flex: 3; border: 1px solid var(--border-color); border-radius: 4px; background: #fff; height: 100%; overflow: hidden; position: relative; }
#excel-grid { width: 100%; height: 450px !important; overflow: hidden; }
.assistant-panel { flex: 1; background: #f8f9fa; border: 1px solid #ddd; border-radius: 4px; display: flex; flex-direction: column; min-width: 250px; height: 100%; }
.panel-header { background: var(--primary-color); color: white; padding: 10px; font-weight: bold; font-size: 0.9rem; text-align: center; }
.panel-content { padding: 10px; overflow-y: auto; flex-grow: 1; }
.panel-empty-text { color: #777; text-align: center; font-size: 0.85rem; margin-top: 20px; }

.sugerencia-card { background: white; border: 1px solid #ccc; border-left: 4px solid var(--primary-color); padding: 10px; margin-bottom: 10px; border-radius: 4px; cursor: pointer; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.sugerencia-card:hover { border-left-color: var(--success-color); transform: translateY(-1px); }
.sugerencia-card.last-used { border-left-color: #f39c12; background: #fffdf5; }
.sugerencia-card.card-resaltada { border-left-color: #3498db !important; background-color: #eaf8ff !important; box-shadow: 0 4px 8px rgba(0,0,0,0.15); transform: scale(1.02); }
.sug-title { font-weight: bold; font-size: 0.85rem; color: #333; margin-bottom: 5px; }

.invoice-footer { border-top: 2px solid var(--primary-color); padding-top: 15px; }
.totals-container { display: flex; justify-content: space-between; margin-bottom: 20px; background-color: #f8f9fa; border: 1px solid #eee; padding: 15px; border-radius: 4px; flex-wrap: wrap; gap: 15px;}
.adjustments-panel, .results-panel { display: flex; flex-direction: column; gap: 10px; width: 48%; min-width: 250px;}
.adj-row, .res-row { display: flex; justify-content: space-between; align-items: center; }
.res-row strong { font-size: 1.1rem; }
.highlight { color: var(--success-color); font-size: 1.2rem; border-top: 1px solid #ccc; padding-top: 5px; }
.actions-bar { display: flex; justify-content: flex-end; gap: 15px; flex-wrap: wrap;}
.handsontable th { background-color: var(--primary-color); color: white; font-weight: bold; }

/* PANEL DE AGREGADO RAPIDO MOVIL */
.mobile-quick-add { display: none; background: white; padding: 15px; border-radius: 8px; border: 1px solid var(--primary-color); margin-bottom: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.mobile-quick-add h4 { margin: 0 0 10px 0; color: var(--primary-color); font-size: 0.9rem; }
.mob-search-container { position: relative; display: flex; gap: 10px; align-items: center; }
.mob-search-container input { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 1rem; }
#mob-qty { max-width: 60px; text-align: center; } 
#mob-panel-sugerencias { max-height: 200px; overflow-y: auto; background: white; margin-top: 10px; border-radius: 4px; }

/* =========================================
   MODAL DE LABORATORIOS Y CATÁLOGOS
   ========================================= */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000000; justify-content: center; align-items: center; padding: 15px; }
.modal-content { background: white; padding: 25px; border-radius: 8px; width: 100%; max-width: 600px; max-height: 85vh; overflow-y: auto; position: relative; box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.modal-close { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--danger-color); }
.modal-title { margin-top: 0; color: var(--primary-color); border-bottom: 2px solid var(--accent-color); padding-bottom: 10px; margin-bottom: 15px; }
.lab-list { display: flex; flex-direction: column; gap: 10px; }
.lab-item { padding: 15px; border: 1px solid #eee; border-radius: 6px; background: #f8f9fa; display: flex; justify-content: space-between; align-items: center; }
.lab-item strong { font-size: 1.1rem; color: #333; }
.lab-item span { font-size: 0.8rem; color: #777; display: block; margin-top: 5px; }
.lab-item button { padding: 8px 12px; font-size: 0.8rem; }

/* =========================================
   BOTTOM SHEET MÓVIL (MENÚ "MÁS")
   ========================================= */
.bottom-sheet { position: fixed; bottom: -100%; left: 0; right: 0; background: white; border-radius: 20px 20px 0 0; padding: 25px 20px 40px 20px; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); transition: bottom 0.3s ease-in-out; z-index: 10000; }
.bottom-sheet.open { bottom: 65px; } /* Se coloca justo encima del menú inferior */
.bottom-sheet-backdrop { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 9999; }
.bottom-sheet-backdrop.open { display: block; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 15px; }
.menu-item { background: #f8f9fa; border: 1px solid #ddd; padding: 20px; border-radius: 10px; text-align: center; color: var(--primary-color); text-decoration: none; font-weight: bold; display: flex; flex-direction: column; gap: 10px;}
.menu-item i { font-size: 2rem; }

/* =========================================
   DASHBOARD & KPIS
   ========================================= */
.kpi-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 15px; margin-bottom: 20px; }
.kpi-card { background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); border-left: 5px solid var(--primary-color); text-align: center; }
.kpi-card.kpi-green { border-left-color: var(--success-color); }
.kpi-card.kpi-yellow { border-left-color: #f1c40f; }
.kpi-card h3 { margin: 0; font-size: 0.75rem; color: #7f8c8d; text-transform: uppercase; letter-spacing: 1px; }
.kpi-card p { margin: 8px 0 0 0; font-size: 1.4rem; font-weight: bold; color: #2c3e50; }
.kpi-subtitle { font-size: 0.7rem; color: #95a5a6; display: block; margin-top: 5px; }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 15px;}
.notes-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.notes-table th { background: var(--primary-color); color: white; padding: 12px; text-align: left; }
.notes-table td { padding: 12px; border-bottom: 1px solid #eee; color: #333; }
.notes-table tr:hover { background-color: #f1f1f1; }
.badge { padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; display: inline-block; white-space: nowrap; text-align: center;}
.bg-green { background: #d4edda; color: #155724; }
.bg-red { background: #f8d7da; color: #721c24; }
.bg-yellow { background: #fff3cd; color: #856404; }
.bg-blue { background: #cce5ff; color: #004085; }
.bg-gray { background: #e2e3e5; color: #383d41; }
.action-btn { text-decoration: none; color: #555; margin-right: 8px; font-size: 1.1rem; }
.action-btn:hover { color: var(--accent-color); }
.pagination-container { display: flex; justify-content: center; gap: 5px; margin-top: 20px; padding-bottom: 20px; flex-wrap: wrap; }
.page-btn { padding: 8px 12px; border: 1px solid var(--primary-color); background: white; color: var(--primary-color); cursor: pointer; border-radius: 4px; font-weight: bold; }
.page-btn.active { background: var(--primary-color); color: white; }

.filtros-wrapper { transition: max-height 0.3s ease-out; overflow: hidden; background: #f8f9fa; padding: 15px; border-radius: 8px; margin-bottom: 15px; border: 1px solid #eee; }
.btn-toggle-filtros { display: none; width: 100%; padding: 10px; background: #ecf0f1; border: 1px solid #bdc3c7; border-radius: 8px; font-weight: bold; color: #2c3e50; margin-bottom: 10px; cursor: pointer; }
.btn-exit-pc { display: none !important; position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: #e74c3c; color: white; padding: 15px 30px; border-radius: 50px; font-size: 18px; z-index: 999999; box-shadow: 0 5px 15px rgba(0,0,0,0.5); cursor: pointer; border: none; font-weight: bold; }

/* FORZAR MODO PC EN MOVIL */
body.force-desktop { min-width: 1200px !important; padding-bottom: 20px !important; background-color: #e9ecef !important; }
body.force-desktop .btn-exit-pc { display: block !important; } 
body.force-desktop .bottom-nav { display: none !important; }
body.force-desktop .desktop-only { display: flex !important; }
body.force-desktop .hide-mobile { display: table-cell !important; } 
body.force-desktop .main-container { margin: 0 auto; min-height: 100vh; }
body.force-desktop .header-nav { flex-direction: row !important; justify-content: space-between !important;}
body.force-desktop .search-row { display: flex !important; flex-wrap: nowrap; flex-direction: row; }

/* =========================================
   MÓVILES (Responsividad Real y Exacta)
   ========================================= */
.bottom-nav { display: none; }
.btn-mobile-pc { display: none; } 

@media (max-width: 768px) {
    /* Padding inferior enorme para que el menú jamás tape el contenido */
    body { padding: 5px; padding-bottom: 120px !important; } 
    .main-container { padding: 10px; min-height: calc(100vh - 120px); margin-bottom: 20px;}
    
    .desktop-only { display: none !important; }
    .hide-mobile { display: none !important; } 
    
    .notes-table { min-width: 450px; }
    .notes-table th, .notes-table td { padding: 8px 4px !important; font-size: 0.80rem !important; }
    .action-btn { margin-right: 8px; font-size: 1.2rem; }
    .badge { padding: 3px 5px; font-size: 0.70rem; border-radius: 4px;}

    .header-nav { display: flex; flex-direction: row !important; justify-content: space-between; align-items: center; margin-bottom: 10px !important; }
    .header-nav h2 { font-size: 1.2rem; }
    .btn-mobile-pc { display: inline-block; background: var(--primary-color); color: white; border: none; padding: 6px 12px; border-radius: 4px; font-size: 0.75rem; cursor: pointer; font-weight:bold;}
    
    .btn-toggle-filtros { display: block; }
    .filtros-collapsed { max-height: 0; opacity: 0; padding: 0; margin: 0; pointer-events: none; border: none; }
    
    /* FIX: Filtros apilados en móvil para que no se deformen */
    .search-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
    .search-row .search-field { width: 100%; }
    .search-row .search-field label { font-size: 0.7rem; margin-bottom: 2px;}
    .search-row .search-field input, .search-row .search-field select { padding: 8px; font-size: 0.9rem; height: auto;}
    .btn-group-mobile { display: flex; flex-wrap: wrap; gap: 5px; width: 100%; }
    .btn-group-mobile button { flex: 1; padding: 10px 5px; font-size: 0.9rem; min-width: 30%; }
    
    .quick-filters { display: flex; gap: 5px; justify-content: space-between; border-top: 1px dashed #ccc; padding-top: 8px; margin-top: 8px; }
    .quick-filters button { flex: 1; padding: 8px 0; font-size: 0.75rem;}

    .summary-bar { padding: 10px; gap: 5px; justify-content: space-around; text-align: center; }
    .summary-bar div { align-items: center; }
    .summary-bar span { font-size: 0.65rem; }
    .summary-bar strong { font-size: 1.1rem; }

    /* EDITOR DE NOTAS (index.php) */
    .header-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .header-row > .input-group:nth-child(1), .header-row > .input-group:nth-child(2) { grid-column: span 2; } 
    .mobile-quick-add { display: block; } 
    .workspace-container { display: block; height: auto; margin-bottom: 5px;}
    .assistant-panel { display: none; } 
    #excel-grid { height: 250px !important; border: 1px solid #ccc;}

    .adjustments-panel, .results-panel { width: 100%; min-width: 100%;}
    .actions-bar { justify-content: stretch; margin-bottom: 20px;}
    .actions-bar .btn { flex: 1; }

    /* MENU INFERIOR NATIVO (5 BOTONES) */
    .bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0;
        background: #ffffff; box-shadow: 0 -5px 15px rgba(0,0,0,0.15);
        justify-content: space-between; align-items: center;
        height: 60px; z-index: 9999; border-top: 1px solid #eee; padding: 0 5px;
    }
    .bottom-nav button, .bottom-nav a {
        background: none; border: none; color: #7f8c8d; text-decoration: none;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        font-size: 0.65rem; width: 20%; height: 100%; padding: 0; margin: 0; cursor: pointer;
    }
    .bottom-nav .nav-item.active { color: var(--primary-color); font-weight: bold; }
    .bottom-nav .nav-item i { font-size: 1.3rem; margin-bottom: 3px; }
    
    /* Botón central (+) Círculo Perfecto */
    .bottom-nav .nav-btn-add {
        background: var(--success-color); color: white !important;
        aspect-ratio: 1 / 1;
        width: 55px !important; height: 55px !important; 
        max-width: 55px !important; min-width: 55px !important;
        border-radius: 50% !important; 
        display: flex; justify-content: center; align-items: center;
        margin-top: -25px; box-shadow: 0 4px 8px rgba(39, 174, 96, 0.4); 
        border: 3px solid #fff; box-sizing: border-box; flex-shrink: 0;
    }
    .bottom-nav .nav-btn-add i { font-size: 1.5rem; margin: 0; padding: 0; color: white;}
}