/**
 * MLD Modal Skin — unified "modern glass" treatment for every public modal.
 * v6.175.0
 *
 * Load order/specificity contract:
 *  - Enqueued with dep 'mld-property-modules' on property pages so it sorts
 *    LAST in <head>. That alone is NOT enough against the CMA module's inline
 *    <style> block (prints in <body>, wins order ties) — so every rule here is
 *    ID-SCOPED (Pitfall #87D). Never add a bare `.mld-modal-content` rule.
 *  - No modal ids/classes are renamed anywhere (Pitfall #82: the staticModals
 *    allow-list in mld-comparable-sales.js keys on these ids).
 *  - Scrim/backdrop styling only ever applies under the modal's own shown
 *    mechanism (the parent #id container is display:none when closed), so an
 *    orphan overlay can never intercept touch (Pitfall #42).
 */

/* ------------------------------------- contact/tour modals: mobile sheets --
   Migrated verbatim from mld-property-modules.css (v6.154.0, lines 464-573)
   so the sheet geometry has exactly one owner. History: on real iPhones these
   form modals rendered as ~266px floating boxes (generic .mld-modal-content
   rules from the CMA module's stylesheet — top:50%/max-width:500/radius:8 —
   leak onto them; the class name is shared across stylesheets). Id-scoped
   rules here win the cascade without an !important war. On phones the modals
   are full-height bottom sheets with a sticky edge-to-edge submit — the
   Zillow-standard treatment. Desktop (≥768px) keeps its centered dialog. */
@media (max-width: 767px) {
    /* Geometry carries !important on purpose: the CMA stylesheet centers any
       .mld-modal-content with important'd top/transform (computed top:50%
       survived plain overrides — verified live 2026-07-02). */
    #contactModal .mld-modal-content,
    #tourModal .mld-modal-content {
        position: fixed !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        transform: none !important;
        height: auto !important;
        max-height: calc(100dvh - 28px) !important;
        min-height: 72dvh;
        border-radius: 20px 20px 0 0 !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0 !important;
        box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.24);
        animation: mldSheetUp 0.26s ease;
    }
    #contactModal .mld-modal-header,
    #tourModal .mld-modal-header {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 16px 20px;
        background: #fff !important;
        border-bottom: 1px solid #e5e7eb;
        border-radius: 20px 20px 0 0;
    }
    #contactModal .mld-modal-header h3,
    #tourModal .mld-modal-header h3 {
        color: #111827 !important;
        font-size: 1.1rem;
        font-weight: 700;
        margin: 0;
    }
    #contactModal .mld-contact-agent-label {
        color: #6b7280 !important;
    }
    #contactModal .mld-modal-close,
    #tourModal .mld-modal-close {
        flex: 0 0 auto;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: #f3f4f6 !important;
        color: #374151 !important;
        font-size: 1.5rem;
        line-height: 1;
        border: 0;
    }
    #contactModal .mld-modal-body,
    #tourModal .mld-modal-body {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px 20px 0;
    }
    /* Edge-to-edge sticky action bar — the submit is always reachable
       (the old inner-scroll box hid it below the fold, audit P3). */
    #contactModal .mld-form-submit,
    #tourModal .mld-form-submit {
        position: sticky;
        bottom: 0;
        display: block;
        width: calc(100% + 40px);
        margin: 20px -20px 0;
        border: 0;
        border-radius: 0;
        padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px));
        background: #0e7490;
        color: #fff;
        font-size: 1.05rem;
        font-weight: 600;
        box-shadow: 0 -8px 18px -6px rgba(0, 0, 0, 0.18);
    }
    #contactModal .mld-form-status,
    #tourModal .mld-form-status {
        padding-bottom: 12px;
    }
}
@keyframes mldSheetUp {
    /* translate (not transform): the sheet rule above sets transform:none
       !important, which would defeat a transform keyframe — see mldModalIn. */
    from { translate: 0 48px; opacity: 0.4; }
    to { translate: 0 0; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    #contactModal .mld-modal-content,
    #tourModal .mld-modal-content { animation: none; }
}

/* ------------------------------- share-with-client modal (agent-only) --
   Migrated verbatim from the inline <style> block in
   single-property-desktop-v3.php (~line 3055) so it lives in a stylesheet. */
.mld-share-client-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mld-share-client-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}
.mld-share-client-modal__content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.mld-share-client-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}
.mld-share-client-modal__header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}
.mld-share-client-modal__close {
    background: none;
    border: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.mld-share-client-modal__close:hover {
    color: #333;
}
.mld-share-client-modal__body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.mld-share-client-modal__desc {
    margin: 0 0 16px 0;
    color: #666;
    font-size: 14px;
}
.mld-share-client-modal__clients {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
}
.mld-share-client-modal__client {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.mld-share-client-modal__client:hover {
    border-color: #2563eb;
    background: #f0f7ff;
}
.mld-share-client-modal__client:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
}
.mld-share-client-radio {
    accent-color: #2563eb;
    width: 18px;
    height: 18px;
}
.mld-share-client-modal__client-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.mld-share-client-modal__client-name {
    font-weight: 500;
    color: #333;
}
.mld-share-client-modal__client-email {
    font-size: 13px;
    color: #666;
}
.mld-share-client-modal__note-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mld-share-client-modal__note-wrapper label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}
.mld-share-client-modal__note {
    width: 100%;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
}
.mld-share-client-modal__note:focus {
    outline: none;
    border-color: #2563eb;
}
.mld-share-client-modal__footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    justify-content: flex-end;
}
.mld-share-client-modal__btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.mld-share-client-modal__btn--cancel {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    color: #666;
}
.mld-share-client-modal__btn--cancel:hover {
    background: #eee;
}
.mld-share-client-modal__btn--share {
    background: #2563eb;
    border: none;
    color: #fff;
}
.mld-share-client-modal__btn--share:hover:not(:disabled) {
    background: #1d4ed8;
}
.mld-share-client-modal__btn--share:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}
.mld-share-client-modal__status {
    padding: 12px 20px;
    text-align: center;
    font-size: 14px;
}
.mld-share-client-modal__status.success {
    background: #dcfce7;
    color: #166534;
}
.mld-share-client-modal__status.error {
    background: #fee2e2;
    color: #991b1b;
}
/* Button in nav bar styling */
.mld-v3-share-client-btn {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff !important;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
}
.mld-v3-share-client-btn:hover {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}
.mld-v3-share-client-btn svg {
    stroke: #fff;
}

