/* inked/assets/css/masters-v2/map.css */
/**
 * Masters Listing v2 — Map View Styles
 * Grid/Map toggle, MapLibre GL JS overrides, address search,
 * popup cards, responsive.
 *
 * Based on studios-v2/map.css, adapted for masters listing.
 */

/* ======================================================
   MAP CONTAINER
   ====================================================== */

.masters-map-wrapper {
    /* DSv2 §G.2 #7 — drop 1400px cap */
    max-width: var(--container-max, none);
    margin: 24px auto 0;
    padding: 0 24px;
}

/* ======================================================
   SPLIT LAYOUT — card panel (25%) + map (75%)
   ====================================================== */

.masters-map-split {
    display: flex;
    gap: 0;
    height: 600px;
    border-radius: var(--radius-lg, 12px);
    border: 1px solid var(--color-border, var(--color-border));
    overflow: hidden;
    background: var(--color-bg-card);
}

#mastersMap {
    flex: 0 0 75%;
    width: 75%;
    height: 100%;
    border-radius: 0;
    border: none;
    background: var(--color-bg-card);
}

/* --- Card Panel (left side) --- */

.masters-map-panel {
    flex: 0 0 25%;
    width: 25%;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-border, var(--color-border));
    background: var(--color-bg, var(--color-bg));
}

.light-theme .masters-map-panel {
    background: var(--color-gray-50);
    border-right-color: rgba(0, 0, 0, 0.1);
}

.masters-map-panel-header {
    padding: 12px 16px;
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border, var(--color-border));
    flex-shrink: 0;
}

.light-theme .masters-map-panel-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
    color: var(--color-text-muted);
}

