* {
    box-sizing: border-box;
}

:root {
    --blue: #2476d9;
    --blue-dark: #155fc0;
    --blue-light: #eef5ff;
    --text: #172033;
    --muted: #697386;
    --border: #e1e6ee;
    --background: #f5f7fa;
    --white: #ffffff;
    --green: #31ad6b;
    --purple: #8a5bd6;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--background);
    line-height: 1.4;
}

/* ============================================================
   ELEMENTS GÉNÉRAUX
============================================================ */

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid #7daef0;
    outline-offset: 1px;
}

/* ============================================================
   TOPBAR
============================================================ */

.topbar {
    height: 74px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.brand h1 {
    margin: 0;
    font-size: 19px;
    line-height: 1.2;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.btn-primary {
    border: 0;
    background: var(--blue);
    color: white;
    border-radius: 7px;
    padding: 11px 18px;
    font-weight: 600;
    transition:
        background 0.15s ease,
        transform 0.1s ease;
}

.btn-primary:hover {
    background: var(--blue-dark);
}

.btn-primary:active {
    transform: translateY(1px);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.top-actions button {
    border: 0;
    background: transparent;
    color: var(--text);
}

/* ============================================================
   LAYOUT
============================================================ */

.app-layout {
    display: grid;
    grid-template-columns: 228px minmax(0, 1fr);
    min-height: calc(100vh - 74px);
}

.main-content {
    padding: 22px;
    min-width: 0;
}

.app-page {
    width: 100%;
}

.page-title {
    margin: 0 0 18px;
}

.page-title h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
}

.page-title p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

/* ============================================================
   SIDEBAR
============================================================ */

.sidebar {
    background: white;
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 13px 14px;
    border-radius: 8px;
    color: #5c6677;
    display: flex;
    align-items: center;
    gap: 14px;
    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.nav-item.active {
    background: var(--blue-light);
    color: var(--blue);
    font-weight: 600;
}

.nav-item:hover {
    background: var(--blue-light);
}

.quick-summary {
    margin-top: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.quick-summary h3 {
    margin: 0 0 18px;
    font-size: 14px;
}

.summary-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin: 15px 0;
    font-size: 11px;
    color: var(--muted);
}

.summary-line strong {
    color: var(--text);
    white-space: nowrap;
}

.version {
    text-align: center;
    color: #9aa3b2;
    font-size: 10px;
    margin-top: 14px;
}

/* ============================================================
   CARTES
============================================================ */

.card,
.map-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.card h3 {
    margin: 0 0 16px;
    font-size: 14px;
}

.card p {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.main-grid {
    display: grid;
    grid-template-columns: 320px minmax(400px, 1fr) 460px;
    gap: 12px;
    align-items: stretch;
}

.left-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================================
   FORMULAIRES
============================================================ */

label {
    display: block;
    font-size: 12px;
    margin-bottom: 14px;
}

label:last-child {
    margin-bottom: 0;
}

label > span {
    color: var(--muted);
}

input,
select {
    width: 100%;
    border: 1px solid #d8dee8;
    border-radius: 7px;
    background: white;
    padding: 9px 10px;
    margin-top: 6px;
    color: var(--text);
    min-height: 38px;
}

input::placeholder {
    color: #9aa3b2;
}

input:focus,
select:focus {
    border-color: #8ab5ed;
    outline: none;
}

.inline-fields {
    display: grid;
    grid-template-columns: 1fr 88px;
    gap: 8px;
}

.inline-fields select,
.inline-fields input {
    margin-top: 6px;
}

/* ============================================================
   SITES
============================================================ */

#rechercheSite {
    margin-bottom: 8px;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

#listeSites {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #ffffff;
    padding: 5px;
}

.site-row {
    display: grid;
    grid-template-columns: 18px 1fr auto;
    align-items: start;
    gap: 8px;
    padding: 9px 3px;
    border-bottom: 1px solid #edf0f4;
    margin: 0;
}

.site-flacons-tournee {
    grid-column: 2 / -1;
    margin-top: 2px;
}

.site-flacons-tournee label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 9px;
    color: var(--muted);
}

.site-flacons-tournee input.input-flacons-tournee {
    width: 45px;
    padding: 3px 5px;
    margin: 0;
    font-size: 10px;
    text-align: center;
}


.site-row:last-child {
    border-bottom: 0;
}

.site-row input {
    width: auto;
    min-height: 0;
    margin: 0;
}

.site-row strong {
    display: block;
    font-size: 11px;
    line-height: 1.3;
}

.site-row small {
    display: block;
    color: var(--muted);
    font-size: 9px;
    margin-top: 4px;
    line-height: 1.3;
}

.tag {
    font-size: 9px;
    padding: 3px 7px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.tag-purple {
    color: var(--purple);
    border: 1px solid #cdb9ed;
    background: #f7f2ff;
}

.tag-green {
    color: var(--green);
    border: 1px solid #a9dfc3;
    background: #effbf5;
}

.selection-footer {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    font-size: 10px;
    color: var(--muted);
}

.selection-footer > span {
    margin-left: auto;
    white-space: nowrap;
}

.selection-footer .btn-primary,
.selection-footer .btn-secondary {
    padding: 9px 12px;
    font-size: 11px;
}

/* ============================================================
   BOUTONS SECONDAIRES
============================================================ */

.btn-secondary {
    border: 1px solid #d8dee8;
    background: white;
    color: var(--blue);
    border-radius: 7px;
    padding: 9px 12px;
    font-size: 11px;
    font-weight: 600;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--blue-light);
    border-color: #b9d3f4;
}

.btn-secondary:disabled {
    opacity: 0.45;
}

/* ============================================================
   CARTE
============================================================ */

.map-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#map {
    height: 300px;
    min-height: 300px;
    flex: none;
    position: relative;
    background:
        linear-gradient(
            135deg,
            #e9efe4,
            #dce8d7 45%,
            #eef0e7
        );
    border-radius: 12px 12px 0 0;
}

.map-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #7a8477;
    gap: 8px;
}

