/* Colores de los calendarios - DEFINICIÓN BASE */
:root {
    --cal-color-0: #ffeb3b;         /*Amarillo Intenso*/
    --cal-color-1: #03a9f4;         /*Azul*/
    --cal-color-2: #cb8665;         /*Tierra*/
    --cal-color-3: #ff686b;         /*Naranja*/
    --cal-color-4: #b79a00;         /*Amarillo oscuro*/
    --cal-color-5: #5fcf87;         /*Verde*/
    --cal-color-6: #a662f9;         /*Lila*/
    --cal-color-7: #f405fc;         /*Fucsia*/
    --cal-color-default: #9e9e9e;
    --today-border-color: #00ffff;
}

/* Estilos base de los colores - APLICAN A AMBOS MODOS */
.cal-color-0 { background-color: var(--cal-color-0); color: #000000 !important; }
.cal-color-1 { background-color: var(--cal-color-1); color: #ffffff !important; }
.cal-color-2 { background-color: var(--cal-color-2); color: #000000 !important; }
.cal-color-3 { background-color: var(--cal-color-3); color: #000000 !important; }
.cal-color-4 { background-color: var(--cal-color-4); color: #ffffff !important; }
.cal-color-5 { background-color: var(--cal-color-5); color: #000000 !important; }
.cal-color-6 { background-color: var(--cal-color-6); color: #ffffff !important; }
.cal-color-7 { background-color: var(--cal-color-7); color: #000000 !important; }
.cal-color-default { background-color: var(--cal-color-default); color: #000000 !important; }

/* ESTILOS ESPECÍFICOS PARA EL MODO CLARO - DEFINIR PRIMERO */
body.light-mode {
    background-color: #f0f0f0;
    color: #333;
}

body.light-mode .calendar-container {
    background-color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.light-mode .calendar-header h2 {
    color: #0077b6;
}

body.light-mode .calendar-header button {
    background-color: #0077b6;
    color: #fff;
}

body.light-mode .calendar-header button:hover {
    background-color: #005f73;
}

body.light-mode .nav-btn {
    background-color: transparent !important;
    color: #0077b6 !important;
}

body.light-mode .calendar-weekdays {
    color: #666;
}

body.light-mode .day {
    background-color: #eee;
    color: #333;
}

body.light-mode .day.occupied {
    color: black !important;
}

body.light-mode .day.selected-day {
    box-shadow: 0 0 0 5px red;
}

body.light-mode .event-details-container {
    border-top: 1px solid #ddd;
}

body.light-mode .event-list li {
    background-color: #e6e6e6;
}

body.light-mode .event-info h4, 
body.light-mode .event-info p {
    color: #333;
}

/* Ajustes para el modo claro en los iconos */
body.light-mode .theme-toggle {
    color: #333;
}

body.light-mode #moon-icon {
    opacity: 0;
}

body.light-mode #sun-icon {
    opacity: 1;
}

/* ESTILOS ESPECÍFICOS PARA EL MODO OSCURO - DEFINIR DESPUÉS */
body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #121212;
    color: #e0e0e0;
}

body:not(.light-mode) {
    background-color: #121212;
    color: #e0e0e0;
}

.calendar-container {
    width: 95%;
    max-width: 500px;
    background-color: #1e1e1e;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    padding: 15px;
    box-sizing: border-box;
    font-size: 0.9em;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

body:not(.light-mode) .calendar-container {
    background-color: #1e1e1e;
}

/* Encabezado del calendario */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.calendar-header h2 {
    margin: 0;
    font-size: clamp(1.5em, 5vw, 2em);
    color: #0077b6;
    text-align: center;
    flex-grow: 1;
    white-space: nowrap;
}

/* Estilos de los botones de navegación y vista */
.calendar-header button {
    background-color: transparent;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2em;
    transition: background-color 0.2s;
}

/* Estilo para los botones de navegación mes y año */
.nav-btn {
    font-size: 1.2em;
    font-weight: bold;
    background-color: #0077b6;
    color: #fff;
}

.nav-btn:hover {
    background-color: #005f73;
}

/* Estilo específico para los botones "Hoy", "Mes" y "Año" */
.today-btn {
    background-color: #A9A9A9 !important;
    color: #121212 !important;
    font-weight: bold;
}

.today-btn:hover {
    background-color: #888 !important;
}

/* Nuevas clases para agrupar los elementos y distribuir el espacio */
.navigation-controls,
.right-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Nombres de los días de la semana */
.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-weight: bold;
    color: #a0a0a0;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.calendar-weekdays div {
    text-align: center;
}

/* Cuadrícula de días del mes */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.day {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #2c2c2c;
    border-radius: 5px;
    font-size: 1.2em;
    font-weight: bold;
    transition: background-color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    color: #e0e0e0;
}

body:not(.light-mode) .day {
    background-color: #2c2c2c;
    color: #e0e0e0;
}

/* Estilo para el día actual: Borde fluorescente */
.day.today {
    box-shadow: inset 0 0 0 3px var(--today-border-color);
}

.day.occupied {
    cursor: pointer;
    background-size: 100% 100%;
    font-weight: bold;
}

.day:not(.empty):hover {
    transform: scale(1.02);
}

.day.selected-day {
    box-shadow: 0 0 0 5px red;
    z-index: 1;
    transform: scale(1.02);
}

.day.empty {
    background-color: transparent;
    cursor: default;
}

/* Controles de los calendarios */
.calendar-controls-container {
    margin-top: 15px;
    padding: 10px;
    border-top: 1px solid #444;
}

body.light-mode .calendar-controls-container {
    border-top: 1px solid #ddd;
}

#calendar-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.calendar-control-item {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: grab;
}

.calendar-control-item:active {
    cursor: grabbing;
}

/* Estilo para el elemento que se está arrastrando */
.calendar-control-item.dragging {
    opacity: 0.5;
    z-index: 999;
}

.calendar-control-item input[type="checkbox"] {
    display: none;
}

.calendar-control-item label {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.2);
    border: 1px solid transparent;
    transition: all 0.2s ease;
    font-size: 1em;
    font-weight: bold;
}

/* Asegurar que las etiquetas tengan buen contraste en ambos modos */
body.light-mode .calendar-control-item label {
    color: #000000;
}

body:not(.light-mode) .calendar-control-item label {
    color: #000000;
}

/* Contenedor de fichas de eventos */
.events-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    margin-top: 15px;
    border-top: 1px solid #444;
    padding-top: 15px;
}

body.light-mode .events-wrapper {
    border-top: 1px solid #ddd;
}

/* Detalles de los eventos */
.event-details-container {
    padding: 0;
    margin: 0;
}

.event-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

/* Estilos de la ficha de evento */
.event-list li {
    border-left: 5px solid; /* La línea vertical tomará el color del calendario */
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 5px;
}

body:not(.light-mode) .event-list li {
    background-color: #1a1a1a;
}

/* Estilos de la etiqueta del calendario */
.event-tag {
    display: inline-block;
    margin-bottom: 3px;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: bold;
}

.event-info h4 {
    margin: 0;
    font-size: 1rem;
}

.event-info p {
    margin: 3px 0 0;
    font-size: 0.8rem;
}

body:not(.light-mode) .event-info h4, 
body:not(.light-mode) .event-info p {
    color: #f0f0f0;
}

/* Estilos del interruptor de tema (sol/luna) */
.theme-toggle {
    cursor: pointer;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    color: #e0e0e0;
}

body.light-mode .theme-toggle {
    color: #333;
}

.theme-icon {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: opacity 0.3s ease-in-out;
}

.theme-icon.active {
    opacity: 1;
}

.theme-icon:not(.active) {
    opacity: 0;
}

#moon-icon {
    opacity: 1;
}

#sun-icon {
    opacity: 0;
}

/* Adaptación a dispositivos móviles */
@media (max-width: 600px) {
    .calendar-container {
        width: 100%;
        min-height: 100vh;
        border-radius: 0;
        box-shadow: none;
        padding: 10px;
    }
    .event-details-container {
        max-height: calc(100vh - 350px);
        overflow-y: auto;
    }
}

/* Estilos para la vista anual */
.calendar-container.year-view .calendar-header h2 {
    font-size: 1.8em;
}

.calendar-container.year-view .calendar-weekdays,
.calendar-container.year-view .month-view-only {
    display: none;
}

.calendar-container.year-view .year-view-only {
    display: block;
}

.month-view-only {
    display: block;
}

.year-view-only {
    display: none;
}

.calendar-container.year-view .calendar-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.calendar-container.year-view .month-calendar {
    display: flex;
    flex-direction: column;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

body.light-mode .calendar-container.year-view .month-calendar {
    border: 1px solid #ccc;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.month-calendar h4 {
    margin: 0 0 5px;
    text-align: center;
    font-size: 1.1em;
    color: #0077b6;
}

.month-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}

.month-calendar-grid .day {
    font-size: 0.8em;
    padding: 0;
    width: 100%;
    aspect-ratio: 1 / 1;
}

.month-calendar-grid .day.today {
    box-shadow: inset 0 0 0 3px var(--today-border-color);
}

.month-calendar-grid .day.empty {
    background-color: transparent;
    cursor: default;
}

/* Recuadro para los selectores de calendario activos */
.calendar-control-item input[type="checkbox"]:checked + label {
    box-shadow: 0 0 0 3px #007bff;
    border-color: #007bff;
}

/* Modo claro */
body.light-mode .calendar-control-item input[type="checkbox"]:checked + label {
    box-shadow: 0 0 0 3px #007bff;
    border-color: #007bff;
}
