/* ==========================================================
   TABLAS CRUD
========================================================== */

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.table {
    font-size: 0.9rem;
}

th,
td {
    border: 1px solid #ccc;
    padding: 4px;
    vertical-align: middle;
    white-space: normal;
    word-break: break-word;
}

th {
    background: #eee;
    text-align: center;
    font-weight: 600;
}

td {
    text-align: left;
}

.table-hover tbody tr:hover {
    background-color: #f5f7fa;
}

th.acciones,
td.acciones {
    width: 90px;
    text-align: center;
}


/* ==========================================================
   FILTROS POR COLUMNA
========================================================== */

thead select.form-select {
    font-size: 0.75rem;
    padding: 2px 6px;
    height: 28px;
}

thead th {
    min-width: 110px;
}

.uandes-filter-row th {
    background: #f8f9fb;
    padding: 6px 8px;
    border-bottom: 1px solid #e5e7eb;
}

.uandes-filter-input {
    width: 90%;
    height: 28px;
    font-size: 0.75rem;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #1f2937;
    background: #ffffff;
}

.uandes-filter-input::placeholder {
    color: #9ca3af;
    font-style: italic;
}

.uandes-filter-input:focus {
    outline: none;
    border-color: #d71920;
    box-shadow: 0 0 0 1px rgba(215, 25, 32, 0.25);
}

.uandes-filter-select {
    width: 100%;
    height: 26px;
    font-size: 0.75rem;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    color: #4b5563;
    background: #ffffff;
}

.uandes-filter-select:focus {
    outline: none;
    border-color: #d71920;
    box-shadow: 0 0 0 1px rgba(215, 25, 32, 0.25);
}

.uandes-btn-filter {
    width: 100%;
    height: 28px;
    font-size: 0.75rem;
    font-weight: 500;
    background: #d71920;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.uandes-btn-filter:hover {
    background: #b9151b;
}

.app-body:has(.uandes-list-container) {
    height: 100vh;
    overflow: hidden;
}

.main-wrapper:has(.uandes-list-container) {
    height: 100vh;
    padding: 84px 20px 12px;
    overflow: hidden;
    box-sizing: border-box;
}

.uandes-list-header {
    position: sticky;
    top: 0;
    z-index: 60;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    margin-bottom: 2px;
    padding: 10px 0;
    flex-wrap: wrap;
}

.uandes-list-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.uandes-list-header .uandes-title {
    margin-right: auto;
}

.uandes-list-header .btn-add {
    white-space: nowrap;
}

.uandes-table-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
}

.uandes-filter-form {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

.app-body:has(.uandes-form-container) {
    height: 100vh;
    overflow: hidden;
}

.main-wrapper:has(.uandes-form-container) {
    height: 100vh;
    padding: 84px 20px 12px;
    overflow: hidden;
    box-sizing: border-box;
}

.uandes-form-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.uandes-form-container > .uandes-header {
    flex: 0 0 auto;
    margin-bottom: 8px;
}

.uandes-form-container .crud-form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.uandes-form-container .folder-form-card {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    margin-top: 0;
}

.uandes-form-container .folder-tabs {
    flex: 0 0 auto;
}

.uandes-form-container .folder-content,
.uandes-form-container .form-card {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
}

.uandes-form-container .form-actions {
    flex: 0 0 auto;
    margin-top: 10px;
}

.uandes-table thead th {
    position: sticky;
    z-index: 20;
}

.uandes-table .uandes-th-row th {
    top: 0;
    padding: 6px 8px;
    min-height: 54px;
    height: 54px;
    line-height: 1.15;
    font-size: 0.78rem;
    vertical-align: middle;
}

.uandes-table .uandes-filter-row th {
    top: 54px;
    padding: 2px 6px;
    height: 28px;
    background: #ffffff;
    vertical-align: middle;
}

.uandes-table .uandes-filter-input,
.uandes-table .uandes-filter-select,
.uandes-table .uandes-filter-input-hybrid {
    height: 26px;
    min-height: 26px;
    font-size: 0.72rem;
    padding: 2px 6px;
}

.form-group input[type="checkbox"],
.form-check-input,
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-height: 18px;
    padding: 0;
    align-self: flex-start;
}

.uandes-filter-status {
    min-width: 70px;
    text-align: center;
}

.uandes-filter-status span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    min-width: 44px;
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    color: #64748b;
    background: #f8fafc;
    font-size: 0.68rem;
    font-weight: 700;
}


