/* MeshCore Wardrive Map - Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #121212;
    color: #ffffff;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Info Panel */
.info-panel {
    position: absolute;
    top: 70px;
    left: 10px;
    background: rgba(30, 30, 30, 0.95);
    padding: 15px;
    border-radius: 8px;
    z-index: 1000;
    min-width: 250px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    transition: transform 0.3s, opacity 0.3s;
}

.info-panel.hidden {
    transform: translateX(-110%);
    opacity: 0;
    pointer-events: none;
}

.info-panel h2 {
    font-size: 18px;
    margin-bottom: 10px;
    color: #e8eaed;
}

.stat {
    margin: 8px 0;
    font-size: 14px;
}

.stat-label {
    color: #aaa;
    display: inline-block;
    width: 120px;
}

.stat-value {
    color: #fff;
    font-weight: 500;
}

/* Layer toggles */
.layer-toggles {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #444;
}

.toggle-item {
    display: flex;
    align-items: center;
    margin: 6px 0;
    cursor: pointer;
    user-select: none;
}

.toggle-item input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.toggle-item label {
    cursor: pointer;
    font-size: 13px;
}

/* Legend */
.legend {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #444;
}

.legend-title {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #aaa;
}

.legend-item {
    display: flex;
    align-items: center;
    margin: 4px 0;
    font-size: 11px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    margin-right: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Loading */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    color: #e8eaed;
    z-index: 2000;
}

/* Popup styling */
.leaflet-popup-content-wrapper {
    background: #1e1e1e;
    color: #fff;
    border-radius: 8px;
}

.leaflet-popup-tip {
    background: #1e1e1e;
}

.leaflet-popup-content,
.popup-content {
    max-height: 60vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.popup-content {
    padding: 5px;
}

.popup-content div {
    margin: 5px 0;
    font-size: 13px;
}

.popup-label {
    color: #aaa;
    display: inline-block;
    width: 80px;
}

/* Map style selector (dark / voyager / light) — matches the menu/tools buttons. */
.theme-select {
    position: absolute;
    top: 10px;
    right: 68px;            /* clears the 48px tools-button (right:10..58) + 10px gap */
    height: 48px;           /* same height as the 24px buttons (font 24 + padding 12×2) */
    padding: 0 12px;
    background: rgba(30, 30, 30, 0.95);
    color: #fff;
    border: none;
    border-radius: 8px;
    z-index: 1001;          /* same layer as the buttons — won't tuck under them */
    cursor: pointer;
    font-size: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: background 0.3s;
}

.theme-select:hover {
    background: rgba(50, 50, 50, 0.95);
}

/* Solid option background so the dropdown stays readable in both themes. */
.theme-select option {
    background: #1e1e1e;
    color: #fff;
}

/* Clickable repeater links */
.repeater-link {
    color: #60a5fa;
    cursor: pointer;
    text-decoration: underline;
    margin: 0 2px;
}

.repeater-link:hover {
    color: #93c5fd;
}

/* Bottom-left detail panel (selected cell / repeater info) */
.detail-panel {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(30, 30, 30, 0.95);
    color: #fff;
    padding: 12px 14px;
    border-radius: 8px;
    z-index: 1000;
    min-width: 240px;
    max-width: 320px;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: transform 0.2s, opacity 0.2s;
}

.detail-panel.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.detail-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}

.detail-panel-title {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 700;
    font-size: 14px;
    color: #e8eaed;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-panel-close {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
}

.detail-panel-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

/* Let the injected .popup-content flow naturally inside the panel */
.detail-panel-body .popup-content {
    padding: 0;
    max-height: none;
    overflow: visible;
}

.detail-panel-body .popup-content div {
    margin: 4px 0;
}

/* Freshness label (Live / Recent / Last Known) — readable, theme-aware */
.freshness-label {
    font-weight: bold;
    margin-bottom: 8px;
}

