/* ==========================================================================
   HHC LOCATION PICKER
   ==========================================================================

   Layout and ink for `App\Filament\Forms\Components\LocationPicker`.

   ---------------------------------------------------------------------------
   WHY THE LEAFLET STYLESHEET IS NOT PATCHED
   ---------------------------------------------------------------------------

   `public/css/hhc/leaflet.css` is Leaflet 1.9.4's own `dist/leaflet.css`,
   byte-for-byte, sha256 a7837102824184820dfa198d1ebcd109ff6d0ff9a2672a074b9a1b4d147d04c6
   — the same digest as `unpkg.com/leaflet@1.9.4/dist/leaflet.css` and as the file
   at the `v1.9.4` tag. Editing it would destroy that check for every future
   upgrade, for two URL rewrites that belong here anyway.

   Leaflet's stylesheet asks for its marker images at `images/…`, relative to
   wherever the stylesheet is served from — which is `/css/hhc/`, where there is
   no `images/` directory. The bundle lives at `/js/hhc/leaflet/`, which is where
   Filament keeps every vendored script this console loads.

   AND THE REWRITE FOR THE PIN IS NOT HERE EITHER. It is in `location-picker.js`,
   as `L.Icon.Default.mergeOptions({ iconUrl, iconRetinaUrl, shadowUrl })`, because
   Leaflet 1.9 owns this problem: `L.Icon.Default._detectIconPath()` PROBES THE
   PAGE to find where the images are, and it does that by reading the computed
   `background-image` of a throwaway `.leaflet-default-icon-path` element.

   WHICH MEANS A CSS RULE ON THAT CLASS IS NOT A FIX — IT IS THE INPUT TO THE
   GUESS. The first version of this file had

       .leaflet-default-icon-path { background-image: url("/js/hhc/leaflet/images/marker-icon.png"); }

   intending to point the pin at the vendored file. Leaflet read that value back as
   its `imagePath` PREFIX and prepended it to its own relative default, producing

       /js/hhc/leaflet/images//js/hhc/leaflet/images/marker-icon.png

   — a 404, on a map whose tiles, pin, circle, drag and readout all worked. Measured
   in headless Chrome, and it cost two rounds of "but the pin is in the DOM".

   .leaflet-control-layers-toggle keeps its rule below for the opposite reason: that
   class has no detection logic at all, so a rule there IS the fix.

   ---------------------------------------------------------------------------
   THE RULE THAT IS NOT COSMETIC: THE CONTAINER'S HEIGHT
   ---------------------------------------------------------------------------

   A Leaflet map whose container has no height renders as **nothing** — no error,
   no warning, an empty box that looks like a failed network request. Leaflet
   cannot invent a size and deliberately does not try. So the height below is not
   styling; it is the difference between a map and an invisible map, and it is
   written in `min-height` as well as `height` because Filament's own grid can
   apply an `align-items: stretch` that collapses a bare `height`.
   ========================================================================== */

/* ---- the field itself ----------------------------------------------------- */
.hhc-location-picker {
    display: flex;
    flex-direction: column;
    gap: var(--hhc-space-3, 0.75rem);
}

.hhc-location-picker__label {
    display: block;
    margin-bottom: var(--hhc-space-2, 0.5rem);
    font-size: 0.875rem;
    font-weight: 500;
}

/* ---- address search ------------------------------------------------------- */
.hhc-location-picker__search-row {
    display: flex;
    align-items: stretch;
    gap: var(--hhc-space-2, 0.5rem);
}

.hhc-location-picker__search-input {
    flex: 1 1 auto;
    min-width: 0;
}

.hhc-location-picker__search-button {
    flex: 0 0 auto;
}

/*
 * The status line is ALWAYS RESERVED, never `display: none` when empty.
 *
 * A message that appears and pushes the map down moves the pin the coordinator was
 * about to click. `min-height` keeps the layout still and the failure visible —
 * and the failure message is the one thing on this screen that must not be missed.
 */
