/* ========================================
   PWA CALENDAR VIEW OVERRIDES
   ======================================== */

/* Only apply when in PWA mode */
body.glos-pwa #glos-pwa-view-calendar {
    /* Ensure calendar view fills available space */
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

body.glos-pwa #glos-calendar-smart-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Important for flex children */
}

body.glos-pwa .glos-calendar-layout {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Hide sidebar in PWA - calendar takes full width */
body.glos-pwa .glos-calendar-sidebar {
    display: none !important;
}

/* Make calendar fill the available space */
body.glos-pwa .glos-calendar-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
}

body.glos-pwa #glos-calendar-main {
    flex: 1;
    min-height: 0;
    height: 100%;
}

/* Ensure FullCalendar renders and is visible */
body.glos-pwa #glos-calendar-main .fc {
    height: 100%;
}

/* PWA Booking Panel - Full Screen Overlay */
body.glos-pwa .glos-slide-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 10000;
    overflow-y: auto;
}

body.glos-pwa #glos-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

body.glos-pwa #glos-panel-overlay.open {
    display: block;
}

/* Hide mobile sidebar toggle in PWA */
body.glos-pwa #glos-mobile-sidebar-toggle {
    display: none !important;
}

/* Hide sidebar overlay in PWA */
body.glos-pwa #glos-sidebar-overlay {
    display: none !important;
}

/* PWA-only: Make booking panel full-screen instead of side panel */
body.glos-pwa .glos-slide-panel {
    left: 0 !important;
    width: 100% !important;
    max-width: none !important;
    border-radius: 0 !important;
}

body.glos-pwa .glos-slide-panel.open {
    transform: translateX(0) !important;
}

/* Ensure panel content is scrollable on small screens */
body.glos-pwa .glos-panel-content {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

/* --- Calendar View --- */
#glos-pwa-view-calendar {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

#glos-pwa-calendar {
    /* Full height minus header if needed, but flex handles it */
    flex: 1;
    min-height: 0;
    background: #fff;
    /* Basic FC tweaks for mobile */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding: 0 5px;
}

/* Readability on phone */
.fc .fc-toolbar-title {
    font-size: 1.1em;
    font-weight: 600;
}

.fc .fc-button {
    font-size: 0.9em;
    padding: 0.4em 0.6em;
}

/* Event Styling to match Desktop generally but cleaner */
.fc-event {
    cursor: pointer;
    border-radius: 3px;
    font-size: 0.85em;
    border: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* --- Desktop Parity Styles (From glos-calendar.css) --- */

/* 1. Grid Scale (Target 45px per 15min slot - 1.5x zoom) */
#glos-pwa-calendar .fc-timegrid-slot {
    height: 45px !important;
    line-height: 44px !important;
    border-bottom: 1px dotted #e0e0e0 !important;
}

#glos-pwa-calendar .fc-timegrid-slot-label {
    height: 45px !important;
    vertical-align: middle !important;
}

/* 2. Open/Closed Hours Coloring */
/* Open Hours -> White/Transparent */
#glos-pwa-calendar .fc-timegrid-slot.fc-timegrid-slot-lane {
    background-color: #ffffff;
}

/* Closed Hours (Non-Business) -> Light Gray */
#glos-pwa-calendar .fc-non-business {
    background-color: #f3f3f3 !important;
    opacity: 1 !important;
}

/* 3. Event Styling Match */
#glos-pwa-calendar .fc-v-event {
    border: none;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    padding: 2px;
    transition: transform 0.1s, box-shadow 0.1s;
}

#glos-pwa-calendar .glos-event-time {
    font-size: 11px;
    opacity: 0.9;
    margin-bottom: 2px;
    display: block;
}

#glos-pwa-calendar .glos-event-title {
    font-weight: 600;
    display: block;
}

/* Specific Booking Colors */
#glos-pwa-calendar .glos-event-open-racing {
    background-color: #27ae60 !important;
    border-left: 3px solid #1e8449 !important;
}

#glos-pwa-calendar .glos-event-private {
    background-color: #8e44ad !important;
    border-left: 3px solid #6c3483 !important;
}

#glos-pwa-calendar .glos-event-system {
    background-color: #95a5a6 !important;
    border-left: 3px solid #7f8c8d !important;
    color: #fff !important;
}

