* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #008B8B;
    --primary-dark: #006666;
    --primary-light: #00a8a8;
    --secondary-color: #00aa66;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --light-bg: #f5f7fa;
    --dark-text: #212529;
    --border-color: #dee2e6;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--dark-text);
    background: var(--light-bg);
    overflow-x: hidden;
}

/* =====================
   HEADER
   ===================== */
header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 1.25rem 2rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content h1 {
    font-size: 1.75rem;
    margin-bottom: 0.2rem;
    font-weight: 600;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
    font-weight: 400;
}

.help-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.help-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

/* =====================
   PANNEAU D'AIDE
   ===================== */
.help-panel {
    position: fixed;
    top: 0;
    right: -520px;
    width: 500px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    transition: right 0.3s ease;
    overflow-y: auto;
}

.help-panel.active {
    right: 0;
}

.help-content {
    padding: 2rem;
}

.help-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: #999;
    transition: color 0.3s;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.help-close:hover {
    color: var(--dark-text);
    background: var(--light-bg);
}

.help-panel h2 {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    padding-right: 2.5rem;
}

.help-steps {
    margin-bottom: 2rem;
}

.help-step {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
    align-items: flex-start;
}

.help-step-number {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
}

.help-step-content {
    flex: 1;
    padding-top: 0.1rem;
}

.help-step-content h3 {
    color: var(--primary-color);
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    font-weight: 600;
}

.help-step-content p {
    font-size: 0.88rem;
    color: #666;
    margin: 0;
    line-height: 1.5;
}

.help-info {
    background: var(--light-bg);
    padding: 1.25rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.help-info h3 {
    color: var(--primary-color);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.help-info ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-info li {
    padding: 0.35rem 0;
    padding-left: 1rem;
    font-size: 0.88rem;
    color: #666;
    line-height: 1.5;
    position: relative;
}

.help-info li::before {
    content: "▸";
    position: absolute;
    left: 0;
    color: var(--primary-color);
}

/* =====================
   CONTAINER PRINCIPAL
   ===================== */
.container {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    max-width: 1600px;
    margin: 1.5rem auto;
    padding: 0 1.5rem 1.5rem 1.5rem;
    height: calc(100vh - 90px);
    min-height: 600px;
}

/* =====================
   PANNEAU DE CONTRÔLE
   ===================== */
.control-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.control-panel-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 0.5rem;
}

.control-panel-scroll::-webkit-scrollbar {
    width: 5px;
}

.control-panel-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.control-panel-scroll::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.control-panel-scroll::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* =====================
   BOUTON EXPORT STICKY
   ===================== */
.export-sticky {
    flex-shrink: 0;
    padding: 0.75rem 0.5rem 0 0;
    background: var(--light-bg);
    border-top: 2px solid var(--border-color);
}

.export-sticky .btn-secondary {
    margin: 0;
}

/* =====================
   CARDS
   ===================== */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    flex-shrink: 0;
}

.card-primary {
    border-top: 3px solid var(--primary-color);
}

.card-header {
    background: var(--light-bg);
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--dark-text);
    margin: 0;
}

.card-body {
    padding: 1.25rem;
}

.card-results .card-body {
    padding-bottom: 1rem;
}

/* =====================
   FORMULAIRES
   ===================== */
.form-group {
    margin-bottom: 1rem;
    position: relative;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--dark-text);
    font-size: 0.88rem;
}

.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.92rem;
    transition: all 0.3s;
    background: white;
    color: var(--dark-text);
}

.form-group input[type="text"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 139, 139, 0.1);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.92rem;
    margin-bottom: 0.4rem;
}

