/* Buttons and interactive elements */
.filter-button {
    padding: 6px 14px;
    font-size: 13px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-button:hover {
    background-color: #e9ecef;
}

.filter-button.active {
    background-color: #007bff;
    color: #fff;
    border-color: #007bff;
}

.tweaking-toggle {
    padding: 8px 14px;
    font-size: 13px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background-color: #007bff;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.tweaking-toggle:hover {
    background-color: #0056b3;
}

/* Version Dropdown */
.version-dropdown {
    position: relative;
}

.version-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    text-decoration: none !important;
}

.version-toggle:hover {
    color: #007bff !important;
}

.dropdown-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.version-menu.active .dropdown-arrow {
    transform: rotate(180deg);
}

.version-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1002;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.version-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.version-menu li {
    margin: 0;
}

.version-option {
    display: block;
    padding: 12px 16px;
    color: #333 !important;
    text-decoration: none !important;
    font-size: 14px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.version-option:last-child {
    border-bottom: none;
}

.version-option:hover {
    background-color: #f8f9fa;
    color: #007bff !important;
}

/* Filter buttons container */
#filterButtons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    text-align: left;
}

/* Results and data display */
#results {
    font-size: 16px;
}

#results .data-box {
    background-color: #fff;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
}

#results .score-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

#results .score-header {
    background-color: #e9ecef;
    border-bottom: 2px solid #dee2e6;
    font-weight: 700;
    font-size: 16px;
}

#results .score-header th {
    padding: 10px 12px;
}

#results .score-header th:nth-child(2) {
    text-align: left;
}

#results .row-title {
    text-align: left;
    font-weight: 600;
    color: #212529;
    width: 40%;
}

#results .row-title.sub-row {
    padding-left: 25px;
    font-weight: 400;
    font-style: italic;
}

#results .score-main {
    text-align: left;
    color: #212529;
    width: 30%;
}

#results .score-compare {
    text-align: right;
    color: #6c757d;
    width: 30%;
}

#results .score-row td {
    padding: 10px 12px;
    border-bottom: 1px solid #ececec;
}

#results .score-row td:nth-child(2) {
    text-align: left;
}

#results .score-row:nth-child(even) {
    background-color: #f8f9fa;
}

#results .score-row:last-child {
    border-bottom: none;
}

#results .score-row.sub-row-hidden {
    display: none;
}

#results .score-row:not(.sub-row) .row-title {
    cursor: pointer;
}

#results .score-row:not(.sub-row) .row-title:hover {
    background-color: #f0f0f0;
}

#results .score-table a {
    color: #007bff;
    text-decoration: none;
}

#results .score-table a:hover {
    color: #0056b3;
    text-decoration: underline;
}

#results .score-table th:nth-child(3),
#results .score-table td:nth-child(3),
#results .score-table th:nth-child(4),
#results .score-table td:nth-child(4) {
    text-align: right;
}

/* Executive details */
.executive-box {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    width: 100%;
    text-align: left;
    overflow-wrap: break-word;
}

.executive-box p {
    margin: 0;
    font-size: 14px;
    color: #343a40;
}

.executive-name {
    font-weight: 700;
}

.executive-famille {
    font-weight: 700;
}

/* Articles section */
#articles {
    text-align: left;
}

#articles h2 {
    font-size: 20px;
    margin-bottom: 16px;
    color: #343a40;
}

.article-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    background-color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.article-item {
    margin-bottom: 12px;
}

.article-item p {
    margin: 0;
    font-size: 14px;
    color: #343a40;
}

.article-item a {
    color: #007bff;
    text-decoration: none;
}

.article-item a:hover {
    text-decoration: underline;
}

/* Charts */
#namesChart {
    height: 500px !important;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 20px 0;
}

@media (max-width: 768px) {
    .chart-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

.chart-container {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#namesChartContainer {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 20px;
    min-height: 400px;
}

#namesChartContainer:empty {
    min-height: auto;
    padding: 15px;
}

#namesChartContainer:has(p:only-child) {
    min-height: auto;
    padding: 15px;
}

.chart-container canvas {
    height: 300px !important;
    width: 100% !important;
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin: 15px 0;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.qpv-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.qpv-table th,
.qpv-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #ececec;
    white-space: normal;
}

.qpv-table th {
    background-color: #e9ecef;
    font-weight: 700;
    font-size: 13px;
    position: sticky;
    top: 0;
    z-index: 2;
}

.qpv-table th:first-child,
.qpv-table td:first-child {
    position: sticky;
    left: 0;
    background-color: #fff;
    z-index: 3;
    width: 30%;
}