/* Now Indicator matches desktop */
#glos-pwa-calendar .fc-now-indicator-line {
    border-color: #d83e3e;
    border-width: 2px 0 0;
    box-shadow: 0 0 4px rgba(216, 62, 62, 0.4);
    z-index: 99;
}

#glos-pwa-calendar .fc-now-indicator-arrow {
    border-color: #d83e3e;
    border-width: 5px 0 5px 6px;
    border-bottom-color: transparent;
    border-top-color: transparent;
}

/* --- Phase 9: UI Refinement (Full Bleed & Toolbar Parity) --- */

/* 1. Layout: Full Bleed for Calendar View */
/* Counteract the padding on .glos-pwa-content (15px horizontal, 71px top, safe-bottom) */
body.glos-pwa #glos-pwa-view-calendar {
    /* Top: Content padding is 71px (56 + 15). We want 56px. So -15px. */
    margin-top: -15px !important;

    /* Sides: Content padding is 15px. We want 0. So -15px. */
    margin-left: -15px !important;
    margin-right: -15px !important;

    /* Bottom: Content padding is safe-area. We want to control it ourselves or fill it. */
    /* Let's negative margin it so we have full control. */
    margin-bottom: calc(-1 * env(safe-area-inset-bottom, 20px)) !important;

    padding: 0 !important;
    width: calc(100% + 30px) !important;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
}

#glos-pwa-calendar {
    width: 100%;
    /* Height: Viewport - Header (56+SafeTop) - SafeBottom */
    /* Note: We use 100vh, then subtract the known header layout. */
    /* Header takes 56px + env(safe-area-inset-top). */
    /* Bottom safe area takes env(safe-area-inset-bottom). */
    height: calc(100vh - var(--glos-pwa-header-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    background: #fff;
}

/* 2. Toolbar Parity (Match Desktop Buttons) */

/* Primary Buttons (Views only - exclude Today) */
#glos-pwa-calendar .fc-button-primary:not(.fc-prev-button):not(.fc-next-button):not(.fc-today-button) {
    background-color: #157acc !important;
    border-color: #157acc !important;
    color: #fff !important;
    border-radius: 50px !important;
    text-transform: capitalize;
    font-weight: 500;
    box-shadow: none !important;
    padding: 8px 16px !important;
    /* Slightly smaller for mobile than desktop\'s 24px */
    font-size: 13px !important;
    height: 36px !important;
    /* Touch friendly */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Nav Buttons (Prev/Next + Today) */
#glos-pwa-calendar .fc-prev-button,
#glos-pwa-calendar .fc-next-button,
#glos-pwa-calendar .fc-today-button {
    background-color: #fff !important;
    border: 1px solid #dcdcde !important;
    color: #555 !important;
    border-radius: 50px !important;
    min-width: 36px !important;
    height: 36px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 10px !important;
    /* Padding for Today text, icon buttons will override if needed */
    margin: 0 2px !important;
    box-shadow: none !important;
    text-transform: capitalize;
    font-weight: 500;
    opacity: 1 !important;
    /* Ensure enabled look */
}

/* Specific icon override for prev/next to prevent wide padding */
#glos-pwa-calendar .fc-prev-button,
#glos-pwa-calendar .fc-next-button {
    width: 36px !important;
    /* Fixed width for circles */
    padding: 0 !important;
}

#glos-pwa-calendar .fc-prev-button:hover,
#glos-pwa-calendar .fc-next-button:hover,
#glos-pwa-calendar .fc-today-button:hover {
    background-color: #f5f5f7 !important;
}

/* Toolbar Title */
#glos-pwa-calendar .fc-toolbar-title {
    font-size: 1.1em !important;
    font-weight: 700 !important;
    color: #111 !important;
    position: relative !important;
    top: 5px !important;
    /* Force visual centering */
}

/* Adjust toolbar padding & Grid Layout */
#glos-pwa-calendar .fc-header-toolbar {
    padding: 10px !important;
    margin-bottom: 0 !important;
    display: grid !important;
    grid-template-columns: auto 1fr auto !important;
    align-items: center !important;
    gap: 0 !important;
}

/* Center Chunk (Title) */
#glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk:nth-child(2) {
    justify-self: center !important;
    display: flex !important;
    justify-content: center !important;
    width: 100%;
    /* Ensure flex centering works in grid cell */
}

