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

/* ============================================
   Back Link
   ============================================ */
a.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 14px;
}

a.back-link:hover {
    text-decoration: underline;
}

/* ============================================
   Shared Calendar UI Controls
   ============================================ */
.calendar-header {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.calendar-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.calendar-header-bottom {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
}

.calendar-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

.calendar-title h2 {
    font-size: 24px;
    color: #2c3e50;
    font-weight: 600;
}

.calendar-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.calendar-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-btn {
    padding: 8px 12px;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    background: none;
    transition: all 0.3s;
}

.date-display {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
    min-width: 150px;
    text-align: center;
}

/* ============================================
   Export Modal Content (inside modal structure from modal.css)
   ============================================ */

/* Export modal content styles (inside modal) */
.export-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.export-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.export-option:hover {
    border-color: var(--color-primary);
    background: #f5f7ff;
}

.export-option input[type="radio"] {
    accent-color: var(--color-primary);
    width: 16px;
    height: 16px;
}

.export-option label {
    cursor: pointer;
    font-size: 14px;
    color: #2c3e50;
    font-weight: 500;
    flex: 1;
}

.export-date-range {
    display: none;
    gap: 10px;
    margin-top: 10px;
    padding: 12px 14px;
    background: #f9fafb;
    border-radius: 6px;
}

.export-date-range.visible {
    display: flex;
}

.export-date-range .date-field {
    flex: 1;
}

.export-date-range .date-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    margin-bottom: 4px;
}

.export-date-range .date-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

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

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

.month-week-number:hover {
    background: var(--color-primary);
    color: white;
    font-weight: 700;
}

