:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --surface-alt: #fafafa;
    --text: #333333;
    --text-muted: #666666;
    --text-strong: #2c3e50;
    --border: #dddddd;
    --border-soft: #eeeeee;
    --accent: #3498db;
    --error: #e74c3c;
    --tag-bg: #fef3c7;
    --tag-border: #fde68a;
    --tag-text: #b45309;
    --footnote: #999999;
    --hover-bg: #ecf0f1;
    --hover-bg-strong: #bdc3c7;
    --shadow: rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] {
    --bg: #15171a;
    --surface: #1e2125;
    --surface-alt: #25282d;
    --text: #e4e6eb;
    --text-muted: #a8adb5;
    --text-strong: #f0f2f5;
    --border: #383b40;
    --border-soft: #2a2d31;
    --accent: #5dade2;
    --error: #ec7063;
    --tag-bg: #3b2f12;
    --tag-border: #5a4520;
    --tag-text: #fbbf24;
    --footnote: #777a80;
    --hover-bg: #2d3137;
    --hover-bg-strong: #3b4046;
    --shadow: rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 2rem;
    color: var(--text-strong);
    margin-bottom: 8px;
}

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

.experimental-tag {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--tag-text);
    background: var(--tag-bg);
    border: 1px solid var(--tag-border);
    border-radius: 999px;
    vertical-align: middle;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}


/* Controls */
#controls {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-soft);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control-group > label {
    font-weight: 500;
    color: var(--text);
    font-size: 0.9rem;
}

#location-selector {
    position: relative;
}

.btn {
    padding: 6px 28px 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    min-width: 160px;
    text-align: left;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color 0.2s;
}

.btn:hover {
    border-color: var(--footnote);
}

.btn:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.btn-small {
    background: var(--surface-alt);
    color: var(--text);
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-small:hover {
    background: var(--hover-bg-strong);
}

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 100;
    min-width: 280px;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 5px;
}

.dropdown-header {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-alt);
    border-radius: 8px 8px 0 0;
    position: sticky;
    top: 0;
}

#location-list {
    padding: 10px;
}

.location-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-radius: 4px;
    cursor: pointer;
}

.location-item:hover {
    background: var(--surface-alt);
}

.location-item input {
    cursor: pointer;
}

.location-item label {
    cursor: pointer;
    flex: 1;
    font-size: 0.9rem;
}

.location-item.austria {
    font-weight: 600;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 8px;
    padding-bottom: 10px;
}

#chart-container {
    min-height: 500px;
    position: relative;
}

#chart {
    width: 100%;
    height: 500px;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: var(--text-muted);
}

#error {
    text-align: center;
    padding: 40px;
    color: var(--error);
}

.hidden {
    display: none;
}

footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

footer .data-freshness {
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: var(--text-muted);
}

footer .data-freshness:empty {
    display: none;
}

footer .impressum {
    font-size: 0.75rem;
    margin-top: 10px;
    color: var(--footnote);
}

footer .impressum a {
    color: var(--footnote);
}

/* SARI Section */
.sari-section {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 2px 10px var(--shadow);
    padding: 20px;
    margin-bottom: 30px;
}

.sari-section header {
    margin-bottom: 20px;
}

.sari-section h2 {
    font-size: 1.5rem;
    color: var(--text-strong);
    margin-bottom: 8px;
}

#sari-controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-soft);
    flex-wrap: wrap;
}

.select-input {
    padding: 6px 28px 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    min-width: 160px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.select-input option {
    background: var(--surface);
    color: var(--text);
}

.select-input:hover {
    border-color: var(--footnote);
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

#sari-chart-container {
    min-height: 500px;
    position: relative;
}

#sari-chart {
    width: 100%;
    height: 500px;
}

#sari-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: var(--text-muted);
}

#sari-error,
#sari-demographics-error {
    text-align: center;
    padding: 40px;
    color: var(--error);
}

#sari-demographics-controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-soft);
    flex-wrap: wrap;
}

#sari-demographics-chart-container {
    min-height: 550px;
    position: relative;
}

