/* css/main.css - Hoja de Estilos Unificada */

/* =============================================== */
/* 1. LAYOUT Y CONTENEDORES PRINCIPALES            */
/* =============================================== */
body {
    background-color: var(--color-background);
    font-family: 'Inter', sans-serif;
    color: var(--color-text-primary);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

.page-wrapper {
    padding: 1.5rem;
}

.main-content {
    flex: 1;
}

.card {
    background: var(--color-background-card);
    border: 1px solid var(--color-border);
    border-radius: 0.75rem; /* 12px */
    padding: 1.5rem; /* 24px */
    box-shadow: var(--color-shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.25rem; /* 20px */
    font-weight: 600;
    color: var(--color-text-primary);
}

.card-actions {
    display: flex;
    gap: 0.75rem; /* 12px */
}

/* =============================================== */
/* 2. HEADER Y NAVEGACIÓN (top-nav)                */
/* =============================================== */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem; /* 12px 24px */
    background: var(--color-background-card);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 20;
    margin-bottom: 1.5rem;
}

.main-menu {
    display: flex;
    justify-content: center;
    flex-grow: 1;
    gap: 0.5rem; /* 8px */
}

.main-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem; /* 8px */
    font-size: 0.875rem; /* 14px */
    font-weight: 600;
    text-decoration: none;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
}
.main-menu-item:hover {
    background-color: var(--color-hover-background);
    color: var(--color-text-primary);
}
.main-menu-item.active {
    background-color: var(--color-accent); /* Usar variable de acento del tema */
    color: white;
}
.main-menu-item.active svg { stroke: white; }

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.user-info .user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
}
.nav-icon {
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
}
.nav-icon:hover { color: var(--color-accent); }
/* Icono de logout usa color secundario por defecto, rojo al hover */
.nav-icon.logout { color: var(--color-text-secondary); }
.nav-icon.logout:hover { color: var(--color-error); }

/* =============================================== */
/* 3. BOTONES                                      */
/* =============================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem; /* 8px 16px */
    border-radius: 0.5rem;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-accent {
    background-color: var(--color-accent);
    color: white;
}
.btn-accent:hover {
    background-color: var(--color-accent-hover);
}

.btn-secondary {
    background-color: var(--color-background);
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background-color: var(--color-hover-background);
    border-color: var(--color-text-secondary);
    color: var(--color-text-primary);
}

.edit-btn, .delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s;
}
.edit-btn { color: var(--color-accent); }
.edit-btn:hover { background-color: var(--color-accent-soft); }
.delete-btn { color: var(--color-error); }
.delete-btn:hover { background-color: var(--color-error-soft); }


/* =============================================== */
/* 4. FORMULARIOS                                  */
/* =============================================== */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    font-size: 0.75rem; /* 12px */
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 0.375rem; /* 6px */
}

input[type="text"], input[type="email"], input[type="number"], input[type="tel"],
input[type="file"], select, textarea {
    width: 100%;
    padding: 0.5rem 0.75rem; /* 8px 12px */
    border-radius: 0.5rem;
    border: 1px solid var(--color-border);
    font-size: 0.875rem;
    box-sizing: border-box;
    background-color: var(--color-background);
    color: var(--color-text-primary);
}

.row { display: flex; flex-wrap: wrap; gap: 0.5rem; } /* Espacio entre columnas */
.col { flex: 1; min-width: 130px; } /* Ancho mínimo para columnas */

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-primary);
}

