/* mappa-sedi — frontend map styles */

.ms-wrap {
    position: relative;
    width: 100%;
    font-family: inherit;
    /* Lets the stacking rule below react to the actual space this block has
       (e.g. a narrow sidebar column on an otherwise wide desktop page),
       not just the viewport width. */
    container-type: inline-size;
}

/* ── Toolbar (region select) ──────────────────────────────────────────────── */

.ms-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.ms-toolbar__label {
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

.ms-region-select {
    padding: 5px 10px;
    font-size: 13px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.ms-region-select:focus {
    border-color: #364E6E;
}

/* ── Search bar (typeahead) ───────────────────────────────────────────────── */

.ms-search-bar {
    position: relative;
    margin-bottom: 12px;
}

.ms-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: #999;
    pointer-events: none;
}

.ms-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px 12px 40px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid #e3ddd2;
    border-radius: 999px;
    background: #faf7f2;
    color: #222;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ms-search-input::placeholder { color: #999; }

.ms-search-input:focus {
    border-color: #364E6E;
    box-shadow: 0 0 0 3px rgba(54, 78, 110, 0.12);
}

.ms-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 50;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    max-height: 320px;
    overflow-y: auto;
}

.ms-suggestions[hidden] { display: none; }

.ms-suggestion {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.ms-suggestion:hover,
.ms-suggestion--active {
    background: #eef4fb;
}

.ms-suggestion__name {
    font-size: 13px;
    color: #222;
    font-weight: 500;
}

.ms-suggestion__prov {
    font-size: 11px;
    color: #888;
}

.ms-suggestions__empty {
    padding: 8px 12px;
    font-size: 12px;
    color: #888;
    font-style: italic;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

.ms-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.ms-map-col {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
}

.ms-list-col {
    flex: 0 0 220px;
    width: 220px;
    display: flex;
    flex-direction: column;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fafafa;
    overflow: hidden;
    align-self: stretch;
}

/* Wider sidebar on large viewports */
@media (min-width: 1280px) {
    .ms-list-col { flex-basis: 260px; width: 260px; }
}
@media (min-width: 1600px) {
    .ms-list-col { flex-basis: 300px; width: 300px; }
}

/* ── Sidebar header ───────────────────────────────────────────────────────── */

.ms-list-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid #e0e0e0;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
}

.ms-list-title {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #555;
    white-space: nowrap;
}

/* ── Entry list ───────────────────────────────────────────────────────────── */

.ms-entry-list,
.ms-prov-entries {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ms-entry-list {
    overflow-y: auto;
    flex: 1 1 0;
    padding: 4px 0;
}

/* Stack map-above-list once there isn't enough room to show them side by
 * side — same rules from two triggers:
 *   - @media   → the browser viewport itself is narrow (phones/tablets, up
 *     to a standard tablet-landscape width)
 *   - @container → this block's own box is narrow even on a wide desktop
 *     viewport (e.g. dropped into a narrow sidebar/column layout). Without
 *     this, the list column got squeezed down to a sliver in that case —
 *     which is also why the search box inside it looked broken/unusable.
 * Without align-items: stretch, .ms-map-col keeps the row-layout's
 * align-items: flex-start (a cross-axis rule) after switching to a column
 * flex direction, so it shrinks to content width instead of filling the
 * row — that's what was narrowing the map.
 * The list column gets no max-height here (unlike the side-by-side layout,
 * where it's capped to the map's own height): stacked below the map, it
 * should show every entry in full — the page scrolls, not an inner box —
 * so .ms-list-header also drops position: sticky, which only makes sense
 * relative to a scrolling ancestor.
 * .ms-entry-list also needs flex: none + overflow-y: visible here. In the
 * side-by-side layout .ms-list-col gets a definite height by stretching to
 * match .ms-map-col, so .ms-entry-list's flex: 1 1 0 can grow to fill it and
 * scroll internally past that height. Stacked, nothing gives .ms-list-col a
 * definite height any more — and a flex-grow child with overflow-y: auto
 * gets an automatic min-height of 0 (not its content height), so with
 * nothing to grow into it was collapsing to ~0 instead of hugging its
 * content — which is what actually produced the "narrow sliver with a
 * stray horizontal scrollbar" look, not the <aside> tag or anything to do
 * with width.
 * IMPORTANT: this block must stay BELOW the .ms-list-header/.ms-entry-list
 * base rules above — equal-specificity selectors resolve ties by source
 * order regardless of whether the winning rule sits inside an @media block,
 * so placing this earlier in the file (as an earlier version of this file
 * did) silently lost every override here to those later base rules, even
 * when the media query matched. */
@media (max-width: 1024px) {
    .ms-layout      { flex-direction: column; align-items: stretch; }
    .ms-map-col     { width: 100%; }
    .ms-list-col    { flex: none; width: 100%; max-height: none; }
    .ms-list-header { position: static; }
    .ms-entry-list  { flex: none; overflow-y: visible; }
    .ms-toolbar     { justify-content: flex-start; }
}

@container (max-width: 1024px) {
    .ms-layout      { flex-direction: column; align-items: stretch; }
    .ms-map-col     { width: 100%; }
    .ms-list-col    { flex: none; width: 100%; max-height: none; }
    .ms-list-header { position: static; }
    .ms-entry-list  { flex: none; overflow-y: visible; }
    .ms-toolbar     { justify-content: flex-start; }
}

.ms-list-empty {
    padding: 12px 12px;
    font-size: 12px;
    color: #888;
    font-style: italic;
}

.ms-prov-group {
    padding: 0;
}

.ms-prov-heading {
    display: block;
    padding: 6px 10px 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
}

.ms-entry-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: 4px;
    margin: 1px 4px;
    transition: background 0.1s;
}

.ms-entry-item:hover,
.ms-entry-item--hover {
    background: #eef4fb;
}

.ms-entry-link {
    font-size: 13px;
    color: #222;
    text-decoration: none;
    line-height: 1.3;
    word-break: break-word;
    cursor: pointer;
}

.ms-entry-item:hover .ms-entry-link,
.ms-entry-item--hover .ms-entry-link {
    color: #364E6E;
}

.ms-entry-item--pinned .ms-entry-link {
    color: #8d6705;
    font-weight: 600;
}

.ms-entry-item--pinned {
    background: #e5b111;
    border-radius: 3px;
}

/* ── Map container ────────────────────────────────────────────────────────── */

/* Default responsive height — overridden by inline style when height="X" is set
   in the shortcode. clamp(min, preferred, max):
   • mobile  (< 640px, map is full-width): min 300px
   • tablet / laptop: grows with viewport height
   • large desktop: capped at 640px
   Italy's bounding box (including Sardinia/Sicily) is wider than it is
   tall, so a shorter box leaves less empty sea above/below the peninsula
   once it's fitted to the available width.                                    */
#ms-map {
    position: relative;
    width: 100%;
    height: clamp(300px, 50vh, 640px);
    background: var(--ms-map-bg, #364e6e);
    border-radius: 6px;
    overflow: hidden;
}

#ms-map svg {
    display: block;
    width: 100%;
    height: 100%;
}

