/* ============================================================
   Sleuth Territory — map.css
   BDI Alpha theme, satellite map aesthetic
   ============================================================ */

:root {
    --bdi-orange:   #ffa22b;
    --bdi-red:      #fb4d5d;
    --bdi-green:    #53FC18;
    --bdi-discord:  #5865F2;
    --bg-base:      #060504;
    --bg-surface:   rgba(14, 11, 7, 0.96);
    --bg-card:      rgba(10, 8, 4, 0.98);
    --border:       rgba(255, 255, 255, 0.07);
    --border-warm:  rgba(255, 162, 43, 0.25);
    --text-primary: #f0ece6;
    --text-muted:   #888880;
    --text-dim:     #444440;
    --radius-sm:    6px;
    --radius-md:    12px;
    --radius-lg:    18px;

    /* rank colors */
    --den-mother-color: #fb4d5d;
    --designer-color:   #ffa22b;
    --member-color:     #53FC18;
    --unverified-color: #444440;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── HEADER ── */
.map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(6, 5, 4, 0.97);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    z-index: 200;
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}

.map-header-left, .map-header-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.map-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
}

.map-logo-text {
    font-weight: 900;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.map-badge {
    background: rgba(255,162,43,0.12);
    border: 1px solid var(--border-warm);
    color: var(--bdi-orange);
    font-size: 0.58rem;
    font-weight: 900;
    padding: 2px 7px;
    border-radius: 20px;
    letter-spacing: 1.5px;
}

.map-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.map-divider { color: var(--text-dim); }

.map-page-title {
    font-weight: 900;
    font-size: 1rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.map-sub-tag {
    background: rgba(83,252,24,0.08);
    border: 1px solid rgba(83,252,24,0.2);
    color: var(--bdi-green);
    font-size: 0.58rem;
    font-weight: 900;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 1.5px;
}

.map-stat-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,162,43,0.07);
    border: 1px solid var(--border-warm);
    color: var(--bdi-orange);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 5px 14px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.live-pulse {
    width: 8px;
    height: 8px;
    background: var(--bdi-red);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--bdi-red);
    animation: blink 1.4s infinite;
    display: inline-block;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

.map-back-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    text-decoration: none;
    text-transform: uppercase;
    transition: border-color 0.2s, color 0.2s;
    letter-spacing: 0.5px;
}
.map-back-btn:hover { border-color: var(--bdi-orange); color: var(--bdi-orange); text-decoration: none; }

/* ── OUTER LAYOUT ── */
.map-outer {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ── SIDEBAR ── */
.map-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 50;
}

.map-sidebar::-webkit-scrollbar { width: 4px; }
.map-sidebar::-webkit-scrollbar-track { background: transparent; }
.map-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-label {
    font-size: 0.65rem;
    font-weight: 900;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

/* Legend */
.map-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: 0.82rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-den-mother  { background: var(--den-mother-color); box-shadow: 0 0 8px var(--den-mother-color); }
.dot-designer    { background: var(--designer-color);   box-shadow: 0 0 8px var(--designer-color); }
.dot-member      { background: var(--member-color);     box-shadow: 0 0 6px var(--member-color); }
.dot-unverified  { background: var(--unverified-color); }

/* Filters */
.map-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.filter-chip:hover  { border-color: var(--border-warm); color: var(--bdi-orange); }
.filter-chip.active { background: rgba(255,162,43,0.1); border-color: var(--bdi-orange); color: var(--bdi-orange); }

/* Grid info */
.grid-info { display: flex; flex-direction: column; gap: 6px; }
.grid-row { display: flex; justify-content: space-between; align-items: center; }
.grid-k { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
.grid-v { font-size: 0.75rem; color: var(--bdi-green); font-family: 'Share Tech Mono', monospace; font-weight: 600; }

/* Search */
.map-search-wrap { position: relative; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: 0.75rem; }
.map-search {
    width: 100%;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 8px 10px 8px 30px;
    transition: border-color 0.2s;
}
.map-search:focus { outline: none; border-color: var(--bdi-orange); }
.map-search::placeholder { color: var(--text-dim); }

.search-results {
    margin-top: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    max-height: 160px;
    overflow-y: auto;
}
.search-results.hidden { display: none; }
.search-result-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s;
}
.search-result-item:hover { background: rgba(255,162,43,0.07); color: var(--bdi-orange); }
.search-result-item img { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border-warm); object-fit: cover; background: #111; }
.sr-handle { font-weight: 700; }

.sidebar-footer-section { flex: 1; }
.sidebar-note {
    font-size: 0.75rem;
    color: var(--text-dim);
    line-height: 1.7;
}

/* ── MAP CANVAS WRAP ── */
.map-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #0a0a0a;
}

