/**
 * Schedule Date Range Picker Styles
 * Custom styling for daterangepicker library
 */

/* ===================================
  Schedule Form - Reduced Gap
  =================================== */

/* Multiple selectors with max specificity to override everything */
#schedule-filters-form .fields--flex,
#schedule-filters-form.search-form .fields--flex,
form#schedule-filters-form .fields--flex,
form#schedule-filters-form .dropdowns-selectors .fields--flex,
form.search-form#schedule-filters-form .fields--flex,
.search-form#schedule-filters-form .dropdowns-selectors .fields--flex {
    gap: 0.5rem !important;
    column-gap: 0.5rem !important;
}

/* Specific override for the schedule page */
body .search-form#schedule-filters-form .fields--flex {
    gap: 0.5rem !important;
}

/* Fix Select2 fixed widths - make them flex */
#schedule-filters-form .fields--flex > .field {
    flex: 1 1 0 !important;
    min-width: 0 !important;
}

/* Make date field slightly wider */
#schedule-filters-form .fields--flex > .field:has(.daterange-wrapper) {
    flex-grow: 1.3 !important;
}

#schedule-filters-form .fields--flex > .field .select2-container {
    width: 100% !important;
}

#schedule-filters-form .fields--flex > .field select,
#schedule-filters-form .fields--flex > .field input {
    width: 100% !important;
    box-sizing: border-box !important;
}

/* ===================================
 Unified control heights (desktop)
 =================================== */

#schedule-filters-form .fields--flex > .field {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-bottom: 0 !important;
}

#schedule-filters-form .fields--flex > .field select,
#schedule-filters-form .fields--flex > .field .daterange-input,
#schedule-filters-form .fields--flex > .field--submit input[type="submit"],
#schedule-filters-form .fields--flex > .field .select2-selection--single {
    height: 44px !important;
    min-height: 44px !important;
    border-radius: var(--radius-lg);
}

#schedule-filters-form .fields--flex > .field select,
#schedule-filters-form .fields--flex > .field .daterange-input,
#schedule-filters-form .fields--flex > .field--submit input[type="submit"] {
    line-height: 44px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

#schedule-filters-form .fields--flex > .field .select2-container {
    margin-bottom: 0 !important;
}

/*
 * Select2: forms.css adds vertical padding on .select2-selection — inner box becomes
 * shorter than line-height and the label sits at the bottom after JS init.
 * Zero vertical padding + line-height matching box height (arrow stays position:absolute).
 */
#schedule-filters-form .fields--flex > .field .select2 .select2-selection--single {
    position: relative !important;
    box-sizing: border-box !important;
    padding: 0 2.25rem 0 1rem !important;
}

#schedule-filters-form .fields--flex > .field .select2-selection--single .select2-selection__rendered {
    line-height: 44px !important;
    padding: 0 !important;
    margin: 0 !important;
}

#schedule-filters-form .fields--flex > .field .select2-selection--single .select2-selection__arrow {
    height: 100% !important;
    top: 0 !important;
    right: 0.35rem !important;
}

/* Kill legacy min-width from global forms.css on schedule filter only */
#schedule-filters-form .fields--flex > .field input,
#schedule-filters-form .fields--flex > .field select,
#schedule-filters-form .fields--flex > .field .select2-container,
#schedule-filters-form .fields--flex > .field .select2-selection--single {
    min-width: 0 !important;
    max-width: 100% !important;
}

/* Keep button visible and aligned on desktop widths */
#schedule-filters-form .fields--flex > .field--submit {
    flex: 0 0 168px !important;
}

/* ===================================
  Date Range Input Field
  =================================== */

.daterange-wrapper {
    position: relative;
    width: 100%;
}

/* Desktop: Show date range picker, hide native inputs */
.daterange-wrapper--desktop {
    display: block;
}

.daterange-wrapper--mobile {
    display: none;
}

.daterange-input {
    width: 100%;
    min-width: 10rem;
    cursor: pointer;
    font-size: 15px;
    font-weight: 400;
    background-image: url("../../../assets/images/icons/calendar%203.svg");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
}

/* Mobile native date inputs */
.daterange-mobile-fields {
    display: flex;
    gap: 0.5rem;
}

.daterange-input-mobile {
    flex: 1;
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px;
    border: 2px solid var(--color-secondary-100);
    border-radius: var(--radius-lg);
    background-color: var(--color-light-grey);
    color: var(--color-secondary-950);
}

/* ===================================
  Daterangepicker Popup Overrides
  =================================== */

/* Popup container */
.daterangepicker {
    border: 1px solid var(--color-grey);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgb(var(--color-black-rgb) / 0.15);
    padding: 0;
    font-family: inherit;
}

