/* static/css/style.css */
@import url('[https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap](https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap)');

body {
    font-family: 'Inter', sans-serif;
    background-color: #f3f4f6;
}
/* --- 1. ESTRUCTURA PRINCIPAL Y SIDEBAR ESTÁTICO --- */
.app-container {
    display: flex;
}
.sidebar {
    width: 220px; /* Ancho reducido */
    background-color: #fff7ed; /* Naranja claro (Tailwind orange-50) */
    border-right: 1px solid #fed7aa; /* Naranja más oscuro (orange-200) */
    padding: 1rem;
    display: flex;
    flex-direction: column;
    position: fixed; /* Barra lateral estática */
    height: 100vh;
    top: 0;
    left: 0;
}
.main-content {
    flex-grow: 1;
    margin-left: 220px; /* Mismo ancho que el sidebar para evitar superposición */
    overflow-y: auto;
}
/* --- 2. ESTILOS DEL SIDEBAR --- */
.sidebar-header {
    margin-bottom: 2rem;
    padding: 0.5rem 0;
}
.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.nav-button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    font-weight: 500;
    color: #9a3412; /* Naranja oscuro (orange-800) */
    transition: background-color 0.2s ease, color 0.2s ease;
    text-decoration: none;
}
.nav-button:hover {
    background-color: #fed7aa; /* Naranja más oscuro (orange-200) */
    color: #7c2d12; /* Naranja más oscuro (orange-900) */
}
.nav-button.active {
    background-color: #fb923c; /* Naranja principal (orange-400) */
    color: #ffffff;
    font-weight: 600;
}

/* --- 3. ESTILOS DE TÍTULOS MODERNOS --- */
.content-header h1 {
    font-size: 2.25rem; /* Más grande */
    font-weight: 800; /* Extra bold */
    color: #1f2937; /* gray-800 */
    letter-spacing: -0.025em; /* Ligeramente más junto */
}