/* ================================================== modern glass (v6.175.0) --
   Entrance uses @keyframes, never transitions: every modal family here flips
   between display:none and rendered (style.display, .active class, or jQuery
   fadeIn), and keyframes re-fire each time the element re-enters the render
   tree. Panels animate transform only, so jQuery's inline-opacity fades (CMA
   family, Phase B) compose without fighting. */

/* Entrance keyframes animate the INDEPENDENT translate/scale properties, not
   transform: mld-schools.css forces `transform: ... !important` on every
   .mld-modal-content, and an !important declaration defeats any keyframe that
   animates the same property. translate/scale are separate properties, so the
   animation survives. Older browsers without them simply skip the entrance. */
@keyframes mldModalIn {
    from { translate: 0 10px; scale: 0.97; }
}
@keyframes mldScrimIn {
    from { opacity: 0; }
}

/* Scrim — flat tint everywhere, frosted where backdrop-filter is supported.
   Blur stays on this single compositing layer only, capped at 8px (the iOS
   Safari budget). Media viewers (#mapModal, #photoLightbox, #v3PhotoModal,
   #virtualTourModal, #youtubeVideoModal) keep their near-opaque dark surfaces
   on purpose — no blur over photo/video content. */
#contactModal .mld-modal-backdrop,
#tourModal .mld-modal-backdrop,
.mld-share-client-modal__overlay {
    background: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
    animation: mldScrimIn 0.2s ease;
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    #contactModal .mld-modal-backdrop,
    #tourModal .mld-modal-backdrop,
    .mld-share-client-modal__overlay {
        background: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
        -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
        backdrop-filter: blur(var(--ds-modal-blur, 8px));
    }
}

/* Desktop (≥768px): centered glass dialog. Geometry fallback lives in
   property-desktop-v3.css; this layers the panel treatment + scroll pattern. */