#sari-demographics-chart {
    width: 100%;
    height: 550px;
}

.timeline-widget {
    margin: 10px 0 0;
    padding: 8px 12px 6px;
}

.timeline-presets {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.timeline-preset {
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.8rem;
    cursor: pointer;
}

.timeline-preset:hover {
    background: var(--hover-bg);
}

.timeline-slider-wrap {
    position: relative;
    height: 56px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.timeline-bars {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.timeline-mask {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(250, 250, 250, 0.75);
    pointer-events: none;
}

.timeline-mask-left { left: 0; width: 0; }
.timeline-mask-right { right: 0; width: 0; }

.timeline-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: none;
}

.timeline-input::-webkit-slider-runnable-track {
    background: transparent;
    height: 100%;
}

.timeline-input::-moz-range-track {
    background: transparent;
    height: 100%;
}

.timeline-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 56px;
    background: var(--accent);
    border: none;
    border-radius: 2px;
    cursor: ew-resize;
    pointer-events: all;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

.timeline-input::-moz-range-thumb {
    width: 14px;
    height: 56px;
    background: var(--accent);
    border: none;
    border-radius: 2px;
    cursor: ew-resize;
    pointer-events: all;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

.timeline-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.timeline-label-sep {
    color: var(--footnote);
    font-size: 0.75rem;
}

#sari-demographics-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: var(--text-muted);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.toggle-text {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.zeitraum-slider-wrapper {
    padding: 15px 20px 10px;
    border-bottom: 1px solid var(--border-soft);
}

.zeitraum-slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.slider-label {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 500;
    white-space: nowrap;
    min-width: 90px;
}

.slider-label.left {
    text-align: right;
}

.slider-label.right {
    text-align: left;
}

.dual-slider {
    position: relative;
    flex: 1;
    height: 30px;
    min-width: 200px;
}

.slider-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
}

.slider-range {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    background: var(--accent);
    border-radius: 4px;
}

.range-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    top: 0;
    margin: 0;
}

.range-slider::-webkit-slider-runnable-track {
    height: 30px;
    background: transparent;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: ew-resize;
    pointer-events: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    margin-top: 0;
}

.range-slider::-webkit-slider-thumb::before {
    content: '||';
    color: var(--footnote);
}

.range-slider::-moz-range-track {
    height: 30px;
    background: transparent;
}

.range-slider::-moz-range-thumb {
    width: 24px;
    height: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: ew-resize;
    pointer-events: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Heatmap Section */
#sari-heatmap-controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-soft);
    flex-wrap: wrap;
}

#sari-heatmap-chart-container {
    min-height: 600px;
    position: relative;
}

#sari-heatmap-chart {
    width: 100%;
    height: 600px;
}

#sari-heatmap-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: var(--text-muted);
}

#sari-heatmap-error {
    text-align: center;
    padding: 40px;
    color: var(--error);
}

.footnote {
    font-size: 0.7rem;
    color: var(--footnote);
    margin-top: 8px;
}

/* Combined Signal */
#combined-signal-chart-container {
    min-height: 500px;
    position: relative;
}

#combined-signal-chart {
    width: 100%;
    height: 500px;
}

#combined-signal-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: var(--text-muted);
}

#combined-signal-error {
    text-align: center;
    padding: 40px;
    color: var(--error);
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.5rem;
    }

    #chart,
    #sari-chart,
    #sari-demographics-chart,
    #sari-heatmap-chart,
    #combined-signal-chart {
        height: 350px;
    }

    .sari-section {
        padding: 10px;
    }

    #sari-controls,
    #sari-demographics-controls,
    #sari-heatmap-controls {
        flex-direction: column;
        gap: 10px;
    }

    .select-input {
        width: 100%;
    }
}

:root[data-theme="dark"] .btn,
:root[data-theme="dark"] .select-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a8adb5' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
}

.theme-toggle {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1000;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--shadow);
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.theme-toggle:hover {
    background: var(--hover-bg);
    transform: scale(1.05);
}

.theme-toggle:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}
