/* ==========================================================================
   Variables
   ========================================================================== */
:root {
    /* Colores principales */
    --color-cfgb: #28a745;
    --color-cfgm: #fd7e14;
    --color-cfgs: #dc3545;
    --color-cem: #92480c;
    --color-ces: #880350;
    --color-multiple: #6c757d;
    --color-default: #2196F3;
    --color-primary: #0d6efd;
    --color-text: #495057;
    --color-border: #ced4da;
    --color-bg-light: #f8f9fa;
    
    /* Colores para familias profesionales */
    --color-adg: #4A69BD;  /* Azul medio */
    --color-afd: #45B7AF;  /* Verde turquesa */
    --color-aga: #F4D03F;  /* Amarillo mostaza */
    --color-arg: #E67E22;  /* Naranja medio */
    --color-com: #2E86DE;  /* Azul brillante */
    --color-ele: #16A085;  /* Verde esmeralda */
    --color-ena: #3498DB;  /* Azul claro */
    --color-eoc: #A3CB38;  /* Verde lima */
    --color-fme: #626567;  /* Gris medio */
    --color-hot: #D35400;  /* Naranja oscuro */
    --color-iex: #A04000;  /* Marrón rojizo */
    --color-ifc: #1B9CFC;  /* Azul cielo */
    --color-ima: #82E0AA;  /* Verde menta */
    --color-imp: #C0392B;  /* Rojo oscuro */
    --color-ims: #8E44AD;  /* Púrpura */
    --color-ina: #F1C40F;  /* Amarillo dorado */
    --color-mam: #935116;  /* Marrón medio */
    --color-qui: #27AE60;  /* Verde medio */
    --color-san: #E74C3C;  /* Rojo medio */
    --color-sea: #229954;  /* Verde bosque */
    --color-ssc: #BA4A00;  /* Terracota */
    --color-tcp: #9B59B6;  /* Morado medio */
    --color-tmv: #2C3E50;  /* Azul marino */
    
    /* Colores para niveles educativos */
    --color-fpb: #8fd321;  /* Verde amarillento para Nivel Básico */
    --color-gm: #3498DB;   /* Azul para Nivel Medio */
    --color-gs: #d12a2a;   /* Rojo para Nivel Superior */
    
    /* Sombras */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 16px rgba(0,0,0,0.15);
    
    /* Bordes */
    --border-radius-sm: 0.375rem;
    --border-radius-md: 0.75rem;
    --border-radius-lg: 1rem;
}

/*
 ==========================================================================
   Base Styles
 ========================================================================== */