/* Header (ranges sidebar) */
.daterangepicker .ranges {
    width: 180px;
    padding: 15px 0;
    background: var(--color-light-grey);
    border-right: 1px solid var(--color-grey);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.daterangepicker .ranges ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.daterangepicker .ranges li {
    padding: 10px 20px;
    font-size: 14px;
    color: var(--color-secondary-900);
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.daterangepicker .ranges li:hover {
    background: var(--color-primary-50);
    color: var(--color-primary);
}

.daterangepicker .ranges li.active {
    background: var(--color-primary-50);
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 600;
}

/* Calendar container */
.daterangepicker .drp-calendar {
    padding: 15px;
}

.daterangepicker .calendar-table {
    border: none;
    padding: 0;
}

/* Month/Year headers */
.daterangepicker .calendar-table th {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-secondary-700);
    padding: 8px 5px;
}

.daterangepicker select.monthselect,
.daterangepicker select.yearselect {
    font-size: 13px;
    padding: 5px;
    border: 1px solid var(--color-grey);
    border-radius: var(--radius);
    background: var(--color-white);
    cursor: pointer;
}

/* Day cells */
.daterangepicker td {
    font-size: 13px;
    text-align: center;
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.daterangepicker td.available:hover {
    background: var(--color-primary-50);
    color: var(--color-primary);
}

.daterangepicker td.active,
.daterangepicker td.active:hover {
    background-color: var(--color-primary);
    color: white;
}

.daterangepicker td.in-range {
    background-color: var(--color-primary-50);
    color: var(--color-primary);
}

.daterangepicker td.start-date,
.daterangepicker td.end-date {
    background-color: var(--color-primary);
    color: white;
    font-weight: 600;
}

.daterangepicker td.off,
.daterangepicker td.off.in-range,
.daterangepicker td.off.start-date,
.daterangepicker td.off.end-date {
    background-color: var(--color-secondary-50);
    color: var(--color-secondary-400);
}

.daterangepicker td.disabled,
.daterangepicker td.disabled:hover {
    color: var(--color-secondary-200);
    cursor: not-allowed;
}

/* Today marker */
.daterangepicker td.today {
    font-weight: 600;
    position: relative;
}

.daterangepicker td.today::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--color-primary);
    border-radius: 50%;
}

/* Buttons */
.daterangepicker .drp-buttons {
    padding: 12px 15px;
    border-top: 1px solid var(--color-grey);
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.daterangepicker .drp-buttons .btn {
    padding: 8px 20px !important;
    font-size: 13px !important;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 0 0 auto !important;
    min-width: 80px !important;
    max-width: 120px !important;
    width: auto !important;
    display: inline-block !important;
    float: none !important;
}

.daterangepicker .cancelBtn {
    background: var(--color-secondary-50) !important;
    color: var(--color-secondary-700) !important;
    order: 1;
}

.daterangepicker .cancelBtn:hover {
    background: var(--color-grey) !important;
}

.daterangepicker .applyBtn {
    background: var(--color-primary) !important;
    color: white !important;
    order: 2;
}

.daterangepicker .applyBtn:hover {
    background: var(--color-primary-600) !important;
    box-shadow: 0 2px 8px rgb(var(--color-primary-500-rgb) / 0.3);
}

/* Arrow (caret) */
.daterangepicker:before,
.daterangepicker:after {
    border-bottom-color: var(--color-grey);
}

.daterangepicker:after {
    border-bottom-color: var(--color-white);
}

/* ===================================
  Responsive
  =================================== */

/* Tablet and below - stack filters in 2 columns */
@media (max-width: 1024px) {
    #schedule-filters-form .fields--flex {
        flex-wrap: wrap !important;
    }

    #schedule-filters-form .fields--flex > .field {
        flex: 1 1 calc(50% - 0.25rem) !important;
        min-width: calc(50% - 0.25rem) !important;
    }

    /* Date field takes full width on last row if needed */
    #schedule-filters-form .fields--flex > .field:has(.daterange-wrapper) {
        flex: 1 1 calc(50% - 0.25rem) !important;
        flex-grow: 1 !important;
    }

    /* Submit button takes full width */
    #schedule-filters-form .fields--flex .field--submit {
        flex: 1 1 100% !important;
    }
}

