/* ========================================
   CALENDAR PAGE STYLES
   Styles for calendar views (day, week, month)
   
   Dependencies:
   - Requires MudBlazor CSS variables (--mud-palette-*)
   - Requires glassmorphism.css for glass effects
   
   Used by:
   - AllCalendar.razor (main calendar page)
   - WeekCalendarGrid.razor, MonthCalendarGrid.razor, DayCalendarGrid.razor
   - OrganisationCalendar.razor
   ======================================== */

/* ========================================
   SECTION 1: OVERFLOW UTILITIES
   Allow date picker popup to overflow glass cards
   ======================================== */
.glass-card.allow-overflow,
.glass-card.allow-overflow > div,
.glass-card.allow-overflow .mud-stack {
    overflow: visible !important;
}

/* Calendar Action Bar Buttons */
.calendar-view-buttons {
    gap: 0.75rem;
}

.calendar-view-buttons .mud-button.calendar-view-btn {
    flex: 1;
    min-width: max-content;
    padding: 0.25rem 1rem;
    height: 1.75rem;
    line-height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 600px) {
    .calendar-view-buttons .mud-button.calendar-view-btn {
        min-width: 5.5rem;
        height: 1.75rem;
    }
}

/* ========================================
   SECTION 2: CSS CUSTOM PROPERTIES
   Calendar-specific variables
   
   Event status colors map to MudBlazor palette:
   - Pending: warning (orange/amber)
   - Confirmed: success (green)
   - Cancelled: error (red)
   ======================================== */
:root {
    /* Event Status Colors */
    --event-pending: var(--mud-palette-warning);
    --event-confirmed: var(--mud-palette-success);
    --event-cancelled: var(--mud-palette-error);
    
    /* Calendar Layout Dimensions */
    --calendar-cell-min-height: 120px;
    --calendar-time-slot-height: 60px;
    --calendar-header-height: 40px;
}

/* ========================================
   SHARED EVENT STYLES
   Common styles for calendar events across
   day, week, and month views.
   ======================================== */

/* Shared Event Status Styles */
.event-chip-pending {
    border-color: var(--event-pending);
    color: var(--event-pending);
}

.event-chip-confirmed {
    border-color: var(--event-confirmed);
    color: var(--event-confirmed);
}

.event-chip-cancelled {
    border-color: var(--event-cancelled);
    color: var(--event-cancelled);
}

/* Shared Event Source Styles - Outlook events */
.event-source-outlook {
    border-color: var(--mud-palette-info) !important;
    color: var(--mud-palette-info) !important;
    background-color: rgba(var(--mud-palette-info-rgb), 0.1) !important;
}

.event-source-outlook:hover {
    background-color: rgba(var(--mud-palette-info-rgb), 0.2) !important;
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .week-event-card {
        background-color: rgba(255, 255, 255, 0.05);
    }
    
    .calendar-empty-state {
        color: rgba(255, 255, 255, 0.5);
    }
}

/* ========================================
   SECTION 4: CALENDAR GRID CELLS
   Base styles for calendar grid layout
   ======================================== */
.calendar-cell {
    min-height: var(--calendar-cell-min-height);
    border: 1px solid var(--mud-palette-divider);
    cursor: pointer;
    transition: background-color 0.2s;
}

.calendar-cell:hover {
    background-color: var(--mud-palette-action-hover);
}

.calendar-cell-today {
    background-color: var(--mud-palette-primary-lighten);
}

/* ========================================
   SECTION 5: TIME SLOT GRID
   Hour-based time slots for day/week views
   ======================================== */
.time-slot {
    height: var(--calendar-time-slot-height);
    border-bottom: 1px solid var(--mud-palette-divider-light);
}

.time-slot:hover {
    background-color: var(--mud-palette-action-hover-opacity);
}

.time-slot-time {
    border-right: 1px solid var(--mud-palette-divider);
}


/* ========================================
   SECTION 6: WEEK VIEW
   Weekly calendar grid layout and styling
   Used by: WeekCalendarGrid.razor
   ======================================== */
.week-calendar-container {
    width: 100%;
}

.week-range-title {
    font-weight: 600;
    min-width: 200px;
    text-align: center;
}

/* Month date picker styled as text */
.month-date-picker {
    font-weight: 600;
    min-width: 200px;
    text-align: center;
}

.month-date-picker .mud-input-control {
    margin: 0;
}

.month-date-picker .mud-input-root {
    margin: 0;
}

