/* ===================================================
   VARIABLES FLAT UI
   =================================================== */
:root {
    --color-primary: #2c81ba;
    --color-primary-dark: #22668f;
    --color-secondary: #27ae60;
    --color-danger: #e74c3c;
    --color-bg: #f4f6f7;
    --color-panel: #ffffff;
    --color-text: #2c3e50;
    --color-border: #dfe6e9;
    --radius: 6px;
    --transition: all 0.2s ease-in-out;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

/* ===================== HEADER ===================== */
.app-header {
    background: var(--color-primary);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-header h1 { font-size: 1.2rem; margin: 0; font-weight: 600; }

.header-buttons { display: flex; gap: 8px; }

.btn-mobile-only { display: none; }

/* ===================== LAYOUT GÉNÉRAL ===================== */
.app-container {
    display: flex;
    height: calc(100vh - 56px);
}

/* ===================== PANNEAU GAUCHE : FILTRES GÉO / DATE / ALTITUDE ===================== */
.filter-panel {
    width: 260px;
    flex-shrink: 0;
    background: var(--color-panel);
    border-right: 1px solid var(--color-border);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.filter-block h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-primary-dark);
    margin: 0 0 8px 0;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 6px;
}

.filter-block label {
    display: block;
    font-size: 0.8rem;
    margin: 8px 0 4px;
    color: #636e72;
}

.filter-checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #636e72;
    margin-top: 10px !important;
    cursor: pointer;
}
.filter-checkbox-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
}

.filter-block-grow {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.filter-hint {
    display: block;
    font-size: 0.7rem;
    color: #999;
    margin-top: 2px;
    margin-bottom: 6px;
}

.input-flat {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fff;
    font-size: 0.9rem;
    transition: var(--transition);
}
.input-flat:focus {
    outline: none;
    border-color: var(--color-primary);
}
.input-small { width: 45%; }

.range-row { display: flex; align-items: center; gap: 6px; }

select.input-flat[multiple] {
    height: auto;
    padding: 4px;
}
select.input-flat[multiple] option {
    padding: 5px 8px;
    border-radius: 3px;
}
select.input-flat[multiple] option:checked {
    background: var(--color-primary);
    color: #fff;
}

/* ===================== ZONE CENTRALE : CARTE + TABLEAU (redimensionnables) ===================== */
.map-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
    overflow-y: auto;
}

.status-bar {
    background: #fff;
    border-left: 4px solid var(--color-primary);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.status-bar.error { border-left-color: var(--color-danger); color: var(--color-danger); }

.resizable-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 500px;
    gap: 0;
}

.resize-handle {
    height: 12px;
    flex-shrink: 0;
    background: var(--color-border);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    margin: 4px 0;
    transition: var(--transition);
    user-select: none;
}
.resize-handle:hover,
.resize-handle.active {
    background: var(--color-primary);
}
.resize-handle-icon {
    font-size: 0.7rem;
    color: #fff;
    letter-spacing: 1px;
    transform: rotate(90deg);
    pointer-events: none;
}

.resizable-container .map-wrapper {
    min-height: 200px;
    flex-shrink: 0;
    flex-grow: 0;
}
.resizable-container .species-table-container {
    min-height: 120px;
    flex-shrink: 0;
    flex-grow: 0;
    overflow-y: auto;
}

.map-wrapper {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-border);
}
#map { width: 100%; height: 100%; min-height: 200px; }

.edition-stamp {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(255,255,255,0.85);
    padding: 4px 8px;
    font-size: 0.7rem;
    border-radius: 4px;
    color: #555;
    z-index: 1000;
    pointer-events: none;
}

/* ===================== ÉTIQUETTES (sans ligne de rattachement) ===================== */
.species-tooltip-leader {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}
.species-tooltip-leader::before {
    display: none !important; /* supprime la petite flèche par défaut de Leaflet */
}

.species-label {
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(0,0,0,0.15);
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    font-style: italic;
    font-weight: normal; /* jamais en gras */
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 3px;
    white-space: nowrap;
}
.species-label .genus-part {
    font-style: italic; /* toujours en italique, y compris le genre */
    font-weight: normal; /* jamais en gras */
}

/* ===================== CLUSTERS PAR ESPÈCE (avec nom de l'espèce) ===================== */
.species-cluster-wrapper {
    background: transparent;
    border: none;
}
.species-cluster-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 68px;
    height: 44px;
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
    opacity: 0.9;
    padding: 2px 4px;
    text-align: center;
}
.species-cluster-icon .cluster-count {
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1.1;
}
.species-cluster-icon .cluster-species-name {
    font-style: italic;
    font-weight: normal; /* jamais en gras, même sur les clusters */
    font-size: 0.62rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px;
}
.species-cluster-icon .cluster-species-name .genus-part {
    font-style: italic;
    font-weight: normal;
}

