/* TWS Calendar Custom Styles */

/* Main Calendar Container */
.tws-calendar-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto;
    font-family: inherit;
}

.tws-calendar-container.mobile {
    position: relative;
    z-index: 1;
}

.tws-calendar-container.desktop {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Price Display Styles */
.tws-price-display {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 15px;
    margin-top: 15px;
    margin-bottom: 15px;
    font-family: inherit;
    transition: all 0.3s ease;
}

.tws-price-display h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.tws-price-amount {
    margin-bottom: 8px;
}

.tws-price-amount .tws-regular-price del {
    color: #999;
    margin-right: 8px;
}

.tws-price-amount .tws-current-price {
    font-size: 18px;
    font-weight: bold;
    color: #e30517;
}

.tws-price-details {
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

.tws-price-details .tws-duration,
.tws-price-details .tws-date-range {
    margin-bottom: 4px;
}

.tws-price-loading {
    color: #666;
    font-style: italic;
    padding: 10px 0;
}

.tws-price-error {
    color: #dc3545;
    font-weight: 500;
    padding: 10px 0;
}

/* Selected Dates Section */
.tws-selected-dates-section {
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e9ecef;
}

.tws-selected-dates-label {
    font-size: 14px;
    color: #6c757d;
    margin-bottom: 5px;
    font-weight: 500;
}

.tws-selected-dates-range {
    font-size: 15px;
    min-height: 20px;
    line-height: 1.4;
}

.tws-selected-dates-range.selected {
    color: #2e7d32;
    font-weight: bold;
    font-style: normal;
}

.tws-selected-dates-range.empty {
    color: #666;
    font-weight: normal;
    font-style: italic;
}

/* Average Price Display */
.tws-average-price {
    margin-top: 5px;
}

.tws-average-price-label {
    font-size: inherit;
}

/* Calendar Error Fallback Styles */
.tws-calendar-error-fallback {
    padding: 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f9f9f9;
}

.tws-calendar-error-fallback p {
    margin: 0;
    color: #666;
}

.tws-calendar-error-fallback small {
    color: #999;
}

/* Display Input */
.tws-calendar-display {
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    background-color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    min-height: 48px;
}

.tws-calendar-display.mobile {
    border-radius: 8px;
}

.tws-calendar-display.desktop {
    cursor: default;
    border-radius: 8px 8px 0 0;
}

.tws-calendar-display.loading {
    opacity: 0.7;
    cursor: wait;
}

.tws-calendar-display.open.mobile {
    border-bottom: none;
    border-radius: 8px 8px 0 0;
}


.tws-calendar-display.loading:hover {
    border-color: #e1e5e9;
}

/* Display Text */
.tws-calendar-display-text {
    flex: 1;
    text-align: left;
}

.tws-calendar-display-text.has-dates {
    color: #2c3e50;
    font-weight: 500;
}

.tws-calendar-display-text.placeholder {
    color: #6c757d;
}

/* Calendar Icon */
.tws-calendar-icon {
    font-size: 16px;
    transition: transform 0.2s ease;
    margin-left: 8px;
}

.tws-calendar-icon.open {
    transform: rotate(180deg);
}

/* Loading Spinner */
.tws-calendar-loader {
    width: 20px;
    height: 20px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Calendar Popup */
.tws-calendar-popup {
    background-color: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.tws-calendar-popup.mobile {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    border-radius: 0 0 8px 8px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    min-width: auto;
}

.tws-calendar-popup.desktop {
    position: relative;
    flex: 1;
}

/* Calendar Header */
.tws-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 8px 0;
}

/* Navigation Buttons */
.tws-calendar-nav-btn {
    border: none;
    background: #f8f9fa;
    font-size: 16px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    color: #495057;
    transition: background-color 0.2s;
}

.tws-calendar-nav-btn:hover {
    background-color: #e9ecef;
}

/* Hide disabled previous button */
.tws-calendar-nav-btn.prev:disabled,
.tws-calendar-nav-btn.prev[disabled] {
    visibility: hidden;
}

/* Calendar Title */
.tws-calendar-title {
    font-weight: 600;
    font-size: 16px;
    color: #2c3e50;
    margin: 0;
}

/* Day Headers */
.tws-calendar-day-headers {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0px;
    margin-bottom: 8px;
}

.tws-calendar-day-header {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    padding: 8px 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Calendar Grid */
.tws-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0px;
}

/* Calendar Days */
.tws-calendar-day {
    text-align: center;
    border-radius: 6px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
    font-size: 14px;
}

.tws-calendar-day.empty {
    padding: 8px;
    cursor: default;
}

.tws-calendar-day.selectable {
    padding: 8px 4px;
    cursor: pointer;
}

.tws-calendar-day.unavailable-for-selection {
    padding: 8px 4px;
    cursor: not-allowed;
}

/* Day States */
.tws-calendar-day:not(.empty):hover {
    background-color: #333;
    color: white;
}

.tws-calendar-day.past-date {
    color: rgba(158, 158, 158, 0.6);
    background-color: transparent;
    cursor: not-allowed;
}

.tws-calendar-day.unavailable {
    background-color: #ffebee;
    color: rgba(198, 40, 40, 0.6);
    cursor: not-allowed;
}

.tws-calendar-day.unavailable:hover {
    background-color: rgba(255, 205, 210, 0.6);
    color: rgba(183, 28, 28, 0.6);
}

.tws-calendar-day.disabled {
    background-color: transparent;
    color: rgba(158, 158, 158, 0.6);
    opacity: 0.7;
}

.tws-calendar-day.disabled:hover {
    background-color: #333;
}

.tws-calendar-day.available {
    background-color: white;
    color: #2c3e50;
}

.tws-calendar-day.available:hover {
    background-color: #333;
    color: white;
}

/* Selection States */
.tws-calendar-day.start-date,
.tws-calendar-day.end-date {
    background-color: #333;
    color: white;
    font-weight: 600;
    border-radius: 0;
}

.tws-calendar-day.start-date {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.tws-calendar-day.end-date {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

.tws-calendar-day.start-date:hover {
    background-color: #333;
    color: white;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.tws-calendar-day.end-date:hover {
    background-color: #333;
    color: white;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

.tws-calendar-day.start-date.end-date {
    border-radius: 6px;
}

.tws-calendar-day.in-range {
    background-color: #333;
    color: white;
    border-radius: 0;
}

.tws-calendar-day.hover-range {
    background-color: white;
    color: #333;
    border-radius: 0;
}

.tws-calendar-day.hover-end {
    background-color: #333;
    color: white;
    border-top-left-radius: 0px;
    border-bottom-left-radius: 0px;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* Calendar Indicators */
.tws-calendar-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    font-size: 8px;
}

.tws-calendar-indicator.past, .calendar-day.past-date .tws-calendar-indicator.unavailable, .invalid-range-start .tws-calendar-indicator.available, .after-maximum-date .tws-calendar-indicator.available {
    background-color: rgba(158, 158, 158, 0.6);
}

.calendar-day:not(.past-date) .tws-calendar-indicator.unavailable {
    background-color: rgba(244, 67, 54, 0.6);
}

.tws-calendar-indicator.disabled {
    background-color: rgba(158, 158, 158, 0.6);
}

.calendar-day:not(.invalid-range-start, .after-maximum-date) .tws-calendar-indicator.available {
    background-color: #4caf50;
}

/* Action Buttons */
.tws-calendar-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    gap: 8px;
}

.tws-calendar-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.tws-calendar-btn.clear {
    background-color: #6c757d;
    color: white;
    border-radius: 6px;
}

.tws-calendar-btn.clear:hover {
    background-color: #5a6268;
}

.tws-calendar-clear-link:hover {
    cursor: pointer;
}

.tws-calendar-btn.done {
    background-color: #e30517;
    color: white;
    border-radius: 5px;
    border: 1px solid #e30517;
}

.tws-calendar-btn.done:hover {
    background-color: white;
    color: #e30571;
    border: 1px solid #e30571;
}

/* WordPress Wrapper */
.tws-calendar-wrapper {
    max-width: 100%;
    margin: 0 auto;
    font-family: inherit;
}

.tws-calendar-wrapper * {
    box-sizing: border-box;
}

/* Screen Reader Only */
.tws-calendar-sr-only {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Messages */
.tws-calendar-message {
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid;
}

.tws-calendar-message.success {
    background-color: #d1edcc;
    color: #155724;
    border-color: #c3e6cb;
}

.tws-calendar-message.error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.tws-calendar-message-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    line-height: 1;
    opacity: 0.7;
}

.tws-calendar-message-close:hover {
    opacity: 1;
}

/* Calendar Widget Container */
.tws-calendar-widget {
    margin-bottom: 20px;
}

/* Selected Dates Display */
.tws-calendar-selected-dates {
    margin-top: 20px;
    padding: 16px 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.tws-calendar-selected-label {
    font-size: 13px;
    color: #6c757d;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tws-calendar-selected-range {
    font-size: 16px;
    color: #2c3e50;
    font-weight: 500;
}

/* Grey out dates that cannot be selected as end date */
.tws-calendar-day.invalid-end-date:not(.start-date),
.tws-calendar-day.invalid-range-start:not(.start-date),
.tws-calendar-day.invalid-range:not(.start-date),
.tws-calendar-day.unavailable-for-selection:not(.disabled, .start-date, .unavailable, .after-maximum-date) {
    background-color: rgba(245, 245, 245, 0.5) !important;
    color: rgba(153, 153, 153, 0.5) !important;
    cursor: not-allowed;
}

.tws-calendar-day.invalid-end-date:hover,
.tws-calendar-day.invalid-range-start:hover,
.tws-calendar-day.invalid-range:hover {
    background-color: #e9e9e9;
    color: #777;
}

.calendar-day.invalid-range:hover::after,
.calendar-day.invalid-range-start:hover::after,
.calendar-day.unavailable:hover::after,
.calendar-day.disabled:hover::after,
.calendar-day.past-date:hover::after,
.calendar-day.after-maximum-date:hover::after,
.tws-calendar-day.invalid-end-date:hover::after {
    opacity: 1;
}

/* Tooltip for unavailable dates */
.calendar-day.unavailable::after,
.calendar-day.disabled::after,
.calendar-day.past-date::after,
.calendar-day.after-maximum-date::after,
.calendar-day.invalid-end-date::after,
.calendar-day.invalid-range::after,
.calendar-day.invalid-range-start::after {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 999999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .calendar-day.unavailable::after,
    .calendar-day.disabled::after,
    .calendar-day.past-date::after,
    .calendar-day.after-maximum-date::after,
    .calendar-day.invalid-end-date::after,
    .calendar-day.invalid-range::after,
    .calendar-day.invalid-range-start::after {
        /* Position below the day on mobile to avoid header cutoff */
        bottom: -65px;
        top: auto;
        white-space: pre-wrap;
        max-width: 200px;
        text-align: center;
        /* Ensure tooltip stays within viewport */
        left: 50%;
        transform: translateX(-50%);
        z-index: 10000;
    }
    
    /* For days in the first row (1-7), position tooltip below to avoid header cutoff */
    .tws-calendar-grid .calendar-day:nth-child(-n+7)::after {
        bottom: -110px;
        top: auto;
    }
    
    /* For days in the last rows that might get cut off at bottom, position above */
    .tws-calendar-grid .calendar-day:nth-last-child(-n+7)::after {
        bottom: auto;
        top: -110px;
    }
    
    /* Adjust positioning for edge days that might overflow */
    .tws-calendar-grid .calendar-day:nth-child(7n)::after,
    .tws-calendar-grid .calendar-day:nth-child(7n-1)::after {
        /* Days on the right edge - position tooltip to the left */
        left: auto;
        right: 0;
        transform: none;
    }
    
    .tws-calendar-grid .calendar-day:nth-child(7n-6)::after,
    .tws-calendar-grid .calendar-day:nth-child(7n-5)::after {
        /* Days on the left edge - position tooltip to the right */
        left: 0;
        right: auto;
        transform: none;
    }
}   

.calendar-day.unavailable::after {
    content: "Not available";
}

.calendar-day.disabled::after {
    content: "Not available as start / end date";
}

.calendar-day.past-date::after {
    content: "Before minimum selectable date";
}

.calendar-day.after-maximum-date::after {
    content: "After maximum bookable date (unavailable for booking)";
}

.calendar-day.invalid-range::after {
    content: "Invalid end date";
}

.calendar-day.invalid-range-start::after {
    content: "Invalid start date";
}

.calendar-day.invalid-end-date::after {
    content: "Cannot select before start date";
}

/* Fix to show the tooltip for disabled dates */
.tws-calendar-day.disabled {
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 768px) {
    .tws-calendar-wrapper {
        padding: 16px;
    }
    
    .tws-calendar-popup.desktop {
        min-width: auto;
    }
    
    .tws-calendar-day {
        min-height: 36px;
        font-size: 13px;
    }
    
    .tws-calendar-day-header {
        font-size: 11px;
        padding: 6px 2px;
    }
}

/* Focus Management */
.tws-calendar-day:focus {
    outline: none;
    z-index: 1;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .tws-calendar-day.start-date,
    .tws-calendar-day.end-date {
        border: 2px solid;
    }
    
    .tws-calendar-day.in-range {
        border: 1px solid;
    }
    
    .tws-calendar-day.disabled {
        border: 1px dashed;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .tws-calendar-day,
    .tws-calendar-display,
    .tws-calendar-nav-btn,
    .tws-calendar-btn,
    .tws-calendar-icon,
    .tws-calendar-message-close {
        transition: none;
    }
    
    .tws-calendar-loader {
        animation: none;
    }
}

/* Additional styles from main.js */

/* Animation for loading spinner */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Calendar wrapper font inheritance */
.tws-calendar-wrapper {
    font-family: inherit;
}

.tws-calendar-wrapper * {
    box-sizing: border-box;
}

/* Calendar day hover effects */
.calendar-day:hover {
    background-color: #333;
}

.calendar-day.unavailable {
    background-color: #ffebee;
    color: rgba(198, 40, 40, 0.6);
    cursor: not-allowed;
}

.calendar-day.unavailable:hover {
    background-color: rgba(255, 205, 210, 0.6);
    color: rgba(183, 28, 28, 0.6);
}

/* Mobile-first calendar container override */
.tws-calendar-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto;
    font-family: inherit;
}

/* Mobile calendar display */
.tws-calendar-display {
    display: block;
    padding: 12px 16px;
    border-radius: 8px;
    background-color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    min-height: 48px;
}

/* Mobile calendar popup */
.tws-calendar-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tws-calendar-popup.open {
    display: block;
}

/* Done button styling */
.tws-calendar-btn.done {
    background-color: #e30517;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

/* Selected range display */
.tws-calendar-selected-range-display {
    display: none;
    margin-top: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

/* Months container layout */
.tws-calendar-months-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Month title styling */
.tws-calendar-month-title {
    margin: 16px 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    color: #333;
}

/* Next month container */
.tws-calendar-next-month-container {
    display: none;
}

/* Title visibility controls */
.tws-calendar-title-desktop {
    display: none;
}

.tws-calendar-title-mobile {
    display: inline;
}

/* Desktop styles - 769px and up */
@media (min-width: 769px) {
    .tws-calendar-container {
        max-width: none;
        z-index: 9999;
        background: white;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
    
    .tws-calendar-display {
        display: none;
    }
    
    .tws-calendar-popup {
        display: block;
        position: static;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: transparent;
        padding: 0;
        margin: 0;
        z-index: auto;
    }
    
    .tws-calendar-months-container {
        flex-direction: row;
        gap: 20px;
    }
    
    .tws-calendar-month-grid {
        flex: 1;
    }
    
    .tws-calendar-next-month-container {
        display: block;
        width: 50%;
    }
    
    .tws-calendar-month-title:first-child {
        margin-top: 0;
    }
    
    .tws-calendar-selected-range-display {
        display: block;
    }
    
    .tws-calendar-title-mobile {
        display: none;
    }
    
    .tws-calendar-title-desktop {
        display: inline;
    }
}

/* Mobile styles - up to 768px */
@media (max-width: 768px) {
    /* Make calendar always visible in a fixed container like desktop */
    .tws-calendar-popup {
        display: block;
        position: static;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        border: 1px solid #ddd;
        border-radius: 8px;
        background: white;
        padding: 12px;
        margin: 12px 0;
        max-width: 100%;
        overflow: hidden;
    }
    
    /* Ensure calendar container fits viewport */
    .tws-calendar-container {
        max-width: 100%;
        margin: 0;
        padding: 0px;
        box-sizing: border-box;
    }
    
    /* Hide the calendar display button on mobile since calendar is always visible */
    .tws-calendar-display {
        display: none;
    }
    
    .tws-calendar-selected-range-display {
        display: none;
    }
    
    /* Hide second month on mobile to show only one month */
    .tws-calendar-desktop-only {
        display: none;
    }
    
    /* Ensure single month takes full width on mobile */
    .tws-calendar-months-container {
        flex-direction: column;
        gap: 0;
        max-width: 100%;
        overflow: hidden;
    }
    
    .tws-calendar-month-grid {
        min-width: auto;
        max-width: 100%;
        overflow: hidden;
    }
    
    /* Improve touch interaction on mobile */
    .tws-calendar-day {
        min-height: 44px; /* Apple's recommended minimum touch target */
        touch-action: manipulation; /* Prevent double-tap zoom */
        font-size: 12px; /* Smaller font for mobile */
        padding: 8px 2px; /* Reduced padding */
    }
    
    /* Ensure calendar grid stays within bounds */
    .tws-calendar-grid {
        max-width: 100%;
        overflow: hidden;
        gap: 0;
    }
    
    /* Make day headers smaller on mobile */
    .tws-calendar-day-header {
        font-size: 10px;
        padding: 4px 2px;
    }
    
    /* Adjust calendar wrapper for mobile */
    .tws-calendar-wrapper {
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        padding: 0px;
        max-width: 100%;
        overflow-x: hidden;
    }
       
    /* Fix day headers grid for mobile */
    .tws-calendar-day-headers {
        max-width: 100%;
        overflow: hidden;
        margin-bottom: 4px;
    }

    div.tws-calendar-month-grid {
        max-width: 100%;
    }
    
    .tws-calendar-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 36px;
    }
    
    .tws-calendar-wrapper {
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
}

/* Button styles for date selection */
button.button.alt.date-selection-needed:disabled {
    background-color: white !important;
    color: #e30517 !important;
    font-size: 14px !important;
    opacity: .5;
    cursor: not-allowed;
}

.bundle_price {
    display: none !important;
}

.tws-price-content {
    min-height: 112px;
}