.month-date-picker input {
    text-align: center;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    border: none;
}

.month-date-picker .mud-input-underline::before,
.month-date-picker .mud-input-underline::after {
    display: none;
}

.month-date-picker .mud-input-adornment {
    display: none;
}

.week-grid-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 8px;
    overflow: hidden;
}

.week-grid-header {
    display: flex;
    background: var(--mud-palette-surface);
    border-bottom: 2px solid var(--mud-palette-divider);
    position: sticky;
    top: 0;
    z-index: 10;
}

.week-time-header {
    width: 70px;
    min-width: 70px;
    flex-shrink: 0;
    border-right: 1px solid var(--mud-palette-divider);
}

.week-day-header {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    border-right: 4px solid var(--mud-palette-divider);
}

.week-day-header:last-child {
    border-right: none;
}

.week-header-status-counts {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 4px;
    flex-wrap: wrap;
}

.week-grid-body {
    display: flex;
    max-height: 600px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.week-grid-body::-webkit-scrollbar {
    display: none;
}

.week-time-column {
    width: 70px;
    min-width: 70px;
    flex-shrink: 0;
    background: var(--mud-palette-surface);
    border-right: 1px solid var(--mud-palette-divider);
    position: sticky;
    left: 0;
    z-index: 5;
}

.week-time-slot {
    height: 60px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 2px 8px;
    border-bottom: 1px solid var(--mud-palette-divider-light);
    background: var(--mud-palette-surface);
}

.week-day-column {
    flex: 1;
    position: relative;
    cursor: pointer;
    border-right: 4px solid var(--mud-palette-divider);
    min-height: 1440px; /* 24 hours * 60px */
    display: flex;
    flex-direction: column;
}

.week-day-column:last-child {
    border-right: none;
}

.week-hour-cell {
    height: 60px;
    border-bottom: 1px solid var(--mud-palette-divider-light);
    background: transparent;
}

.week-hour-cell:hover {
    background-color: var(--mud-palette-action-hover);
}

.week-events-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.week-event {
    position: absolute;
    padding: 4px 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid;
    background-color: rgba(255, 255, 255, 0.05);
    overflow: hidden;
    box-sizing: border-box;
    pointer-events: auto;
    z-index: 2;
}

.week-event:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    background-color: rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.week-event-time {
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.week-event-title {
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    padding: 2px 0;
}

.event-count-primary {
    color: var(--mud-palette-primary);
    font-weight: 600;
}

.upcoming-event-card {
    cursor: pointer;
}

.status-count {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-count-confirmed {
    color: var(--event-confirmed);
}

.status-count-pending {
    color: var(--event-pending);
}

.status-count-cancelled {
    color: var(--event-cancelled);
}

.status-count-organisation {
    color: var(--mud-palette-primary);
}

.status-count-outlook {
    color: var(--mud-palette-info);
}

/* ========================================
   SECTION 7: MONTH VIEW
   Monthly calendar grid layout and styling
   Used by: MonthCalendarGrid.razor
   ======================================== */
.month-day-cell {
    vertical-align: top;
    padding: 0 !important;
    border: 1px solid var(--mud-palette-divider);
    width: 14.28%;
}

.month-day-content {
    height: 150px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    cursor: pointer;
}

.month-day-content:hover {
    background-color: var(--mud-palette-action-hover);
}

/* Month View Status Counts */
.month-day-status-counts {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    margin-top: 4px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

/* Month View Events */
.month-event {
    padding: 5px 6px;
    border-radius: 8px;
    margin-bottom: 6px;
    margin-left: auto;
    margin-right: auto;
    width: 90%;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    display: block;
    font-size: 0.75rem;
    border: 1px solid;
    background-color: rgba(255, 255, 255, 0.05);
}

.month-event:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    background-color: rgba(255, 255, 255, 0.1);
}

.month-event-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    line-height: 1.2;
    display: block;
    max-width: 150px;
}

/* Force zero spacing between events in month view */
.calendar-cell .gap-0 {
    gap: 0 !important;
}

/* Month View - Stack events with no spacing */
.calendar-cell .mud-chip-root {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

.calendar-cell .mud-chip {
    margin: 0 !important;
}

.calendar-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--mud-palette-text-secondary);
}

/* Calendar Navigation */
.calendar-controls {
    display: flex;
    align-items: center;
    gap: var(--mud-spacing-3);
}

/* Make MudSimpleTable backgrounds transparent to inherit glassmorphism */
.glass-card .mud-table,
.glass-card .mud-simple-table,
.glass-card .mud-table-container {
    background-color: transparent !important;
}

.glass-card .mud-table thead,
.glass-card .mud-table tbody,
.glass-card .mud-table tr,
.glass-card .mud-table th,
.glass-card .mud-table td {
    background-color: transparent !important;
}

/* Scrollbar Styling for Calendar Cells */
.week-day-content::-webkit-scrollbar,
.month-day-content::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.week-day-content,
.month-day-content {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* ========================================
   SECTION 8: DAY VIEW
   Daily calendar grid layout and styling
   Used by: DayCalendarGrid.razor
   ======================================== */
.day-calendar-container {
    width: 100%;
}

.day-grid-wrapper {
    position: relative;
    border: 2px solid var(--mud-palette-divider);
    border-radius: 8px;
    overflow: hidden;
}

.day-grid-header {
    display: grid;
    grid-template-columns: 80px 1fr;
    border-bottom: 2px solid var(--mud-palette-divider);
    background-color: var(--mud-palette-surface);
}

.day-time-header {
    border-right: 2px solid var(--mud-palette-divider);
}

.day-header {
    padding: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.day-header-status-counts {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 4px;
}

.day-grid-body {
    display: grid;
    grid-template-columns: 80px 1fr;
    height: 600px;
    overflow-y: auto;
    position: relative;
}

.day-time-column {
    border-right: 2px solid var(--mud-palette-divider);
    background-color: var(--mud-palette-background-grey);
}

.day-time-slot {
    height: 60px;
    padding: 4px 8px;
    text-align: right;
    border-bottom: 1px solid var(--mud-palette-divider-light);
}

.day-column {
    position: relative;
    cursor: pointer;
    min-height: 1440px;
}

.day-hour-cell {
    height: 60px;
    border-bottom: 1px solid var(--mud-palette-divider-light);
}

.day-hour-cell:hover {
    background-color: var(--mud-palette-action-hover);
}

.day-events-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.day-event {
    position: absolute;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    pointer-events: auto;
    overflow: hidden;
    border: 1px solid;
    background-color: rgba(255, 255, 255, 0.05);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 2px 0;
    box-sizing: border-box;
}

.day-event:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    background-color: rgba(255, 255, 255, 0.1);
    z-index: 10;
}

.day-event-title {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* ========================================
   SECTION: CALENDAR RESPONSIVE
   Mobile and tablet-friendly calendar layouts
   ======================================== */

@media (max-width: 599px) {
    /* Calendar grid becomes scrollable on mobile */
    .week-view-container,
    .calendar-grid-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Week view: reduce column width, enable horizontal scroll */
    .week-view-grid {
        min-width: 700px !important; /* Ensures 7 days visible with scroll */
    }
    
    .week-day-column {
        min-width: 90px !important;
    }
    
    /* Time column stays fixed */
    .time-column {
        position: sticky;
        left: 0;
        z-index: 5;
        background: var(--mud-palette-background);
    }
    
    /* Month view: smaller cells */
    .month-grid-cell {
        min-height: 60px !important;
        padding: 4px !important;
    }
    
    .month-event-chip {
        font-size: 0.625rem !important;
        padding: 2px 4px !important;
    }
    
    /* Day view: full width */
    .day-view-container {
        padding: 8px !important;
    }
    
    .day-event {
        padding: 6px 8px !important;
        border-radius: 6px !important;
    }
    
    .day-event-title {
        font-size: 0.75rem !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
    }
    
    /* Calendar action bar */
    .calendar-action-bar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .calendar-view-buttons {
        order: 2;
        width: 100%;
        justify-content: center;
        max-width: 100% !important;
    }
    
    .calendar-view-buttons .mud-button-group {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .calendar-view-buttons .mud-button.calendar-view-btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        max-width: 33.333% !important;
        padding: 0.25rem 0.5rem !important;
        font-size: 0.875rem !important;
    }
    
    /* New Event button matches the width of the view buttons on mobile */
    .calendar-new-event-btn {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .calendar-date-picker {
        order: 1;
    }
    
    /* Hide calendar type selector on mobile, show as dropdown */
    .calendar-type-chips {
        display: none !important;
    }
}

@media (min-width: 600px) and (max-width: 959px) {
    /* Tablet: comfortable sizes */
    .week-day-column {
        min-width: 100px !important;
    }
    
    .month-grid-cell {
        min-height: 80px !important;
    }
}