*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */

#header {
    background: #1a1a2e;
    color: white;
    padding: 0 16px;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    z-index: 1000;
}

#sidebar-toggle-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
#sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#header h1 {
    font-size: 1.1rem;
    color: #e63946;
    white-space: nowrap;
}

#search-bar {
    max-width: 800px;
    display: flex;
    gap: 6px;
    margin: 0 auto;
}

#search-input {
    flex: 1;
    min-width: 400px;
    padding: 10px 36px 10px 14px;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    width: 100%;
}

#search-clear-btn {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
}
#search-clear-btn:hover { color: #555; }

#search-btn {
    padding: 10px 20px;
    background: #e63946;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
}
#search-btn:hover {
    background: #c1121f;
}

#search-suggestions .suggestion-item {
    padding: 8px 10px;
    cursor: pointer;
    font-size: 0.82rem;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
}
#search-suggestions .suggestion-item:hover {
    background: #f5f5f5;
}
#search-suggestions .suggestion-item .suggestion-type {
    font-size: 0.7rem;
    color: #999;
    margin-left: 4px;
}

/* ── Main ────────────────────────────────────────────────────────────────────── */

#main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */

#sidebar {
    width: 350px;
    background: white;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    transition:
        width 0.2s,
        opacity 0.15s;
}
#sidebar.collapsed {
    width: 0;
    opacity: 0;
    overflow: hidden;
}

.sb-section {
    border-bottom: 1px solid #eee;
}

.sb-section-hdr {
    padding: 10px 14px;
    font-size: 0.72rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #888;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}
.sb-section-hdr:hover {
    background: #fafafa;
}
.sb-section-hdr .caret {
    transition: transform 0.2s;
    display: inline-block;
}
.sb-section-hdr.open .caret {
    transform: rotate(180deg);
}

.sb-section-body {
    padding: 10px 14px 14px;
}
.sb-section-body.hidden {
    display: none;
}

.filter-group {
    margin-bottom: 10px;
}
.filter-group label {
    display: block;
    font-size: 0.8rem;
    color: #555;
    margin-bottom: 3px;
}
.filter-group select,
.filter-group input[type="date"],
.filter-group input[type="number"] {
    width: 100%;
    padding: 5px 7px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.82rem;
    background: white;
}

.range-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.range-row input {
    flex: 1;
    min-width: 0;
}
.range-row span {
    font-size: 0.8rem;
    color: #bbb;
    flex-shrink: 0;
}

.btn-primary {
    width: 100%;
    padding: 7px;
    background: #e63946;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 8px;
}
.btn-primary:hover {
    background: #c1121f;
}

.btn-ghost {
    width: 100%;
    padding: 6px;
    background: white;
    color: #777;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    margin-top: 4px;
}
.btn-ghost:hover {
    background: #f5f5f5;
}

/* ── Mode toggle (Markers / Heatmap / Scatter) ────────────────────────────── */

.mode-toggle {
    display: flex;
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}

.mode-btn {
    flex: 1;
    padding: 8px 4px;
    border: none;
    border-right: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    text-align: center;
    transition:
        background 0.15s,
        color 0.15s;
}
.mode-btn:last-child {
    border-right: none;
}
.mode-btn:hover:not(.active) {
    background: #f5f5f5;
}
.mode-btn.active {
    background: #e63946;
    color: white;
    font-weight: 600;
}

/* ── Secondary map control buttons ──────────────────────────────────────── */


.map-ctrl-btn {
    width: 100%;
    padding: 7px 10px;
    margin-bottom: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.82rem;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}
.map-ctrl-btn:last-child {
    margin-bottom: 0;
}
.map-ctrl-btn:hover {
    background: #f5f5f5;
}
.map-ctrl-btn.active {
    background: #e63946;
    color: white;
    border-color: #e63946;
}

/* ── Content ─────────────────────────────────────────────────────────────────── */

#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

#map {
    flex: 1;
    min-height: 0;
}

/* ── Bottom panel ────────────────────────────────────────────────────────────── */