/* PWA: Hide Original View Buttons (Replaced by Custom Switch) */
body.glos-pwa #glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk button.fc-resourceTimeGridDay-button,
body.glos-pwa #glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk button.fc-timeGridDay-button,
body.glos-pwa #glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk button.fc-dayGridDay-button,
body.glos-pwa #glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk button.fc-dayGridMonth-button,
body.glos-pwa #glos-pwa-calendar .fc-header-toolbar .fc-toolbar-chunk button.fc-month-button {
    display: none !important;
}

/* PWA View Switch (Segmented Control) */
.glos-pwa-view-switch {
    display: inline-flex;
    background: #e9e9eb;
    border-radius: 8px;
    /* App-like rounded rect */
    padding: 2px;
    margin-left: 8px;
    vertical-align: middle;
    cursor: pointer;
    /* Clickable container */
    position: relative;
    top: -2px;
    /* Visual alignment with Nav buttons */
}

.glos-pwa-view-segment {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 4px 12px;
    /* Increased hit area */
    font-size: 13px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    line-height: 1.4;
    transition: all 0.2s ease;
    min-width: 32px;
    /* Ensure D and M have width */
    text-align: center;
    pointer-events: none;
    /* Let clicks pass to container */
}

.glos-pwa-view-segment.active {
    background: #fff;
    color: #000;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.glos-pwa-view-segment:active {
    opacity: 0.7;
}

/* ========================================
   PWA Calendar Event Styling Parity with Desktop
   ======================================== */

/* 1. Main Event Container Parity (.fc-v-event from Desktop) */
/* Desktop: border: none; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.08); padding: 2px; */
body.glos-pwa #glos-pwa-calendar .fc-v-event {
    border: none !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
    padding: 2px !important;
    transition: transform 0.1s, box-shadow 0.1s !important;
}

/* Desktop Hover Effect (Good for active state on touch too) */
body.glos-pwa #glos-pwa-calendar .fc-v-event:active,
body.glos-pwa #glos-pwa-calendar .fc-v-event:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
    z-index: 9999 !important;
}

/* 2. Event Content Interior (.fc-event-main from Desktop) */
/* Desktop: padding: 4px; color: #fff; font-size: 12px; line-height: 1.3; */
body.glos-pwa #glos-pwa-calendar .fc-event-main {
    padding: 4px !important;
    color: #fff !important;
    font-size: 12px !important;
    line-height: 1.3 !important;
}

/* 3. Time Label (.glos-event-time -> .fc-event-time) */
/* Desktop: font-size: 11px; opacity: 0.9; margin-bottom: 2px; */
body.glos-pwa #glos-pwa-calendar .fc-event-time {
    font-size: 11px !important;
    opacity: 0.9 !important;
    margin-bottom: 2px !important;
    display: block !important;
    font-weight: normal !important;
    /* FC defaults usually bold */
}

/* 4. Title Label (.glos-event-title -> .fc-event-title) */
/* Desktop: font-weight: 600; */
body.glos-pwa #glos-pwa-calendar .fc-event-title {
    font-weight: 600 !important;
    display: block !important;
    font-size: inherit !important;
    /* Inherit 12px from main */
}

/* 5. Month View Parity (.fc-h-event) */
/* Apply similar rounding and shadow to horizontal events */
body.glos-pwa #glos-pwa-calendar .fc-h-event {
    border: none !important;
    border-radius: 4px !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
    color: #fff !important;
    /* Ensure text is white */
}

body.glos-pwa #glos-pwa-calendar .fc-h-event .fc-event-main {
    padding: 2px 4px !important;
    /* Slightly tighter for month view strips */
}

/* Ensure Booking Colors apply to bg (Already present but scoping ensures priority) */
/* Note: The classnames are on the <a> tag (.fc-event), so they control bg */

/* --- Custom Event Content Specifics (JS Injected) --- */
.glos-pwa-event-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.glos-pwa-event-details {
    /* Keep smaller font per request */
    font-size: 10px;
    font-weight: 400;
    opacity: 0.8;
    line-height: 1.1;
    display: flex;
    flex-direction: column;
}

.glos-pwa-event-details div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}