/* ============================================================
   Suivi-Ops — Styles
   Palette : bleu profond (#1e3a5f) + vert (#22c55e) + orange (#f97316) + rouge (#dc2626)
   ============================================================ */

:root {
    --blue: #1e3a5f;
    --blue-light: #2a5082;
    --blue-dark: #142940;
    --green: #22c55e;
    --green-dark: #16a34a;
    --orange: #f97316;
    --orange-dark: #ea580c;
    --red: #dc2626;
    --red-dark: #b91c1c;
    --yellow: #eab308;

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: #334155;
    --border-light: #475569;

    --sidebar-width: 300px;
    --header-height: 56px;

    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ========== HEADER ========== */
#header {
    height: var(--header-height);
    background: var(--blue-dark);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--green);
}

.logo-separator {
    color: var(--text-muted);
}

.logo-app {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    max-width: 400px;
    margin: 0 auto;
}

.select-mission {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
}

.header-right {
    display: flex;
    gap: 8px;
}

.btn-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-header:hover {
    background: var(--bg-tertiary);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
}

.btn-icon:hover {
    color: var(--green);
}

/* ========== MAIN LAYOUT ========== */
#main-content {
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transition: margin-left 0.3s ease;
    z-index: 500;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.filter-group {
    margin-bottom: 12px;
}

.filter-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.filter-select,
.filter-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-small {
    width: 70px;
    padding: 6px 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.btn-primary {
    width: 100%;
    padding: 8px 16px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 6px;
}

.btn-primary:hover {
    background: var(--green-dark);
}

.btn-secondary {
    width: 100%;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: var(--border-light);
}

.basemap-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

/* Stats sidebar */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.stat-row .label {
    color: var(--text-secondary);
}

.stat-row .value {
    font-weight: 600;
}

.stat-bar {
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    margin: 4px 0 8px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* ========== MAP ========== */
#map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.map-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    z-index: 400;
    min-width: 160px;
    box-shadow: var(--shadow);
}

.map-legend h4 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.map-counter {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    z-index: 400;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow);
}

/* ========== POPUP MODAL ========== */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-overlay.hidden {
    display: none;
}

.popup-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.popup-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.popup-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.popup-header-actions .btn-secondary {
    width: auto;
    padding: 6px 14px;
}

.popup-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--green);
    border-bottom-color: var(--green);
}

.popup-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========== SYNTHESE TAB ========== */
.synthese-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.synthese-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.synthese-card h4 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.score-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
}

.score-badge.critique { background: rgba(220, 38, 38, 0.2); color: var(--red); }
.score-badge.eleve { background: rgba(249, 115, 22, 0.2); color: var(--orange); }
.score-badge.modere { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.score-badge.faible { background: rgba(34, 197, 94, 0.2); color: var(--green); }

.statut-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.statut-badge.repéré { background: rgba(148, 163, 184, 0.2); color: var(--text-secondary); }
.statut-badge.diagnostiqué { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.statut-badge.en_traitement { background: rgba(249, 115, 22, 0.2); color: var(--orange); }
.statut-badge.arrêté_pris { background: rgba(220, 38, 38, 0.2); color: var(--red); }
.statut-badge.travaux_en_cours { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.statut-badge.travaux_terminés { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.statut-badge.soldé { background: rgba(34, 197, 94, 0.3); color: var(--green); }

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--text-muted); }
.info-row .value { color: var(--text-primary); font-weight: 500; }

.streetview-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    margin-top: 8px;
}

/* ========== TIMELINE TAB ========== */
.timeline-container {
    position: relative;
    padding-left: 24px;
}

.timeline-container::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 20px;
    padding-left: 20px;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--green);
    border: 2px solid var(--bg-secondary);
}