.map-placeholder strong {
    font-size: 24px;
}

.map-placeholder span {
    font-size: 12px;
}

.btn-optimize {
    width: calc(100% - 32px);
    margin: 10px 16px 16px;
    padding: 12px;
    border: 0;
    border-radius: 7px;
    background: var(--blue);
    color: white;
    font-weight: 600;
    transition:
        background 0.15s ease,
        transform 0.1s ease;
}

.btn-optimize:hover {
    background: var(--blue-dark);
}

.btn-optimize:active {
    transform: translateY(1px);
}

/* ============================================================
   MARQUEURS LEAFLET
============================================================ */

.hydro-marker {
    background: transparent;
    border: none;
}

.hydro-marker div {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #2476d9;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* ============================================================
   FLACONS
============================================================ */

.flacons-control {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    font-size: 9px;
    color: var(--muted);
}

.flacons-input {
    width: 45px;
    min-height: 0;
    padding: 2px 4px;
    border: 1px solid #dfe4f4;
    border-radius: 5px;
    font-size: 10px;
    text-align: center;
    background: white;
}

.flacons-input:focus {
    outline: none;
    border-color: #5b8def;
}

/* ============================================================
   RESULTATS
============================================================ */

.result-card {
    min-width: 0;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: #f8faff;
    border-radius: 8px;
    padding: 13px 8px;
    gap: 8px;
}

.result-stats div {
    text-align: center;
    min-width: 0;
}

.result-stats span {
    display: block;
    color: var(--muted);
    font-size: 9px;
    margin-bottom: 6px;
    line-height: 1.3;
}

.result-stats strong {
    color: var(--blue);
    font-size: 14px;
    white-space: nowrap;
}

.timeline {
    margin-top: 14px;
}

.timeline-item {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    min-height: 65px;
    border-bottom: 1px solid #edf0f4;
    padding: 10px 0;
}

.timeline-item:last-child {
    border-bottom: 0;
}

.timeline-item > b {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--blue);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 11px;
    flex-shrink: 0;
}

.timeline-item div {
    position: relative;
    padding-right: 10px;
    min-width: 0;
}

.timeline-item strong {
    display: block;
    font-size: 11px;
    margin-bottom: 6px;
    line-height: 1.3;
}

.timeline-item small {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.4;
}

.timeline-item span {
    position: absolute;
    right: 0;
    top: 0;
    color: var(--muted);
    font-size: 9px;
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 14px;
}

.result-actions button,
.statistics-card button {
    width: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 10px;
    font-size: 10px;
    color: var(--text);
}

.result-actions button:hover,
.statistics-card button:hover {
    background: #f8faff;
}

/* ============================================================
   BAS / HISTORIQUE
============================================================ */

.bottom-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.history-card {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9px;
}

th,
td {
    padding: 10px 7px;
    text-align: left;
    border-bottom: 1px solid #edf0f4;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-weight: 500;
}

.history-empty {
    text-align: center;
    color: var(--muted);
    padding: 28px !important;
}

.history-action {
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    padding: 5px 7px;
    cursor: pointer;
}

.history-action:hover {
    background: #fff4f4;
}

/* ============================================================
   STATISTIQUES
============================================================ */

.fake-chart {
    height: 120px;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    padding: 10px 35px;
    border-bottom: 1px solid var(--border);
}

.bar {
    width: 25px;
    border-radius: 4px 4px 0 0;
}

.bar-blue {
    height: 75px;
    background: #357fdb;
}

.bar-green {
    height: 95px;
    background: #42b879;
}

.bar-purple {
    height: 60px;
    background: #8a5bd6;
}

.statistics-list {
    font-size: 10px;
    margin: 12px 0;
}

.statistics-list p {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin: 9px 0;
}

.statistics-list strong {
    white-space: nowrap;
}

.statistics-card > button {
    width: 100%;
}

/* ============================================================
   DASHBOARD
============================================================ */