@media (min-width: 768px) {
    #contactModal .mld-modal-content,
    #tourModal .mld-modal-content {
        /* Geometry carries !important on purpose (#87D): the CMA inline
           <style> sets max-width:1200px + margin:5vh auto, and mld-schools.css
           forces position:fixed/top:50%/left:50%/transform !important on the
           generic class. Id-scoped !important beats both (important rules
           still cascade by specificity) — verified in the preview harness. */
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        margin: auto !important;
        height: fit-content;
        width: var(--ds-modal-w, min(92vw, 480px)) !important;
        max-width: var(--ds-modal-w, min(92vw, 480px)) !important;
        max-height: var(--ds-modal-max-h, min(85dvh, 720px)) !important;
        transform: none !important;
        padding: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--ds-modal-surface, #ffffff);
        border: 1px solid var(--ds-modal-border, rgba(255, 255, 255, 0.55));
        border-radius: var(--ds-modal-radius, 16px);
        box-shadow: var(--ds-modal-shadow, 0 1px 2px rgba(15, 23, 42, 0.06), 0 12px 24px -8px rgba(15, 23, 42, 0.18), 0 32px 64px -16px rgba(15, 23, 42, 0.22));
        animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
    }
    /* Clean light header (the CMA inline block leaks a navy gradient +
       white text onto every .mld-modal-header — off-direction here). */
    #contactModal .mld-modal-header,
    #tourModal .mld-modal-header {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 16px 20px;
        background: #fff;
        color: #111827;
        border-bottom: 1px solid #e5e7eb;
    }
    #contactModal .mld-modal-header h3,
    #tourModal .mld-modal-header h3 {
        color: #111827;
        font-size: 1.1rem;
        font-weight: 700;
        margin: 0;
    }
    #contactModal .mld-contact-agent-label {
        color: #6b7280;
    }
    #contactModal .mld-modal-body,
    #tourModal .mld-modal-body {
        flex: 1 1 auto;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    #contactModal .mld-modal-close,
    #tourModal .mld-modal-close {
        flex: 0 0 auto;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: #f3f4f6;
        color: #374151;
        border: 0;
        font-size: 1.4rem;
        line-height: 1;
        transition: background 0.15s ease;
    }
    #contactModal .mld-modal-close:hover,
    #tourModal .mld-modal-close:hover {
        background: #e5e7eb;
        transform: none;
    }
}

/* Mobile sheets: drag-handle affordance. Pure CSS, pointer-events:none —
   closing stays the X / backdrop / Escape; do NOT "finish" this with JS drag. */
@media (max-width: 767px) {
    #contactModal .mld-modal-content::before,
    #tourModal .mld-modal-content::before {
        content: "";
        position: absolute;
        top: 8px;
        left: 50%;
        translate: -50% 0;
        width: 36px;
        height: 4px;
        border-radius: 999px;
        background: var(--ds-modal-handle, rgba(107, 114, 128, 0.35));
        z-index: 2;
        pointer-events: none;
    }
    #contactModal .mld-modal-header,
    #tourModal .mld-modal-header {
        padding-top: 22px;
    }
}

/* Share-with-client: same glass panel language as the form dialogs. */
.mld-share-client-modal__content {
    border: 1px solid var(--ds-modal-border, rgba(255, 255, 255, 0.55));
    border-radius: var(--ds-modal-radius, 16px);
    box-shadow: var(--ds-modal-shadow, 0 20px 60px rgba(0, 0, 0, 0.3));
    animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
}

/* ==================================================== Phase B (v6.175.0) --
   Map/search, CMA, saved-search and schools modals. Same rules of engagement:
   id-scoped only, no geometry changes where the existing layout works, media
   viewers keep their dark surfaces. */

/* --- Map filters modal (desktop only: mobile is deliberately fullscreen,
       and this file loads after main.css, so an unscoped radius would beat
       main.css's mobile border-radius:0 at equal specificity). --- */
@media (min-width: 783px) {
    #bme-filters-modal-overlay {
        background: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
    }
    #bme-filters-modal-content {
        border: 1px solid var(--ds-modal-border, rgba(255, 255, 255, 0.55));
        border-radius: var(--ds-modal-radius, 16px);
        box-shadow: var(--ds-modal-shadow, 0 1px 2px rgba(15, 23, 42, 0.06), 0 12px 24px -8px rgba(15, 23, 42, 0.18), 0 32px 64px -16px rgba(15, 23, 42, 0.22));
        animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
    }
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    @media (min-width: 783px) {
        #bme-filters-modal-overlay {
            background: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
            -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
            backdrop-filter: blur(var(--ds-modal-blur, 8px));
        }
    }
}

/* --- Save-search modal: already modern (16px radius, spring entrance) —
       align the scrim tint to the shared token only. --- */
#bme-save-search-modal.bme-modal-overlay {
    background-color: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
    -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
    backdrop-filter: blur(var(--ds-modal-blur, 8px));
}