html {
    height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: var(--color-bg-light);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* Forzamos al contenedor principal a ocupar el espacio disponible */
.container-fluid.mt-4 {
    flex: 1;
}

/* Alerts */
.alert {
    border-radius: 0.375rem;
    border: none;
    box-shadow: var(--shadow-sm);
}

.alert-info {
    background-color: rgba(13, 110, 253, 0.1);
    color: var(--color-text);
}

/* Navbar */
.navbar {
    position: relative;
    height: 80px;
    z-index: 1030;
}

.navbar-expand-custom {
    padding: 0.5rem 1rem;
}

.navbar-expand-custom .navbar-brand {
    color: white;
    display: flex;
    align-items: center;
    text-decoration: none;
    margin-right: 0;
    padding: 0;
}

.navbar-expand-custom .navbar-brand .brand-text {
    font-size: 1.25rem;
    font-weight: 500;
}

.navbar-expand-custom .navbar-brand:hover {
    color: rgba(255, 255, 255, 0.85);
}

.navbar-expand-custom .navbar-title {
    color: var(--color-bg-light);
    position: absolute;
    right: 1rem;
    bottom: -37px;
    margin: 0;
    font-size: 3.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1;
    padding: 0;
    transform: none;
    left: auto;
}

.navbar-expand-custom .container-fluid {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    background-color: transparent;
}

/* Clase personalizada para el breakpoint del navbar */
@media (max-width: 800px) {
    .navbar-collapse {
        position: absolute;
        top: 100%;
        right: 1rem;
        left: 1rem;
        background-color: var(--color-primary);
        padding: 0.5rem;
        border-radius: 0.25rem;
        box-shadow: var(--shadow-md);
        z-index: 1040;
    }

    .navbar-toggler {
        display: block;
        border: none;
        padding: 0.25rem 0.5rem;
        background: none;
        cursor: pointer;
    }

    .navbar-nav {
        padding: 0.5rem;
    }

    .nav-item {
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }

    .nav-item:last-child {
        border-bottom: none;
    }

    .navbar-collapse .nav-link,
    .navbar-collapse .btn-link.nav-link {
        padding: 0.75rem 1rem;
        color: white !important;
        width: 100%;
        text-align: left;
        display: block;
    }

    .navbar-collapse .nav-link:hover {
        background-color: rgba(255,255,255,0.1);
    }

    .navbar-expand-custom .navbar-title {
        font-size: 2.5rem;
        bottom: -34px;
        right: 0.5rem;
    }
}

@media (min-width: 801px) {
    .navbar-collapse {
        display: flex !important;
        flex-basis: auto;
    }
    
    .navbar-toggler {
        display: none;
    }

    .navbar-nav {
        flex-direction: row;
        gap: 1rem;
    }
}

/* Unificar estilos de links en el navbar */
.navbar .nav-link,
.navbar .btn-link {
    color: white !important;
    text-decoration: none;
    padding: 0.5rem 1rem;
}

/* Modal */
.modal-dialog {
    max-width: 800px;
}

.modal-content {
    border: none;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border: none;
    padding: 1rem;
}

.modal-body {
    padding: 1.5rem 2rem;
}

.modal-body h6 {
    color: var(--color-primary);
    margin-bottom: 1rem;
}

.modal-body p {
    color: var(--color-text);
    line-height: 1.6;
}

.modal-body ul {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

/* Excepción: los popups de Leaflet dentro del modal no deben heredar el padding */
.modal-body .leaflet-popup-content ul {
    padding-left: 0 !important;
}

.modal-body li {
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.modal-body .alert {
    margin-bottom: 0;
}

/* ==========================================================================
   Map Components
   ========================================================================== */

/* Ocultar atribución de Leaflet */
.leaflet-control-attribution {
    display: none !important;
}

.card-body {
    padding: 0.5rem;
}

/* Marcadores */
.marker-default .fa-map-marker-alt,
.marker-CFGB .fa-map-marker-alt,
.marker-CFGM .fa-map-marker-alt,
.marker-CFGS .fa-map-marker-alt,
.marker-CEM .fa-map-marker-alt,
.marker-CES .fa-map-marker-alt,
.marker-multiple .fa-map-marker-alt {
    font-size: 30px;
    filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.5));
}

/* Colores de los marcadores */
.marker-default .fa-map-marker-alt { color: var(--color-default); }
.marker-CFGB .fa-map-marker-alt { color: var(--color-cfgb); }
.marker-CFGM .fa-map-marker-alt { color: var(--color-cfgm); }
.marker-CFGS .fa-map-marker-alt { color: var(--color-cfgs); }
.marker-CEM .fa-map-marker-alt { color: var(--color-cem); }
.marker-CES .fa-map-marker-alt { color: var(--color-ces); }
.marker-multiple .fa-map-marker-alt { color: var(--color-multiple); }

/* Clusters */
.marker-cluster,
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(33, 150, 243, 0.6) !important;
    border: none !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    margin: -20px 0 0 -20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.marker-cluster div {
    background: none !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    text-align: center !important;
    font-size: 14px !important;
    font-weight: bold !important;
    color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.2) !important;
}

/* Popups y controles */
.leaflet-popup-content {
    margin: 8px;
    width: auto !important;
    line-height: 1.4;
    max-height: 600px;
    overflow-y: auto;
    -ms-overflow-style: none;  /* IE y Edge */
    scrollbar-width: none;  /* Firefox */
}

.leaflet-popup-content::-webkit-scrollbar {
    display: none;  /* Chrome, Safari y Opera */
}

.leaflet-popup-content-wrapper {
    width: auto !important;
    min-width: 200px;
    max-width: 450px;
    max-height: 650px;
    border-radius: var(--border-radius-md) !important;
    box-shadow: var(--shadow-md) !important;
    overflow-y: auto;
}

.popup-content {
    font-family: Arial, sans-serif;
    padding: 5px;
}

.popup-content h6 {
    margin: 0 0 10px 0;
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.popup-content p {
    margin: 5px 0;
    font-size: 0.9em;
    color: #666;
    line-height: 1.4;
}

/* Controles del mapa */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-sm) !important;
}

.leaflet-control-zoom a {
    background-color: white !important;
    color: #333 !important;
    border: 1px solid #ddd !important;
}

/* ==========================================================================
   UI Components
   ========================================================================== */
/* Cards y Contenedores */
.card {
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 0.25rem;
}