.qpv-table th:first-child {
    background-color: #e9ecef;
    z-index: 4;
}

.qpv-table tr:nth-child(even) {
    background-color: #f8f9fa;
}

.qpv-table tr:last-child td {
    border-bottom: none;
}

.qpv-table a {
    color: #007bff;
    text-decoration: none;
}

.qpv-table a:hover {
    text-decoration: underline;
}

/* Map components */
#map {
    height: 500px;
    width: 100%;
    margin: 0;
}

/* Leaflet back button styling */
.leaflet-control-back {
    background-color: #fff;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    margin-bottom: 5px;
}

.leaflet-control-back:hover {
    background-color: #f8f9fa;
    border-color: rgba(0,0,0,0.3);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.leaflet-control-back:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

#mapContainer {
    margin: 0;
    text-align: left;
    width: 100%;
}

.loading-container {
    position: relative;
    /* Ensure consistent flex properties */
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Ensure loading containers maintain their original display properties */
.loading-container.grid {
    display: grid;
}

.loading-container.inline-flex {
    display: inline-flex;
}

.loading-container.inline-block {
    display: inline-block;
}

/* Spinner Styles */
.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    min-height: 120px;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-message {
    font-size: 14px;
    color: #6c757d;
    text-align: center;
    font-weight: 500;
}

/* Small spinner variant for inline use */
.spinner-small {
    width: 20px;
    height: 20px;
    border-width: 2px;
    margin-bottom: 8px;
}

.spinner-container.small {
    padding: 20px;
    min-height: 80px;
}

.spinner-container.small .spinner-message {
    font-size: 13px;
}

/* Map legend styles */
.info.legend {
    line-height: 18px;
    color: #555;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 8px;
    border-radius: 4px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.info.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 8px;
    opacity: 0.7;
}

.custom-popup {
    opacity: 0.85;
    pointer-events: none;
}

.custom-popup .leaflet-popup-content {
    padding: 0px 0px;
}

/* Tweaking box */
#tweakingBox {
    margin: 0;
    position: relative;
}

.tweaking-box {
    background-color: #fff;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    width: 400px;
    text-align: left;
    box-sizing: border-box;
    position: absolute;
    z-index: 100;
    top: 30px;
    right: 0;
    display: none;
}

.tweaking-box.active {
    display: block;
}

.tweaking-box h3 {
    font-size: 16px;
    margin-bottom: 8px;
    color: #343a40;
}

.tweaking-box .population-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.tweaking-box .population-controls div {
    flex: 1;
}

.tweaking-box label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
}

.tweaking-box select,
.tweaking-box input[type="number"] {
    width: 100%;
    padding: 6px;
    font-size: 13px;
    border-radius: 6px;
    border: 1px solid #ccc;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.tweaking-box input[type="number"] {
    width: 80px;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.button-container {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

.tweaking-box button {
    padding: 6px 12px;
    font-size: 13px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background-color: #007bff;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.tweaking-box button:hover {
    background-color: #0056b3;
}

/* Mobile responsive adjustments */
@media (max-width: 1024px) {
    .grid.lg\:grid-cols-2 {
        grid-template-columns: 1fr;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Ensure all tiles in the grid respect mobile width */
    .grid.lg\:grid-cols-2 > div {
        max-width: 100vw;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    /* Constrain all white background tiles */
    .bg-white {
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
}

@media (max-width: 768px) {
    #tweakingBox {
        margin-top: 10px;
    }

    .tweaking-box {
        position: static;
        width: 100%;
    }

    #results .score-table {
        font-size: 12px;
        min-width: 0;
        width: 100%;
    }

    #results .score-header th,
    #results .score-row td {
        padding: 6px 8px;
        font-size: 12px;
        white-space: normal;
        word-wrap: break-word;
    }

    #results .row-title,
    #results .score-main,
    #results .score-compare {
        font-size: 12px;
        white-space: normal;
        word-wrap: break-word;
    }

    #results .row-title.sub-row {
        padding-left: 10px;
    }

    #namesChart {
        height: 400px !important;
        width: 100% !important;
    }

    .executive-box {
        padding: 0;
    }

    .executive-box p {
        font-size: 13px;
    }

    .qpv-table {
        font-size: 12px;
        min-width: 0;
    }

    .tweaking-box input[type="number"] {
        width: 40px;
    }

    .tweaking-box .population-controls {
        flex-direction: column;
        gap: 5px;
    }

    .chart-container {
        padding: 10px;
    }

    .chart-container canvas {
        height: 200px !important;
    }

    .grid.md\:grid-cols-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}

