:root {
    --bg: #1a1a2e;
    --panel: #16213e;
    --accent: #0f3460;
    --highlight: #e94560;
    --text: #eaeaea;
    --text-muted: #8892a4;
    --border: #2a3a5c;
    --chart-bg: #0d1b2a;
    --font: "Inter", system-ui, sans-serif;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

#app {
    display: grid;
    height: 100vh;
    grid-template-rows: auto 1fr;
    grid-template-columns: 280px 1fr;
    grid-template-areas:
        "header header"
        "sidebar main";
}

/* ── Header ── */
header {
    grid-area: header;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

header h1 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--highlight);
    letter-spacing: 0.02em;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 0.8rem;
}

header .load-status {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--text-muted);
}

header .data-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 1rem;
}

header .data-status:empty { display: none; }

/* ── Sidebar ── */
aside {
    grid-area: sidebar;
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.35rem;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

button {
    background: var(--accent);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

button:hover { background: #1a4a8a; border-color: #4a6fa0; }
button.active { background: var(--highlight); border-color: var(--highlight); color: #fff; }
button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
button:disabled:hover { background: var(--accent); border-color: var(--border); }

.source-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.12s;
}

.source-item:hover { background: var(--accent); }
.source-item.selected { border-color: var(--highlight); background: rgba(233,69,96,0.12); }

.source-group {
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.source-group .source-item {
    border: none;
    border-radius: 0;
}
.source-group .source-item + .source-item {
    border-top: 1px solid var(--border);
}
.source-group .source-item.selected {
    border-left: 2px solid var(--highlight);
}

.source-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.source-name { font-size: 0.8rem; }
.source-dates { font-size: 0.7rem; color: var(--text-muted); }

/* ── Date range inputs ── */
.date-range {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.date-range input[type="date"] {
    background: var(--chart-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    width: 100%;
    color-scheme: dark;
}

/* ── Main content ── */
main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-container {
    flex: 1;
    background: var(--chart-bg);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-container svg {
    flex: 1;
    width: 100%;
    min-height: 0;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1.1rem;
    padding: 0.45rem 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--chart-bg);
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.71rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.legend-stats {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.66rem;
    opacity: 0.75;
    margin-left: 0.25rem;
}

.map-container {
    height: 220px;
    background: #0a1628;
    border-top: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.map-content {
    position: absolute;
    inset: 0;
    transform-origin: 50% 50%;
}

.map-tiles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.map-tile {
    position: absolute;
    width: 256px;
    height: 256px;
    user-select: none;
    -webkit-user-drag: none;
}

.map-marker {
    position: absolute;
    cursor: pointer;
    z-index: 1;
}

.map-marker:hover,
.map-marker.selected {
    z-index: 10;
}

.marker-dot {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #a8b8d0;
    background: #1a2a4a;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.map-marker.selected .marker-dot {
    border-width: 3px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7);
}

.marker-label {
    position: absolute;
    left: 0;
    top: 12px;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 11px;
    line-height: 1.2;
    color: #ffffff;
    text-shadow:
        -1px -1px 0 #000, 1px -1px 0 #000,
        -1px  1px 0 #000, 1px  1px 0 #000,
        -2px  0   0 #000, 2px  0   0 #000,
         0  -2px  0 #000, 0   2px  0 #000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s;
}

.map-marker:hover .marker-label,
.map-marker.selected .marker-label {
    opacity: 1;
}

.map-marker.label-above .marker-label {
    top: auto;
    bottom: 12px;
}

.map-hint {
    position: absolute;
    top: 6px;
    left: 8px;
    color: #c0c8d8;
    font-size: 10px;
    text-shadow:
        -1px -1px 0 #000, 1px -1px 0 #000,
        -1px  1px 0 #000, 1px  1px 0 #000;
    pointer-events: none;
}

.map-attribution {
    position: absolute;
    bottom: 4px;
    right: 8px;
    color: #ffffff;
    font-size: 9px;
    opacity: 0.75;
    text-shadow:
        -1px -1px 0 #000, 1px -1px 0 #000,
        -1px  1px 0 #000, 1px  1px 0 #000;
    pointer-events: none;
}

/* SVG chart elements */
.chart-axis line, .chart-axis path { stroke: var(--border); }
.chart-axis text { fill: var(--text-muted); font-size: 11px; }
.chart-grid line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart-line { fill: none; stroke-width: 2; }
.chart-area { opacity: 0.15; }
.chart-title { fill: var(--text); font-size: 12px; }

/* Loading / empty states */
.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