.card-title {
    font-size: 1.25rem;
    color: var(--color-text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.card:hover {
    transform: translateY(-2px);
}

.placeholder-content {
    flex: 1;
    min-height: 700px; /* Ajustar para que coincida con la altura del mapa */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.placeholder-content::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        45deg,
        transparent 25%,
        rgba(13, 110, 253, 0.03) 25%,
        rgba(13, 110, 253, 0.03) 50%,
        transparent 50%,
        transparent 75%,
        rgba(13, 110, 253, 0.03) 75%
    );
    background-size: 40px 40px;
    mask-image: linear-gradient(
        to right, 
        transparent 0%, 
        white 20%, 
        white 80%, 
        transparent 100%
    );
}

@keyframes placeholderAnim {
    0% { background-position: 0 0; }
    100% { background-position: 100% 100%; }
}

.placeholder-content p {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    font-size: 1.5rem;
    color: var(--color-primary);
    font-weight: 500;
    padding: 0.5rem 2rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    text-align: center;
    max-width: 90%;
    min-width: 300px;
    white-space: normal;
    line-height: 1.4;
}

/* Forms y Controles */
.form-label {
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--color-text);
    font-size: 0.9rem;
}

.form-select {
    margin-bottom: 0.25rem;
}

.form-switch {
    padding-left: 2em;
    min-width: 50px;
    margin-left: 1rem;
    transform: translateY(-2px);
}

.form-check-input[type="checkbox"] {
    height: 1.2em;
    width: 2.4em !important;
    background-color: #ffd700;
    border-color: #e6c200;
    cursor: pointer;
    margin-left: -2em;
}

.form-check-input:checked[type="checkbox"] {
    background-color: #0d3b66;
    border-color: #092744;
}

/* Buttons */
.btn-group {
    gap: 0.5rem;
}

.btn-group .btn {
    padding: 0.5rem 1rem;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 1rem;
}

.btn-outline-primary:hover {
    background-color: var(--color-primary);
    color: white;
}

/* Select2 Customization */
.select2-container {
    width: 100% !important;
    margin-bottom: 0.5rem;
}

.select2-container--default .select2-selection--single {
    height: 38px !important;
    min-height: 38px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px;
    padding: 8px 30px 8px 12px !important;
    color: var(--color-text);
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #939ea7;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--color-primary);
}

/* Filtros */
.filter-group {
    margin-bottom: 1.5rem;
}

.filter-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--color-primary);
    font-weight: 500;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}

canvas {
    max-width: 100%;
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Loading */
.loading {
    position: relative;
    min-height: 200px;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Tablas */
.table {
    margin-bottom: 0;
}

.table th {
    background-color: var(--color-bg-light);
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.9rem;
}

.table td {
    vertical-align: middle;
    padding: 0.75rem;
    font-size: 0.9rem;
}

/* Información del ciclo */
.ciclo-info {
    scroll-margin-top: 90px;
    background: white;
    border-radius: var(--border-radius-md);
    width: 100%;
    box-sizing: border-box;
}

.info-section {
    margin-bottom: 20px;
    width: 100%;
}

.curso-title {
    color: var(--color-primary);
    font-weight: 600;
    margin: 0;
    padding: 0.5rem 0;
    border-bottom: 2px solid var(--color-bg-light);
    flex: 1;
}

/* Floating Tab */
.floating-tab {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--color-primary);
    color: white;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    font-weight: 500;
    transition: all 0.3s ease;
}

.floating-tab:hover {
    background-color: #0b5ed7;
    padding-bottom: 20px;
}

.floating-tab .bi {
    font-size: 1.2rem;
    vertical-align: middle;
}

/* Listado de ciclos */
.list-group {
    max-height: 900px;
    overflow-y: auto;
    border-radius: var(--border-radius-md);
    width: 100%;
}

.list-group-item {
    padding: 15px;
    border: none;
    border-bottom: 1px solid var(--color-bg-light);
    width: 100%;
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item a {
    color: var(--color-text);
    text-decoration: none;
    display: block;
}

.list-group-item a:hover {
    color: var(--color-primary);
}

.list-group::-webkit-scrollbar {
    width: 8px;
}

.list-group::-webkit-scrollbar-track {
    background: var(--color-bg-light);
    border-radius: 4px;
}

.list-group::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

.list-group::-webkit-scrollbar-thumb:hover {
    background: var(--color-text);
}

/* ==========================================================================
   Media Queries
   ========================================================================== */
/* Mobile Styles */
@media (max-width: 800px) {
    #map {
        height: 550px;
        max-height: 550px;
    }

    .leaflet-control-zoom {
        display: none !important;
    }

    .floating-tab {
        display: none;
    }

    .floating-tab.visible {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .btn-group-vertical {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group-vertical .btn {
        margin-bottom: 5px;
        width: 100%;
    }

    #infoCicloHeader {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    #infoCicloHeader .btn {
        font-size: 0.875rem;
        padding: 0.25rem 0.5rem;
    }

    .placeholder-content {
        min-height: 350px;
    }
    
    .col-md-6 {
        width: 100%;
        padding: 0 4px;
    }

    .placeholder-content p {
        max-width: 100%;
        min-width: auto;
        padding: 0.75rem 1rem;
        font-size: 1.5rem;
        margin: 0 10px;
        width: calc(100% - 20px);
    }

    .list-group-item {
        padding: 12px 4px;
    }
    
    .ciclo-info {
        padding: 12px 4px;
    }

    /* Navbar mobile styles */
    .navbar-title {
        font-size: 2.5rem;
        bottom: -34px;
        right: 0.5rem;
        text-transform: uppercase;
        letter-spacing: 1px;
        line-height: 1;
        position: absolute;
        color: var(--color-bg-light);
        font-weight: 700;
        margin: 0;
        padding-bottom: 0.5rem;
    }
}

/* Small Screens */
@media (max-width: 576px) {
    /* Los popups usan los mismos estilos que en escritorio */
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .info-item {
        background: #ffffff;
        border: 2px solid #000;
        color: #000;
    }
}

/* Estilos para la página del módulo */
.module-header {
    background: white;
    border-radius: var(--border-radius-md);
    padding: 1.5rem 2rem;
    margin-bottom: 3rem;
}

.module-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-bg-light);
}

