/**
 * Shared Calendar Styles
 * Used by calendar-list.php and calendar-view.php
 * Provides consistent styling for all calendar views (month, week, year, day)
 */

/* Calendar Grid Layout */
.calendar-grid {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    gap: 1px;
    background: #e0e6ed;
    padding: 1px;
    min-height: 100%;
}

.calendar-grid.day-grid {
    grid-template-columns: 60px 1fr;
}

/* ============================================
   Month View Styles
   ============================================ */
.month-view {
    display: grid;
    grid-template-columns: 50px repeat(7, 1fr);
    gap: 1px;
    background: #e0e6ed;
    padding: 1px;
    min-height: 100%;
}

.month-week-number {
    background: #f5f7fa;
    padding: 8px;
    text-align: center;
    font-weight: 600;
    color: #999;
    font-size: 12px;
    border-right: 2px solid #e0e6ed;
    cursor: pointer;
    transition: all 0.2s;
}

.month-week-number:hover {
    background: #667eea;
    color: white;
    font-weight: 700;
}

.month-day-header {
    background: #f5f7fa;
    padding: 12px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    font-size: 13px;
}

.month-day-cell {
    background: white;
    min-height: 100px;
    padding: 8px;
    position: relative;
    border-right: 1px solid #e0e6ed;
    display: flex;
    flex-direction: column;
}

.month-day-cell.other-month {
    background: #fafafa;
    opacity: 0.5;
}

.month-day-cell.today {
    background: #f0f4ff;
    border: 2px solid #667eea;
}

.month-day-number {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
    margin-bottom: 6px;
}

.month-day-events {
    font-size: 11px;
    overflow: auto;
    max-height: none;
    flex: 1;
}

.month-event {
    background: #667eea;
    color: white;
    padding: 2px 4px;
    margin: 2px 0;
    border-radius: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: opacity 0.2s;
}

.month-event:hover {
    opacity: 0.8;
}

/* ============================================
   Year View Styles
   ============================================ */
.year-view {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    padding: 20px;
    background: #f5f7fa;
    overflow-y: auto;
}

.year-month-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.year-month-header {
    background: #f5f7fa;
    padding: 12px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 2px solid #e0e6ed;
    cursor: pointer;
    transition: background 0.2s;
}

.year-month-header:hover {
    background: #e8ecf1;
}

.year-month-grid {
    display: grid;
    grid-template-columns: 30px repeat(7, 1fr);
    gap: 1px;
    background: #e0e6ed;
    padding: 1px;
    flex: 1;
}

.year-week-number {
    background: #f5f7fa;
    padding: 2px;
    text-align: center;
    font-weight: 600;
    color: #999;
    font-size: 9px;
    border-right: 1px solid #e0e6ed;
    cursor: pointer;
    transition: all 0.2s;
}

.year-week-number:hover {
    background: #667eea;
    color: white;
}

.year-day-header {
    background: #f5f7fa;
    padding: 6px 4px;
    text-align: center;
    font-weight: 600;
    color: #666;
    font-size: 11px;
}

.year-day-cell {
    background: white;
    padding: 4px;
    text-align: center;
    font-size: 12px;
    position: relative;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.year-day-cell.other-month {
    background: #fafafa;
    color: #ccc;
}

.year-day-cell.today {
    background: #f0f4ff;
    color: #667eea;
    font-weight: 600;
    border-left-color: #667eea;
}

.year-day-cell.has-events {
    font-weight: 600;
    border-left-width: 4px;
    border-left-color: #667eea;
}

/* ============================================
   Week & Day View — New Layout
   ============================================ */

/* Wrapper stacks headers → all-day → scrollable time grid */
.calendar-week-day-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    border: 1px solid #e0e6ed;
    border-radius: 6px;
    overflow: hidden;
    background: #e0e6ed;
}

/* --- Header row (time gutter label + day headers) --- */
.calendar-headers {
    display: grid;
    gap: 1px;
    flex-shrink: 0;
}
.calendar-headers.week-headers {
    grid-template-columns: 60px repeat(7, 1fr);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}
.calendar-headers.day-headers {
    grid-template-columns: 60px 1fr;
}

.time-gutter-header {
    background: #f5f7fa;
    border-bottom: 2px solid #e0e6ed;
}

.day-header {
    background: #f5f7fa;
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 2px solid #e0e6ed;
    font-size: 14px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background-color 0.2s ease, border-bottom-color 0.2s ease;
}

.day-header:hover {
    background: #eef2f7;
}

.day-header.today {
    background: #f0f4ff;
    color: #667eea;
    border-bottom-color: #667eea;
}

.day-header.today:hover {
    background: #e8ecff;
}

.day-header-date {
    font-size: 12px;
    color: #999;
    margin-top: 2px;
}

.day-header.today .day-header-date {
    color: #667eea;
}