/* =============================================== */
/* 5. TABLAS                                       */
/* =============================================== */
.table-wrapper {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
th, td {
    padding: 0.75rem; /* 12px */
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}
th {
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
td {
    color: var(--color-text-primary);
}
.text-right { text-align: right; }

/* =============================================== */
/* 6. MODALES (CORREGIDO Z-INDEX Y SCROLL)         */
/* =============================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    /* CAMBIO: flex-start para que no se corte arriba en móviles al hacer scroll */
    align-items: flex-start; 
    justify-content: center;
    /* CAMBIO: Z-Index superior al Header (100) */
    z-index: 2000; 
    padding: 1rem;
    /* CAMBIO: Espacio superior para separar del techo */
    padding-top: 80px; 
    /* CAMBIO: Scroll en el overlay completo */
    overflow-y: auto; 
    visibility: hidden; opacity: 0; transition: all 0.3s ease;
}

.modal-overlay:not(.hidden) {
    visibility: visible;
    opacity: 1;
}

.modal-container {
    background-color: var(--color-background-card);
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); /* Sombra más profunda */
    width: 100%;
    max-width: 600px; /* Ancho por defecto */
    /* CAMBIO: Margen inferior para permitir scroll completo */
    margin-bottom: 50px; 
    display: flex;
    flex-direction: column;
    position: relative;
    /* Animación de entrada suave */
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 { font-size: 1.25rem; font-weight: 600; color: var(--color-text-primary); margin: 0; }

.modal-close-btn { 
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-text-secondary);
    transition: color 0.2s;
}
.modal-close-btn:hover { color: var(--color-danger); }

.modal-body {
    padding: 1.5rem;
    /* Eliminamos max-height fijo para que use el scroll del overlay */
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background-color: var(--color-background);
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
}

/* =============================================== */
/* 7. ALERTAS                                      */
/* =============================================== */
.alert {
    padding: 1rem;
    border-left-width: 4px;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
}
.alert-info {
    background-color: var(--color-accent-soft);
    border-color: var(--color-accent);
    color: var(--color-accent);
}
.alert-info strong {
    color: var(--color-accent);
}
.alert-info ol {
    list-style-position: inside;
    list-style-type: decimal;
    margin-top: 0.5rem;
}

/* Clases de texto para reportes de importación */
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }

/* =============================================== */
/* 7. ESTILOS ESPECÍFICOS DE PÁGINA: FACTURADOR    */
/* =============================================== */
/* ... (estilos existentes de .facturador-layout) ... */

