/* Events Page Layout */
.events-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 2rem;
    margin-top: 3rem;
}

.calendar-sidebar {
    position: sticky;
    top: 11rem; /* Account for fixed header height (~8em) + some margin */
    align-self: start;
}

.events-main-content {
    min-width: 0; /* Prevents overflow */
}

/* Month Calendar Component */
.month-calendar {
    margin: 0;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.05); /* Slightly white translucent */
    backdrop-filter: blur(100px); /* Blur effect */
    -webkit-backdrop-filter: blur(100px); /* Safari support */
    border-radius: 24px;
    border: none;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Gradient border effect for calendar */
.month-calendar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 24px;
    padding: 1px;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.4) 0%, 
        rgba(255, 255, 255, 0.1) 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.1) 75%, 
        rgba(255, 255, 255, 0.3) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
    z-index: 0;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 0.5rem;
    position: relative;
    z-index: 1; /* Ensure header is above the border gradient */
}

.calendar-header h2 {
    color: var(--text-heading);
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    min-width: 0;
}

.calendar-nav {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.calendar-nav-btn {
    background: rgba(106, 169, 245, 0.1);
    border: 1px solid rgba(106, 169, 245, 0.2);
    color: #6aa9f5;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0;
    padding: 0;
    flex-shrink: 0;
}

.calendar-nav-btn:hover {
    background: rgba(106, 169, 245, 0.2);
    border-color: rgba(106, 169, 245, 0.4);
    transform: scale(1.05);
}

.calendar-nav-btn .material-symbols-outlined {
    font-size: 24px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    justify-items: center;
    position: relative;
    z-index: 1; /* Ensure grid is above the border gradient */
}

.calendar-weekday {
    text-align: center;
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 0.5rem 0.25rem;
    border-bottom: 2px solid rgba(106, 169, 245, 0.2);
    width: 100%;
}

.calendar-day {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    cursor: default;
}

.calendar-day-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent; /* Remove default background */
    border: none; /* Remove default border */
    border-radius: 50%;
    z-index: 1;
}

.calendar-day.has-event .calendar-day-bg {
    background: rgba(106, 169, 245, 0.15); /* Only show background for events */
    border: 2px solid rgba(106, 169, 245, 0.1);
    border-radius: 8px; /* Rounded square for events */
}

.calendar-day.has-event {
    border-radius: 8px; /* Rounded square for events */
}

.calendar-day.other-month {
    opacity: 0.3;
}

.calendar-day.other-month .calendar-day-bg {
    background: rgba(255, 255, 255, 0.2);
}

.calendar-day.today .calendar-day-bg {
    border: 2px solid #6aa9f5;
    background: rgba(106, 169, 245, 0.15);
    box-shadow: 0 0 0 3px rgba(106, 169, 245, 0.1);
}

.calendar-day.has-event {
    cursor: pointer;
}

.calendar-day.has-event:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.calendar-day-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-heading);
    position: relative;
    z-index: 1;
}

.calendar-day.has-event .calendar-day-number {
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.calendar-day.other-month .calendar-day-number {
    color: var(--text-secondary);
}

.calendar-day.other-month.has-event .calendar-day-number {
    color: rgba(255, 255, 255, 0.7);
}

/* Event popup */
.calendar-event-popup {
    position: fixed;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(100px);
    -webkit-backdrop-filter: blur(100px);
    border-radius: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    padding: 1.5rem;
    max-width: 400px;
    width: calc(100vw - 2rem);
    z-index: 1000;
    border: none;
    animation: popupFadeIn 0.3s ease;
    pointer-events: auto;
    isolation: isolate; /* Create a new stacking context */
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.calendar-event-popup::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 24px;
    padding: 1px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.5) 0%, transparent 50%, rgba(255, 255, 255, 0.5) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
    z-index: 0;
}

.popup-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
    z-index: 1; /* Ensure close button is above border */
}

.popup-close:hover {
    background: rgba(106, 169, 245, 0.15);
    color: #6aa9f5;
    border-color: rgba(106, 169, 245, 0.3);
    transform: scale(1.1);
}

.popup-close .material-symbols-outlined {
    font-size: 20px;
    line-height: 1;
}

.popup-event-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-heading);
    margin: 0 0 0.5rem 0;
    padding-right: 2rem;
    line-height: 1.3;
}

.popup-event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.popup-event-category {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
}

.popup-event-category .material-symbols-outlined {
    font-size: 14px;
}