.dashboard-summary-card {
    margin-top: 10px;
}

.dashboard-statistics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.dashboard-stat {
    background: #f8faff;
    border: 1px solid #edf1f7;
    border-radius: 9px;
    padding: 14px;
}

.dashboard-stat span {
    display: block;
    color: var(--muted);
    font-size: 10px;
    margin-bottom: 7px;
}

.dashboard-stat strong {
    color: var(--blue);
    font-size: 18px;
}

/* ============================================================
   GESTION DES SITES
============================================================ */

.sites-management {
    width: 100%;
    overflow-x: auto;
}

.sites-management-head,
.sites-management-row {
    display: grid;
    grid-template-columns: 1.7fr 1.2fr 1fr 90px 90px;
    gap: 10px;
    align-items: center;
    min-width: 760px;
}

.sites-management-head {
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
}

.sites-management-row {
    padding: 9px 10px;
    border-bottom: 1px solid #edf0f4;
}

.sites-management-row:last-child {
    border-bottom: 0;
}

.sites-management-row > div:first-child strong {
    display: block;
    font-size: 11px;
}

.sites-management-row > div:first-child small {
    display: block;
    margin-top: 3px;
    color: #9aa3b2;
    font-size: 9px;
}

.gestion-site-input {
    margin: 0;
    min-height: 34px;
    padding: 7px 8px;
    font-size: 10px;
}

.gestion-flacons {
    text-align: center;
}

.empty-state {
    padding: 22px;
    text-align: center;
    color: var(--muted);
    font-size: 11px;
}

/* ============================================================
   RESPONSIVE
============================================================ */

@media (max-width: 1250px) {
    .main-grid {
        grid-template-columns: 300px minmax(0, 1fr);
    }

    .result-card {
        grid-column: 1 / -1;
    }
}

@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .main-grid {
        grid-template-columns: 1fr;
    }

    .result-card {
        grid-column: auto;
    }

    .bottom-grid {
        grid-template-columns: 1fr;
    }

    .top-actions {
        display: none;
    }

    .dashboard-statistics {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .topbar {
        height: 64px;
        padding: 0 12px;
    }

    .brand {
        gap: 10px;
    }

    .brand-logo {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .brand h1 {
        font-size: 15px;
    }

    .brand p {
        display: none;
    }

    .app-layout {
        min-height: calc(100vh - 64px);
    }

    .main-content {
        padding: 12px;
    }

    .page-title {
        margin-bottom: 14px;
    }

    .page-title h2 {
        font-size: 21px;
    }

    .page-title p {
        font-size: 12px;
    }

    .card,
    .map-card {
        border-radius: 10px;
        padding: 14px;
    }

    .map-card {
        padding: 0;
    }

    #map {
        height: 280px;
        min-height: 280px;
    }

    .btn-primary {
        padding: 9px 11px;
        font-size: 11px;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .selection-footer {
        align-items: stretch;
    }

    .selection-footer .btn-primary,
    .selection-footer .btn-secondary {
        flex: 1 1 auto;
    }

    .selection-footer > span {
        width: 100%;
        margin-left: 0;
        text-align: right;
    }

    .result-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px 8px;
    }

    .result-actions {
        grid-template-columns: 1fr;
    }

    .dashboard-statistics {
        grid-template-columns: 1fr 1fr;
    }

    .timeline-item {
        grid-template-columns: 34px minmax(0, 1fr);
        gap: 8px;
    }

    .timeline-item > b {
        width: 28px;
        height: 28px;
    }
}

/* ============================================================
   HISTORIQUE — LISTE DÉROULANTE
   ============================================================ */

#pageHistorique table tbody {
    display: block;
    max-height: 500px;
    overflow-y: auto;
}

#pageHistorique table thead,
#pageHistorique table tbody tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

/* ============================================================
   SITES SÉLECTIONNÉS — AFFICHAGE
   ============================================================ */

.sites-selectionnes {
    margin-top: 18px;
    padding: 18px;
    background: #ffffff;
    border: 1px solid #dfe5ec;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.sites-selectionnes h4 {
    margin: 0 0 14px 0;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
}

.sites-selectionnes-liste {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.selection-vide {
    text-align: center;
    padding: 12px;
    color: #7a8490;
    font-size: 14px;
}

.site-selectionne {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: #f7f9fc;
    border: 1px solid #e3e8ee;
    border-radius: 10px;
    box-sizing: border-box;
}

.site-selectionne-info {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.site-selectionne-info strong {
    display: block;
    font-size: 14px;
    line-height: 1.3;
}

.site-selectionne-info small {
    display: block;
    margin-top: 3px;
    color: #7a8490;
    font-size: 12px;
}

.site-selectionne-flacons {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    color: #3d4a57;
    white-space: nowrap;
}

.site-selectionne-supprimer {
    order: 3;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #d7dde4;
    border-radius: 7px;
    background: #ffffff;
    color: #68737e;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.site-selectionne-supprimer:hover {
    background: #f1f4f7;
    color: #c0392b;
}