/* --- All-day events row --- */
.all-day-row {
    display: grid;
    gap: 1px;
    flex-shrink: 0;
    grid-auto-rows: 28px;
    border-bottom: 2px solid #cbd5e0;
    position: relative;
    overflow: visible;
}
.all-day-row.week-all-day {
    grid-template-columns: 60px repeat(7, 1fr);
    overflow-y: visible;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}
.all-day-row.day-all-day {
    grid-template-columns: 60px 1fr;
}

.all-day-label {
    background: #f5f7fa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px;
    grid-row: 1 / -1;
}

.all-day-cell {
    background: white;
    padding: 3px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    align-items: flex-start;
    align-content: flex-start;
    min-height: 28px;
    grid-row: 1 / -1;
}

.allday-event {
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    max-width: 100%;
    line-height: 1.4;
    transition: opacity 0.15s;
}
.allday-event:hover {
    opacity: 0.85;
}

/* Spanning all-day events */
.allday-event-spanning {
    color: white;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 24px;
    transition: opacity 0.15s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.allday-event-spanning:hover {
    opacity: 0.85;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* --- Scrollable time-slots area --- */
.time-slots-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.time-slots {
    display: grid;
    gap: 1px;
    /* 60px per hour × 24 hours = 1440px total height */
}
.time-slots.week-time-slots {
    grid-template-columns: 60px repeat(7, 1fr);
}
.time-slots.day-time-slots {
    grid-template-columns: 60px 1fr;
}

/* Time gutter (left column with hour labels) */
.time-gutter {
    background: #f5f7fa;
}

.time-slot-label {
    background: #f5f7fa;
    width: max-content;
    height: 60px; /* 60px = 1 hour = 1px per minute */
    padding: 2px 6px 0;
    font-size: 11px;
    color: #888;
    text-align: right;
    border-bottom: 1px solid #edf0f4;
    line-height: 1;
}

/* Day column — holds all time blocks + absolutely positioned events */
.day-col {
    background: white;
    position: relative; /* events positioned relative to this */
    border-right: 1px solid #f0f0f0;
}

.day-col.today-col {
    background: #fafbff;
}

/* Each hour block */
.time-block {
    position: relative;
    height: 60px; /* must match time-slot-label */
    border-bottom: 1px solid #edf0f4;
    box-sizing: border-box;
}

/* 15-minute gridlines */
.quarter-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-bottom: 1px dotted #f0f0f0;
}
.quarter-line.q15 { top: 25%; }
.quarter-line.q30 { top: 50%; border-bottom-style: dashed; border-color: #e8e8e8; }
.quarter-line.q45 { top: 75%; }

/* --- Timed events (absolutely positioned in day-col) --- */
.timed-event {
    position: absolute;
    border-radius: 4px;
    color: white;
    font-size: 11px;
    padding: 3px 6px;
    overflow: hidden;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    border-left: 3px solid rgba(0,0,0,0.15);
    transition: box-shadow 0.15s, z-index 0s;
    line-height: 1.3;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
.timed-event:hover {
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
    z-index: 20;
}

.timed-event-time {
    font-size: 10px;
    opacity: 0.9;
    font-weight: 500;
}
.timed-event-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Legacy compat — keep for month grid if still used elsewhere */
.calendar-grid {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    gap: 1px;
    background: #e0e6ed;
    padding: 1px;
    min-height: 100%;
}

.calendar-grid.day-grid {
    grid-template-columns: 60px 1fr;
}

.time-header {
    background: #f5f7fa;
    padding: 10px;
    border-right: 1px solid #e0e6ed;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Old event-item kept for backward compat */
.event-item {
    position: absolute;
    left: 2px;
    right: 2px;
    padding: 4px 6px;
    border-radius: 3px;
    color: white;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    min-height: 20px;
    display: flex;
    align-items: center;
}

.event-item:hover {
    opacity: 0.9;
    z-index: 20;
}

.empty-message {
    text-align: center;
    padding: 40px;
    color: #999;
    grid-column: 1 / -1;
}

.empty-message p {
    margin-top: 10px;
    font-size: 14px;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e0e6ed;
        max-height: 200px;
        padding: 15px;
    }

    .calendar-content {
        flex: 1;
    }
}

@media (max-width: 768px) {
    .calendar-header-top {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .calendar-controls {
        flex-wrap: wrap;
        width: 100%;
    }

    .date-display {
        width: 100%;
    }

    .nav-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* ============================================
   Scrollbar Styling
   ============================================ */
.sidebar::-webkit-scrollbar,
#calendarView::-webkit-scrollbar,
.calendar-view::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
#calendarView::-webkit-scrollbar-track,
.calendar-view::-webkit-scrollbar-track {
    background: #f5f7fa;
}

.sidebar::-webkit-scrollbar-thumb,
#calendarView::-webkit-scrollbar-thumb,
.calendar-view::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
#calendarView::-webkit-scrollbar-thumb:hover,
.calendar-view::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Modal visibility control */
.event-modal {
    display: none !important;
}

.event-modal.active {
    display: flex !important;
}