.popup-event-info {
    margin-bottom: 1rem;
}

.popup-info-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.popup-info-item .material-symbols-outlined {
    font-size: 18px;
    color: #6aa9f5;
    margin-top: 2px;
}

.popup-info-item strong {
    color: var(--text-heading);
    display: block;
    font-size: 0.85rem;
}

.popup-info-item p {
    margin: 0.25rem 0 0 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.popup-event-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.popup-event-actions {
    display: flex;
    gap: 0.75rem;
}

.popup-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.375em;
    font-size: 0.8em;
    font-weight: 700;
    font-family: var(--font-heading);
    letter-spacing: 0.075em;
    text-transform: uppercase;
    text-decoration: none;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(100px);
    -webkit-backdrop-filter: blur(100px);
}

/* Gradient border for popup buttons */
.popup-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0.375em;
    padding: 1px;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.4) 0%, 
        rgba(255, 255, 255, 0.1) 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.1) 75%, 
        rgba(255, 255, 255, 0.3) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
    z-index: 0;
}

.popup-btn .material-symbols-outlined {
    position: relative;
    z-index: 1;
}

.popup-btn-primary {
    background-color: var(--accent-primary);
    color: var(--text-heading) !important;
}

.popup-btn-primary::before {
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.5) 0%, 
        rgba(255, 255, 255, 0.15) 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.15) 75%, 
        rgba(255, 255, 255, 0.4) 100%);
}

.popup-btn-primary:hover {
    background-color: var(--accent-hover);
}

.popup-btn-primary:hover::before {
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.7) 0%, 
        rgba(255, 255, 255, 0.25) 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.25) 75%, 
        rgba(255, 255, 255, 0.6) 100%);
}

.popup-btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-heading) !important;
}

.popup-btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.popup-btn-secondary:hover::before {
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.6) 0%, 
        rgba(255, 255, 255, 0.2) 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.2) 75%, 
        rgba(255, 255, 255, 0.5) 100%);
}

/* Backdrop for popup */
.calendar-popup-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    animation: backdropFadeIn 0.3s ease;
}

@keyframes backdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .calendar-day {
        background: transparent; /* Remove grey background */
        border-color: rgba(106, 169, 245, 0.2);
    }
    
    .calendar-day.other-month {
        background: transparent; /* Remove grey background */
    }
    
    .calendar-event-popup {
        background: rgba(255, 255, 255, 0.05);
        backdrop-filter: blur(100px);
        -webkit-backdrop-filter: blur(100px);
        border-color: rgba(106, 169, 245, 0.3);
    }
}

/* Mobile responsive */
@media screen and (max-width: 1024px) {
    .events-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .calendar-sidebar {
        position: relative;
        top: 0;
    }
    
    .month-calendar {
        max-width: 500px;
        margin: 0 auto;
    }
}

@media screen and (max-width: 768px) {
    .events-layout {
        margin-top: 2rem;
        gap: 1.5rem;
    }
    
    .month-calendar {
        padding: 1.5rem 1rem;
    }
    
    .calendar-header {
        margin-bottom: 1.5rem;
        gap: 0.5rem;
    }
    
    .calendar-header h2 {
        font-size: 1.15rem;
    }
    
    .calendar-nav-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .calendar-nav-btn .material-symbols-outlined {
        font-size: 20px;
    }
    
    .calendar-grid {
        gap: 0.5rem;
    }
    
    .calendar-weekday {
        font-size: 0.7rem;
        padding: 0.4rem 0.2rem;
    }
    
    .calendar-day {
        width: 35px;
        height: 35px;
    }
    
    .calendar-day-number {
        font-size: 0.75rem;
    }
    
    .calendar-event-popup {
        padding: 1.25rem;
        max-width: calc(100vw - 2rem);
    }
    
    .popup-event-title {
        font-size: 1.1rem;
    }
    
    .popup-event-actions {
        flex-direction: column;
    }
}

@media screen and (max-width: 480px) {
    .calendar-header h2 {
        font-size: 1rem;
    }
    
    .calendar-nav-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .calendar-nav-btn .material-symbols-outlined {
        font-size: 18px;
    }
    
    .calendar-grid {
        gap: 0.4rem;
    }
    
    .calendar-weekday {
        font-size: 0.65rem;
    }
    
    .calendar-day {
        width: 30px;
        height: 30px;
    }
    
    .calendar-day-number {
        font-size: 0.7rem;
    }
}
