/**
 * Estilos Modernos y Responsivos para el Sistema de Presupuesto Escolar
 * TuBackup.cl
 */

:root {
    --primary-color: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-dark: #172554;
    --secondary-color: #0d9488;
    --success-color: #16a34a;
    --warning-color: #ca8a04;
    --danger-color: #dc2626;
    --info-color: #0284c7;
    --bg-light: #f8fafc;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --card-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-light);
    color: #1e293b;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    width: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: rgba(30, 58, 138, 0.1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Compatibilidad Cross-Browser y Multiplataforma (Windows, macOS, iOS, Android) */
* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

button, .btn, .nav-link, .dropdown-item, .card-item-depto {
    touch-action: manipulation;
}

html {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Navbar */
.navbar-custom {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    width: 100%;
    z-index: 1030;
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: -0.5px;
    font-size: 1.15rem;
}

.navbar-custom .nav-link {
    font-weight: 500;
    font-size: 0.84rem;
    transition: all 0.2s ease;
    border-radius: 6px;
    padding: 0.42rem 0.55rem !important;
    white-space: nowrap;
}

.navbar-custom .nav-link:hover, .navbar-custom .nav-link.active {
    background-color: rgba(255, 255, 255, 0.18);
    color: #ffffff !important;
}

/* Tarjetas y Contenedores */
.card-custom {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.card-custom:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header-custom {
    background-color: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-weight: 600;
    border-top-left-radius: 12px !important;
    border-top-right-radius: 12px !important;
}

/* Estilo para las Tarjetas Resumen Tipo Planilla (como la foto enviada) */
.budget-kpi-card {
    border-radius: 10px;
    padding: 1.1rem;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    position: relative;
    overflow: hidden;
}

.budget-kpi-card.aprobado {
    background: #fffbeb;
    border-color: #fde68a;
}

.budget-kpi-card.solicitado {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.budget-kpi-card.diferencia-ok {
    background: #f0fdfa;
    border-color: #99f6e4;
}

.budget-kpi-card.diferencia-negativa {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.budget-kpi-card.diferencia-negativa .kpi-value {
    color: #dc2626 !important;
    font-weight: 800;
}

.budget-kpi-card .kpi-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.budget-kpi-card .kpi-value {
    font-size: 1.45rem;
    font-weight: 700;
    color: #0f172a;
}

/* Estilo idéntico a la tabla resumen superior de la imagen */
.table-resumen-presupuesto {
    border: 2px solid #334155;
    background: #ffffff;
}

.table-resumen-presupuesto th {
    background-color: #f1f5f9;
    font-weight: 700;
    font-size: 0.85rem;
    text-align: center;
    border: 1px solid #cbd5e1;
    padding: 8px;
}

.table-resumen-presupuesto td {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
}

.cell-aprobado {
    background-color: #fed7aa !important; /* Tono durazno/dorado como en la imagen de Google Sheets */
    color: #431407;
    font-weight: 700;
}

.cell-diferencia-alerta {
    background-color: #ef4444 !important; /* Rojo vivo de alerta cuando sobrepasa presupuesto */
    color: #ffffff !important;
    font-weight: 800;
    text-align: right;
}

.cell-diferencia-positiva {
    background-color: #ecfdf5 !important;
    color: #065f46 !important;
    font-weight: 700;
    text-align: right;
}

/* Tabla del Presupuesto Dinámico */
.table-presupuesto-grid {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    overflow: hidden;
}

.table-presupuesto-grid thead th {
    background: #e2e8f0;
    color: #1e293b;
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    padding: 10px;
    border-bottom: 2px solid #94a3b8;
    vertical-align: middle;
}

.table-presupuesto-grid tbody tr:hover {
    background-color: #f8fafc;
}

.table-presupuesto-grid tbody td {
    padding: 9px;
    vertical-align: middle;
    font-size: 0.88rem;
    border-top: 1px solid #e2e8f0;
}

/* Badges y chips */
.badge-general {
    background-color: #0284c7;
    color: white;
    font-weight: 600;
}

.badge-sep {
    background-color: #7c3aed;
    color: white;
    font-weight: 600;
}

.badge-pie {
    background-color: #0d9488;
    color: white;
    font-weight: 600;
}

.bg-pie {
    background-color: #0d9488 !important;
}

.text-pie {
    color: #0d9488 !important;
}

.border-pie {
    border-color: #0d9488 !important;
}

.badge-adicional {
    background-color: #ea580c;
    color: white;
    font-weight: 600;
}

/* Botones flotantes de acción rápida */
.btn-action-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Footer */
footer {
    margin-top: auto;
    background-color: #ffffff;
    border-top: 1px solid #e2e8f0;
    padding: 1rem 0;
    font-size: 0.85rem;
    color: #64748b;
}

/* Estilos de impresión para sacar informes limpios */
@media print {
    .no-print, .navbar, footer, .btn, .card-header .btn-group {
        display: none !important;
    }
    body {
        background-color: #ffffff !important;
    }
    .card-custom {
        border: none !important;
        box-shadow: none !important;
    }
}

/* ==========================================================================
   Tom Select - Buscador Inteligente en Selects
   ========================================================================== */
.ts-wrapper.form-select {
    padding: 0 !important;
    border: none !important;
}

.ts-control {
    border: 1px solid #ced4da !important;
    border-radius: 8px !important;
    padding: 0.55rem 0.85rem !important;
    font-size: 0.95rem !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    background-color: #ffffff !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
}

.ts-wrapper.focus .ts-control {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.2) !important;
}

.ts-dropdown {
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
    z-index: 1065 !important;
    margin-top: 4px !important;
    overflow: hidden !important;
    background-color: #ffffff !important;
}

.ts-dropdown .ts-dropdown-content {
    max-height: 280px !important;
    padding: 4px 0 !important;
}

.ts-dropdown .option {
    cursor: pointer !important;
    transition: background-color 0.12s ease !important;
    padding: 8px 12px !important;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background-color: #f1f5f9 !important;
}

.ts-dropdown .option.selected {
    background-color: #eff6ff !important;
}

.ts-dropdown .highlight {
    background-color: #fef08a !important;
    color: #854d0e !important;
    font-weight: 700 !important;
    padding: 0 2px !important;
    border-radius: 2px !important;
}

/* ==========================================================================
   DISEÑO RESPONSIVO (MÓVILES, TABLETS Y ESCRITORIO)
   ========================================================================== */

/* 1. Comportamiento Táctil y Scroll Horizontal en Tablas */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    border-radius: 8px;
    position: relative;
    max-width: 100%;
}

/* Scrollbar sutil y estilizado para dispositivos táctiles */
.table-responsive::-webkit-scrollbar {
    height: 7px;
}
.table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Anchos mínimos seguros para mantener legibilidad sin aplastar columnas */
.table-presupuesto-grid {
    min-width: 880px;
}
.table-resumen-presupuesto {
    min-width: 520px;
}
#tablaItems {
    min-width: 820px;
}
#tablaUsuarios, #tablaArticulos, #tablaDepartamentos, #tablaCentrosCosto, #tablaProveedores, #tablaDeptosResumen {
    min-width: 760px;
}
#tablaControlPresupuesto {
    min-width: 1200px;
}
#tablaAutorizacionesItems,
.table-autorizaciones-items {
    min-width: 860px;
}
.table-solicitudes {
    min-width: 820px;
}