.checkbox-label input[type="checkbox"] {
    width: 17px;
    height: 17px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.help-text {
    display: block;
    color: #888;
    font-size: 0.82rem;
    font-weight: 400;
    margin-top: 0.2rem;
    line-height: 1.4;
}

/* =====================
   INFOS COMMUNE
   ===================== */
.commune-info {
    background: var(--light-bg);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-top: 0.75rem;
    font-size: 0.88rem;
    border-left: 3px solid var(--primary-color);
}

.commune-info small {
    color: #888;
    font-size: 0.85rem;
}

/* =====================
   SUGGESTIONS
   ===================== */
.suggestions {
    position: absolute;
    background: white;
    border: 2px solid var(--primary-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 220px;
    overflow-y: auto;
    width: 100%;
    z-index: 5000;
    display: none;
    box-shadow: var(--shadow-lg);
}

.suggestions.active {
    display: block;
}

.suggestion-item {
    padding: 0.7rem 0.9rem;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    line-height: 1.4;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: #e8f5f5;
}

.suggestion-item strong {
    color: var(--primary-color);
}

/* =====================
   BOUTONS
   ===================== */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 139, 139, 0.35);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #008855;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 170, 102, 0.35);
}

.btn-secondary:disabled {
    background: #b0b0b0;
    cursor: not-allowed;
    opacity: 0.65;
    transform: none;
    box-shadow: none;
}

.btn-icon {
    font-size: 1rem;
}

/* =====================
   STATUS
   ===================== */
.status {
    margin-top: 0.85rem;
    padding: 0.85rem 1rem;
    border-radius: 6px;
    display: none;
    font-size: 0.88rem;
    line-height: 1.4;
}

.status.active {
    display: block;
}

.status.loading {
    background: #e3f2fd;
    color: #1565c0;
    border-left: 4px solid #1976d2;
}

.status.success {
    background: #e8f5e9;
    color: #1b5e20;
    border-left: 4px solid #2e7d32;
}

.status.error {
    background: #ffebee;
    color: #b71c1c;
    border-left: 4px solid #c62828;
}

/* =====================
   RÉSULTATS
   ===================== */
.results-info {
    background: var(--light-bg);
    padding: 0.9rem 1rem;
    border-radius: 6px;
    font-size: 0.88rem;
    line-height: 1.6;
}

.results-info strong {
    color: var(--primary-color);
}

.results-info > div {
    margin-bottom: 0.35rem;
}

.results-info > div:last-child {
    margin-bottom: 0;
}

/* =====================
   SECTION CARTE
   ===================== */
.map-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.map-container {
    position: relative;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    flex: 1;
    min-height: 0;
}

#map {
    width: 100%;
    height: 100%;
}

.map-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 0.9rem 1rem;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    min-width: 140px;
}

.map-legend h4 {
    margin-bottom: 0.6rem;
    font-size: 0.85rem;
    color: var(--primary-color);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    color: var(--dark-text);
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
}

/* =====================
   FOOTER
   ===================== */
footer {
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
}

.footer-content {
    max-width: 1600px;
    margin: 0 auto;
    text-align: center;
}

.footer-content p {
    font-size: 0.85rem;
    color: #888;
    margin: 0;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* =====================
   RESPONSIVE
   ===================== */
@media (max-width: 1200px) {
    .container {
        grid-template-columns: 320px 1fr;
        height: calc(100vh - 90px);
    }
}

@media (max-width: 968px) {
    .container {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
        margin: 1rem auto;
        padding: 0 1rem 1rem 1rem;
    }

    .control-panel {
        height: auto;
        min-height: unset;
        overflow: visible;
    }

    .control-panel-scroll {
        overflow-y: visible;
        min-height: unset;
        height: auto;
    }

    .map-section {
        height: 500px;
        min-height: 400px;
    }

    .map-container {
        height: 100%;
    }

    .help-panel {
        width: 100%;
        right: -100%;
    }

    header {
        padding: 1rem 1.5rem;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .header-content h1 {
        font-size: 1.4rem;
    }

    .export-sticky {
        position: relative;
        padding: 1rem 0 0 0;
        border-top: none;
        background: transparent;
    }
}

@media (max-width: 576px) {
    header {
        padding: 1rem;
    }

    .header-content h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        font-size: 0.82rem;
    }

    .card-body {
        padding: 1rem;
    }

    .map-legend {
        bottom: 10px;
        right: 10px;
        padding: 0.6rem 0.75rem;
    }

    .help-content {
        padding: 1.25rem;
    }

    .help-panel {
        width: 100%;
    }
}