.masters-map-cards {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.light-theme .masters-map-cards {
    scrollbar-color: rgba(0,0,0,0.15) transparent;
}

/* --- Map Card --- */

.map-card {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--color-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    transition: background var(--transition-fast, 150ms);
    cursor: pointer;
}

.map-card:hover {
    background: rgba(255, 255, 255, 0.06);
}

.map-card--active {
    background: rgba(232, 197, 71, 0.1);
    border-left: 3px solid var(--color-brand-accent, #E8C547);
    padding-left: 13px;
}

.light-theme .map-card {
    color: var(--color-text);
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

.light-theme .map-card:hover {
    background: rgba(0, 0, 0, 0.04);
}

.light-theme .map-card--active {
    background: rgba(232, 197, 71, 0.08);
}

.map-card__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--color-bg-card);
}

.map-card__info {
    flex: 1;
    min-width: 0;
}

.map-card__name {
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-card__location {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-card__meta {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-top: 4px;
}

.map-card__rating {
    font-size: var(--text-xs);
    color: var(--color-brand-accent, #E8C547);
}

.map-card__reviews {
    font-size: var(--text-3xs);
    color: var(--color-text-muted, var(--color-text-muted));
}

.map-card__styles {
    font-size: var(--text-3xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- "Zoom in" notice --- */

.masters-map-zoom-notice {
    padding: 10px 16px;
    font-size: var(--text-xs);
    color: var(--color-text-muted, var(--color-text-muted));
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.light-theme .masters-map-zoom-notice {
    border-top-color: rgba(0, 0, 0, 0.06);
}

/* --- Empty state --- */

.masters-map-empty {
    padding: var(--space-10) 16px;
    text-align: center;
    color: var(--color-text-muted, var(--color-text-muted));
    font-size: var(--text-sm);
}

/* When map view is active, hide grid and load more */
.map-view-active .masters-grid {
    display: none;
}

.map-view-active .masters-scroll-sentinel,
.map-view-active .masters-scroll-spinner {
    display: none;
}

/* ======================================================
   VIEW TOGGLE BUTTONS
   ====================================================== */

.masters-view-toggle {
    display: flex;
    gap: 4px;
    margin-left: 8px;
    flex-shrink: 0;
}

.masters-view-toggle .view-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* DSv2 §G.2 #12 — 44px touch target minimum */
    min-width: 44px;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: var(--radius-sm, 4px);
    background: transparent;
    border: 1px solid var(--color-border, var(--color-border));
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast, 150ms);
    line-height: 1;
}

.masters-view-toggle .view-toggle-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--color-text);
}

.light-theme .masters-view-toggle .view-toggle-btn:hover {
    border-color: rgba(0, 0, 0, 0.2);
    color: var(--color-text);
}

.masters-view-toggle .view-toggle-btn.active {
    background: var(--color-brand-accent, #E8C547);
    color: var(--color-bg);
    border-color: var(--color-brand-accent, #E8C547);
}

.masters-view-toggle .view-toggle-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* ======================================================
   ADDRESS SEARCH BAR
   ====================================================== */

.masters-map-search {
    position: relative;
    margin-bottom: 12px;
}

.masters-map-search input {
    width: 100%;
    /* DSv2 §G.2 #12 — 44px touch target minimum */
    min-height: 44px;
    padding: 10px 16px;
    border-radius: var(--radius-md, 8px);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border, var(--color-border));
    color: var(--color-text);
    font-size: var(--text-sm);
    font-family: inherit;
    transition: border-color var(--transition-fast, 150ms);
    box-sizing: border-box;
}

.masters-map-search input::placeholder {
    color: var(--color-text-muted, var(--color-text-muted));
}

.masters-map-search input:focus {
    outline: none;
    border-color: var(--color-brand-accent, #E8C547);
}

.light-theme .masters-map-search input {
    background: var(--color-white);
    border-color: rgba(0, 0, 0, 0.12);
    color: var(--color-text);
}

.masters-map-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border, var(--color-border));
    border-radius: var(--radius-md, 8px);
    max-height: 240px;
    overflow-y: auto;
    display: none;
    margin-top: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.light-theme .masters-map-search-results {
    background: var(--color-white);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.masters-map-search-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--color-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background var(--transition-fast, 150ms);
}

.masters-map-search-item:last-child {
    border-bottom: none;
}

.masters-map-search-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.light-theme .masters-map-search-item {
    color: var(--color-text);
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

.light-theme .masters-map-search-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

/* ======================================================
   MAPLIBRE POPUP OVERRIDES — Dark/Light theme support
   ====================================================== */

.masters-listing-page .maplibregl-popup-content {
    background: var(--color-bg-card) !important;
    color: var(--color-text) !important;
    border-radius: var(--radius-md, 8px) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6) !important;
    border: 1px solid var(--color-border, var(--color-border)) !important;
    padding: 12px !important;
}

.masters-listing-page .maplibregl-popup-tip {
    border-top-color: var(--color-bg-card) !important;
}

.masters-listing-page .maplibregl-popup-close-button {
    color: var(--color-text-muted, var(--color-text-muted));
    font-size: var(--text-lg);
    padding: 4px 8px;
}

.masters-listing-page .maplibregl-popup-close-button:hover {
    color: var(--color-text);
    background: transparent;
}

/* Light theme variants */
.light-theme .masters-listing-page .maplibregl-popup-content {
    background: var(--color-white) !important;
    color: var(--color-text) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
}

.light-theme .masters-listing-page .maplibregl-popup-tip {
    border-top-color: var(--color-white) !important;
}

.light-theme .masters-listing-page .maplibregl-popup-close-button {
    color: var(--color-text-muted);
}

.light-theme .masters-listing-page .maplibregl-popup-close-button:hover {
    color: var(--color-border);
}

/* ======================================================
   POPUP CARD (mini master card)
   ====================================================== */

.master-map-popup {
    display: flex;
    gap: 10px;
    max-width: 280px;
}

.master-map-popup .popup-photo {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm, 4px);
    object-fit: cover;
    flex-shrink: 0;
}

.master-map-popup .popup-info {
    flex: 1;
    min-width: 0;
}

.master-map-popup .popup-name {
    font-weight: var(--font-weight-semibold);
    font-size: var(--text-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.master-map-popup .popup-location {
    font-size: var(--text-xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.master-map-popup .popup-rating {
    font-size: var(--text-sm);
    color: var(--color-brand-accent, #E8C547);
    margin-top: 4px;
}

.master-map-popup .popup-reviews {
    color: var(--color-text-muted, var(--color-text-muted));
    font-size: var(--text-3xs);
}

.master-map-popup .popup-styles {
    font-size: var(--text-3xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.master-map-popup .popup-link {
    display: inline-block;
    margin-top: 6px;
    font-size: var(--text-sm);
    color: var(--color-brand-accent, #E8C547);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    transition: opacity var(--transition-fast, 150ms);
}

.master-map-popup .popup-link:hover {
    opacity: 0.8;
}

/* ======================================================
   CLUSTER LIST POPUP (same-coordinate masters)
   ====================================================== */

.masters-cluster-list { max-width: 280px; }
.cluster-list-header { font-weight: var(--font-weight-semibold); font-size: var(--text-sm); margin-bottom: 8px; color: var(--color-text); }
.cluster-list-scroll { max-height: 300px; overflow-y: auto; }
.cluster-list-item { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); text-decoration: none; color: inherit; }
.cluster-list-item:last-child { border-bottom: none; }
.cluster-list-item:hover { opacity: 0.8; }
.cluster-list-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.cluster-list-info { flex: 1; min-width: 0; }
.cluster-list-name { font-weight: var(--font-weight-medium); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cluster-list-meta { font-size: var(--text-3xs); color: var(--color-text-secondary); margin-top: 2px; }
.light-theme .cluster-list-item { border-bottom-color: rgba(0,0,0,0.06); }

/* ======================================================
   MAPLIBRE CONTROLS — theme override
   ====================================================== */

.masters-listing-page .maplibregl-ctrl-group button {
    background-color: var(--color-bg-card) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border, var(--color-border)) !important;
}

.light-theme .masters-listing-page .maplibregl-ctrl-group button {
    background-color: var(--color-white) !important;
    color: var(--color-border) !important;
}

/* Attribution — compact icon, minimal footprint (MapTiler ToS requires visible attribution) */
.masters-listing-page .maplibregl-ctrl-attrib {
    font-size: 10px !important;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.masters-listing-page .maplibregl-ctrl-attrib:hover {
    opacity: 0.9;
}

/* Compact mode */
.masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact {
    min-height: 20px;
    padding: 0;
    margin: 0 10px 10px 0;
    background: transparent !important;
    box-shadow: none !important;
}

.masters-listing-page .maplibregl-ctrl-attrib-button {
    width: 22px !important;
    height: 22px !important;
    background-color: rgba(0,0,0,0.4) !important;
    border-radius: 50% !important;
    cursor: pointer;
}
.light-theme .masters-listing-page .maplibregl-ctrl-attrib-button {
    background-color: rgba(255,255,255,0.5) !important;
}

.masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact:not([open]) .maplibregl-ctrl-attrib-inner {
    display: none !important;
}

.masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact[open] {
    background: var(--color-bg-card) !important;
    padding: 4px 28px 4px 8px !important;
    border-radius: var(--radius-sm, 4px) !important;
    border: 1px solid var(--color-border, var(--color-border)) !important;
    opacity: 0.9;
}
.masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact[open] .maplibregl-ctrl-attrib-inner {
    display: block;
    color: var(--color-text-muted, var(--color-text-muted));
}
.masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact[open] .maplibregl-ctrl-attrib-inner a {
    color: var(--color-text-secondary);
}
.light-theme .masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact[open] {
    background: var(--color-white) !important;
    border-color: rgba(0,0,0,0.1) !important;
}
.light-theme .masters-listing-page .maplibregl-ctrl-attrib.maplibregl-compact[open] .maplibregl-ctrl-attrib-inner a {
    color: var(--color-text-muted);
}

/* ======================================================
   WEBGL FALLBACK
   ====================================================== */

.masters-listing-page .map-unsupported {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted, var(--color-text-muted));
    text-align: center;
    padding: var(--space-10);
}

/* ======================================================
   BACK TO LIST BUTTON (mobile floating)
   ====================================================== */

.masters-back-to-list {
    display: none;
    position: fixed;
    /* Reserves bottom-nav height (56px) + safe-area-inset + spacing.
       Prevents overlay over .bottom-nav (z:90). See SPEC INK-DEV-VISUAL-FIX-2026-05-06 #1. */
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + var(--space-3, 12px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    /* DSv2 §G.2 #12 — 44px touch target minimum */
    min-height: 44px;
    padding: 10px 24px;
    border-radius: 100px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border, var(--color-border));
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: all var(--transition-fast, 150ms);
}

.masters-back-to-list:hover {
    background: var(--color-brand-accent, #E8C547);
    color: var(--color-bg);
    border-color: var(--color-brand-accent, #E8C547);
}

.light-theme .masters-back-to-list {
    background: var(--color-white);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ======================================================
   RESPONSIVE
   ====================================================== */

@media (max-width: 900px) {
    .masters-map-split {
        height: 500px;
    }

    .masters-view-toggle {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    /* Stack vertically: cards on top, map below */
    .masters-map-split {
        flex-direction: column;
        height: auto;
        border-radius: var(--radius-md, 8px);
    }

    #mastersMap {
        flex: none;
        width: 100%;
        height: 50vh;
        min-height: 300px;
    }

    .masters-map-panel {
        flex: none;
        width: 100%;
        height: auto;
        max-height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--color-border, var(--color-border));
    }

    .masters-map-cards {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 0;
    }

    .map-card {
        flex: 0 0 260px;
        scroll-snap-align: start;
        border-bottom: none;
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }

    .light-theme .map-card {
        border-right-color: rgba(0, 0, 0, 0.06);
    }

    .map-card--active {
        border-left: none;
        padding-left: 16px;
        border-bottom: 3px solid var(--color-brand-accent, #E8C547);
    }

    .masters-map-zoom-notice {
        flex: 0 0 200px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top: none;
    }
}

@media (max-width: 540px) {
    .masters-map-wrapper {
        padding: 0 16px;
    }

    .map-view-active .masters-back-to-list {
        display: block;
    }

    .map-view-active .masters-map-wrapper {
        padding: 0;
    }

    .map-view-active .masters-map-search {
        padding: 0 16px;
    }

    #mastersMap {
        height: 45vh;
        min-height: 260px;
    }

    .masters-map-split {
        border-radius: 0;
    }
}
