/* ══════════════════════════════════════════════════════════════════════════
   Map Type Picker — prompt-box control + selection modal.

   Self-contained tokens: the modal is portalled to <body>, and on the landing
   page the palette lives on .landing-hero-bg (not :root), so nothing here may
   depend on inherited custom properties.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Toolbar trigger ──────────────────────────────────────────────────────
   Inherits .aspect-ratio-btn from the page it sits on; only the "Map" label,
   truncation and width behaviour live here. Width is deliberately NOT capped
   in layouts whose parent already stretches the controls to equal widths
   (detail modal always, floating prompt + landing on small screens) — a cap
   there would leave one odd-sized button in the row.
   ───────────────────────────────────────────────────────────────────────── */
.map-type-btn {
    max-width: 150px;
    overflow: hidden;
}

    .map-type-btn .mtp-btn-label {
        flex-shrink: 0;
        color: var(--gray-500, #6C7688);
        font-weight: 500;
    }

    .map-type-btn .ratio-text {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.detail-dropdowns-container .map-type-btn {
    max-width: none;
}

.mtp-overlay {
    --mtp-white: #FFFFFF;
    --mtp-gray-50: #FAFBFC;
    --mtp-gray-100: #F5F7FA;
    --mtp-gray-200: #E8ECF0;
    --mtp-gray-300: #D7DCE3;
    --mtp-gray-400: #A0A8B5;
    --mtp-gray-500: #6C7688;
    --mtp-gray-700: #2D3748;
    --mtp-gray-900: #0F1419;
    --mtp-accent: #3B82F6;
    --mtp-accent-soft: rgba(59, 130, 246, 0.12);
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(15, 20, 25, 0.55);
    backdrop-filter: blur(3px);
}

    .mtp-overlay.mtp-open {
        display: flex;
    }

.mtp-panel {
    width: 100%;
    max-width: 560px;
    max-height: min(86vh, 720px);
    max-height: min(86dvh, 720px);
    display: flex;
    flex-direction: column;
    background: var(--mtp-white);
    border: 1px solid var(--mtp-gray-200);
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    animation: mtpPanelIn 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes mtpPanelIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* ── Header ── */
.mtp-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.5rem 1rem;
}

.mtp-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--mtp-gray-900);
}

.mtp-subtitle {
    margin: 0.25rem 0 0;
    font-size: 0.8125rem;
    color: var(--mtp-gray-500);
}

.mtp-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--mtp-gray-200);
    border-radius: 10px;
    background: var(--mtp-white);
    color: var(--mtp-gray-500);
    cursor: pointer;
    transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

    .mtp-close:hover {
        background: var(--mtp-gray-100);
        color: var(--mtp-gray-900);
    }

/* ── The modal body ── */
.mtp-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem 1.5rem;
}

/* ══ THE style browser (map-type-picker.js browser()) — the composer's settings panel AND this modal ══
   Self-contained tokens (the modal is portalled to <body>; the landing page keeps its palette off :root). */
.mtb {
    --mtb-ink: #16161a; --mtb-ink-2: #55565e; --mtb-ink-3: #686973;
    --mtb-line: #e7e7ea; --mtb-line-2: #d8d8de; --mtb-surface-2: #f2f2f4;
    --mtb-accent: rgb(var(--color-action, 37 99 235)); --mtb-accent-ink: rgb(var(--color-action-press, 30 64 175));   /* the one primary (H-7) */
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--mtb-ink);
}
.mtb-ic { width: 16px; height: 16px; flex: none; }
.mtb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
.mtb-head-all { align-items: center; justify-content: flex-start; margin-bottom: 10px; }
.mtb-title { font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--mtb-ink-3); }
.mtb-head-all .mtb-title { font-size: 14px; color: var(--mtb-ink); letter-spacing: 0; }
.mtb-link { padding: 0; border: 0; background: none; font-weight: 600; font-size: 12px; line-height: 1.4; font-family: inherit; color: var(--mtb-accent-ink); cursor: pointer; }
.mtb-link:hover { text-decoration: underline; }
.mtb-back { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--mtb-line-2); border-radius: 9px; background: #fff; color: var(--mtb-ink); cursor: pointer; }
.mtb-back:hover { background: var(--mtb-surface-2); }

/* strip: Auto + the admin's first styles + "+N More" — five equal tiles */
.mtb-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.mtb-radios { display: contents; }