.timeline-dot.visite { background: #3b82f6; }
.timeline-dot.arrêté { background: var(--red); }
.timeline-dot.courrier { background: var(--orange); }
.timeline-dot.réunion { background: #8b5cf6; }
.timeline-dot.travaux { background: var(--yellow); }
.timeline-dot.diagnostic { background: #06b6d4; }

.timeline-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.timeline-type {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--green);
    font-weight: 600;
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.timeline-auteur {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.btn-add-event {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 16px;
}

.btn-add-event:hover { background: var(--green-dark); }

/* ========== DONNÉES TAB ========== */
.data-section {
    margin-bottom: 20px;
}

.data-section h4 {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}

/* ========== BILANS TAB (inline éditable) ========== */
.bilan-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.bilan-table th,
.bilan-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.bilan-table th {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    background: var(--bg-primary);
    position: sticky;
    top: 0;
}

.bilan-table td {
    color: var(--text-primary);
}

.bilan-input {
    width: 100%;
    padding: 4px 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid transparent;
    border-radius: 3px;
    font-size: 13px;
    text-align: right;
}

.bilan-input:focus {
    border-color: var(--green);
    outline: none;
}

.bilan-input.modified {
    border-color: var(--orange);
}

.bilan-total {
    font-weight: 700;
    color: var(--green);
}

.bilan-deficit {
    color: var(--red);
    font-weight: 700;
}

/* ========== DASHBOARD MODAL ========== */
.dashboard-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 1100px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.dashboard-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.dash-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.dash-card .number {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.dash-card .label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.chart-container h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.alertes-list {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.alertes-list h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.alerte-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.alerte-item:last-child { border-bottom: none; }

.alerte-warning {
    color: var(--orange);
    font-size: 12px;
}

/* ========== BILANS TABLE MODAL ========== */
.bilans-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 95%;
    max-width: 1400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.bilans-body {
    padding: 16px;
    overflow: auto;
    flex: 1;
}

.bilans-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.bilans-table th,
.bilans-table td {
    padding: 6px 8px;
    border: 1px solid var(--border);
    text-align: right;
}

.bilans-table th {
    background: var(--blue-dark);
    color: var(--text-primary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.bilans-table th:first-child,
.bilans-table td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg-secondary);
    z-index: 5;
    min-width: 200px;
}

.bilans-table th:first-child {
    z-index: 15;
    background: var(--blue-dark);
}

.bilans-table tr:hover td {
    background: var(--bg-tertiary);
}

.bilans-table tr:hover td:first-child {
    background: var(--bg-tertiary);
}

.bilans-table .row-total {
    font-weight: 700;
    background: var(--bg-primary);
}

.bilans-table .row-total td {
    border-top: 2px solid var(--green);
}

.bilans-table .editable-cell {
    cursor: pointer;
    position: relative;
}

.bilans-table .editable-cell:hover {
    background: rgba(34, 197, 94, 0.1);
}

.bilans-table .cell-input {
    width: 80px;
    padding: 2px 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--green);
    border-radius: 2px;
    font-size: 12px;
    text-align: right;
}

/* ========== EVENT MODAL ========== */
.event-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow);
}

.event-form {
    padding: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 8px;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
    width: auto;
    padding: 8px 20px;
}

/* ========== EXPORT ========== */
.export-options {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-export {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.btn-export:hover {
    border-color: var(--green);
}

/* ========== UTILITIES ========== */
.text-muted {
    color: var(--text-muted);
    font-size: 13px;
}

.hidden { display: none !important; }

.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue { color: #3b82f6; }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ========== CUSTOM LEAFLET MARKERS ========== */
.custom-marker {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s;
}

.custom-marker:hover {
    transform: scale(1.3);
    z-index: 10000 !important;
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
}

.leaflet-popup-content {
    margin: 12px !important;
    font-size: 13px !important;
}

.marker-cluster {
    background: rgba(30, 58, 95, 0.7) !important;
}

.marker-cluster div {
    background: var(--blue) !important;
    color: white !important;
    font-weight: 600;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 600;
        height: calc(100vh - var(--header-height));
    }

    .header-right span { display: none; }
    .header-center { max-width: 200px; }

    .popup-modal,
    .dashboard-modal,
    .bilans-modal {
        width: 98%;
        max-height: 92vh;
    }

    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-charts { grid-template-columns: 1fr; }
    .synthese-grid { grid-template-columns: 1fr; }
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ========== LOADING ========== */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