.hhc-location-picker__status {
    margin: var(--hhc-space-2, 0.5rem) 0 0;
    min-height: 1.25rem;
    font-size: 0.8125rem;
    line-height: 1.25rem;
    color: var(--gray-600, #52525b);
}

.hhc-location-picker__note {
    margin: var(--hhc-space-2, 0.5rem) 0 0;
    font-size: 0.8125rem;
    line-height: 1.375rem;
    color: var(--gray-600, #52525b);
}

.hhc-location-picker__note--warn {
    color: var(--warning-700, #9a6700);
}

.hhc-location-picker__results {
    margin: var(--hhc-space-2, 0.5rem) 0 0;
    padding: 0;
    list-style: none;
    max-height: 15rem;
    overflow-y: auto;
    border: 1px solid var(--gray-200, #e4e4e7);
    border-radius: var(--hhc-radius-md, 8px);
    background: var(--gray-50, #fafafa);
}

.hhc-location-picker__result + .hhc-location-picker__result {
    border-top: 1px solid var(--gray-200, #e4e4e7);
}

.hhc-location-picker__result-button {
    display: block;
    width: 100%;
    padding: var(--hhc-space-3, 0.75rem);
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.hhc-location-picker__result-button:hover,
.hhc-location-picker__result-button:focus-visible {
    background: var(--primary-50, #eff6ff);
}

.hhc-location-picker__result-name {
    display: block;
    font-size: 0.875rem;
    line-height: 1.25rem;
}

.hhc-location-picker__result-meta {
    display: block;
    margin-top: 2px;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-500, #71717a);
}

/* ---- the map -------------------------------------------------------------- */
.hhc-location-picker__map-wrap {
    position: relative;
}

.hhc-location-picker__map {
    height: 22rem;
    min-height: 22rem;
    width: 100%;
    border: 1px solid var(--gray-200, #e4e4e7);
    border-radius: var(--hhc-radius-md, 8px);
    /* Leaflet's panes are absolutely positioned; a stacking context here keeps
       them under the panel's own overlays (modals, the sidebar) instead of over. */
    z-index: 0;
    background: var(--gray-100, #f4f4f5);
}

/*
 * THE NOTE SITS ON THE MAP, NOT UNDER IT.
 *
 * It exists to be read while looking at the map, and pushing it below the fold
 * makes it decoration. `pointer-events: none` so it never eats a drag that was
 * aimed at the pin underneath.
 */
.hhc-location-picker__map-wrap > .hhc-location-picker__note {
    position: absolute;
    left: var(--hhc-space-2, 0.5rem);
    right: var(--hhc-space-2, 0.5rem);
    bottom: var(--hhc-space-2, 0.5rem);
    z-index: 500;
    margin: 0;
    padding: var(--hhc-space-2, 0.5rem) var(--hhc-space-3, 0.75rem);
    border-radius: var(--hhc-radius-sm, 4px);
    background: color-mix(in srgb, var(--gray-50, #fafafa) 92%, transparent);
    pointer-events: none;
}

.hhc-location-picker__map-wrap > .hhc-location-picker__note--fallback {
    color: var(--warning-700, #9a6700);
    background: color-mix(in srgb, var(--warning-50, #fffbeb) 95%, transparent);
}

/*
 * `x-cloak` BELONGS TO ALPINE, SO IT MUST NOT BE THE ONLY THING KEEPING A
 * SERVER-RENDERED ELEMENT OFF THE SCREEN.
 *
 * Filament defines `[x-cloak] { display: none }` and removes the attribute when it
 * processes the page. Every element in this view that carries `x-cloak` also
 * carries a `hidden` attribute or is a control that only makes sense with
 * JavaScript — so if Alpine never runs, what is left is: a map that cannot work,
 * a sentence that says so, and three number inputs that save. Nothing depends on
 * a framework that failed.
 */

/* ---- controls ------------------------------------------------------------- */
.hhc-location-picker__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--hhc-space-2, 0.5rem);
}

.hhc-location-picker__readout {
    margin-left: auto;
    display: inline-flex;
    align-items: baseline;
    gap: var(--hhc-space-2, 0.5rem);
    font-size: 0.8125rem;
}

.hhc-location-picker__readout-label {
    color: var(--gray-500, #71717a);
}

.hhc-location-picker__readout code {
    font-variant-numeric: tabular-nums;
    font-size: 0.8125rem;
}

/*
 * NO PIN, NO KEYBOARD TRAP.
 *
 * Leaflet's zoom control and the attribution link are focusable anchors. They stay
 * reachable — a keyboard user can pan and zoom the map even though they cannot
 * drag the pin — but the drag target itself is `aria-hidden` in the markup, which
 * is where that decision is explained.
 */
.hhc-location-picker__map .leaflet-control-attribution {
    font-size: 0.6875rem;
}
