/* ============================================
   AMAPs Gironde - Carte Interactive
   Theme naturel / Agriculture paysanne
   ============================================ */

/* CSS Variables - Palette naturelle */
:root {
    /* Fonds - tons chauds naturels */
    --bg-primary: #faf8f5;
    --bg-secondary: #f0ebe3;
    --bg-card: #ffffff;
    --bg-card-hover: #fdfcfa;
    
    /* Textes - bruns terreux */
    --text-primary: #3d3929;
    --text-secondary: #6b6352;
    --text-muted: #918a7a;
    --text-light: #b5ad9e;
    
    /* Accents végétaux */
    --accent-leaf: #5a8f3e;
    --accent-leaf-light: #7cb356;
    --accent-leaf-pale: #e8f0e3;
    
    /* Accents terre */
    --accent-earth: #e07b39;
    --accent-earth-light: #f0a06a;
    --accent-wheat: #c4a35a;
    --accent-wheat-light: #ddc88a;
    
    /* Couleurs produits */
    --color-legumes: #4caf50;
    --color-pain: #d4a373;
    --color-volaille: #ff9800;
    --color-oeuf: #ffeb3b;
    --color-viande: #c62828;
    --color-poisson: #03a9f4;
    --color-fromage: #ffc107;
    --color-miel: #ff8f00;
    --color-vin: #7b1fa2;
    --color-fruits: #e91e63;
    --color-champignon: #795548;
    --color-plantes: #8bc34a;
    --color-huile: #827717;
    --color-autre: #607d8b;
    
    /* Bordures et ombres */
    --border-color: #e0d9ce;
    --border-light: #ebe6dc;
    --shadow-soft: 0 2px 8px rgba(61, 57, 41, 0.08);
    --shadow-medium: 0 4px 16px rgba(61, 57, 41, 0.12);
    --shadow-large: 0 8px 32px rgba(61, 57, 41, 0.16);
    
    /* Espacement */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    
    /* Rayons */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Typographie */
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   Layout Principal
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-md) var(--space-xl);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.header-title {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo {
    height: 80px;
    width: auto;
    object-fit: contain;
}

.title-text h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.title-text p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.last-update {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: 0.5em;
}

/* Header Controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

/* Toggle AMAPs / Producteurs */
.view-toggle {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 3px;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.toggle-btn.active {
    background: var(--bg-card);
    color: var(--accent-leaf);
    box-shadow: var(--shadow-soft);
}

.toggle-icon {
    font-size: 1rem;
}

/* Search Box */
.search-box {
    position: relative;
}

.search-box input {
    width: 220px;
    padding: var(--space-sm) var(--space-md);
    padding-left: 2.5rem;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.search-box input:focus {
    outline: none;
    background: var(--bg-card);
    border-color: var(--accent-leaf);
}

.search-box input::placeholder {
    color: var(--text-light);
}

.search-icon {
    position: absolute;
    left: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-md) var(--space-xl);
    gap: var(--space-md);
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Carte */
.map-container {
    position: relative;
    min-height: 400px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-medium);
}

#map {
    height: 100%;
    min-height: 400px;
    background: var(--bg-secondary);
}

/* Légende carte */
.map-legend {
    position: absolute;
    bottom: var(--space-md);
    left: var(--space-md);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
    z-index: 1000;
    max-width: 200px;
    display: none;
}

.map-legend.visible {
    display: block;
}

.legend-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: var(--space-xs);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Customisation Leaflet */
.leaflet-container {
    font-family: var(--font-body);
    background: var(--bg-secondary) !important;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.leaflet-popup-content {
    margin: var(--space-sm) var(--space-md);
    font-size: 0.85rem;
}

.leaflet-popup-content h4 {
    font-family: var(--font-display);
    color: var(--accent-leaf);
    font-size: 1rem;
    margin-bottom: 4px;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* ============================================
   Slider Temporel Compact
   ============================================ */
.timeline-compact {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.timeline-year {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
}

.timeline-year-current {
    color: var(--accent-leaf);
    background: var(--accent-leaf-pale);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.timeline-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(
        to right,
        var(--accent-leaf) 0%,
        var(--accent-leaf) var(--progress, 100%),
        var(--border-color) var(--progress, 100%),
        var(--border-color) 100%
    );
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--bg-card);
    border: 2px solid var(--accent-leaf);
    border-radius: 50%;
    cursor: grab;
    box-shadow: var(--shadow-soft);
}

.timeline-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--bg-card);
    border: 2px solid var(--accent-leaf);
    border-radius: 50%;
    cursor: grab;
}

/* Filtre catégorie */
.category-filter {
    display: flex;
    gap: var(--space-sm);
}

.filter-select {
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-leaf);
}

/* ============================================
   Liste
   ============================================ */