/* ==========================================================
   PAGINACIÓN
========================================================== */

.pagination {
    --bs-pagination-color: #d71920;
    --bs-pagination-hover-color: #b9151b;
    --bs-pagination-active-bg: #d71920;
    --bs-pagination-active-border-color: #d71920;
    font-size: 0.9rem;
}

.pagination .page-link {
    padding: 0.35rem 0.75rem;
    border-radius: 0.35rem;
    margin: 0 0.15rem;
}

.pagination-horizontal {
    background: #f5f6f9;
    padding: 0.4rem 0.6rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pagination input[type="number"] {
    height: 30px;
    width: 70px;
    font-size: 0.8rem;
    text-align: center;
}


/* ==========================================================
   FACETS / CATEGORÍAS
========================================================== */

.facet-box {
    max-height: 120px;
    overflow-y: auto;
    border: 1px solid #ddd;
    background: #ffffff;
    padding: 4px;
    font-size: 0.75rem;
}

.facet-item {
    display: block;
    padding: 2px 4px;
    color: #d71920;
}

.facet-item:hover {
    background: rgba(215, 25, 32, 0.08);
}


/* ==========================================================
   UANDES DETAIL / LIST
========================================================== */

.uandes-container {
    max-width: 1400px;
    margin: auto;
}

.uandes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #e5e5e5;
    padding-bottom: 10px;
}

.uandes-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: #1c2b39;
}

.uandes-back {
    font-size: 0.85rem;
    color: #d71920;
    text-decoration: none;
}

.uandes-back:hover {
    color: #b9151b;
    text-decoration: underline;
}

.uandes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.uandes-table th {
    background: #f3f5f7;
    font-weight: 600;
    color: #1c2b39;
    padding: 8px;
}

.uandes-table td {
    padding: 8px;
    border-bottom: 1px solid #e5e5e5;
}

.uandes-actions {
    text-align: center;
    width: 90px;
}

.uandes-btn-view {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.8rem;
    border: 1px solid #d71920;
    color: #d71920;
    border-radius: 4px;
    text-decoration: none;
}

.uandes-btn-view:hover {
    background: #d71920;
    color: #ffffff;
}

.uandes-pagination {
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}


/* ==========================================================
   INPUT HÍBRIDO TEXT + DATALIST
========================================================== */

.uandes-filter-input-hybrid {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    height: 38px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background-color: #ffffff;
    font-size: 14px;
    color: #1f2937;
    box-sizing: border-box;
}

.uandes-filter-input-hybrid:focus {
    outline: none;
    border-color: #d71920;
    box-shadow: 0 0 0 2px rgba(215, 25, 32, 0.15);
}

.uandes-filter-input-hybrid::placeholder {
    color: #9ca3af;
}


/* ==========================================================
   TARJETAS / SELECT2
========================================================== */

.crud-card {
    border-radius: 0.75rem;
}

.select2-disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.select2-container--disabled .select2-selection {
    background-color: #f0f0f0 !important;
    cursor: not-allowed !important;
}

.select2-container--disabled .select2-selection__choice {
    opacity: 0.6;
}


/* ==========================================================
   FORMULARIOS CRUD CON PESTAÑAS TIPO CARPETA
========================================================== */

.form-page-header {
    margin-bottom: 1.5rem;
}

.crud-form {
    width: 100%;
}

.folder-form-card {
    margin-top: 1rem;
}

.form-completion-summary {
    margin: 0 0 0.85rem;
    padding: 0.85rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
}

.form-completion-summary-text {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.55rem;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 600;
}

.form-completion-count {
    color: #1f2937;
    font-size: 0.9rem;
}

.form-completion-bar {
    width: 100%;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}

.form-completion-bar-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: #d71920;
    transition: width 0.18s ease;
}

.folder-tabs {
    display: flex;
    gap: 0.35rem;
    margin-left: 1rem;
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
}

.folder-tab {
    border: 1px solid #cbd5e1;
    border-bottom: none;
    background: #f3f5f7;
    padding: 0.8rem 1.4rem;
    border-radius: 14px 14px 0 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system,
        "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
        "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    color: #334155;
    transition: all 0.2s ease;
}

.folder-tab:hover {
    background: #ffffff;
    color: #d71920;
}

