* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4facfe;
    --primary-dark: #00f2fe;
    --secondary: #6c757d;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #17a2b8;
    
    /* Dark Theme Colors */
    --bg-main: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a3a;
    --bg-card-hover: #243447;
    --bg-input: #243447;
    
    --text-primary: #e4e4e4;
    --text-secondary: #b0b0b0;
    --text-muted: #7a7a7a;
    
    --border-color: rgba(255, 255, 255, 0.05);
    --border-color-hover: rgba(79, 172, 254, 0.3);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

header {
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
    color: white;
    padding: 30px 40px;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 2.2em;
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

header p {
    font-size: 1em;
    opacity: 0.9;
}

/* TABS */
.tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
}

.tab-btn {
    padding: 18px 30px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-btn:hover {
    background: rgba(79, 172, 254, 0.1);
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--bg-card-hover);
}

/* MAIN CONTENT */
main {
    padding: 30px 40px;
    background: var(--bg-secondary);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.section-header h2 {
    color: var(--text-primary);
    font-size: 1.5em;
    font-weight: 600;
    padding-left: 15px;
    border-left: 4px solid var(--primary);
}

/* BUTTONS */
.btn-primary, .btn-secondary, .btn-success, .btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(79, 172, 254, 0.4);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(40, 167, 69, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(220, 53, 69, 0.4);
}

/* FILTERS */
.filters {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.filters select {
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: all 0.3s;
}

.filters select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

/* GRID CARDS */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 20px;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.card:hover {
    border-color: var(--border-color-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.card-title {
    font-size: 1.2em;
    color: var(--text-primary);
    font-weight: 600;
    flex: 1;
}

.badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success { background: rgba(40, 167, 69, 0.2); color: #20c997; border: 1px solid rgba(40, 167, 69, 0.3); }
.badge-warning { background: rgba(255, 193, 7, 0.2); color: #ffc107; border: 1px solid rgba(255, 193, 7, 0.3); }
.badge-danger { background: rgba(220, 53, 69, 0.2); color: #dc3545; border: 1px solid rgba(220, 53, 69, 0.3); }
.badge-info { background: rgba(79, 172, 254, 0.2); color: #4facfe; border: 1px solid rgba(79, 172, 254, 0.3); }
.badge-secondary { background: rgba(108, 117, 125, 0.2); color: #b0b0b0; border: 1px solid rgba(108, 117, 125, 0.3); }

.card-body {
    color: var(--text-secondary);
    line-height: 1.6;
}

.card-body p {
    margin-bottom: 8px;
}

.card-footer {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

/* STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-hover) 100%);
    color: white;
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.stat-card h3 {
    font-size: 1em;
    margin-bottom: 15px;
    opacity: 0.9;
}

.stat-value {
    font-size: 2.5em;
    font-weight: 700;
}

/* TABLE */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-card);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-card-hover);
}

th, td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

tbody tr:hover {
    background: rgba(79, 172, 254, 0.05);
}

/* Líneas verticales en la matriz de recursos */
#tablaMatrizRecursos {
    border-collapse: collapse;
}
#tablaMatrizRecursos th,
#tablaMatrizRecursos td {
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}
/* Añadir línea izquierda al primer column (Institución) y ajustar la última columna total */
#tablaMatrizRecursos tr th:first-child,
#tablaMatrizRecursos tr td:first-child {
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}
#tablaMatrizRecursos tr th:last-child,
#tablaMatrizRecursos tr td:last-child {
    border-right: none;
}
/* Ajustes: columnas adaptan ancho al contenido (encabezado) y centrar textos */
#tablaMatrizRecursos {
    table-layout: auto; /* permitir que las columnas se ajusten al contenido */
}
#tablaMatrizRecursos th.matriz-col-recursos,
#tablaMatrizRecursos td.matriz-col-recursos,
#tablaMatrizRecursos th.matriz-col-total,
#tablaMatrizRecursos td.matriz-col-total,
#tablaMatrizRecursos th.matriz-col-institucion,
#tablaMatrizRecursos td.matriz-col-institucion {
    white-space: nowrap; /* evitar que el texto haga wrap y así la columna mida al tamaño del texto */
    text-align: center; /* centrar el contenido */
    padding: 8px 10px; /* reducir padding para columns más compactas */
}
#tablaMatrizRecursos th,
#tablaMatrizRecursos td {
    vertical-align: middle;
}
/* Alinear valores numéricos a la derecha para mejor lectura */
#tablaMatrizRecursos td.matriz-cell-value,
#tablaMatrizRecursos td.matriz-total {
    text-align: right;
    padding-right: 12px;
}
#tablaMatrizRecursos td.matriz-cell-empty {
    text-align: center;
}

/* MODAL */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.3s;
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
    animation: slideUp 0.3s;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 32px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: var(--danger);
}

.modal-content h2 {
    color: var(--text-primary);
    font-size: 1.5em;
    font-weight: 600;
}

/* FORMS */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s;
    background: var(--bg-input);
    color: var(--text-primary);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    justify-content: flex-end;
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    display: none;
    animation: slideIn 0.3s;
    z-index: 2000;
}

@keyframes slideIn {
    from { transform: translateX(400px); }
    to { transform: translateX(0); }
}

.toast.show {
    display: block;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* RESPONSIVE */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .container {
        border-radius: 0;
        margin: 0;
    }
    
    header {
        padding: 15px 20px;
    }
    
    header h1 {
        font-size: 1.5em;
    }
    
    header p {
        font-size: 0.9em;
    }
    
    main {
        padding: 15px;
    }
    
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tab-btn {
        padding: 12px 18px;
        font-size: 13px;
        min-width: auto;
    }
    
    .grid-cards {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .card {
        padding: 15px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .form-group label {
        font-size: 13px;
    }
    
    input, select, textarea {
        font-size: 16px; /* Previene zoom en iOS */
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 14px;
        width: 100%;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        max-width: 95%;
        padding: 20px;
        margin: 20px auto;
    }
    
    .modal-header h2 {
        font-size: 1.3em;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .section-header .btn {
        width: 100%;
    }
    
    table {
        font-size: 13px;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    /* Tabla de acciones responsiva */
    .responsive-table thead {
        display: none;
    }
    
    .responsive-table tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        padding: 12px;
        background: white;
    }
    
    .responsive-table tbody td {
        display: block;
        text-align: left !important;
        padding: 8px 0 !important;
        border: none !important;
    }
    
    .responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: bold;
        display: block;
        margin-bottom: 5px;
        color: #64748b;
        font-size: 12px;
    }
    
    .responsive-table select,
    .responsive-table input[type="number"],
    .responsive-table textarea {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* SUGGESTIONS (autocomplete ubicacion) */
.suggestions {
    position: absolute;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
    z-index: 99999;
    color: #0f172a; /* dark text on white */
    font-size: 14px;
}
.suggestions div {
    padding: 8px 10px;
    cursor: pointer;
    color: inherit;
}
.suggestions div:hover {
    background: rgba(79, 172, 254, 0.08);
}
.suggestions .no-results {
    color: #64748b;
    padding: 10px;
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.3em;
    }
    
    .tab-btn {
        padding: 10px 15px;
        font-size: 12px;
    }
    
    .card {
        padding: 12px;
    }
    
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-actions {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }
    
    .table-actions .btn {
        width: 100%;
        padding: 8px 12px;
        font-size: 12px;
    }
}

