:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242736;
    --border: #2e3142;
    --text: #e4e6ef;
    --text-dim: #8b8fa3;
    --primary: #6c8cff;
    --primary-dim: rgba(108, 140, 255, .12);
    --accent: #44d7b6;
    --danger: #ff6b6b;
    --radius: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.topbar h1 span { color: var(--primary); }

.tabs {
    display: flex;
    gap: 4px;
    margin-left: 24px;
}

.tab-btn {
    padding: 6px 16px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
}

.tab-btn:hover { background: var(--primary-dim); color: var(--text); }
.tab-btn.active { background: var(--primary); color: #fff; }

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
}

.status-dot.connected { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.status-text { font-size: 12px; color: var(--text-dim); }

/* ── Tab Content ─────────────────────────────────── */
.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Live Tab ────────────────────────────────────── */
.live-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#map {
    flex: 1;
    min-height: 0;
    z-index: 0;
}

.sidebar {
    width: 320px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* ── Connect Panel ───────────────────────────────── */
.connect-panel {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.connect-panel label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.input-row {
    display: flex;
    gap: 8px;
}

.input-row input {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: var(--mono);
    outline: none;
    transition: border-color .15s;
}

.input-row input:focus { border-color: var(--primary); }

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-dim); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.session-info {
    margin-top: 10px;
    padding: 10px;
    background: var(--surface2);
    border-radius: var(--radius);
    font-size: 12px;
}

.session-info .row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.session-info .label { color: var(--text-dim); }
.session-info .value { font-family: var(--mono); font-weight: 500; }

/* ── Stats Panel ─────────────────────────────────── */
.stats-panel {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.stat-card {
    background: var(--surface2);
    border-radius: var(--radius);
    padding: 10px;
}

.stat-card .stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
}

.stat-card .stat-value {
    font-size: 18px;
    font-weight: 700;
    font-family: var(--mono);
    margin-top: 2px;
}

/* ── Point Log ───────────────────────────────────── */
.point-log {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.point-log h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.log-entry {
    font-size: 11px;
    font-family: var(--mono);
    padding: 6px 8px;
    background: var(--surface2);
    border-radius: 6px;
    margin-bottom: 4px;
    line-height: 1.5;
    color: var(--text-dim);
}

.log-entry .coords { color: var(--accent); }
.log-entry .activity-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--primary-dim);
    color: var(--primary);
    font-size: 10px;
    font-weight: 600;
}

.log-entry .log-time { color: var(--text-dim); opacity: .7; }

/* ── Battery Colors ─────────────────────────────── */
.bat-good { color: var(--accent); }
.bat-mid  { color: #f0ad4e; }
.bat-low  { color: var(--danger); font-weight: 700; }

/* ── Sidebar Actions ─────────────────────────────── */
.sidebar-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.sidebar-actions .btn { flex: 1; text-align: center; }

/* ── Explorer Tab ────────────────────────────────── */
.explorer-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#explorer-map {
    flex: 1;
    min-height: 0;
    z-index: 0;
}

.explorer-sidebar {
    width: 360px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.explorer-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.explorer-header h2 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 10px;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-dim);
    color: var(--text);
}

.drop-zone input { display: none; }

/* ── Loaded Session Info ─────────────────────────── */
.loaded-session {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: none;
}

.loaded-session.visible { display: block; }

.loaded-session h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
}

.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 12px;
}

.meta-grid .meta-label { color: var(--text-dim); }
.meta-grid .meta-value { font-family: var(--mono); text-align: right; }

/* ── Explorer Controls ───────────────────────────── */
.explorer-controls {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: none;
}

.explorer-controls.visible { display: block; }

.explorer-controls h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.control-group select {
    width: 100%;
    padding: 6px 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.toggle-row span { font-size: 13px; }

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 20px;
    cursor: pointer;
    transition: .2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    left: 2px; bottom: 2px;
    background: var(--text);
    border-radius: 50%;
    transition: .2s;
}

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Explorer Point List ─────────────────────────── */
.explorer-points {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.explorer-points h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.point-item {
    padding: 8px;
    background: var(--surface2);
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 11px;
    font-family: var(--mono);
    cursor: pointer;
    transition: background .1s;
}

.point-item:hover { background: var(--primary-dim); }
.point-item .pt-time { color: var(--text-dim); }
.point-item .pt-coords { color: var(--accent); }

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Leaflet overrides ───────────────────────────── */
.leaflet-control-attribution { font-size: 10px !important; }

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    /* Top bar: wrap tabs below title row */
    .topbar {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }

    .tabs {
        order: 3;
        margin-left: 0;
        width: 100%;
        display: flex;
    }

    .tab-btn {
        flex: 1;
        text-align: center;
        padding: 8px 8px;
    }

    .topbar-right { margin-left: auto; }

    /* Tab content: allow scroll */
    .tab-content.active {
        flex: none;
        overflow: visible;
    }

    /* Live tab: stack map above sidebar */
    .live-layout {
        flex-direction: column;
        overflow: visible;
    }

    #map {
        height: 45vh;
        min-height: 250px;
        flex: none;
    }

    .sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        overflow: visible;
    }

    /* Explorer tab: stack map above sidebar */
    .explorer-layout {
        flex-direction: column;
        overflow: visible;
    }

    #explorer-map {
        height: 40vh;
        min-height: 220px;
        flex: none;
    }

    .explorer-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        overflow: visible;
    }

    /* Touch-friendly inputs & buttons */
    .input-row input {
        padding: 10px 12px;
        font-size: 14px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .btn-sm {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Prevent the webhook key value from overflowing */
    .session-info .value {
        font-size: 11px;
        word-break: break-all;
    }

    /* Drop zone: smaller padding */
    .drop-zone {
        padding: 16px;
    }

    /* Point log & explorer points: cap height so the page isn't infinite */
    .point-log {
        max-height: 40vh;
        overflow-y: auto;
    }

    .explorer-points {
        max-height: 40vh;
        overflow-y: auto;
    }
}