.folder-tab.active {
    background: #ffffff;
    color: #1c2b39;
    position: relative;
    top: 1px;
    border-color: #d71920;
    box-shadow: inset 0 3px 0 #d71920;
}

.folder-content {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    padding: 1.25rem;
    border-radius: 14px;
    margin-top: -1px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    max-height: calc(100vh - 270px);
    overflow: auto;
}

.folder-panel {
    display: none;
}

.folder-panel.active {
    display: block;
}

.folder-panel-title {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #1c2b39;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 0.9rem 1rem;
}

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

.form-group label {
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: #334155;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    font-size: 0.95rem;
    width: 100%;
    background-color: #ffffff;
    color: #1f2937;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #d71920;
    box-shadow: 0 0 0 2px rgba(215, 25, 32, 0.15);
}

.required {
    color: #d71920;
    font-weight: 700;
    margin-left: 4px;
}

.form-help-text {
    color: #64748b;
    font-size: 0.8rem;
    margin-top: 0.35rem;
}

.form-error {
    color: #b91c1c;
    font-size: 0.8rem;
    margin-top: 0.35rem;
}

.dependent-field {
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.dependent-field-disabled {
    opacity: 0.78;
}

.dependent-field-hidden {
    display: none;
}

.dependent-field-disabled label {
    color: #64748b;
}

.dependent-field-disabled input,
.dependent-field-disabled select,
.dependent-field-disabled textarea {
    background-color: #f8fafc;
    border-color: #dbe3ef;
    color: #64748b;
    cursor: not-allowed;
}

.dependent-field-note {
    color: #64748b;
    font-size: 0.78rem;
    line-height: 1.35;
    margin-top: 0.35rem;
}

.dependent-field-disabled .select2-container--default .select2-selection--single,
.dependent-field-disabled .select2-container--default .select2-selection--multiple {
    background-color: #f8fafc;
    border-color: #dbe3ef;
    cursor: not-allowed;
}

.has-error input,
.has-error select,
.has-error textarea {
    border-color: #d71920;
}

.form-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 2rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}


/* ==========================================================
   BOTONES FORMULARIOS CRUD
   Mantiene colores del header:
   - Guardar: rojo sólido tipo Salir
   - Cancelar: blanco con borde rojo tipo Cargar planilla
========================================================== */

.form-actions {
    margin-top: 2rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: flex-end;
}

.form-actions .btn {
    padding: 0.65rem 1.25rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 110px;
}

.form-actions .btn-success {
    background-color: #d71920;
    color: #ffffff;
    border: 1px solid #d71920;
}

.form-actions .btn-success:hover {
    background-color: #b9151b;
    border-color: #b9151b;
    color: #ffffff;
}

.form-actions .btn-secondary {
    background-color: #ffffff;
    color: #d71920;
    border: 1px solid #f4a3a6;
}

.form-actions .btn-secondary:hover {
    background-color: #fff5f5;
    color: #b9151b;
    border-color: #d71920;
}


/* ==========================================================
   RESPONSIVE
========================================================== */

@media (max-width: 768px) {
    .app-body:has(.uandes-list-container) {
        height: auto;
        overflow: auto;
    }

    .app-body:has(.uandes-form-container) {
        height: auto;
        overflow: auto;
    }

    .main-wrapper:has(.uandes-list-container) {
        height: auto;
        min-height: 100vh;
        overflow: visible;
        padding: 32px 20px;
    }

    .main-wrapper:has(.uandes-form-container) {
        height: auto;
        min-height: 100vh;
        overflow: visible;
        padding: 32px 20px;
    }

    .uandes-list-container {
        height: auto;
    }

    .uandes-form-container {
        height: auto;
    }

    .uandes-filter-form {
        display: block;
    }

    .uandes-form-container .crud-form,
    .uandes-form-container .folder-form-card {
        display: block;
    }

    .uandes-table-wrapper {
        max-height: 70vh;
    }

    .uandes-form-container .folder-content,
    .uandes-form-container .form-card {
        max-height: 70vh;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .folder-tabs {
        margin-left: 0;
    }

    .folder-tab {
        flex: 1 1 auto;
        text-align: center;
        padding: 0.7rem 1rem;
    }

    .folder-content {
        padding: 1.25rem;
    }

    .form-actions {
        justify-content: stretch;
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .uandes-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.75rem;
    }
}

.select2-container .select2-selection--single {
    min-height: 38px;
}