/* all: search · category chips · small 4:3 tiles */
.mtb-search { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--mtb-line-2); border-radius: 9px; background: #fff; color: var(--mtb-ink); font-weight: 400; font-size: 14px; line-height: 1; font-family: inherit; box-shadow: none; }
.mtb-search:focus { outline: 2px solid var(--mtb-accent); outline-offset: -1px; border-color: transparent; }
.mtb-cats { display: flex; gap: 6px; margin: 10px 0; padding-right: 24px; overflow-x: auto; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
.mtb-cats::-webkit-scrollbar { display: none; }
.mtb-cat { flex: none; height: 28px; padding: 0 11px; border: 1px solid var(--mtb-line-2); border-radius: 999px; background: #fff; color: var(--mtb-ink); font-weight: 500; font-size: 12.5px; line-height: 1; font-family: inherit; cursor: pointer; }
.mtb-cat:hover { background: var(--mtb-surface-2); }
.mtb-cat[aria-pressed="true"] { background: var(--mtb-ink); border-color: var(--mtb-ink); color: #fff; }
.mtb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 3px; margin: 0 -3px; }
.mtb-empty { margin: 16px 0; text-align: center; font-size: 13px; color: var(--mtb-ink-3); }

/* a tile */
.mtb-tile { position: relative; min-width: 0; display: flex; flex-direction: column; gap: 5px; padding: 0; border: 0; background: none; color: var(--mtb-ink-2); font-weight: 500; font-size: 11.5px; line-height: 1.2; font-family: inherit; text-align: center; cursor: pointer; }
.mtb-th { position: relative; display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--mtb-line-2); border-radius: 10px; background: var(--mtb-surface-2); transition: box-shadow .15s; }
.mtb-grid .mtb-th { aspect-ratio: 4 / 3; }
.mtb-th img { display: block; width: 100%; height: 100%; object-fit: cover; }
.mtb-tile:hover .mtb-th { box-shadow: 0 0 0 1px var(--mtb-ink-3); }
.mtb-tile:focus-visible { outline: none; }
.mtb-tile:focus-visible .mtb-th { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--mtb-accent); }
.mtb-tile[aria-checked="true"] { color: var(--mtb-ink); font-weight: 600; }
.mtb-tile[aria-checked="true"] .mtb-th { border-color: transparent; box-shadow: 0 0 0 2px var(--mtb-accent); }
.mtb-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mtb-tick { position: absolute; left: 4px; bottom: 4px; display: none; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--mtb-accent); color: #fff; }
.mtb-tick svg { width: 11px; height: 11px; }
.mtb-tile[aria-checked="true"] .mtb-tick { display: grid; }
.mtb-auto { display: grid; justify-items: center; gap: 2px; color: var(--mtb-accent); font-size: 10.5px; font-weight: 700; letter-spacing: .04em; }
.mtb-auto .mtb-ic { width: 18px; height: 18px; }
/* "More" is a TILE like the others — a 2×2 collage of styles and "+N": seen, not read */
.mtb-more .mtb-th { grid-template-columns: 1fr 1fr; gap: 2px; background: var(--mtb-line); }
.mtb-plus { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(22, 22, 26, .48); color: #fff; font-size: 14px; font-weight: 700; }
.mtb-more:hover .mtb-plus { background: rgba(22, 22, 26, .6); }

/* ── Hover preview ── */
.mtp-preview {
    position: fixed;
    z-index: 10060;
    display: none;
    width: 232px;
    padding: 0.5rem;
    background: var(--mtp-white, #fff);
    border: 1px solid #E8ECF0;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
    pointer-events: none;
}

    .mtp-preview.mtp-preview-visible {
        display: block;
    }

    .mtp-preview img {
        width: 100%;
        aspect-ratio: 1 / 1;
        object-fit: cover;
        border-radius: 10px;
        display: block;
    }

.mtp-preview-caption {
    margin-top: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #2D3748;
    text-align: center;
}

/* ── Responsive ──────────────────────────────────────────────────────────
   The hover preview is gated on the POINTER, not the viewport: a narrow
   desktop window still has a mouse and should keep it, while a large tablet
   should not. Touch users get the tile itself as the preview.
   ───────────────────────────────────────────────────────────────────────── */
@media (hover: none), (pointer: coarse) {
    .mtp-preview {
        display: none !important;
    }
}

/* Phones — bottom sheet: full width, anchored to the bottom edge, thumb-reachable. */
@media (max-width: 640px) {
    .mtp-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .mtp-panel {
        max-width: none;
        max-height: 88vh;
        max-height: 88dvh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        animation: mtpSheetIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mtp-header {
        padding: 1rem 1.125rem 0.75rem;
    }

    .mtp-body {
        padding: 1rem 1.125rem calc(1.25rem + env(safe-area-inset-bottom));
    }

    .mtp-preview {
        display: none !important;
    }
}

@keyframes mtpSheetIn {
    from {
        opacity: 0;
        transform: translateY(24px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* Short viewports (landscape phones): trade panel chrome for grid height. */
@media (max-height: 480px) {
    .mtp-panel {
        max-height: 94vh;
        max-height: 94dvh;
    }

    .mtp-subtitle {
        display: none;
    }
}

/* Large desktops — a wider panel keeps tiles from getting oversized at 4 across. */
@media (min-width: 1280px) {
    .mtp-panel {
        max-width: 620px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mtp-panel {
        animation: none;
    }

    .mtb-th,
    .mtp-close {
        transition: none;
    }
}