/* Estilos para los mensajes Flash */
.flash-messages-container {
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 40;
}
.flash {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 0.375rem;
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}
.flash.success { background-color: #10b981; }
.flash.danger { background-color: #ef4444; }
.flash.warning { background-color: #f59e0b; }
.flash.info { background-color: #3b82f6; }
.flash-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

/* Estilos para las tablas */
thead { background-color: #f9fafb; }
th {
    padding: 12px 24px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
}
td {
    padding: 12px 24px;
    font-size: 0.875rem;
    color: #374151;
}

/* Estilos para formularios */
.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.form-input {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #D1D5DB;
    border-radius: 0.375rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* Estilos para las tarjetas de presupuesto */
.status-badge {
    display: inline-block;
    padding: 0.25em 0.6em;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.375rem;
}

/* Estilos para las secciones desplegables del detalle de presupuesto */
details > summary {
    list-style: none; /* Oculta el marcador por defecto */
}
details > summary::-webkit-details-marker {
    display: none; /* Oculta el marcador en Chrome/Safari */
}
.details-section {
    background-color: #ffffff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
}
.details-summary {
    padding: 1rem;
    font-weight: 700;
    font-size: 1.125rem;
    cursor: pointer;
    border-radius: 0.5rem 0.5rem 0 0;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
}
.details-summary:hover {
    background-color: #f9fafb;
}
.details-summary::before {
    content: '►';
    margin-right: 0.75rem;
    font-size: 0.8em;
    transition: transform 0.2s ease-in-out;
    display: inline-block;
}
details[open] > .details-summary::before {
    transform: rotate(90deg);
}

.details-subsection {
    background-color: #f9fafb; /* Un gris más suave para anidar */
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
}
.details-summary-subsection {
    padding: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    border-radius: 0.375rem 0.375rem 0 0;
    display: flex;
    align-items: center;
}
.details-summary-subsection:hover {
    background-color: #f3f4f6;
}
.details-summary-subsection::before {
    content: '►';
    margin-right: 0.5rem;
    font-size: 0.7em;
    transition: transform 0.2s ease-in-out;
    display: inline-block;
}
details[open] > .details-summary-subsection::before {
    transform: rotate(90deg);
}

/* Estilos para la tabla de resumen */
.summary-table {
    border-top: 1px solid #e5e7eb; /* gray-200 */
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}
.summary-row.total {
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1.75rem;
    border-top-width: 2px;
    border-color: #d1d5db; /* gray-300 */
    padding-top: 0.75rem;
}

/* **CAMBIO REALIZADO:** Nuevos estilos para el spinner de carga */
.spinner {
    border: 2px solid #f3f3f3; /* Light grey */
    border-top: 2px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* **NUEVO:** Estilos para la barra de estado del presupuesto */
.status-bar-container {
    background-color: #ffffff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-radius: 0.375rem;
    color: #ffffff;
    border: 1px solid transparent;
}

.status-text strong {
    font-weight: 600;
}

.status-actions form {
    margin: 0;
}

.action-button-success, .action-button-danger, .action-button-secondary {
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    color: white;
}

.action-button-success { background-color: #16a34a; } /* green-600 */
.action-button-success:hover { background-color: #15803d; } /* green-700 */

.action-button-danger { background-color: #dc2626; } /* red-600 */
.action-button-danger:hover { background-color: #b91c1c; } /* red-700 */

.action-button-secondary { background-color: #4b5563; } /* gray-600 */
.action-button-secondary:hover { background-color: #374151; } /* gray-700 */


/* Colores de fondo para cada estado */
.estado-borrador {
    background-color: #e5e7eb; /* gray-200 */
    color: #1f2937; /* gray-800 */
    border-color: #d1d5db; /* gray-300 */
}
.estado-borrador .action-button-success { background-color: #2563eb; color: white; } /* blue-600 */
.estado-borrador .action-button-success:hover { background-color: #1d4ed8; } /* blue-700 */

.estado-por-revisar {
    background-color: #fef9c3; /* yellow-100 */
    color: #854d0e; /* yellow-800 */
    border-color: #fde68a; /* yellow-300 */
}

.estado-aprobado {
    background-color: #dcfce7; /* green-100 */
    color: #166534; /* green-800 */
    border-color: #86efac; /* green-300 */
}

.estado-rechazado {
    background-color: #fee2e2; /* red-100 */
    color: #991b1b; /* red-800 */
    border-color: #fca5a5; /* red-300 */
}

/* **NUEVO:** Estilo para el botón de exportar a PDF */
.action-button-pdf {
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    color: white;
    background-color: #dc2626; /* Color rojo (red-600) */
    text-decoration: none; /* Asegura que no tenga subrayado de link */
    display: inline-block;
}
.action-button-pdf:hover {
    background-color: #b91c1c; /* Color rojo más oscuro (red-700) */
}

/* === NUEVO: Estilos para la Lista de Contratos === */

/* Contenedor del encabezado de la página (título y botones) */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem 1.5rem;
}

.content-header h1 {
    font-size: 1.875rem; /* 30px */
    font-weight: 700;
    color: #1f2937; /* gray-800 */
}

.actions-container {
    display: flex;
    gap: 1rem;
}

.button-primary {
    background-color: #2563eb; /* blue-600 */
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s;
}
.button-primary:hover {
    background-color: #1d4ed8; /* blue-700 */
}

/* === NUEVO: Estilos para la Lista de Contratos Jerárquica === */
.contract-list-container {
    background-color: #ffffff;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.contract-item-group {
    border-bottom: 1px solid #e5e7eb;
}
.contract-item-group:last-child {
    border-bottom: none;
}

.contract-parent {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    cursor: pointer;
    list-style: none; /* Oculta el triángulo por defecto */
    transition: background-color 0.2s;
}
.contract-parent:hover {
    background-color: #f9fafb;
}
/* Triángulo para indicar que es desplegable */
.contract-parent::-webkit-details-marker { display: none; }
.contract-parent::before {
    content: '►';
    font-size: 0.7em;
    margin-right: 1rem;
    transition: transform 0.2s;
}
details[open] > .contract-parent::before {
    transform: rotate(90deg);
}

.contract-name {
    font-weight: 600;
    color: #111827;
    flex: 2; /* Ocupa más espacio */
}
.contract-code {
    font-family: monospace;
    color: #4b5563;
    margin: 0 1rem;
    flex: 1;
}
.contract-customer {
    color: #374151;
    margin: 0 1rem;
    flex: 2;
}
.contract-parent .card-actions {
    margin-left: auto; /* Empuja las acciones a la derecha */
}

.contract-children {
    padding-left: 3rem; /* Indentación para los hijos */
    border-top: 1px dashed #e5e7eb;
}

.contract-child {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: #f9fafb;
    border-top: 1px solid #e5e7eb;
}
.anexo-icon {
    margin-right: 0.75rem;
    color: #6b7280;
}
.contract-child .card-actions {
    margin-left: auto;
}

.contract-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.card-header, .card-body, .card-footer {
    padding: 1rem 1.25rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid #e5e7eb;
}

.card-header h3 {
    font-size: 1.125rem; /* 18px */
    font-weight: 600;
    color: #111827; /* gray-900 */
}

.card-code {
    font-family: monospace;
    background-color: #f3f4f6; /* gray-100 */
    color: #4b5563; /* gray-600 */
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
}

.card-body {
    flex-grow: 1;
}

.card-body p {
    margin: 0.5rem 0;
    color: #374151; /* gray-700 */
}

.card-footer {
    background-color: #f9fafb; /* gray-50 */
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

/* Etiquetas para tipo y divisa */
.card-tags {
    display: flex;
    gap: 0.3rem;
}
.tag {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25em 0.6em;
    border-radius: 9999px;
}
.type-general { background-color: #dbeafe; color: #1e40af; } /* blue-100/blue-800 */
.currency-clp { background-color: #dcfce7; color: #166534; } /* green-100/green-800 */
.currency-usd { background-color: #ccfbf1; color: #0f766e; } /* teal-100/teal-800 */
.currency-uf { background-color: #e0e7ff; color: #3730a3; } /* indigo-100/indigo-800 */

/* Botones de acción en la tarjeta */
.card-actions {
    display: flex;
    gap: 0.75rem;
}
.action-button {
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s;
}
.detail { color: #059669; } /* green-600 */
.detail:hover { color: #047857; } /* green-700 */
.edit { color: #4f46e5; } /* indigo-600 */
.edit:hover { color: #3730a3; } /* indigo-800 */
.delete { color: #dc2626; background: none; border: none; padding: 0; cursor: pointer; } /* red-600 */
.delete:hover { color: #b91c1c; } /* red-700 */

/* === NUEVO: Estilos para la Página de Detalle del Contrato === */

/* Rejilla principal para las tarjetas de detalle */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
}

/* Estilo para cada tarjeta de información */
.detail-card {
    background-color: #ffffff;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
}

.detail-card h2 {
    font-size: 1.25rem; /* 20px */
    font-weight: 600;
    color: #111827;
    margin-top: 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.75rem;
}

/* Estilo para cada item dentro de una tarjeta (ej. Label: Valor) */
.detail-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dotted #e5e7eb;
}
.detail-item:last-child {
    border-bottom: none;
}
.detail-item label {
    font-weight: 500;
    color: #4b5563; /* gray-600 */
}
.detail-item p {
    color: #1f2937; /* gray-800 */
    margin: 0;
}

/* Estilo para la tarjeta de detalles financieros */
.financial-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.financial-value {
    font-weight: 600;
    font-size: 1.1rem;
}

.full-width {
    grid-column: 1 / -1; /* Hace que la tarjeta ocupe todo el ancho */
}

/* Divisor de secciones */
.section-divider {
    border: 0;
    height: 1px;
    background-color: #e5e7eb;
    margin: 2rem 1.5rem;
}

/* Contenedor para las tablas de líneas de negocio y archivos */
.table-container {
    padding: 0 1.5rem 1.5rem;
}
.table-container table {
    width: 100%;
    border-collapse: collapse;
}
.table-container th, .table-container td {
    border: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
    text-align: left;
}
.table-container thead {
    background-color: #f9fafb;
}
.table-container th {
    font-weight: 600;
    color: #374151;
}

.actions-cell {
    text-align: right;
}

.file-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}
.file-link:hover {
    text-decoration: underline;
}

/* Estilos para los modales que ya podrían estar definidos pero se aseguran */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.5rem;
    max-width: 500px;
    width: 100%;
}

/* --- ESTILOS PARA LA NUEVA VISTA DE TARJETAS DE CONTRATO (VERSIÓN COMPACTA) --- */
.contract-card {
    background-color: #ffffff;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
}
.contract-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.08);
}
.card-header {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem; /* Reducido */
    border-bottom: 1px solid #f3f4f6;
}
.card-title {
    font-size: 1rem; /* Reducido */
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.1rem;
}
.card-customer {
    font-size: 0.8rem; /* Reducido */
    color: #6b7280;
}
.card-code {
    font-family: monospace;
    background-color: #f3f4f6;
    color: #4b5563;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem; /* Reducido */
    align-self: flex-start;
}
.card-body {
    padding: 1rem; /* Reducido */
    flex-grow: 1;
}
.card-financials {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}
.card-amount {
    font-size: 1.5rem; /* Reducido */
    font-weight: 700;
    color: #111827;
}
.card-currency {
    font-weight: 500;
    color: #4b5563;
    font-size: 0.9rem;
}
.card-children {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #e5e7eb;
}
.card-children-title {
    font-size: 0.7rem; /* Reducido */
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
    margin-bottom: 0.4rem;
}
.card-children ul {
    list-style-type: none;
    padding-left: 0;
    font-size: 0.8rem; /* Reducido */
    color: #374151;
}
.card-footer {
    padding: 0.75rem 1rem; /* Reducido */
    background-color: #f9fafb;
    border-top: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- INICIO: Nuevos colores para etiquetas de tipo de contrato --- */
.tag.type-contrato-general {
    background-color: #dcfce7; /* green-100 */
    color: #166534; /* green-800 */
}
.tag.type-anexo {
    background-color: #dbeafe; /* blue-100 */
    color: #1e40af; /* blue-800 */
}
.tag.type-orden-de-compra {
    background-color: #ffedd5; /* orange-100 */
    color: #9a3412; /* orange-800 */
}
/* --- FIN: Nuevos colores para etiquetas de tipo de contrato --- */

/* --- INICIO: Estilos para la lista de Anexos en la tarjeta de Contrato --- */
.child-contract-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid #f3f4f6;
}
.child-contract-item:last-child {
    border-bottom: none;
}
.child-contract-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: #4f46e5; /* indigo-600 */
    text-decoration: none;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    background-color: #e0e7ff; /* indigo-100 */
    transition: background-color 0.2s, color 0.2s;
}
.child-contract-link:hover {
    background-color: #c7d2fe; /* indigo-200 */
    color: #3730a3; /* indigo-800 */
}
/* --- FIN: Estilos para la lista de Anexos --- */

/* --- INICIO: Estilos para montos de contrato en tarjeta --- */
.card-financials {
    display: flex;
    flex-direction: row; /* Coloca los items uno al lado del otro */
    justify-content: space-between; /* Espacio entre "Contrato" y "Total" */
    align-items: baseline;
    flex-wrap: wrap; /* Permite que se envuelva si no hay espacio */
    margin-bottom: 0.75rem;
    border-top: 1px dashed #e5e7eb; /* Separador visual */
    padding-top: 0.75rem;
}

.financial-item {
    display: flex;
    flex-direction: column; /* Apila la etiqueta sobre el monto */
}

.financial-label {
    font-size: 0.7rem; /* Etiqueta más pequeña */
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
}

.financial-amount-wrapper {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}

.card-amount, .card-amount-total {
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

.card-currency {
    font-weight: 500;
    color: #4b5563;
    font-size: 0.8rem;
}

/* Alinea el total a la derecha */
.financial-item.total {
    align-items: flex-end;
}

.financial-item.total .card-amount-total,
.financial-item.total .financial-label {
    color: #166534; /* Verde oscuro para resaltar */
}
/* --- FIN: Estilos para montos de contrato en tarjeta --- */