#bottom-panel {
    height: 230px;
    background: white;
    border-top: 2px solid #e63946;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: height 0.2s;
}
#bottom-panel.collapsed {
    height: 36px;
}

#panel-tab-bar {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    height: 36px;
}

.panel-tab {
    padding: 0 16px;
    cursor: pointer;
    font-size: 0.82rem;
    color: #999;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    white-space: nowrap;
    margin-bottom: -1px;
}
.panel-tab:hover {
    background: #fafafa;
}
.panel-tab.active {
    color: #e63946;
    border-bottom-color: #e63946;
    font-weight: bold;
}

#panel-collapse-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: #bbb;
    padding: 0 12px;
    font-size: 0.8rem;
}
#panel-collapse-btn:hover {
    color: #555;
}

.panel-pane {
    display: none;
    flex: 1;
    overflow: auto;
    padding: 12px 16px;
    gap: 16px;
    min-height: 0;
    position: relative;
}
.panel-pane.active {
    display: flex;
}

/* Stats pane */
#pane-stats {
    position: relative;
}
#pane-trends {
    position: relative;
}

.stat-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    flex-shrink: 0;
    align-items: flex-start;
}

.stat-card {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 10px 14px;
    min-width: 100px;
}
.stat-card .val {
    font-size: 1.4rem;
    font-weight: bold;
    color: #e63946;
    line-height: 1.2;
}
.stat-card .lbl {
    font-size: 0.7rem;
    color: #999;
    margin-top: 3px;
}

.vr {
    width: 1px;
    background: #eee;
    flex-shrink: 0;
    align-self: stretch;
}

.chart-placeholder {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-size: 0.85rem;
    border: 2px dashed #eee;
    border-radius: 6px;
}

/* ── Full-page app loading overlay ───────────────────────────────────────────── */

#app-loading {
    position: fixed;
    inset: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.4s ease;
}
#app-loading.fade-out {
    opacity: 0;
    pointer-events: none;
}
#app-loading.hidden {
    display: none;
}

#app-loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

#app-loading-text {
    font-size: 1rem;
    color: #555;
    font-family: inherit;
}

.app-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #eee;
    border-top-color: #e63946;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ── Map loading overlay ─────────────────────────────────────────────────────── */

#map-loading {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.55);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    z-index: 1000;
    pointer-events: none;
}
#map-loading.hidden {
    display: none;
}

#map-loading-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    padding: 22px 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#map-loading-card span {
    font-size: 0.9rem;
    color: #444;
}

.map-loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #eee;
    border-top-color: #e63946;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Charts loading overlay ────────────────────────────────────────────────── */

#charts-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 100;
    border-radius: 4px;
}
#charts-loading.hidden {
    display: none;
}

#charts-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #eee;
    border-top-color: #e63946;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

#charts-loading-text {
    font-size: 0.85rem;
    color: #666;
}

.charts-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 100;
    border-radius: 4px;
}
.charts-loading.hidden {
    display: none;
}

.charts-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #eee;
    border-top-color: #e63946;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.charts-loading-text {
    font-size: 0.85rem;
    color: #666;
}

/* ── Date range slider ───────────────────────────────────────────────────────── */

.date-slider-container {
    margin-top: 8px;
}

.date-slider-wrap {
    position: relative;
    height: 18px;
}

.date-slider-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    border-radius: 2px;
    background: #e0e0e0;
    pointer-events: none;
}

#date-slider-fill {
    position: absolute;
    top: 0;
    height: 4px;
    background: #e63946;
    border-radius: 2px;
}

.date-slider-wrap input[type="range"] {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    pointer-events: none;
    outline: none;
}

.date-slider-wrap input[type="range"]::-webkit-slider-runnable-track {
    background: transparent;
    height: 4px;
}

.date-slider-wrap input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e63946;
    pointer-events: all;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    margin-top: -5px;
}

.date-slider-wrap input[type="range"]::-moz-range-track {
    background: transparent;
    height: 4px;
}

.date-slider-wrap input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #e63946;
    pointer-events: all;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.date-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: #bbb;
    margin-top: 3px;
}