.freshness-live { color: #4ade80; }
.freshness-recent { color: #fbbf24; }
.freshness-stale { color: #9ca3af; }

body.light-theme .freshness-live { color: #15803d; }
body.light-theme .freshness-recent { color: #b45309; }
body.light-theme .freshness-stale { color: #6b7280; }

/* Modal for repeater details */
.modal {
    display: none;
    position: fixed;
    z-index: 100000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

body.modal-open { overflow: hidden; }

.modal.show {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    touch-action: none;
    overscroll-behavior: contain;
}

.modal-content {
    background: #1e1e1e;
    color: #fff;
    padding: 16px 16px 20px 16px;
    border-radius: 12px 12px 0 0;
    max-width: 640px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: #666;
    border-radius: 2px;
    margin: 0 auto 10px auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #444;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: #e8eaed;
}

.modal-close {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    color: #fff;
}

.signal-entry {
    padding: 10px;
    margin: 8px 0;
    background: rgba(0, 230, 118, 0.1);
    border-radius: 4px;
    border-left: 3px solid #00e676;
}

.signal-entry div {
    margin: 4px 0;
    font-size: 13px;
}

.signal-label {
    color: #aaa;
    display: inline-block;
    width: 80px;
}

/* Resolution select */
.resolution-select {
    width: 100%;
    padding: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.resolution-select option {
    background: #2a2a2a;
    color: #fff;
}

/* Measure tool */
.measure-control {
    position: absolute;
    top: 70px;
    right: 10px;
    background: rgba(30, 30, 30, 0.95);
    padding: 10px;
    border-radius: 8px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    min-width: 200px;
    transition: transform 0.3s, opacity 0.3s;
}

.measure-control.hidden {
    transform: translateX(110%);
    opacity: 0;
    pointer-events: none;
}

.measure-btn {
    width: 100%;
    padding: 8px;
    background: #00e676;
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: background 0.3s;
}

.measure-btn:hover {
    background: #00c853;
}

.measure-btn.active {
    background: #ff5252;
}

.measure-btn.active:hover {
    background: #ff1744;
}

.unit-selector {
    margin-top: 8px;
    display: flex;
    gap: 4px;
}

.unit-btn {
    flex: 1;
    padding: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.3s;
}

.unit-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.unit-btn.active {
    background: #00e676;
    color: #000;
    border-color: #00e676;
}

.measure-info {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 230, 118, 0.1);
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
    display: none;
}

.measure-info.show {
    display: block;
}

.measure-distance {
    font-size: 18px;
    font-weight: 700;
    color: #e8eaed;
    margin: 4px 0;
}

/* Mobile-friendly controls */
.menu-button {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(30, 30, 30, 0.95);
    padding: 12px;
    border-radius: 8px;
    z-index: 1001;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    font-size: 24px;
    line-height: 1;
    transition: background 0.3s;
}

.menu-button:hover {
    background: rgba(50, 50, 50, 0.95);
}

.tools-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(30, 30, 30, 0.95);
    padding: 12px;
    border-radius: 8px;
    z-index: 1001;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    font-size: 24px;
    line-height: 1;
    transition: background 0.3s;
}

.tools-button:hover {
    background: rgba(50, 50, 50, 0.95);
}

/* Time-lapse controls */
.timelapse-control {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    min-width: 320px;
    max-width: calc(100vw - 40px);
    display: none;
}

.timelapse-control.show {
    display: block;
}

.timelapse-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.timelapse-title {
    font-size: 13px;
    font-weight: 600;
    color: #e8eaed;
}

.timelapse-date {
    font-size: 13px;
    color: #fff;
    font-weight: 500;
}

.timelapse-slider {
    width: 100%;
    margin: 4px 0;
    accent-color: #00e676;
}

.timelapse-buttons {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.timelapse-btn {
    flex: 1;
    padding: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.timelapse-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.timelapse-btn.active {
    background: #00e676;
    color: #000;
    border-color: #00e676;
}

/* Light theme overrides */
body.light-theme {
    background: #f5f5f5;
    color: #000000;
}

body.light-theme .info-panel {
    background: rgba(255, 255, 255, 0.95);
    color: #000000;
}

body.light-theme .info-panel h2 {
    color: #1f1f1f;
}

body.light-theme .stat-label {
    color: #666;
}

body.light-theme .stat-value {
    color: #000;
}

body.light-theme .layer-toggles {
    border-top-color: #ddd;
}

body.light-theme .theme-select {
    background: rgba(255, 255, 255, 0.95);
    color: #000;
}

body.light-theme .theme-select:hover {
    background: rgba(240, 240, 240, 0.95);
}

body.light-theme .theme-select option {
    background: #fff;
    color: #000;
}

body.light-theme .leaflet-popup-content-wrapper {
    background: #ffffff;
    color: #000;
}

body.light-theme .leaflet-popup-tip {
    background: #ffffff;
}

body.light-theme .popup-label {
    color: #666;
}

body.light-theme .repeater-link {
    color: #2563eb;
}

body.light-theme .repeater-link:hover {
    color: #1d4ed8;
}

body.light-theme .detail-panel {
    background: rgba(255, 255, 255, 0.97);
    color: #000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

body.light-theme .detail-panel-header {
    border-bottom-color: rgba(0,0,0,0.12);
}

body.light-theme .detail-panel-title {
    color: #1f1f1f;
}

body.light-theme .detail-panel-close {
    color: #666;
}

body.light-theme .detail-panel-close:hover {
    color: #000;
    background: rgba(0,0,0,0.08);
}

body.light-theme .modal-content {
    background: #ffffff;
    color: #000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
}

body.light-theme .modal-header {
    border-bottom-color: #ddd;
}

body.light-theme .modal-title {
    color: #1f1f1f;
}

body.light-theme .modal-close:hover {
    color: #000;
}

body.light-theme .signal-entry {
    background: rgba(0, 200, 83, 0.1);
    border-left-color: #00c853;
}

body.light-theme .signal-label {
    color: #666;
}

body.light-theme .resolution-select {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
    border-color: rgba(0, 0, 0, 0.2);
}

body.light-theme .resolution-select option {
    background: #ffffff;
    color: #000;
}

body.light-theme .measure-control {
    background: rgba(255, 255, 255, 0.95);
}

body.light-theme .unit-btn {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
    border-color: rgba(0, 0, 0, 0.2);
}

body.light-theme .unit-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme .measure-distance {
    color: #1f1f1f;
}

body.light-theme .menu-button {
    background: rgba(255, 255, 255, 0.95);
}

body.light-theme .menu-button:hover {
    background: rgba(240, 240, 240, 0.95);
}

body.light-theme .tools-button {
    background: rgba(255, 255, 255, 0.95);
}

body.light-theme .tools-button:hover {
    background: rgba(240, 240, 240, 0.95);
}

body.light-theme .legend {
    border-top-color: #ddd;
}

body.light-theme .legend-title {
    color: #666;
}

body.light-theme .legend-color {
    border-color: rgba(0, 0, 0, 0.2);
}

body.light-theme .timelapse-control {
    background: rgba(255, 255, 255, 0.95);
}

body.light-theme .timelapse-title {
    color: #1f1f1f;
}

body.light-theme .timelapse-date {
    color: #000;
}

body.light-theme .timelapse-btn {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
    border-color: rgba(0, 0, 0, 0.2);
}

body.light-theme .timelapse-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Repeater markers */
.repeater-marker-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.7), 0 0 2px rgba(0,0,0,0.5);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .info-panel {
        min-width: calc(100vw - 20px);
        left: 10px;
        right: 10px;
    }

    .measure-control {
        min-width: calc(100vw - 20px);
        left: 10px;
        right: 10px;
    }

    .theme-select {
        display: block;
        top: 60px;
        right: 10px;
        z-index: 1002;
    }

    .timelapse-control {
        min-width: calc(100vw - 40px);
    }
}

/* Time filter buttons */
.time-filter-buttons {
    display: flex;
    gap: 4px;
}

.time-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
}

.time-btn:hover {
    background: #3a3a3a;
    border-color: #00e676;
}

.time-btn.active {
    background: #00e676;
    color: #000;
    border-color: #00e676;
    font-weight: bold;
}

.light-theme .time-btn {
    background: #e8e8e8;
    border-color: #ccc;
    color: #333;
}

.light-theme .time-btn.active {
    background: #00c853;
    color: #fff;
    border-color: #00c853;
}

/* ===== App version badge (info panel header) ===== */
.app-version {
    font-size: 11px;
    color: #888;
    font-weight: 400;
    margin-left: 4px;
    vertical-align: middle;
}

/* ===== Tools panel: GPX import section ===== */
.tools-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 12px 0 10px;
}

.tool-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #aaa;
    margin-bottom: 6px;
}

.token-input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    font-size: 12px;
}

.token-input::placeholder {
    color: #888;
}

.gpx-result {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.4;
    word-break: break-word;
}

.gpx-result.muted { color: #888; }
.gpx-result.success { color: #00e676; }
.gpx-result.error { color: #ff5252; }

.muted { color: #888; }

/* Light theme overrides */
body.light-theme .app-version { color: #999; }

body.light-theme .tools-divider {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme .tool-section-title { color: #666; }

body.light-theme .token-input {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
    border-color: rgba(0, 0, 0, 0.2);
}

body.light-theme .token-input::placeholder { color: #999; }

body.light-theme .gpx-result.muted { color: #777; }
body.light-theme .gpx-result.success { color: #00a152; }
body.light-theme .gpx-result.error { color: #c00; }