/* --- Edit-search modal (client dashboard): the wrapper IS the scrim. --- */
#mld-edit-search-modal.mld-modal {
    background-color: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
}
#mld-edit-search-modal .mld-modal-content {
    border: 1px solid var(--ds-modal-border, rgba(255, 255, 255, 0.55));
    border-radius: var(--ds-modal-radius, 16px);
    box-shadow: var(--ds-modal-shadow, 0 4px 20px rgba(0, 0, 0, 0.15));
    animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
    overflow: hidden;
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    #mld-edit-search-modal.mld-modal {
        background-color: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
        -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
        backdrop-filter: blur(var(--ds-modal-blur, 8px));
    }
}

/* --- Multi-unit modal (map pins with several listings). --- */
#mld-multi-unit-modal.mld-modal-overlay {
    background: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
}
#mld-multi-unit-modal .mld-modal-container {
    border: 1px solid var(--ds-modal-border, rgba(255, 255, 255, 0.55));
    border-radius: var(--ds-modal-radius, 16px);
    box-shadow: var(--ds-modal-shadow, 0 12px 24px -8px rgba(15, 23, 42, 0.18));
    animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
    overflow: hidden;
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    #mld-multi-unit-modal.mld-modal-overlay {
        background: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
        -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
        backdrop-filter: blur(var(--ds-modal-blur, 8px));
    }
}

/* --- CMA family (arv/save/my-cmas static + compare/share dynamic + the two
       standalone-CMA modals). Radius/shadow/scrim/entrance only — their
       bespoke widths and internal grids are left alone. Entrance animates
       translate only: jQuery fadeIn owns opacity for this family. --- */
#mld-arv-modal .mld-modal-overlay,
#mld-save-cma-modal .mld-modal-overlay,
#mld-my-cmas-modal .mld-modal-overlay,
#mld-compare-modal .mld-modal-overlay,
#mld-share-modal .mld-modal-overlay,
#mld-scma-edit-modal .mld-modal-overlay,
#mld-scma-share-modal .mld-modal-overlay {
    background: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    #mld-arv-modal .mld-modal-overlay,
    #mld-save-cma-modal .mld-modal-overlay,
    #mld-my-cmas-modal .mld-modal-overlay,
    #mld-compare-modal .mld-modal-overlay,
    #mld-share-modal .mld-modal-overlay,
    #mld-scma-edit-modal .mld-modal-overlay,
    #mld-scma-share-modal .mld-modal-overlay {
        background: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
        -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
        backdrop-filter: blur(var(--ds-modal-blur, 8px));
    }
}
#mld-arv-modal .mld-modal-content,
#mld-save-cma-modal .mld-modal-content,
#mld-my-cmas-modal .mld-modal-content,
#mld-compare-modal .mld-modal-content,
#mld-share-modal .mld-modal-content,
#mld-scma-edit-modal .mld-modal-content,
#mld-scma-share-modal .mld-modal-content {
    border-radius: var(--ds-modal-radius, 16px);
    box-shadow: var(--ds-modal-shadow, 0 10px 40px rgba(0, 0, 0, 0.3));
    animation: mldModalIn 0.28s cubic-bezier(0.32, 0.72, 0.2, 1);
}

/* --- Schools modals: already dialog-semantic + 16px radius; align scrims. --- */
#mld-glossary-modal .mld-modal-overlay,
#mld-comparison-modal .mld-modal-overlay,
#mld-trends-modal .mld-modal-overlay {
    background: var(--ds-modal-scrim, rgba(15, 23, 42, 0.45));
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
    #mld-glossary-modal .mld-modal-overlay,
    #mld-comparison-modal .mld-modal-overlay,
    #mld-trends-modal .mld-modal-overlay {
        background: var(--ds-modal-scrim-blurred, rgba(15, 23, 42, 0.35));
        -webkit-backdrop-filter: blur(var(--ds-modal-blur, 8px));
        backdrop-filter: blur(var(--ds-modal-blur, 8px));
    }
}

@media (prefers-reduced-motion: reduce) {
    #contactModal .mld-modal-content,
    #tourModal .mld-modal-content,
    #contactModal .mld-modal-backdrop,
    #tourModal .mld-modal-backdrop,
    .mld-share-client-modal__overlay,
    .mld-share-client-modal__content,
    #bme-filters-modal-content,
    #mld-edit-search-modal .mld-modal-content,
    #mld-multi-unit-modal .mld-modal-container,
    #mld-arv-modal .mld-modal-content,
    #mld-save-cma-modal .mld-modal-content,
    #mld-my-cmas-modal .mld-modal-content,
    #mld-compare-modal .mld-modal-content,
    #mld-share-modal .mld-modal-content,
    #mld-scma-edit-modal .mld-modal-content,
    #mld-scma-share-modal .mld-modal-content {
        animation: none !important;
    }
}