/* Evitar que botones de acciones se quiebren en 2 líneas */
.table td.text-end, 
.table td.pe-3,
.table td .btn-group {
    white-space: nowrap !important;
}

/* Reglas de Escala para Computadores Portátiles y Pantallas Medianas (1200px a 1440px) */
@media (min-width: 1200px) and (max-width: 1440px) {
    .navbar-custom .nav-link {
        font-size: 0.80rem !important;
        padding: 0.35rem 0.45rem !important;
    }
    .navbar-custom .navbar-brand {
        font-size: 1.05rem;
    }
    .brand-logo-img {
        max-width: 110px !important;
        height: 32px !important;
    }
    .header-year-select {
        max-width: 130px !important;
    }
}

/* 2. Reglas para Tablets y Celulares (< 1200px) */
@media (max-width: 1199.98px) {
    .navbar-brand {
        font-size: 1.1rem;
    }
    .brand-logo-img {
        max-width: 120px !important;
        height: 34px !important;
    }
    
    /* Menú móvil desplegado */
    .navbar-collapse {
        background: rgba(15, 23, 42, 0.98);
        border-radius: 12px;
        padding: 1rem;
        margin-top: 0.5rem;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
        max-height: 85vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .navbar-nav .nav-link {
        padding: 0.65rem 0.85rem !important;
        font-size: 0.95rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }
    
    .navbar-nav .dropdown-menu {
        background-color: rgba(255, 255, 255, 0.96);
        border-radius: 8px;
        margin: 0.25rem 0.5rem;
        border: 0;
    }
    
    .navbar-nav .dropdown-item {
        color: #1e293b !important;
        padding: 0.5rem 1rem;
    }

    .header-year-select {
        max-width: 100% !important;
    }
}

/* Selector de Año Fiscal en Escritorio */
.header-year-select {
    min-width: 125px;
    max-width: 180px;
}

/* 3. Reglas para Smartphones (< 768px) */
@media (max-width: 767.98px) {
    /* Prevención de desbordamiento horizontal en todo el viewport */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Tipografía adaptable */
    h1, .h1 { font-size: 1.4rem !important; }
    h2, .h2 { font-size: 1.25rem !important; }
    h3, .h3 { font-size: 1.1rem !important; }
    
    .brand-title {
        font-size: 0.95rem !important;
    }
    .brand-subtitle {
        font-size: 0.65rem !important;
    }
    .brand-logo-img {
        max-width: 95px !important;
        height: 30px !important;
    }

    /* Reducción inteligente de padding en tarjetas para aprovechar el ancho */
    .card-custom, .card {
        border-radius: 10px;
    }
    .card-custom.p-3, .card-custom.p-4 {
        padding: 0.85rem !important;
    }
    .card-body {
        padding: 0.85rem !important;
    }
    .card-header-custom {
        padding: 0.75rem 0.85rem;
    }

    /* Campos de formulario con tamaño adecuado (evita auto-zoom en iOS Safari) */
    .form-control, .form-select, .ts-control {
        font-size: 16px !important;
        min-height: 42px !important;
    }

    /* Botones táctiles cómodos */
    .btn {
        min-height: 38px;
        font-size: 0.88rem;
    }
    .btn-sm {
        min-height: 34px;
        font-size: 0.82rem;
        padding: 0.35rem 0.65rem;
    }

    /* Pestañas de Workflow apiladas o desplazables */
    .nav-pills {
        gap: 0.35rem;
    }
    .nav-pills .nav-link {
        text-align: left;
        margin-bottom: 0.25rem;
        padding: 0.55rem 0.75rem;
        font-size: 0.85rem;
    }

    /* Tarjetas KPI de presupuesto */
    .budget-kpi-card {
        padding: 0.75rem;
    }
    .budget-kpi-card .kpi-value {
        font-size: 1.15rem;
    }
    .budget-kpi-card .kpi-label {
        font-size: 0.68rem;
    }

    /* Formularios y Filtros */
    form.row.g-2 > div[class*="col-"] {
        margin-bottom: 0.35rem;
    }

    /* Diálogos modales ocupan pantalla cómoda con scroll interno */
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: 96%;
    }
    .modal-content {
        max-height: calc(100vh - 1rem);
    }
    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1rem 0.85rem;
    }
    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .modal-footer .btn {
        flex: 1 1 auto;
    }

    /* Paginadores y tablas responsivas */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 2px;
    }

    /* Ajuste en barras de progreso */
    .progress {
        height: 8px !important;
    }
}

/* 4. Reglas para Teléfonos Muy Pequeños (< 420px) */
@media (max-width: 419.98px) {
    .container-fluid {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    .btn {
        font-size: 0.82rem;
    }
    .badge {
        font-size: 0.70rem !important;
    }
}

/* 5. Visores de Documentos PDF y Órdenes de Compra en Pantallas Pequeñas */
@media screen and (max-width: 850px) {
    .oc-sheet-wrapper, .pdf-sheet-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 4px;
        box-sizing: border-box;
    }
    
    .oc-actions-bar, .no-print-toolbar {
        padding: 10px 12px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .oc-actions-bar .btn, .no-print-toolbar .btn-action {
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }
    
    .oc-sheet, .page-sheet {
        margin: 8px auto !important;
    }
}

/* 6. Optimizaciones para Selector Rápido de Departamentos en Celulares */
@media (max-width: 575.98px) {
    .ajax-deptos-container .btn-group .btn {
        font-size: 0.75rem !important;
        padding: 0.35rem 0.4rem !important;
    }
    .card-item-depto .card-body {
        padding: 0.75rem !important;
    }
}