.module-header h1::after {
    content: "Módulo";
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-primary);
    padding: 0.5rem 0;
    margin-left: auto;
}

.module-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--color-bg-light);
    border-radius: var(--border-radius-sm);
    font-size: 0.9rem;
    color: var(--color-text);
}

.info-item i {
    color: var(--color-primary);
    font-size: 1.1rem;
    min-width: 1.1rem;
}

.ra-card {
    background: white;
    border-radius: var(--border-radius-md);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.ra-header {
    background: var(--color-bg-light);
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.ra-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
}

.ra-header p {
    color: var(--color-text);
    line-height: 1.5;
}

.ce-list {
    list-style: none;
    padding: 1.5rem;
    margin: 0;
}

.ce-item {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-bg-light);
    line-height: 1.5;
}

.ce-item:last-child {
    border-bottom: none;
}

.ce-letter {
    color: var(--color-primary);
    font-weight: 600;
    min-width: 1.5rem;
}

@media (max-width: 768px) {
    .module-header {
        padding: 1.5rem;
    }
    
    .module-info {
        grid-template-columns: 1fr;
    }
    
    .info-item {
        padding: 0.75rem;
    }
}

/* Ajustar altura del contenedor principal */
.container-fluid.mt-4 {
    margin-top: 0.5rem !important;
    margin-bottom: 0.5rem !important;
}

/* Igualar altura de las columnas */
.col-md-6 {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Anular columnas para la información inicial */
#info-ciclo.info-inicial {
    column-count: auto;
    /* Eliminamos height: auto; ya que el contenedor base no tiene altura fija */
    display: block; /* Asegurar que no sea flex para que column-count:auto funcione */
    padding: 1.5rem 2rem; /* Añadir padding similar al del modal-body */
}

/* Estilos específicos para el contenido inicial, copiados del modal */
#info-ciclo.info-inicial h6 {
    color: var(--color-primary);
    margin-bottom: 1rem;
}

#info-ciclo.info-inicial p {
    color: var(--color-text);
    line-height: 1.6;
}

#info-ciclo.info-inicial ul {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

#info-ciclo.info-inicial li {
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

#info-ciclo.info-inicial .alert {
    margin-bottom: 0;
}

/* Ajustar espaciado entre elementos del formulario */
.mb-3 {
    margin-bottom: 0.5rem !important;
}

/* También asegurarnos que la columna derecha tenga la altura correcta */
.col-md-6 {
    display: flex;
    flex-direction: column;
}

/* Y que la tarjeta que contiene el placeholder ocupe todo el espacio disponible */
.card.sticky-top {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.card.sticky-top .card-body {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.row {
    align-items: flex-start;
}

/* Estilos para módulos optativos */
.optativo-card {
    transition: all 0.3s ease;
    border: 1px solid var(--color-border);
}

.optativo-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.optativo-codigo {
    background: var(--color-primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.optativo-card .card-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text);
    line-height: 1.4;
    margin-bottom: 0.75rem;
}

.optativo-card .card-body {
    padding: 1.25rem;
}

.optativo-card small {
    font-size: 0.8rem;
    color: var(--color-text);
}

.optativo-card .fas {
    color: var(--color-primary);
}