/* --- Estilos para la barra de filtros (documents.php) --- */
.filter-bar {
    display: flex;
    flex-wrap: wrap; /* Permite que los elementos pasen a la siguiente línea en pantallas pequeñas */
    gap: 1rem;
    align-items: flex-end; /* Alinea los elementos en la parte inferior */
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group.flex-1 {
    flex: 1;
    min-width: 250px; /* Ancho mínimo para la barra de búsqueda */
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}

/* =============================================== */
/* 8. ESTILOS ADICIONALES PARA COMPONENTES         */
/* =============================================== */

/* --- Estilos para Botones de Acción en Tablas (documents.php) --- */
.action-btn {
    background-color: transparent;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}

/* Estilo para el botón Ver/Imprimir */
.action-btn.view-btn {
    color: var(--color-text-primary); /* Texto del color principal */
    border: 1px solid var(--color-border);/* Borde del color del borde */
    background-color: var(--color-background);  /* Fondo del color de fondo */
}

.action-btn.view-btn:hover {
    background-color: var(--color-hover-background);
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* Estilo para el botón Anular/Eliminar */
.action-btn.delete-btn {
    color: var(--color-error); /* Texto rojo */
    border: 1px solid var(--color-border); /* Borde del color del borde */
    background-color: var(--color-background);  /* Fondo del color de fondo */
}

.action-btn.delete-btn:hover {
    background-color: var(--color-error-soft);
    border-color: var(--color-error);
}

/* --- Estilos para Badges de Estado (documents.php) --- */
.status-badge {
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.status-success { background-color: var(--color-success-soft); color: var(--color-success); }
.status-badge.status-error { background-color: var(--color-error-soft); color: var(--color-error); }
.status-badge.status-info { background-color: var(--color-accent-soft); color: var(--color-accent); }

/* ... (todo tu código CSS existente) ... */

/* --- Estilos para la barra de filtros (documents.php) --- */
.filter-bar {
    display: flex;
    flex-wrap: wrap; /* Permite que los elementos pasen a la siguiente línea en pantallas pequeñas */
    gap: 1rem;
    align-items: flex-end; /* Alinea los elementos en la parte inferior */
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group.flex-1 {
    flex: 1;
    min-width: 250px; /* Ancho mínimo para la barra de búsqueda */
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}

/* =============================================== */
/* 9. CLASES DE ALERTA ADICIONALES                 */
/* =============================================== */

/* Alerta de Éxito (Verde) */
.alert-success {
    background-color: var(--color-success-soft);
    border-color: var(--color-success);
    color: var(--color-success);
}

/* Alerta de Error (Rojo) */
.alert-danger {
    background-color: var(--color-error-soft);
    border-color: var(--color-error);
    color: var(--color-danger);
}

/* =============================================== */
/* 10. CORRECCIONES DE ACCESIBILIDAD (Inputs Readonly) */
/* =============================================== */

/* Esto arregla el texto negro sobre fondo oscuro en campos deshabilitados */
input:disabled, 
input[readonly], 
textarea:disabled {
    background-color: var(--color-hover-background) !important;
    color: var(--color-text-primary) !important; /* Fuerza el color del texto del tema */
    opacity: 1; /* Evita que el navegador lo haga transparente */
    -webkit-text-fill-color: var(--color-text-primary); /* Fix para Chrome/Safari */
    border-color: var(--color-border);
    cursor: not-allowed;
    font-weight: 500;
}

/* =============================================== */
/* 11. Títulos del panel                           */
/* =============================================== */

.page-title-lg { font-size: 1.8rem; font-weight: 700; color: var(--color-text-primary); margin: 0 0 5px 0; }
.page-subtitle { color: var(--color-text-secondary); margin: 0; font-size: 1rem; }

/* GRID DE MÓDULOS (Responsivo) */
/* GRID DE MÓDULOS */
.modules-grid {
    display: grid;  
    grid-template-columns:
    repeat(auto-fill, minmax(160px, 1fr)); 
    gap: 1.25rem;
}

/* Títulos del Panel */
.page-title-lg { font-size: 1.8rem; font-weight: 700; color: var(--color-text-primary); margin: 0 0 5px 0; }
.page-subtitle { color: var(--color-text-secondary); margin: 0; font-size: 1rem; }

/* GRID DE MÓDULOS (Responsivo) */
.modules-grid {
    display: grid;
    /* Minimo 240px para que no se aplasten */
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); 
    gap: 1.25rem; /* 20px */
}

/* ESTILOS BASE DE NOTICIAS */
.news-container { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); 
    gap: 15px; 
}
.news-card { 
    padding: 15px 20px; 
    border-radius: 8px; 
    border-left: 5px solid transparent;
    background: var(--color-bg-secondary, #f8fafc); /* Fallback color */
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
/* Tipos de Noticia - Colores Base */
.news-info { border-left-color: #3b82f6; }
.news-info .news-badge { background: #3b82f6; }
.news-new_feature { border-left-color: #10b981; }
.news-new_feature .news-badge { background: #10b981; }
.news-maintenance { border-left-color: #f59e0b; }
.news-maintenance .news-badge { background: #f59e0b; }
.news-promo { border-left-color: #8b5cf6; }
.news-promo .news-badge { background: #8b5cf6; }

.news-badge { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; color: white; }
.news-title { font-weight: 700; font-size: 1rem; margin: 5px 0; color: var(--color-text-primary); }
.news-content { font-size: 0.9rem; color: var(--color-text-secondary); line-height: 1.5; }

/* --- ESTILOS ESPECÍFICOS DE GESTIÓN DOCUMENTAL (documents.php) --- */

/* Fix Modo Oscuro para Inputs Nativos */
.form-input, input[type="text"], input[type="month"], input[type="date"], input[type="number"], select {
    background-color: var(--color-background-card) !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border) !important;
}

.dark input[type="date"], .dark input[type="month"], .dark input[type="datetime-local"] {
    color-scheme: dark; 
}

/* Navegación de Pestañas */
.tabs-header { 
    display: flex; 
    gap: 15px; 
    border-bottom: 1px solid var(--color-border); 
    margin-bottom: 20px; 
    overflow-x: auto; 
    padding-bottom: 0;
}
.tab-btn {
    padding: 12px 20px; 
    border: none; 
    background: none; 
    cursor: pointer;
    font-weight: 600; 
    color: var(--color-text-secondary);
    border-bottom: 3px solid transparent; 
    transition: all 0.2s; 
    white-space: nowrap;
    font-size: 0.95rem;
    display: flex; align-items: center; gap: 8px;
}
.tab-btn:hover { 
    color: var(--color-accent); 
    background: var(--color-hover-background); 
    border-top-left-radius: 6px; border-top-right-radius: 6px;
}
.tab-btn.active { 
    color: var(--color-accent); 
    border-bottom-color: var(--color-accent); 
    background: var(--color-hover-background);
    border-top-left-radius: 6px; border-top-right-radius: 6px;
}

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Badges y Botones de Acción */
.status-badge { display: inline-block; padding: 3px 8px; font-size: 0.7rem; font-weight: 600; border-radius: 99px; text-transform: uppercase; }
.status-autorizado { background: #dcfce7; color: #166534; }
.status-no_autorizado { background: #fee2e2; color: #991b1b; }
.status-enviado { background: #e0f2fe; color: #075985; }
.status-generado { background: #fef9c3; color: #854d0e; }
.status-cancelado { background: #f3f4f6; color: #374151; }

.action-btn { padding: 4px 8px; border-radius: 4px; border: 1px solid transparent; cursor: pointer; transition: all 0.2s; }
.btn-pdf { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.btn-pdf:hover { background: #fee2e2; }
.btn-xml { color: #4b5563; border-color: #e5e7eb; background: #f9fafb; }
.btn-success-soft { background:#dcfce7; color:#166534; border-color:#bbf7d0; }
.btn-success-soft:hover { background:#bbf7d0; }

/* Dashboard Fiscal */
.fiscal-dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.metric-card { background: var(--color-background-card); border: 1px solid var(--color-border); border-radius: 12px; padding: 1.5rem; box-shadow: var(--color-shadow); position: relative; }
.metric-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: 4px 0 0 4px; }

.card-sales::before { background: #3b82f6; }
.card-expenses::before { background: #ef4444; }
.card-balance::before { background: #10b981; }

.metric-value { font-size: 1.8rem; font-weight: 800; color: var(--color-text-primary); }
.metric-label { font-size: 0.85rem; color: var(--color-text-secondary); text-transform: uppercase; font-weight: 700; display: flex; justify-content: space-between; }
.metric-sub { font-size: 0.8rem; color: var(--color-text-secondary); }

.upload-label { display: block; border: 2px dashed var(--color-border); border-radius: 8px; padding: 2rem; text-align: center; cursor: pointer; transition: all 0.2s; }
.upload-label:hover { border-color: var(--color-accent); background: var(--color-hover-background); }
.upload-label.ready { border-color: #10b981; background: #ecfdf5; }

.chart-box { background: var(--color-background-card); padding: 20px; border-radius: 12px; border: 1px solid var(--color-border); height: 350px; position: relative; }

.cat-select { width: 100%; padding: 4px; border-radius: 4px; border: 1px solid var(--color-border); font-size: 0.8rem; cursor: pointer; }
.sel-negocio { background-color: #f0fdf4; color: #166534; border-color: #86efac; }
.sel-personal { background-color: #fef2f2; color: #991b1b; border-color: #fca5a5; }