.list-panel {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.list-header h2 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.result-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Table */
.table-container {
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    padding: var(--space-xs) var(--space-md);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
    color: var(--text-primary);
}

tbody tr {
    transition: background 0.15s ease;
}

tbody tr:hover {
    background: var(--bg-secondary);
}

.item-name {
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-jour {
    background: var(--accent-wheat-light);
    color: #6b5a2a;
}

.badge-count {
    background: var(--accent-leaf-pale);
    color: var(--accent-leaf);
}

.badge-product {
    padding: 2px 6px;
    font-size: 0.7rem;
}

.td-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    border-color: var(--accent-leaf);
    color: var(--accent-leaf);
    background: var(--accent-leaf-pale);
}

.btn-icon.btn-locate:hover {
    border-color: var(--accent-earth);
    color: var(--accent-earth);
    background: rgba(224, 123, 57, 0.1);
}

.btn-icon svg {
    flex-shrink: 0;
}

/* ============================================
   Modal Détail
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(61, 57, 41, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-large);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--accent-earth);
    border-color: var(--accent-earth);
    color: white;
}

#modalBody {
    padding: var(--space-xl);
}

/* Contenu modal */
.detail-header {
    margin-bottom: var(--space-md);
}

.detail-header h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.detail-header .subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Dual link buttons (Site vitrine + Gestion) */
.detail-links {
    display: flex;
    gap: var(--space-sm);
    margin: var(--space-md) 0;
}

.detail-link-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.detail-link-front {
    background: var(--accent-leaf);
    color: white;
}

.detail-link-front:hover {
    background: var(--accent-leaf-light);
    transform: translateY(-1px);
}

.detail-link-back {
    background: var(--accent-earth);
    color: white;
}

.detail-link-back:hover {
    background: var(--accent-earth-light);
    transform: translateY(-1px);
}

.detail-link-btn svg {
    flex-shrink: 0;
}

/* Producteurs liés */
.detail-producteurs {
    margin: var(--space-md) 0;
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.detail-producteurs h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: var(--space-sm);
}

.producteur-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.producteur-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.producteur-tag:hover {
    background: var(--accent-earth-light);
    color: var(--text-primary);
}

.producteur-icon {
    font-size: 0.9rem;
}

/* Infos compactes */
.detail-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-light);
}

.detail-info-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.detail-info-item.full-width {
    grid-column: 1 / -1;
}

.detail-info-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
}

.detail-info-content {
    flex: 1;
    min-width: 0;
}

.detail-info-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.detail-info-value {
    font-size: 0.85rem;
    color: var(--text-primary);
    word-break: break-word;
}

.detail-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
}

.detail-badge-jour {
    background: var(--accent-wheat-light);
    color: #6b5a2a;
}

.detail-badge-year {
    background: var(--accent-leaf-pale);
    color: var(--accent-leaf);
}

.detail-badge-plateforme {
    background: rgba(224, 123, 57, 0.15);
    color: var(--accent-earth);
}

/* ============================================
   Statut AMAP - Tableau
   ============================================ */
tr.amap-retour {
    background: var(--accent-leaf-pale);
}

tr.amap-retour:hover {
    background: #d5e8cd;
}

.status-dot {
    font-size: 0.65rem;
    margin-right: 4px;
    vertical-align: middle;
}

/* ============================================
   Statut AMAP - Fiche détail
   ============================================ */
.detail-tags {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
    flex-wrap: wrap;
}

.detail-badge-retour {
    background: var(--accent-leaf-pale);
    color: var(--accent-leaf);
    font-size: 0.8rem;
}

.detail-badge-recent {
    background: #e3f2fd;
    color: #1565c0;
    font-size: 0.8rem;
}

.detail-badge-inactive {
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.detail-badge-etat {
    font-size: 0.8rem;
}

.detail-badge-etat-actif {
    background: var(--accent-leaf-pale);
    color: var(--accent-leaf);
}

.detail-badge-etat-fermé {
    background: #fde8e8;
    color: #c62828;
}

.detail-badge-etat-désabonné {
    background: #fff3e0;
    color: #e65100;
}

.legend-dot {
    box-sizing: border-box;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: var(--space-sm) var(--space-xl);
    text-align: center;
}

.footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--accent-leaf);
    text-decoration: none;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .main-content {
        padding: var(--space-md);
    }
    
    .map-container {
        min-height: 300px;
    }
    
    #map {
        min-height: 300px;
    }
}

@media (max-width: 600px) {
    .header {
        padding: var(--space-sm) var(--space-md);
    }
    
    .title-text h1 {
        font-size: 1.2rem;
    }
    
    .view-toggle span:not(.toggle-icon) {
        display: none;
    }
    
    .search-box input {
        width: 150px;
    }
    
    .table-container {
        max-height: 250px;
    }
    
    th, td {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }
    
    .detail-info {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Utilities
   ============================================ */
.hidden {
    display: none !important;
}

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

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.map-container, .list-panel {
    animation: fadeIn 0.3s ease;
}

/* ================================
   Marqueurs Producteurs
   ================================ */
.producteur-marker {
    background: transparent !important;
    border: none !important;
}

.producteur-marker .marker-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: var(--primary);
    border: 3px solid;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.producteur-marker .marker-icon:hover {
    transform: scale(1.15);
}

.producteur-marker .marker-icon::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid;
    border-top-color: inherit;
}
