:root {
    --primary-red: #e52320;
    --dark-bg: #222222;
    --light-bg: #f4f5f7;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #dcdcdc;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--light-bg);
    color: var(--text-color);
    overflow: hidden; /* Evita scrolls globales no deseados */
}

.main-header {
    background-color: var(--primary-red);
    color: white;
    padding: 12px 30px;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    height: 50px;
    display: flex;
    align-items: center;
}

/* Layout Principal Flex de pantalla completa */
.layout-container {
    display: flex;
    height: calc(100vh - 50px);
    max-height: calc(100vh - 50px);
    width: 100vw;
    max-width: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--card-bg);
    padding: 20px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    height: 100%;
}

.sidebar h3 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 15px;
    letter-spacing: 0.5px;
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-btn {
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn strong {
    display: block;
    font-size: 0.9rem;
    color: #333;
}

.nav-btn small {
    display: block;
    font-size: 0.75rem;
    color: #777;
    margin-top: 3px;
}

.nav-btn:hover, .nav-btn.active {
    background-color: #f8f9fa;
    border-color: var(--border-color);
}

/* Área de contenido adaptable a toda la pantalla */
.content-area {
    flex: 1;
    min-width: 0;
    padding: 18px 25px;
    background-color: #f9fafe;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.view-section.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    min-height: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.actions-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Botones principales con alineación flex interna */
.btn-primary {
    background-color: var(--dark-bg);
    color: white;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary {
    background-color: white;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-dark {
    background-color: var(--dark-bg);
    color: white;
    border: none;
    padding: 10px 22px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-dark:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Tarjeta Blanca que se estira automáticamente hasta abajo */
.preview-container {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    margin-bottom: 12px;
}

.preview-container h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
}

/* Table Wrapper Expandido que llena todo el espacio vertical de la tarjeta */
.table-wrapper {
    width: 100%;
    max-width: 100%;
    flex: 1;
    height: 100% !important;
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #ffffff;
    display: block;
    position: relative;
}

.placeholder-text {
    color: #999;
    font-size: 0.9rem;
    padding: 30px;
    text-align: center;
}

/* Footer con separación de botones corregida para Informe General y Control */
.section-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-top: auto;
    padding-top: 4px;
}

/* =========================================================
   ESTILOS EXCLUSIVOS PARA EL MODAL DE REPORTE POR ÁREAS (RESTAURADOS)
   ========================================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-box {
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    width: 85vw !important;
    max-width: 1400px !important;
    height: 85vh !important;
    max-height: 85vh !important;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 15px;
}

#modal-contenido-area {
    flex: 1;
    overflow-x: auto !important;
    overflow-y: auto !important;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
}

/* Restaurar estructura de tablas de reporte por área dentro de modales */
.table-modal-full {
    width: 100%;
    border-collapse: collapse !important;
    font-size: 0.8rem;
    text-align: left;
}

.table-modal-full th {
    position: sticky;
    top: 0;
    background-color: #1e293b;
    color: #ffffff;
    padding: 10px 12px !important;
    border: 1px solid #334155 !important;
    white-space: nowrap;
    z-index: 10;
}

.table-modal-full td {
    padding: 8px 10px !important;
    border: 1px solid #e2e8f0 !important;
    white-space: nowrap;
    background-color: #ffffff;
}

.table-modal-full tr:nth-child(even) td {
    background-color: #f8fafc;
}

/* =========================================================
   CONFIGURACIÓN EXCLUSIVA DE TABLA RESULTADO DE CONTROL
   ========================================================= */
#control-matrix-table {
    table-layout: fixed !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    width: max-content !important;
    min-width: 100% !important;
}

#control-matrix-table th, 
#control-matrix-table td {
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Congelar la fila de encabezados al hacer scroll vertical */
#control-matrix-table thead {
    position: sticky;
    top: 0;
    z-index: 100;
}

#control-matrix-table thead tr {
    position: sticky;
    top: 0;
    z-index: 100;
}

#control-matrix-table thead th {
    position: sticky;
    top: 0;
    background-color: #dc2626 !important;
    z-index: 100 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Esquinas congeladas superiores para ITEM NO e ITEM */
#control-matrix-table thead th[data-col-id="cod"] {
    position: sticky !important;
    top: 0 !important;
    left: 0px !important;
    z-index: 120 !important;
    background-color: #dc2626 !important;
}

#control-matrix-table thead th[data-col-id="item"] {
    position: sticky !important;
    top: 0 !important;
    z-index: 120 !important;
    background-color: #dc2626 !important;
}

/* Divisor interactivo para cambiar el ancho de columnas */
.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 130;
}

.col-resizer:hover,
.col-resizer:active {
    background-color: #0284c7;
}

/* Estilo interactivo para selección de celdas en calculadora */
#control-table-wrapper.selecting-cell-mode input[data-idx] {
    cursor: pointer !important;
    border: 2px dashed #0284c7 !important;
    background-color: #e0f2fe !important;
    transition: all 0.2s ease;
}

#control-table-wrapper.selecting-cell-mode input[data-idx]:hover {
    background-color: #bae6fd !important;
    border-color: #0369a1 !important;
    transform: scale(1.03);
}

/* =========================================================
   RESALTADO DE FILAS Y PERSONALIZACIÓN DE COLORES DE CELDAS
   ========================================================= */

/* Fila Resaltada (Toggle estilo Excel) */
#control-matrix-table tr.row-selected {
    background-color: #e0f2fe !important; /* Azul claro estilo selección */
    outline: 2px solid #0284c7;
    outline-offset: -2px;
}

#control-matrix-table tr.row-selected td {
    background-color: #e0f2fe !important;
}

/* Cursor interactivo para celdas fijas de selección */
#control-matrix-table td.cell-selectable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

#control-matrix-table td.cell-selectable:hover {
    background-color: #bae6fd !important;
}

/* Selector de Color en Inputs */
.color-picker-trigger {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 1px 3px;
    border-radius: 3px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.color-picker-trigger:hover {
    opacity: 1;
}

/* Popover de Paleta de Colores Guía */
.cell-color-popover {
    position: fixed;
    z-index: 2100;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
}

.color-option-circle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    transition: transform 0.15s ease;
}

.color-option-circle:hover {
    transform: scale(1.2);
}

/* Soporte de color guía en celdas de la matriz de control */
#control-matrix-table td.has-custom-color,
#control-matrix-table td.has-custom-color input {
    transition: background-color 0.2s ease;
}

/* Asegura el funcionamiento del scroll con header fijo sin interferencias */
#control-table-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden !important;
}

.table-scroll-container {
    overflow: auto !important;
    position: relative;
    width: 100%;
    height: 100%;
}

#control-matrix-table thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    background-color: #dc2626 !important;
}

#control-matrix-table thead th[data-col-id="cod"] {
    left: 0px !important;
    z-index: 120 !important;
}

#control-matrix-table thead th[data-col-id="item"] {
    z-index: 120 !important;
}

/* Estilo general para las celdas en selección */
#control-table-wrapper.selecting-cell-mode input[data-idx] {
    cursor: pointer !important;
    border: 2px dashed #0284c7 !important;
    background-color: #e0f2fe !important;
}

/* Estilo exclusivo para la CELDA ORIGEN que abrió la calculadora */
#control-table-wrapper.selecting-cell-mode input.calculator-origin-cell {
    border: 2px solid #ea580c !important; /* Borde sólido naranja/fuerte */
    background-color: #ffedd5 !important; /* Fondo naranja claro distintivo */
    box-shadow: 0 0 8px rgba(234, 88, 12, 0.4);
}