.month-day-header {
    background: var(--color-bg-light);
    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 var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.month-day-cell:hover {
    background: #f0f4ff;
}

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

.month-day-cell.other-month:hover {
    background: #f0f4ff;
}

.month-day-cell.today {
    background: #f0f4ff;
    border: 2px solid var(--color-primary);
}

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

.month-day-events {
    font-size: 11px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.month-event {
    background: var(--color-primary);
    color: white; /* overridden by JS for contrast */
    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: var(--color-bg-light);
    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: var(--color-bg-light);
    padding: 12px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 2px solid var(--color-border);
    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: var(--color-border);
    padding: 1px;
    flex: 1;
}

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

.year-week-number:hover {
    background: var(--color-primary);
    color: white;
}

.year-day-header {
    background: var(--color-bg-light);
    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;
    cursor: pointer;
}

.year-day-cell:hover {
    background: #f0f4ff;
}

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

.year-day-cell.today {
    background: #f0f4ff;
    color: var(--color-primary);
    font-weight: 600;
    border-left-color: var(--color-primary);
}

.year-day-cell.has-events {
    font-weight: 600;
    border-left-width: 4px;
    border-left-color: var(--color-primary);
}

/* ============================================
   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 var(--color-border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--color-border);
}

/* --- 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: var(--color-bg-light);
    border-bottom: 2px solid var(--color-border);
}

.day-header {
    background: var(--color-bg-light);
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 2px solid var(--color-border);
    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: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

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

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

.day-header.today .day-header-date {
    color: var(--color-primary);
}

/* --- All-day events row --- */
.all-day-row {
    display: grid;
    gap: 1px;
    flex-shrink: 0;
    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: var(--color-bg-light);
    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;
}

/* Spanning all-day events */
.allday-event-spanning {
    color: white; /* overridden by JS for contrast */
    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: var(--color-bg-light);
}

.time-slot-label {
    background: var(--color-bg-light);
    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;
    cursor: pointer;
}

/* 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; /* overridden by JS for contrast */
    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, width 0.25s ease-in-out;
    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;
}

/* --- Event drag & resize --- */
.timed-event.dragging {
    opacity: 0.5;
    z-index: 100;
    cursor: grabbing;
}

.timed-event-ghost {
    position: absolute;
    border-radius: 4px;
    border: 2px dashed rgba(0, 0, 0, 0.4);
    background: rgba(0, 0, 0, 0.05);
    z-index: 50;
    pointer-events: none;
    box-sizing: border-box;
}

.event-resize-handle {
    position: absolute;
    left: 0;
    right: 0;
    height: 6px;
    cursor: ns-resize;
    z-index: 11;
}
.event-resize-handle-top {
    top: 0;
    border-radius: 4px 4px 0 0;
}
.event-resize-handle-bottom {
    bottom: 0;
    border-radius: 0 0 4px 4px;
}
.event-resize-handle:hover {
    background: rgba(255, 255, 255, 0.25);
}

.timed-event.resizing {
    z-index: 100;
    cursor: ns-resize;
}

.day-col.drag-over {
    background: rgba(28, 105, 212, 0.03);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .year-view {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

    .calendar-controls {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }

    .calendar-nav {
        width: 100%;
        justify-content: center;
        gap: 6px;
    }

    .calendar-nav:first-child {
        justify-content: space-between;
    }

    .calendar-nav:first-child .nav-btn {
        min-width: 44px;
        max-width: 44px;
        padding: 8px;
        flex-shrink: 0;
    }

    .date-display {
        flex: 1;
        min-width: 0;
        font-size: 14px;
    }

    .nav-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 40px;
    }

    .action-buttons {
        flex-wrap: wrap;
        width: 100%;
    }

    .action-buttons .btn {
        flex: 1;
        min-width: 0;
    }

    /* Month view: hide week number column */
    .month-view {
        grid-template-columns: repeat(7, 1fr);
    }

    .month-week-number {
        display: none;
    }

    .month-day-cell {
        min-height: 70px;
        padding: 4px;
    }

    .month-day-header {
        padding: 6px 4px;
        font-size: 11px;
    }

    .month-event {
        font-size: 10px;
        padding: 1px 3px;
    }

    /* Year view: single column */
    .year-view {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 10px;
    }

    /* Week/Day view: reduce gutter width */
    .calendar-headers.week-headers {
        grid-template-columns: 40px repeat(7, 1fr);
    }

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

    .all-day-row.week-all-day {
        grid-template-columns: 40px repeat(7, 1fr);
    }

    .all-day-row.day-all-day {
        grid-template-columns: 40px 1fr;
    }

    .time-slots.week-time-slots {
        grid-template-columns: 40px repeat(7, 1fr);
    }

    .time-slots.day-time-slots {
        grid-template-columns: 40px 1fr;
    }

    .time-slot-label {
        font-size: 9px;
        padding: 2px 3px 0;
    }

    .day-header {
        padding: 8px 2px;
        font-size: 12px;
    }

    .day-header-date {
        font-size: 10px;
    }

    .calendar-week-day-wrapper {
        height: calc(100vh - 220px);
    }

    .timed-event {
        font-size: 10px;
        padding: 2px 4px;
    }

    .timed-event-time {
        font-size: 9px;
    }
}

@media (max-width: 480px) {
    .month-day-cell {
        min-height: 50px;
        padding: 2px;
    }

    .month-day-number {
        font-size: 11px;
    }

    .month-event {
        font-size: 9px;
        padding: 0 2px;
    }

    .year-month-grid {
        grid-template-columns: repeat(7, 1fr);
    }

    .year-week-number {
        display: none;
    }

    .nav-btn {
        padding: 6px 8px;
        font-size: 11px;
    }
}

/* Event modal & details styles consolidated into modal.css */

/* Calendar View Page Overrides */
.calendar-view-page .container {
    max-width: 1600px;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons .btn-create {
    margin-left: auto;
}

.calendar-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

/* ============================================
   Closure / Holiday Indicators
   ============================================ */

/* Month view: tinted background */
.month-day-cell.closure-day {
    background: var(--color-primary-light);
}

.month-day-cell.closure-day.today {
    background: var(--color-primary-light);
}

/* Month view: banner label */
.closure-banner {
    background: var(--color-primary);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 2px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* Week/Day view: tinted column */
.day-col.closure-day-col {
    background: var(--color-primary-light);
}

/* Week/Day view: tinted header */
.day-header.closure-day-header {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* Year view: tinted day */
.year-day-cell.closure-day {
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
}

/* ============================================
   Context Menu
   ============================================ */
.context-menu {
    position: fixed;
    z-index: 1500;
    background: #fff;
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    padding: 4px 0;
    font-size: 14px;
    -webkit-user-select: none;
    user-select: none;
}

.context-menu-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.context-menu-item {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    cursor: pointer;
    gap: 8px;
    position: relative;
    white-space: nowrap;
    transition: background 0.1s;
}

.context-menu-item:hover {
    background: var(--color-primary-light, #f0f4ff);
}

.context-menu-item.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.context-menu-item-danger {
    color: var(--color-danger, #dc3545);
}

.context-menu-item-danger:hover {
    background: #fdf0f0;
}

.context-menu-arrow {
    margin-left: auto;
    font-size: 10px;
    opacity: 0.6;
}

.context-menu-divider {
    height: 1px;
    background: var(--color-border, #e0e0e0);
    margin: 4px 0;
}

/* Submenu */
.context-menu-has-submenu {
    position: relative;
}

.context-menu-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -4px;
    background: #fff;
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    padding: 4px 0;
    list-style: none;
    z-index: 1501;
}

.context-menu-has-submenu:hover > .context-menu-submenu {
    display: block;
}

.context-menu-submenu .context-menu-item {
    padding: 8px 14px;
}

.context-menu-submenu .context-menu-item:hover {
    background: var(--color-primary-light, #f0f4ff);
}
