/* ===== Booking / "Thêm khách xem phòng" form + modal =====
   Shared by the property detail page (desktop inline card + #bookingModal) and
   the room info page (/thong-tin-phong/), both driven by
   static/js/components/booking-form.js. Includes the flatpickr list-select
   date/time picker styles that form uses. */

/* Focus / validation / messages (moved from property_detail.html's inline <style>) */
.booking-form .form-control:focus,
.booking-form .form-select:focus {
    border-color: var(--primary-blue, #0966ff);
    box-shadow: 0 0 0 0.2rem rgba(9, 102, 255, 0.25);
}
.booking-form .invalid-feedback { display: block; }
.booking-form .is-invalid { border-color: #dc3545; }
.booking-form .is-valid { border-color: var(--primary-blue, #0966ff); }
.booking-form .form-control,
.booking-form .form-select {
    line-height: 1.5;
    min-height: calc(1.5em + 0.75rem + 2px);
}
.booking-form input[type="date"].form-control,
.booking-form input[type="datetime-local"].form-control {
    height: calc(1.5em + 0.75rem + 2px);
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
}
.booking-form input[type="date"].form-control::-webkit-datetime-edit,
.booking-form input[type="datetime-local"].form-control::-webkit-datetime-edit {
    line-height: 1.5;
    padding: 0;
}
.booking-messages:not(:empty) { margin-bottom: 0.75rem; }
.booking-messages .alert { margin-bottom: 0; }
.booking-success { font-size: 0.8125rem; }
.booking-success__header { font-size: 0.9375rem; }
.booking-success__row { flex-wrap: nowrap; }
.booking-success__row .booking-success__label,
.booking-success__row .booking-success__value {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.booking-success__row .booking-success__label { flex-shrink: 0; }
.submit-text,
.loading-text { transition: all 0.3s ease; }

/* ===== Booking form: readonly info fields (layout only) =====
   Label color/pill treatment and border/padding/background for these live
   further down in the "Booking Modal — compact pill-label design" block -
   it applies to every .booking-field wherever it renders (modal or the
   desktop sidebar card), not just inside .booking-modal, despite that
   block's name. */
.booking-field {
    position: relative;
}
.booking-field__value {
    display: flex;
    align-items: center;
    word-break: break-word;
}

/* ===== Booking form: reorderable field grid =====
   Every field is a direct flex item (Bootstrap `.row` is `display:flex`) so
   `.is-employee-mode` can freely re-pair/reorder fields via `order` without
   duplicating markup for the employee/CTV "Thêm khách xem phòng" layout.
   Vertical spacing comes from each item's own `mb-2`, not row gutters, so it
   stays consistent regardless of how items wrap after reordering. */
.booking-fields {
    --bs-gutter-y: 0;
}

/* Default (public booking) order — matches the original field sequence */
.field-people         { order: 1; }
.field-vehicles       { order: 2; }
.field-pet            { order: 3; }
.field-datetime       { order: 4; }
.field-estimated-time { order: 5; }
.field-name           { order: 6; }
.field-phone          { order: 7; }
.field-remark         { order: 8; }
.field-house          { order: 9; }
.field-room           { order: 10; }
.field-address        { order: 11; }
.field-from-source    { order: 12; }
.field-consulting-price { order: 13; }
.field-tu-dan-khach   { order: 14; }

/* Employee/CTV order — Nhà/Phòng/Địa chỉ → Tên/SĐT → Ngày giờ xem/Giá tư vấn →
   Nguồn khách → Số người ở/Số lượng xe → Thời gian dự kiến/Nuôi thú cưng →
   Ghi chú → Tự dẫn */
.is-employee-mode .field-house           { order: 1; }
.is-employee-mode .field-room            { order: 2; }
.is-employee-mode .field-address         { order: 3; }
.is-employee-mode .field-name            { order: 4; }
.is-employee-mode .field-phone           { order: 5; }
.is-employee-mode .field-datetime        { order: 6; }
.is-employee-mode .field-consulting-price { order: 7; }
.is-employee-mode .field-from-source     { order: 8; }
.is-employee-mode .field-people          { order: 9; }
.is-employee-mode .field-vehicles        { order: 10; }
.is-employee-mode .field-estimated-time  { order: 11; }
.is-employee-mode .field-pet             { order: 12; }
.is-employee-mode .field-remark          { order: 13; }
.is-employee-mode .field-tu-dan-khach    { order: 14; }

/* Width overrides for fields whose pairing differs between modes: full-width
   standalone in the public form, but paired up in the employee form. */
.is-employee-mode .field-estimated-time {
    flex: 0 0 50%;
    max-width: 50%;
}
.is-employee-mode .field-name,
.is-employee-mode .field-phone {
    flex: 0 0 100%;
    max-width: 100%;
}
@media (min-width: 768px) and (max-width: 991.98px) {
    .is-employee-mode .field-estimated-time {
        flex: 0 0 100%;
        max-width: 100%;
    }
}
@media (min-width: 992px) {
    .is-employee-mode .field-name,
    .is-employee-mode .field-phone {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* "Tự dẫn" checkbox (employee/CTV self-guided visit) */
.field-tu-dan-khach .form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 0;
}
.field-tu-dan-khach .form-check-input {
    margin: 0;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.field-tu-dan-khach .form-check-label {
    font-size: 0.9rem;
    font-weight: 600;
    /* color: #dc2626; */
}

/* "Chỉ định người dẫn" autocomplete (employee/CTV assigned-guide search), paired
   with the "Tự dẫn" checkbox on the same row */
.tu-dan-khach-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.tu-dan-khach-row .form-check {
    flex-shrink: 0;
}
.user-dk-search {
    position: relative;
    flex: 1 1 200px;
    min-width: 160px;
}
.user-dk-search__input:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
}
.user-dk-search__results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.user-dk-search__result {
    padding: 8px 12px;
    font-size: 0.9rem;
    color: #1f2937;
    cursor: pointer;
}
.user-dk-search__result:hover,
.user-dk-search__result.is-active {
    background-color: #f3f4f6;
}
.user-dk-search__result--empty {
    color: var(--text-secondary, #6b7280);
    cursor: default;
}
.user-dk-search__result--empty:hover {
    background-color: transparent;
}

/* ===== Booking Modal — compact pill-label design =====
   Not scoped to a mobile media query: #bookingModal's own trigger button is
   d-lg-none (mobile only), but the chat app's "Đặt lịch hẹn"/"Đặt xem phòng"
   quick action deep-links here with ?open_booking=1 and calls
   showBookingModal() unconditionally (see property-detail.js), which can open
   this same modal on a real desktop viewport. It used to only look right
   below 991px - above that it fell back to bare Bootstrap defaults (plain
   header, un-pilled labels, unstyled buttons). These rules now apply at every
   width so the modal looks intentional however it's opened. */
.booking-modal__header {
    background: var(--color-primary);
    color: #fff;
    border-bottom: 0;
    padding: 14px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}
.booking-modal__back {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 1.1rem;
    padding: 4px 8px;
    line-height: 1;
}
.booking-modal__title {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    margin: 0;
    flex: 1;
}
.booking-modal .modal-body {
    padding: 18px 14px 12px;
    overflow-y: auto;
    flex: 1 1 auto;
}

/* Pill-style labels (used for both inputs and readonly info) - not scoped to
   .booking-modal: applies equally to the desktop sidebar .booking-card, so
   every .booking-field looks the same (floating blue pill label) regardless
   of which of the form's two renderings it's in. `.booking-field`'s own
   `position: relative` (the pill's positioning anchor) is declared once,
   above. */
.booking-field__label,
.booking-field .form-label {
    position: absolute;
    top: -9px;
    left: 12px;
    z-index: 2;
    background: var(--color-primary);
    color: #fff;
    padding: 2px 12px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.4;
    white-space: nowrap;
}

.booking-field .form-control,
.booking-field .form-select {
    border: 1.5px solid var(--primary-blue-150);
    border-radius: 12px;
    padding: 10px 14px 6px;
    font-size: 0.88rem;
    background: #fff;
    /* min-height: 46px;
    height: 46px; */
}
.booking-field textarea.form-control {
    min-height: 46px;
    height: 46px;
    padding-top: 14px;
    resize: none;
}
.booking-field--readonly .booking-field__value {
    border: 1.5px solid var(--primary-blue-150);
    border-radius: 12px;
    padding: 10px 14px 6px;
    font-size: 0.88rem;
    background: #f3f4f6;
    color: #1f2937;
    /* min-height: 46px; */
}
.booking-modal .booking-form .row {
    --bs-gutter-y: 0;
}
.booking-modal .booking-form > .mb-2,
.booking-modal .booking-form > .row.mb-2,
.booking-modal .booking-info.mb-2 {
    margin-bottom: 16px !important;
}
.booking-modal .booking-info > .booking-field.mb-2 {
    margin-bottom: 14px !important;
}
.booking-modal .booking-form .invalid-feedback {
    font-size: 0.7rem;
    margin-top: 2px;
}
.booking-modal .booking-form .form-text {
    display: none;
}

/* Footer action bar */
.booking-modal__footer {
    padding: 8px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-wrap: nowrap;
    gap: 10px;
    align-items: center;
    flex: 0 0 auto;
}
.booking-modal__submit {
    flex: 1 1 auto;
    background: var(--color-primary);
    border: 0;
    border-radius: 999px;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0;
}
.booking-modal__icon-btn {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 8px;
    background: transparent;
    border: 0;
    color: var(--color-primary);
    font-size: 0.7rem;
    font-weight: 500;
    text-decoration: none;
    border-left: 1px solid #e5e7eb;
    line-height: 1.2;
    min-width: 56px;
}
.booking-modal__icon-btn:first-of-type {
    border-left: 0;
}
.booking-modal__icon-btn i {
    font-size: 1.1rem;
    margin-bottom: 1px;
}
.booking-modal__icon-btn:hover {
    color: var(--primary-blue-dark);
}

/* ===== Flatpickr time-picker: hour/minute as 4-row list selects ===== */
.flatpickr-calendar.hasTime .flatpickr-time {
    height: auto !important;
    max-height: none !important;
    line-height: normal;
    align-items: stretch;
    padding: 6px 4px;
}
.flatpickr-calendar.hasTime,
.flatpickr-calendar.hasTime.noCalendar {
    height: auto !important;
    max-height: none !important;
}
.flatpickr-time .flatpickr-list-wrapper {
    height: auto !important;
    max-height: none !important;
    overflow: visible;
    flex: 1 1 auto;
    display: flex;
    align-items: stretch;
}
.flatpickr-time .flatpickr-list-wrapper .flatpickr-hour,
.flatpickr-time .flatpickr-list-wrapper .flatpickr-minute,
.flatpickr-time .flatpickr-list-wrapper .arrowUp,
.flatpickr-time .flatpickr-list-wrapper .arrowDown {
    display: none !important;
}
.flatpickr-list-select {
    width: 100%;
    min-width: 56px;
    height: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
    font-size: 14px;
    text-align: center;
    text-align-last: center;
    padding: 2px 0;
    outline: none;
    overflow-y: auto;
}
.flatpickr-list-select option {
    padding: 4px 8px;
    text-align: center;
}
.flatpickr-list-select option:checked {
    background: var(--primary-blue, #0966ff);
    color: #fff;
}
.flatpickr-time .flatpickr-time-separator {
    align-self: center;
}

/* Hide overflow days (previous/next month) so only current month is visible */
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
    visibility: hidden;
    pointer-events: none;
}

/* Section labels above date / time pickers */
.flatpickr-section-label {
    padding: 8px 10px 4px;
    font-size: 13px;
    font-weight: 600;
    color: #495057;
    background: #fff;
    text-transform: none;
}
.flatpickr-section-label--time {
    border-top: 1px solid #eee;
    margin-top: 4px;
}

/* Action buttons (Đồng ý / Hủy) */
.flatpickr-actions {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-top: 1px solid #eee;
    background: #fff;
}
.flatpickr-actions__btn {
    flex: 1 1 0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: opacity 0.15s ease;
}
.flatpickr-actions__btn--cancel {
    background: #f1f3f5;
    color: #495057;
    border-color: #dee2e6;
}
.flatpickr-actions__btn--ok {
    background: var(--primary-blue, #0966ff);
    color: #fff;
}
.flatpickr-actions__btn:hover { opacity: 0.9; }

/* Mobile: keep the whole picker inside the viewport */
.flatpickr-calendar {
    z-index: 2060 !important; /* above bootstrap modal (1050) */
}
/* Date column visible only on mobile bottom-sheet */
.flatpickr-list-wrapper--date { display: none; }

@media (max-width: 575px) {
    .flatpickr-calendar.open {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 80vh !important;
        border-radius: 16px 16px 0 0 !important;
        overflow-y: auto;
        box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
        animation: flatpickr-slide-up 0.22s ease-out;
    }
    @keyframes flatpickr-slide-up {
        from { transform: translateY(100%); }
        to { transform: none; }
    }

    /* Hide the full calendar grid + the time section label on mobile */
    .flatpickr-calendar.open .flatpickr-months,
    .flatpickr-calendar.open .flatpickr-innerContainer,
    .flatpickr-calendar.open .flatpickr-section-label--time {
        display: none !important;
    }

    /* Title (reuse the date section label) */
    .flatpickr-calendar.open .flatpickr-section-label--date {
        padding: 14px 16px 6px;
        font-size: 15px;
        font-weight: 600;
        color: #212529;
    }

    /* Show date column, make time row a 3-column flex */
    .flatpickr-list-wrapper--date { display: flex !important; }
    .flatpickr-calendar.open .flatpickr-time {
        display: flex !important;
        gap: 8px !important;
        padding: 8px 16px 12px !important;
        align-items: stretch;
    }
    .flatpickr-time .flatpickr-list-wrapper {
        flex: 1 1 0;
        min-width: 0;
    }
    .flatpickr-list-wrapper--date { flex: 1.6 1 0; }
    .flatpickr-time .flatpickr-time-separator { display: none !important; }

    .flatpickr-list-select {
        font-size: 15px;
        padding: 4px 0;
        border-radius: 8px;
    }
    .flatpickr-list-select option {
        padding: 8px 6px;
    }

    .flatpickr-actions {
        padding: 10px 16px 16px;
    }
    .flatpickr-actions__btn { padding: 11px 12px; font-size: 15px; }
}

/* Backdrop on mobile so users see picker is modal-like */
@media (max-width: 575px) {
    body.flatpickr-open-backdrop::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 2055;
    }
}