/* Mobile - single column layout */
@media (max-width: 768px) {
    /* Switch to native date inputs on mobile */
    .daterange-wrapper--desktop {
        display: none !important;
    }

    .daterange-wrapper--mobile {
        display: block !important;
    }

    #schedule-filters-form .fields--flex {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    #schedule-filters-form .fields--flex > .field,
    #schedule-filters-form .fields--flex > .field:has(.daterange-wrapper),
    #schedule-filters-form .fields--flex .field--submit {
        flex: 1 1 100% !important;
        width: 100% !important;
        min-width: 100% !important;
        margin-bottom: 0 !important;
    }

    /* Ensure inputs take full width on mobile */
    #schedule-filters-form .fields--flex > .field select,
    #schedule-filters-form .fields--flex > .field input,
    #schedule-filters-form .fields--flex > .field .select2-container,
    #schedule-filters-form .fields--flex > .field .daterange-input {
        width: 100% !important;
    }

    /* Larger touch targets on mobile */
    #schedule-filters-form .fields--flex > .field input,
    #schedule-filters-form .fields--flex > .field select,
    #schedule-filters-form .fields--flex > .field .daterange-input,
    #schedule-filters-form .fields--flex .field--submit input[type="submit"] {
        padding: 0.875rem 1rem !important;
        font-size: 16px !important;
        min-height: 56px !important;
        height: auto !important;
        line-height: 1.25 !important;
    }

    /* Native select styling on mobile */
    #schedule-filters-form .fields--flex > .field select {
        -webkit-appearance: menulist;
        -moz-appearance: menulist;
        appearance: menulist;
        background-image: none;
        padding-right: 2.5rem;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        vertical-align: middle;
    }

    /* Hide Select2 on mobile if it was initialized */
    #schedule-filters-form .fields--flex > .field .select2-container {
        display: none !important;
    }

    #schedule-filters-form .fields--flex > .field select.select2-hidden-accessible {
        display: block !important;
        opacity: 1 !important;
        position: relative !important;
        width: 100% !important;
    }

    /* Actions spacing on mobile */
    #schedule-filters-form .actions {
        margin-top: 1.25rem;
    }

    #schedule-filters-form .filters {
        gap: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
    }

    #schedule-filters-form .single-filter {
        width: 100%;
    }
}

/* Desktop: schedule form should use custom Select2 selector */
@media (min-width: 769px) {
    #schedule-filters-form .fields--flex > .field .select2-container {
        display: block !important;
        width: 100% !important;
    }

    /* Prevent Select2 from adding extra bottom gap after JS init */
    #schedule-filters-form .fields--flex > .field .select2 {
        margin-bottom: 0 !important;
    }

    #schedule-filters-form .fields--flex > .field select.select2-hidden-accessible {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        border: 0 !important;
    }

    /* Keep checkbox labels visually closer to the filter row on desktop */
    #schedule-filters-form .actions {
        margin-top: 0.5rem;
    }

    #schedule-filters-form .single-filter {
        align-items: center;
        line-height: 1;
    }

    #schedule-filters-form .single-filter input[type="checkbox"] {
        margin: 0;
        transform: translateY(-1px);
    }

    #schedule-filters-form .single-filter .description {
        display: inline-flex;
        align-items: center;
        line-height: 1.2;
    }
}

/* Daterangepicker popup on mobile */
@media (max-width: 768px) {
    .daterangepicker {
        max-width: 100% !important;
        left: 10px !important;
        right: 10px !important;
    }

    .daterangepicker .ranges {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-grey);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .daterangepicker .drp-calendar {
        float: none !important;
        width: 100% !important;
    }

    .daterangepicker .calendar-table {
        font-size: 12px;
    }

    .daterangepicker .drp-buttons {
        flex-direction: row;
        gap: 8px;
    }

    .daterangepicker .drp-buttons .btn {
        flex: 1;
    }
}

/* ===================================
  Disabled State (during loading)
  =================================== */

.daterange-input:disabled,
.daterange-input-mobile:disabled {
    cursor: not-allowed !important;
    opacity: 0.6;
}

/* ===================================
  Filter Actions (Checkboxes)
  =================================== */

#schedule-filters-form .actions {
    margin-top: 1.5rem;
}

#schedule-filters-form .filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

#schedule-filters-form .single-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin: 0;
}

#schedule-filters-form .single-filter input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

#schedule-filters-form .single-filter .description {
    font-size: 0.9rem;
    margin: 0;
    white-space: nowrap;
}

/* Desktop hard override after all base rules (prevents post-JS layout drop) */
@media (min-width: 769px) {
    #schedule-filters-form .fields--flex > .field .select2,
    #schedule-filters-form .fields--flex > .field .select2-container,
    #schedule-filters-form .fields--flex > .field .select2-container .select2-selection--single {
        margin: 0 !important;
    }

    #schedule-filters-form .actions {
        margin-top: 0.5rem !important;
    }
}