/* ── TOOLBAR ── */
.map-toolbar {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(6, 5, 4, 0.92);
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 6px 10px;
    backdrop-filter: blur(10px);
}

.map-tool-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.map-tool-btn:hover  { color: var(--bdi-orange); }
.map-tool-btn.active { background: rgba(255,162,43,0.12); color: var(--bdi-orange); }

.toolbar-divider { width: 1px; height: 18px; background: var(--border); }

/* ── MAP VIEWPORT ── */
.map-viewport {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: grab;
    user-select: none;
    overflow: hidden;
}
.map-viewport.dragging { cursor: grabbing; }

#map-canvas {
    position: absolute;
    top: 0; left: 0;
    image-rendering: pixelated;
}

#map-markers-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Scan line overlay */
.map-scan-line {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(83,252,24,0.15), transparent);
    animation: scan 8s linear infinite;
    pointer-events: none;
    z-index: 5;
}
@keyframes scan { 0%{top:0%} 100%{top:100%} }

/* Corner coords */
.map-corner {
    position: absolute;
    z-index: 10;
    pointer-events: none;
}
.map-corner.top-left    { top: 10px; left: 10px; }
.map-corner.top-right   { top: 10px; right: 10px; }
.map-corner.bottom-left { bottom: 40px; left: 10px; }
.map-corner.bottom-right{ bottom: 40px; right: 10px; }
.coord-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.65rem;
    color: rgba(83,252,24,0.5);
    text-shadow: 0 0 10px rgba(83,252,24,0.3);
    letter-spacing: 1px;
}

/* Scale bar */
.map-scale-bar {
    position: absolute;
    bottom: 28px;
    right: 14px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    pointer-events: none;
}
.scale-inner {
    width: 60px;
    height: 3px;
    background: rgba(255,255,255,0.4);
    border-left: 2px solid rgba(255,255,255,0.6);
    border-right: 2px solid rgba(255,255,255,0.6);
}
.scale-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.4);
}

/* Attribution */
.map-attribution {
    position: absolute;
    bottom: 8px;
    right: 14px;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.2);
    z-index: 10;
    pointer-events: none;
}

/* ── MARKERS ── */
.map-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    pointer-events: all;
    transition: transform 0.15s;
    z-index: 30;
}
.map-marker:hover { transform: translate(-50%, -50%) scale(1.35); z-index: 50; }

.marker-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.6);
    position: relative;
    transition: box-shadow 0.2s;
}
.marker-dot::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    animation: pulse-ring 2.2s ease-out infinite;
    opacity: 0;
}
@keyframes pulse-ring {
    0%   { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(2.2); opacity: 0; }
}

.marker-dot.rank-den-mother  { background: var(--den-mother-color); box-shadow: 0 0 10px var(--den-mother-color); width: 18px; height: 18px; }
.marker-dot.rank-den-mother::after { border: 2px solid var(--den-mother-color); }
.marker-dot.rank-designer    { background: var(--designer-color);   box-shadow: 0 0 8px var(--designer-color); width: 16px; height: 16px; }
.marker-dot.rank-designer::after { border: 2px solid var(--designer-color); }
.marker-dot.rank-member      { background: var(--member-color);     box-shadow: 0 0 6px var(--member-color); }
.marker-dot.rank-member::after { border: 2px solid var(--member-color); }
.marker-dot.rank-unverified  { background: var(--unverified-color); }