/* Popup styling */
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.popup-species {
    font-style: italic;
    font-weight: normal; /* jamais en gras, y compris dans le popup */
    font-size: 1rem;
}
.popup-species .genus-part { font-style: italic; font-weight: normal; }
.popup-table { width: 100%; margin-top: 6px; font-size: 0.85rem; }
.popup-table td { padding: 2px 4px; vertical-align: top; }
.popup-table td:first-child { font-weight: 600; color: #555; white-space: nowrap; }

/* Bouton de copie du contenu du popup */
.btn-copy-popup {
    width: 100%;
    margin-top: 10px;
    padding: 6px 10px;
    font-size: 0.75rem;
}
.btn-copy-popup:disabled {
    opacity: 0.75;
    cursor: default;
}

/* ===================== TOOLTIP AU SURVOL DES CLUSTERS ===================== */
.cluster-tooltip {
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    padding: 4px 8px;
}
.cluster-tooltip::before {
    border-top-color: rgba(255,255,255,0.95);
}
.cluster-tooltip-content {
    font-size: 0.8rem;
    white-space: nowrap;
}
.cluster-tooltip-content .genus-part {
    font-style: italic;
    font-weight: normal;
}
.cluster-tooltip-count {
    font-style: normal;
    font-weight: normal;
    color: #555;
    font-size: 0.75rem;
}
/* ===================== EXPORT TOOLBAR ===================== */
.export-toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===================== SPECIES TABLE (récapitulatif) ===================== */
.species-table-container {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: 12px;
    display: flex;
    flex-direction: column;
}
.species-table-container h2 { font-size: 1rem; margin-top: 0; flex-shrink: 0; }
.species-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.species-table th, .species-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
}
.species-table th { background: #f4f6f7; }
.species-table td:first-child { font-style: italic; font-weight: normal; }

/* ===================== PANNEAU DROIT : LISTE DES ESPÈCES ===================== */
.species-panel {
    width: 280px;
    flex-shrink: 0;
    background: var(--color-panel);
    border-left: 1px solid var(--color-border);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.checkbox-list {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 6px;
    margin-top: 8px;
    background: #fafbfc;
    min-height: 200px;
}
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 4px;
    transition: var(--transition);
}
.checkbox-item:hover { background: #eef4f8; }
.checkbox-item label {
    margin: 0;
    font-style: italic;
    font-weight: normal; /* jamais en gras */
    font-size: 0.85rem;
    cursor: pointer;
}
.checkbox-item .genus-part {
    text-transform: capitalize;
    font-style: italic; /* toujours en italique, y compris le genre */
    font-weight: normal; /* jamais en gras */
}

.loading-text { font-size: 0.85rem; color: #999; }

.species-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ===================== BUTTONS (Flat UI) ===================== */
.btn {
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}
.btn-flat {
    background: var(--color-primary);
    color: #fff;
}
.btn-flat:hover { background: var(--color-primary-dark); }

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: #fff; }

.btn-small { padding: 6px 10px; font-size: 0.75rem; flex: 1; }

.btn-reset {
    width: 100%;
    background: var(--color-danger);
}
.btn-reset:hover { background: #c0392b; }

/* ===================== SERVER ERROR BANNER ===================== */
.server-error-banner {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #fdecea;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    padding: 12px 20px;
    border-radius: var(--radius);
    z-index: 2000;
    max-width: 90%;
    text-align: center;
}

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 1100px) {
    .app-container { flex-direction: column; height: auto; }

    .btn-mobile-only {
        display: inline-block;
        background: transparent;
        border: 1px solid #fff;
        color: #fff;
        border-radius: var(--radius);
        padding: 6px 10px;
    }

    .filter-panel,
    .species-panel {
        width: 100%;
        border-right: none;
        border-left: none;
        border-bottom: 1px solid var(--color-border);
        max-height: 0;
        padding: 0 16px;
        overflow: hidden;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }
    .filter-panel.open,
    .species-panel.open {
        max-height: 2000px;
        padding: 16px;
    }

    .filter-panel { order: 1; }
    .map-area { order: 2; padding: 12px; }
    .species-panel { order: 3; }

    .resizable-container { min-height: auto; }
    .resize-handle { cursor: default; }

    #map, .map-wrapper { min-height: 320px; }
}

@media (max-width: 600px) {
    .app-header { flex-wrap: wrap; gap: 8px; }
    .app-header h1 { font-size: 1rem; }
    .export-toolbar { flex-direction: column; }
    .export-toolbar .btn { width: 100%; }
}