/* France Button Styles */
.france-button {
    padding: 6px; /* Matches #departementSelect padding */
    border: 1px solid #ccc; /* Matches #departementSelect border */
    border-radius: 6px; /* Matches #departementSelect border-radius */
    background-color: white;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-align: left;
    white-space: nowrap;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: 100%; /* Full width on small screens */
    margin: 8px 0; /* Matches #departementSelect margin */
}

.france-button:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.france-button:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Location Selector Styles */
.location-selector select,
#articles select {
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    padding: 0.5rem;
    background-color: white;
    transition: all 0.2s ease-in-out;
}

.location-selector select:focus,
#articles select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.location-selector select:disabled,
#articles select:disabled {
    background-color: #f9fafb;
    color: #6b7280;
    cursor: not-allowed;
}

#articles select:enabled {
    background-color: white;
}

/* Fix alignment issues with spinner containers */
.loading-container {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.loading-container select,
.loading-container input {
    width: 100%;
    flex: 1;
}

/* Ensure grid layout remains consistent */
.grid.md\\:grid-cols-2 > div {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Filter Button Styling for Inline Layout */
.filter-button {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background-color: white;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-size: 0.875rem;
    white-space: nowrap;
}

.filter-button:hover {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

.filter-button.active {
    background-color: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* Ensure lieu selector matches filter button height */
#articleFilters {
    margin-bottom: 1rem;
}

#articleFilters .flex {
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#lieuxSelect {
    min-width: 150px;
    max-width: 200px;
    font-size: 0.875rem;
    display: none; /* Hidden by default, shown when filter buttons are rendered */
}

/* Ensure consistent layout regardless of department or commune level */
#articleFilters > .flex {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* Header */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    overflow: visible;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.branding {
    display: flex;
    align-items: center;
    gap: 16px;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Navigation Menu */
.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 16px;
}

.nav-menu li {
    margin: 0;
}

.nav-menu .nav-link {
    font-size: 14px;
    color: #343a40;
    padding: 6px 12px;
```
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.nav-menu .nav-link:hover {
    background-color: #f8f9fa;
    color: #007bff;
}

.nav-menu .nav-link.active {
    font-weight: 600;
    color: #007bff;
    background-color: #e9ecef;
}

/* Menu Toggle Button */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.hamburger,
.hamburger::before,
.hamburger::after {
    width: 24px;
    height: 3px;
    background-color: #343a40;
    transition: all 0.3s ease;
}

.hamburger {
    position: relative;
    display: block;
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    left: 0;
}

.hamburger::before {
    top: -8px;
}

.hamburger::after {
    top: 8px;
}

.menu-toggle.active .hamburger {
    background-color: transparent;
}

.menu-toggle.active .hamburger::before {
    transform: rotate(45deg);
    top: 0;
}

.menu-toggle.active .hamburger::after {
    transform: rotate(-45deg);
    top: 0;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex !important;
    }

    .nav-menu {
        display: none !important;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background-color: #fff;
        flex-direction: column;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        padding: 15px 0;
        z-index: 1001;
    }

    .nav-menu.active {
        display: flex !important;
    }

    .nav-menu li {
        margin: 0;
        width: 100%;
    }

    .nav-menu .nav-link {
        display: block;
        padding: 12px 20px;
        text-align: center;
        border-bottom: 1px solid #f0f0f0;
        color: #333;
        text-decoration: none;
    }

    .nav-menu .nav-link:last-child {
        border-bottom: none;
    }

    .nav-menu .nav-link:hover,
    .nav-menu .nav-link.active {
        background-color: #f8f9fa;
        color: #007bff;
    }

    /* Mobile version dropdown */
    .version-dropdown .version-toggle {
        justify-content: center;
    }

    .version-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: #f8f9fa;
        margin-top: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .version-menu.active {
        max-height: 200px;
    }

    .version-option {
        padding: 8px 20px;
        font-size: 13px;
        border-bottom: 1px solid #eee;
        background: #f8f9fa;
    }

    /* Mobile title styling - responsive font size */
    .branding h1 {
        font-size: clamp(1.1rem, 4vw, 1.5rem) !important;
    }
    
    /* Additional mobile breakpoints for very small screens */
    @media (max-width: 480px) {
        .branding h1 {
            font-size: clamp(0.9rem, 3.5vw, 1.2rem) !important;
        }
    }
    
    @media (max-width: 360px) {
        .branding h1 {
            font-size: clamp(0.8rem, 3vw, 1rem) !important;
        }
    }
}