.marker-label {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(6,5,4,0.92);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.map-marker:hover .marker-label { opacity: 1; }

.map-marker.dimmed .marker-dot { opacity: 0.2; }
.map-marker.dimmed .marker-label { opacity: 0; }
.map-marker.dimmed:hover .marker-dot { opacity: 1; }

/* ── CABIN POPUP ── */
.cabin-popup {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: 3px solid var(--bdi-orange);
    border-radius: var(--radius-lg);
    z-index: 200;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8), 0 0 40px rgba(255,162,43,0.05);
    animation: popupIn 0.25s ease;
    overflow: hidden;
}
.cabin-popup.hidden { display: none; }
@keyframes popupIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(0,0,0,0.4);
    border-bottom: 1px solid var(--border);
}

.popup-name-group { display: flex; align-items: center; gap: 10px; }

.popup-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--bdi-orange);
    object-fit: cover;
    background: #111;
}

.popup-handle {
    font-size: 1rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1.2;
}

.popup-rank {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}

.popup-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    transition: color 0.15s;
    line-height: 1;
}
.popup-close:hover { color: var(--text-primary); }

/* Cabin preview */
.popup-cabin-wrap {
    background: rgba(0,0,0,0.5);
    padding: 10px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
}

.popup-cabin-img-container {
    width: 100%;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-cabin-img-container img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
}

.popup-cabin-img-container svg {
    width: 100%;
    max-height: 200px;
}

.popup-no-cabin {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 20px;
}
.popup-no-cabin i { font-size: 1.8rem; }
.popup-no-cabin.hidden { display: none; }

/* Flags */
.popup-flags {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    min-height: 42px;
}

.flag-chip {
    background: rgba(255,162,43,0.08);
    border: 1px solid var(--border-warm);
    color: var(--bdi-orange);
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.flag-empty {
    color: var(--text-dim);
    font-size: 0.73rem;
    font-style: italic;
}

/* Stats row */
.popup-stats-row {
    display: flex;
    gap: 0;
    padding: 0;
}

.popup-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border-right: 1px solid var(--border);
}
.popup-stat:last-child { border-right: none; }
.ps-label { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; }
.ps-value { font-size: 0.9rem; font-weight: 900; color: var(--bdi-orange); margin-top: 2px; font-family: 'Share Tech Mono', monospace; }

/* ── LOADING OVERLAY ── */
.map-loading {
    position: fixed;
    inset: 0;
    background: rgba(6,5,4,0.97);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s;
}
.map-loading.fade-out { opacity: 0; pointer-events: none; }
.map-loading.gone { display: none; }

.loading-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-radar {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.radar-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(83,252,24,0.25);
}
.r1 { width: 40px;  height: 40px;  animation: radar-expand 2s linear infinite 0s; }
.r2 { width: 40px;  height: 40px;  animation: radar-expand 2s linear infinite 0.67s; }
.r3 { width: 40px;  height: 40px;  animation: radar-expand 2s linear infinite 1.33s; }

@keyframes radar-expand {
    0%   { width: 10px;  height: 10px;  opacity: 0.8; }
    100% { width: 100px; height: 100px; opacity: 0; }
}

.radar-sweep {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 70%, rgba(83,252,24,0.2));
    animation: sweep 1.8s linear infinite;
}
@keyframes sweep { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

.loading-paw {
    position: relative;
    z-index: 10;
    font-size: 1.6rem;
    color: var(--bdi-green);
    text-shadow: 0 0 20px rgba(83,252,24,0.6);
    animation: paw-pulse 1s ease-in-out infinite alternate;
}
@keyframes paw-pulse { from{opacity:0.6} to{opacity:1} }

.loading-text {
    font-weight: 900;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-primary);
}
.loading-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    .map-sidebar { display: none; }
    .map-page-title { display: none; }
    .map-sub-tag { display: none; }
    .cabin-popup { width: 280px; top: auto; right: 8px; bottom: 8px; }
    .map-toolbar { flex-wrap: wrap; border-radius: var(--radius-md); }
}

/* ── Popup achievements ─────────────────────────────── */
#popup-achievements {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 12px;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 4px;
}
.popup-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 12px 4px;
    min-height: 20px;
}