:root {
    --primary-color: #1a5f3f;
    --secondary-color: #2a7f5f;
    --accent-color: #f0ad4e;
    --text-dark: #333;
    --text-light: #666;
    --border-light: #ddd;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-dark);
    background-color: #ffffff;
}

body {
    display: flex;
    flex-direction: column;
}

p {
    line-height: 1.4;
}

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 2rem 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

header .subtitle {
    font-size: 1.1rem;
    font-weight: 300;
    opacity: 0.9;
}

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

.intro {
    background-color: white;
    padding: 3rem 0;
}

.intro-text {
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text-dark);
    max-width: 900px;
    margin: 0 auto;
    margin-bottom: 0;
}

/* Chart section */
.chart-section {
    background-color: white;
    padding: 3rem 0;
    border-bottom: 1px solid var(--border-light);
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

#town-search {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

#town-search-input {
    width: 300px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: 4px 0 0 4px;
    outline: none;
}

#town-search-button {
    padding: 0.5rem 1rem;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    transition: background-color 0.2s;
}

/* Chart styles */
#avg-turnout-chart {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 1rem;
    background-color: #fafafa;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
}

#population-turnout-scatter {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 1rem;
    background-color: #fafafa;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
}

.chart-tooltip {
    position: absolute;
    padding: 12px;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    font-size: 13px;
    line-height: 1.6;
    z-index: 1000;
}

.chart-tooltip strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text-dark);
}

#avg-turnout-chart svg {
    overflow: visible;
}

@media (max-width: 768px) {
    #avg-turnout-chart {
        padding: 0.5rem;
    }
    
    #avg-turnout-chart svg {
        height: 350px !important;
    }
    
    .chart-tooltip {
        font-size: 11px;
        padding: 8px;
    }
}

.map-section {
    flex: 1;
    display: flex;
    min-height: 600px;
}

#map-sidebar {
    width: 40%;
    max-width: 40%;
    background-color: white;
    border-right: 1px solid var(--border-light);
    padding: 1.5rem 1.25rem;
    overflow-y: auto;
}

#map-sidebar-placholder {
    color: var(--text-light);
    font-size: 0.95rem;
    line-height: 1.5;
}

.sidebar-header h3 {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
}

.sidebar-header p {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.sidebar-empty {
    color: var(--text-light);
    font-size: 0.9rem;
}

#map-sidebar-chart {
    width: 100%;
    background-color: #fafafa;
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    position: relative;
}

#map-sidebar-chart svg {
    overflow: visible;
}

#map {
    width: 100%;
    height: 100%;
    background-color: #e8e8e8;
}

footer {
    background-color: var(--primary-color);
    color: white;
    padding: 2rem 0;
    text-align: center;
    margin-top: 2rem;
}

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

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

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .intro {
        padding: 2rem 0;
    }

    .intro-text {
        font-size: 1rem;
    }
    
    .chart-section {
        padding: 2rem 0;
    }

    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .map-section {
        min-height: 400px;
        flex-direction: column;
        display: flex;
    }

    #map-sidebar {
        width: 100%;
        max-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        padding: 1rem;
        display: flex;
    }

    /* Hide year control and metric selector on mobile */
    .year-control {
        display: none !important;
    }

    .metric-selector {
        display: none !important;
    }
}

/* Leaflet Popup Customization */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 13px 19px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.town-popup h3 {
    color: var(--primary-color);
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
}

.town-popup p {
    margin: 0.25rem 0;
    color: var(--text-light);
}

.polling-popup h3 {
    color: #227253;
    margin: 0 0 0.75rem 0;
    font-size: 1.1rem;
    border-bottom: 2px solid #227253;
    padding-bottom: 0.25rem;
}

.polling-popup p {
    margin: 0.4rem 0;
    color: var(--text-dark);
    font-size: 0.9rem;
}

.polling-popup strong {
    color: var(--primary-color);
    font-weight: 600;
}

/* Year control slider */
.year-control {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.year-control span {
    color: var(--text-dark);
    font-size: 14px;
}

/* Metric selector */
.metric-selector {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.metric-selector label {
    color: var(--text-dark);
}

.metric-selector select:hover {
    border-color: var(--primary-color);
}

.metric-selector select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(26, 95, 63, 0.2);
}

.year-slider {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(to right, #ddd 0%, var(--primary-color) 100%);
    border-radius: 3px;
    outline: none;
}

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.year-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.year-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.year-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Layer control */
.layer-control {
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.layer-control label {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}

.layer-control label:hover {
    background-color: #f8f8f8;
    border-radius: 3px;
    padding: 2px;
    margin: -2px;
}

.layer-control input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-color);
}

.layer-control input[type="checkbox"]:hover {
    cursor: pointer;
}