.ms-loading,
.ms-error {
    margin: 0;
    padding: 16px;
    font-size: 13px;
    color: #888;
    text-align: center;
}

.ms-error {
    color: #c0392b;
}

/* ── Provinces ────────────────────────────────────────────────────────────── */
/* Active provinces get their fill/stroke set inline by JS from the entry's
   (or the global default's) base/border color. --ms-hover is only set on
   active provinces, so inactive ones cleanly fall back to a neutral grey. */

.ms-province {
    fill: #dde0e0;
    stroke: #fff;
    cursor: pointer;
    stroke-width: 0.6px;
    transition: fill 0.15s ease;
}

.ms-province--active {
    stroke-width: 1px;
}

.ms-province--hover {
    fill: var(--ms-hover, #c8cbcb) !important;
    cursor: pointer;
}

.ms-province--pinned {
    stroke-width: 2px;
    filter: brightness(1.08);
}

/* ── Pins (vector markers: tail + head + hole, colors from --ms-*) ───────── */

.ms-pin-anchor {
    cursor: pointer;
}

.ms-pin {
    fill: var(--ms-base, #364E6E);
    stroke: var(--ms-border, #1f2e42);
    stroke-width: 1px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
    transition: fill 0.15s ease, filter 0.15s ease, transform 0.15s ease;
    transform-box: fill-box;
    transform-origin: center bottom;
}

.ms-pin-hole {
    fill: #fff;
    pointer-events: none;
}

.ms-pin-anchor--hover .ms-pin,
.ms-pin-anchor:hover .ms-pin {
    fill: var(--ms-hover, #4a6690);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
    transform: scale(1.2);
}

/* ── Tooltip ──────────────────────────────────────────────────────────────── */

#ms-tooltip {
    position: absolute;
    display: none;
    background: #fff;
    border: 1px solid #d8d8d8;
    border-radius: 8px;
    padding: 12px 16px 12px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: #222;
    width: 300px;
    /* On a narrow phone the map column itself is often less than 300px wide,
     * which used to be masked by a mobile-only fixed-to-viewport-bottom
     * layout for this tooltip. That's gone now (see history), so without
     * this the JS clamping in moveTooltip() — container.clientWidth -
     * tooltip.offsetWidth - 16 — goes negative and pushes the tooltip off
     * the left edge, where the page's own overflow-x guard clips it
     * entirely: it looked like the tooltip "wasn't displaying" at all. */
    max-width: calc(100% - 24px);
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
    z-index: 100;
    transition: opacity 0.1s ease;
    opacity: 0;
}

#ms-tooltip.ms-tooltip--visible {
    display: block;
    pointer-events: auto;
    opacity: 1;
}

#ms-tooltip.ms-tooltip--pinned {
    display: block;
    pointer-events: auto;
    opacity: 1;
}

/* Close button — hidden until tooltip is pinned */
.ms-tooltip__close {
    display: none;
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    color: #888;
    cursor: pointer;
    padding: 2px 4px;
}
.ms-tooltip__close:hover { color: #222; }
#ms-tooltip.ms-tooltip--pinned .ms-tooltip__close { display: block; }

#ms-tooltip strong {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #111;
    padding-right: 20px; /* room for close button when pinned */
}

#ms-tooltip ul {
    margin: 4px 0 0;
    padding-left: 16px;
}

#ms-tooltip ul li {
    margin: 2px 0;
    font-size: 12px;
}

/* Indirizzo/telefono/sito rows — only whichever are filled in appear. */
#ms-tooltip p {
    margin: 3px 0 0;
    color: #444;
    font-size: 12px;
}

#ms-tooltip a {
    color: #364E6E;
    text-decoration: none;
}

#ms-tooltip a:hover {
    text-decoration: underline;
}

.ms-prov-name {
    color: #555;
    font-size: 12px;
}
