/* Map Explorer tab styles */

.map-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - 130px);
    min-height: 500px;
}

.map-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-sidebar-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.map-sidebar-header .section-label {
    margin-bottom: 8px;
}

.map-search-wrap {
    position: relative;
}

#mapSearch {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
}

#mapSearchResults {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0 0 6px 6px;
    max-height: 300px;
    overflow-y: auto;
}

.map-search-item {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.map-search-item:hover {
    background: rgba(255,255,255,0.05);
}

.map-search-text {
    font-size: 12px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-search-source {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Show/hide toggle for inactive layers */
.map-layer-controls {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

.map-show-hidden-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
}

.map-show-hidden-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

.map-layer-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* Hidden layer items (unchecked) when toggle is off */
.map-layer-list.hide-inactive .map-layer-item:not(.active) {
    display: none;
}
.map-layer-list.hide-inactive .map-layer-group:not(:has(.map-layer-item.active)) {
    display: none;
}

/* ---- Swipeable layer items (mobile) ---- */
.map-layer-item {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.map-layer-swipe-bg {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 0 14px;
    pointer-events: none;
}
.map-layer-swipe-bg.left {
    right: 0;
    justify-content: flex-end;
    background: linear-gradient(90deg, transparent, rgba(244,67,54,0.4));
    color: #ef9a9a;
}
.map-layer-swipe-bg.right {
    left: 0;
    justify-content: flex-start;
    background: linear-gradient(270deg, transparent, rgba(255,193,7,0.4));
    color: #ffe082;
}

.map-layer-item.swiping .map-layer-swipe-bg {
    display: flex;
}

.map-layer-item-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
    background: inherit;
    transition: transform 0.15s ease;
    z-index: 1;
}

/* Starred indicator */
.map-layer-star {
    display: none;
    color: #ffd54f;
    font-size: 12px;
    flex-shrink: 0;
}
.map-layer-item.starred .map-layer-star {
    display: inline;
}

/* Hide transition */
.map-layer-item.hiding {
    max-height: 40px;
    overflow: hidden;
    animation: slideOutLeft 0.3s ease forwards;
}
@keyframes slideOutLeft {
    to {
        transform: translateX(-100%);
        opacity: 0;
        max-height: 0;
        padding: 0;
        margin: 0;
    }
}

.map-layer-group {
    margin-bottom: 4px;
}

.map-layer-era {
    padding: 6px 14px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    font-weight: 600;
}

.map-layer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    transition: background 0.15s;
}

.map-layer-item:hover {
    background: rgba(255,255,255,0.04);
}

.map-layer-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
}

.map-layer-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.map-layer-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-layer-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.map-sidebar-footer {
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-sidebar-footer button {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
}

.map-sidebar-footer button:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

/* Map container */
.map-canvas-wrap {
    flex: 1;
    position: relative;
}

#mapCanvas {
    width: 100%;
    height: 100%;
    background: #1a1a2e;
}

/* Override Leaflet dark theme */
.leaflet-container {
    background: #1a1a2e;
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.leaflet-popup-tip {
    background: var(--card-bg);
    border: 1px solid var(--border);
}

.leaflet-popup-content {
    margin: 10px 14px;
    font-size: 12px;
    line-height: 1.5;
}

.map-popup strong {
    color: var(--accent);
}

.leaflet-control-zoom a {
    background: var(--card-bg) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: rgba(255,255,255,0.1) !important;
}

.leaflet-control-attribution {
    background: rgba(30,30,30,0.8) !important;
    color: var(--text-dim) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-muted) !important;
}

/* ================================================================
   Mobile detail panel (slide-up sheet)
   ================================================================ */

.map-detail-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1100;
}
.map-detail-backdrop.open { display: block; }

.map-detail-panel {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 75vh;
    background: var(--bg-card, #12121f);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 1200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 env(safe-area-inset-bottom, 20px) 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
.map-detail-panel.open {
    display: block;
    transform: translateY(0);
}

/* Drag handle */
.map-detail-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 4px;
    cursor: pointer;
}
.map-detail-handle span {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--text-dim, #555);
}

/* Header: feature title */
.map-detail-header {
    padding: 8px 20px 12px;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    border-bottom: 1px solid var(--border);
}

/* Body: property list */
.map-detail-body {
    padding: 16px 20px;
}

.map-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 12px;
}
.map-detail-row:last-child { border-bottom: none; }

.map-detail-label {
    font-size: 13px;
    color: var(--text-dim, #666);
    text-transform: capitalize;
    min-width: 90px;
    flex-shrink: 0;
}

.map-detail-value {
    font-size: 14px;
    color: var(--text, #e0e0e0);
    text-align: right;
    word-break: break-word;
    flex: 1;
}

/* Action buttons */
.map-detail-actions {
    display: flex;
    gap: 10px;
    padding: 12px 20px 20px;
}
.map-detail-actions .btn {
    flex: 1;
    text-align: center;
    font-size: 14px;
    padding: 12px 16px;
}

/* ---- Desktop: hide mobile panel, keep popups ---- */
@media (min-width: 641px) {
    .map-detail-panel,
    .map-detail-backdrop {
        display: none !important;
    }
}

/* ---- Mobile: map layout overrides ---- */
@media (max-width: 640px) {
    .map-layout {
        flex-direction: column;
        height: calc(100vh - 100px);
    }

    .map-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 140px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .map-sidebar-header {
        width: 100%;
        padding: 8px 12px;
    }

    .map-sidebar-header .section-label { display: none; }

    .map-layer-list {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 4px 8px;
        gap: 0;
    }

    .map-layer-group {
        display: flex;
        align-items: center;
        gap: 0;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .map-layer-era {
        writing-mode: horizontal-tb;
        padding: 2px 6px;
        font-size: 9px;
        white-space: nowrap;
    }

    .map-layer-item {
        padding: 4px 8px;
        font-size: 11px;
        white-space: nowrap;
    }

    .map-sidebar-footer {
        display: none;
    }

    /* Suppress Leaflet popups on mobile — we use the detail panel */
    .leaflet-popup { display: none !important; }
}
