/* ====================================
   VARIABLES
   ==================================== */
:root {
    --blue: #003DA5;
    --blue-dark: #002B75;
    --blue-light: #0052CC;
    --blue-pale: #E8F0FE;
    --white: #FFFFFF;
    --success: #0D7A3E;
    --success-light: #E6F4EC;
    --error: #C41E3A;
    --error-light: #FCE8EC;
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1E293B;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans 3', -apple-system, sans-serif;
    --radius: 0.75rem;
    --shadow: 0 4px 12px rgba(0,61,165,0.08);
}

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

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, var(--blue-pale) 0%, var(--white) 100%);
    color: var(--gray-800);
    min-height: 100vh;
    line-height: 1.5;
}

.hidden { display: none !important; }

.fleur-de-lys-bg {
    position: fixed; inset: 0;
    pointer-events: none; z-index: 0; opacity: 0.015;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='%23003DA5'%3E%3Cpath d='M50 5c-3 8-8 15-8 25 0 8 4 12 8 15 4-3 8-7 8-15 0-10-5-17-8-25zm-30 35c8 3 15 8 25 8 8 0 12-4 15-8-3-4-7-8-15-8-10 0-17 5-25 8zm60 0c-8-3-15-8-25-8-8 0-12 4-15 8 3 4 7 8 15 8 10 0 17-5 25-8zM50 95c3-8 8-15 8-25 0-8-4-12-8-15-4 3-8 7-8 15 0 10 5 17 8 25z'/%3E%3Ccircle cx='50' cy='50' r='8'/%3E%3C/svg%3E");
    background-size: 120px;
}

.app-container {
    position: relative; z-index: 1;
    max-width: 1600px; margin: 0 auto; padding: 1rem 2rem;
    min-height: 100vh; display: flex; flex-direction: column;
}

/* ====================================
   HEADER
   ==================================== */
.header {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    position: relative;
}

.header::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--blue), var(--blue-light));
    border-radius: var(--radius) var(--radius) 0 0;
}

.header-content {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 2rem; flex-wrap: wrap; gap: 1rem;
}

.logo { display: flex; align-items: center; gap: 1rem; }

.fleur-icon { width: 48px; height: 48px; color: var(--blue); }

.logo-text h1 {
    font-family: var(--font-display); font-size: 1.6rem;
    font-weight: 700; color: var(--blue); line-height: 1.1;
}

.logo-text .subtitle { font-size: 0.85rem; color: var(--gray-500); }

.header-nav { display: flex; align-items: center; gap: 1rem; }

.help-link {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 1.25rem; background: var(--gray-100);
    color: var(--gray-600); text-decoration: none;
    font-size: 0.9rem; font-weight: 500; border-radius: 100px;
    transition: all 0.2s;
}
.help-link:hover { background: var(--blue-pale); color: var(--blue); }

.header-badge {
    background: var(--blue); color: white;
    padding: 0.3rem 0.8rem; border-radius: 100px;
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
}

/* ====================================
   SECTION IMPORT (visible au départ)
   ==================================== */
.section-import {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 3rem 2rem;
}

.import-box {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 3rem 4rem;
    max-width: 800px; width: 100%;
}

.file-input-hidden { display: none; }

.drop-zone {
    border: 2px dashed var(--gray-300); border-radius: var(--radius);
    padding: 5rem 3rem; text-align: center; cursor: pointer;
    transition: all 0.25s; background: var(--gray-50);
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--blue); background: var(--blue-pale);
}

.drop-zone i {
    font-size: 5rem; color: var(--gray-400); margin-bottom: 1.5rem;
    transition: color 0.25s;
}
.drop-zone:hover i { color: var(--blue); }

.drop-text-main { font-size: 1.5rem; font-weight: 600; color: var(--gray-700); margin-bottom: 0.5rem; }
.drop-text-sub { font-size: 1.1rem; color: var(--gray-500); margin-bottom: 1.5rem; }
.drop-text-hint { font-size: 0.95rem; color: var(--gray-400); }

/* ====================================
   SECTION APERÇU (après chargement)
   ==================================== */
.section-preview { animation: fadeIn 0.4s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.loaded-file-bar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--success-light); border: 1px solid var(--success);
    border-radius: var(--radius); padding: 0.75rem 1rem;
    margin-bottom: 1rem; flex-wrap: wrap; gap: 0.75rem;
}

.loaded-file-info { display: flex; align-items: center; gap: 0.75rem; }

.loaded-file-icon {
    background: var(--success); color: white;
    padding: 0.4rem 0.6rem; border-radius: 0.3rem;
    font-size: 0.65rem; font-weight: 700;
}

.loaded-file-name { font-weight: 600; color: var(--gray-800); display: block; }
.loaded-file-meta { font-size: 0.75rem; color: var(--gray-500); }

.btn-text {
    background: none; border: none; color: var(--gray-600);
    font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 0.3rem;
}
.btn-text:hover { color: var(--blue); }

/* Detection box */
.detection-box, .preview-box, .analyze-box, .progress-box {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem;
}

.detection-box h3, .preview-box h3 {
    font-size: 0.9rem; font-weight: 600; color: var(--gray-700);
    margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.4rem;
}
.detection-box h3 i, .preview-box h3 i { color: var(--blue); }

.detected-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.tag {
    padding: 0.3rem 0.7rem; border-radius: 0.3rem;
    font-size: 0.75rem; font-weight: 600;
}
.tag.ok { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.tag.ok::before { content: '✓ '; }
.tag.missing { background: var(--error-light); color: var(--error); border: 1px solid var(--error); }
.tag.missing::before { content: '✗ '; }
.tag.optional { background: var(--gray-100); color: var(--gray-500); }

.preview-count { font-weight: 400; color: var(--gray-400); font-size: 0.8rem; margin-left: 0.5rem; }

.preview-table-container {
    max-height: 280px; overflow: auto;
    border: 1px solid var(--gray-200); border-radius: 0.4rem;
}

.preview-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }

.preview-table th {
    background: var(--gray-100); padding: 0.5rem;
    text-align: left; font-weight: 600; color: var(--gray-700);
    border-bottom: 2px solid var(--gray-200);
    position: sticky; top: 0; white-space: nowrap;
}
.preview-table th.detected { background: var(--success-light); color: var(--success); }

.preview-table td {
    padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--gray-100);
    color: var(--gray-600); max-width: 140px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.preview-table tr:hover td { background: var(--gray-50); }

/* Analyze box */
.analyze-box { text-align: center; padding: 1.5rem; }

.analyze-message {
    margin-top: 0.75rem; font-size: 0.8rem;
}
.analyze-message.error { color: var(--error); }
.analyze-message.ok { color: var(--success); }

/* Progress */
.progress-box { padding: 1rem 1.25rem; }
.progress-info { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.4rem; }
#progressText { color: var(--gray-600); }
#progressPercent { font-weight: 600; color: var(--blue); }
.progress-bar { height: 8px; background: var(--gray-200); border-radius: 100px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--blue), var(--blue-light)); transition: width 0.3s; }

/* ====================================
   SECTION RÉSULTATS (après analyse)
   ==================================== */
.section-results { animation: fadeIn 0.5s ease; }

.stats-row {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem;
}
@media (max-width: 650px) { .stats-row { grid-template-columns: 1fr; } }

.stat-box {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1rem; display: flex;
    align-items: center; gap: 1rem; position: relative;
}

.stat-box i { font-size: 1.75rem; }
.stat-total i { color: var(--blue); }
.stat-valid i { color: var(--success); }
.stat-invalid i { color: var(--error); }

.stat-number {
    display: block; font-family: var(--font-display);
    font-size: 1.6rem; font-weight: 700; line-height: 1;
}
.stat-total .stat-number { color: var(--blue); }
.stat-valid .stat-number { color: var(--success); }
.stat-invalid .stat-number { color: var(--error); }

.stat-label { font-size: 0.8rem; color: var(--gray-500); }

.stat-badge {
    position: absolute; top: 0.5rem; right: 0.5rem;
    background: var(--success); color: white;
    padding: 2px 8px; border-radius: 100px;
    font-size: 0.65rem; font-weight: 700;
}
.stat-badge.invalid { background: var(--error); }

/* Results grid - Sidebar gauche, carte large à droite */
.results-grid {
    display: grid; grid-template-columns: 380px 1fr; gap: 1.5rem;
    align-items: stretch;
}
@media (max-width: 1100px) { .results-grid { grid-template-columns: 1fr; } }

/* Sidebar gauche */
.sidebar-results { 
    display: flex; flex-direction: column; gap: 1rem;
    order: 1;
    min-height: 600px;
}

/* Card stats prend l'espace restant */
.card-stats {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.card-stats .tab-content {
    flex: 1;
    overflow-y: auto;
}

/* Carte à droite */
.card-map { 
    display: flex; flex-direction: column;
    order: 2;
}

.map-container { flex: 1; min-height: 600px; }
#map { width: 100%; height: 100%; }

.card {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}

.card-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--gray-100);
    flex-wrap: wrap; gap: 0.5rem;
}

.card-head h3 {
    font-size: 0.9rem; font-weight: 600; color: var(--gray-800);
    display: flex; align-items: center; gap: 0.4rem;
}
.card-head h3 i { color: var(--blue); }

.map-toolbar { display: flex; align-items: center; gap: 0.5rem; }

.map-toolbar select {
    padding: 3px 6px; border: 1px solid var(--gray-200);
    border-radius: 0.3rem; font-size: 0.7rem;
}

.map-pts {
    background: var(--blue-pale); color: var(--blue);
    padding: 2px 8px; border-radius: 100px; font-size: 0.65rem; font-weight: 600;
}

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--gray-100); }

.tab {
    flex: 1; padding: 0.6rem; background: none; border: none;
    font-size: 0.75rem; font-weight: 500; color: var(--gray-500);
    cursor: pointer; position: relative;
}
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--blue); }
.tab.active::after {
    content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
    height: 2px; background: var(--blue);
}

.tab-content { padding: 0.75rem; flex: 1; overflow-y: auto; max-height: 300px; }

.stat-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.4rem 0.5rem; border-radius: 0.3rem; margin-bottom: 0.25rem;
    background: var(--gray-50);
}
.stat-item:hover { background: var(--blue-pale); }
.stat-item-label { font-size: 0.78rem; color: var(--gray-700); }
.stat-item-value {
    font-size: 0.7rem; font-weight: 600; color: var(--blue);
    background: white; padding: 2px 6px; border-radius: 100px;
}

/* Export */
.export-section { padding: 0.75rem 1rem; border-bottom: 1px solid var(--gray-100); }
.export-section:last-child { border-bottom: none; }

.export-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.export-icon {
    width: 32px;
    height: 32px;
    border-radius: 0.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.export-icon.valid { background: var(--success-light); color: var(--success); }
.export-icon.invalid { background: var(--error-light); color: var(--error); }
.export-icon.map { background: var(--blue-pale); color: var(--blue); }

.export-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin: 0;
}

.export-count {
    font-size: 0.7rem;
    color: var(--gray-500);
    margin: 0;
}

.export-buttons { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.btn-export {
    padding: 4px 10px; background: var(--gray-100);
    border: 1px solid var(--gray-200); border-radius: 0.3rem;
    font-size: 0.68rem; font-weight: 500; color: var(--gray-600);
    cursor: pointer; transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 0.25rem;
}
.btn-export:hover { background: var(--blue); border-color: var(--blue); color: white; }

/* New analysis */
.new-analysis-box { text-align: center; margin-top: 1.5rem; }

/* ====================================
   BUTTONS
   ==================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.75rem 1.5rem; border: none; border-radius: 0.5rem;
    font-family: var(--font-body); font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: all 0.25s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: white; box-shadow: 0 4px 12px rgba(0,61,165,0.25);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,61,165,0.35); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-large { padding: 1rem 2rem; font-size: 1rem; }

.btn-outline {
    background: white; color: var(--gray-600); border: 2px solid var(--gray-300);
}
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }

/* ====================================
   FOOTER
   ==================================== */
.footer {
    text-align: center; padding: 1.5rem 0; margin-top: auto;
    color: var(--gray-500); font-size: 0.8rem;
}
.footer strong { color: var(--blue); }
.footer .version {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* ====================================
   NOTIFICATIONS
   ==================================== */
.notification {
    position: fixed; bottom: 20px; right: 20px;
    padding: 0.9rem 1.25rem; border-radius: 0.5rem;
    display: flex; align-items: center; gap: 0.75rem;
    font-weight: 500; z-index: 9999; animation: slideIn 0.3s ease;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15); max-width: 360px;
}
.notification.success { background: var(--success); color: white; }
.notification.error { background: var(--error); color: white; }
.notification.info { background: var(--blue); color: white; }

.notification button {
    background: none; border: none; color: inherit;
    font-size: 1.1rem; cursor: pointer; opacity: 0.8;
}
.notification button:hover { opacity: 1; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ====================================
   LEAFLET
   ==================================== */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
    background-color: rgba(0,61,165,0.25);
}
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
    background-color: var(--blue); color: white; font-weight: 700;
}

/* ====================================
   RESPONSIVE
   ==================================== */

/* Tablette paysage et petits écrans desktop */
@media (max-width: 1200px) {
    .app-container {
        padding: 1rem;
    }
    
    .results-grid {
        grid-template-columns: 340px 1fr;
        gap: 1rem;
    }
    
    .sidebar-results {
        min-height: 500px;
    }
    
    .map-container {
        min-height: 500px;
    }
}

/* Tablette portrait */
@media (max-width: 1100px) {
    .results-grid {
        grid-template-columns: 1fr;
    }
    
    .sidebar-results {
        order: 2;
        min-height: auto;
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .sidebar-results .card-stats,
    .sidebar-results .card-export {
        flex: 1;
        min-width: 300px;
    }
    
    .card-stats {
        max-height: 400px;
    }
    
    .card-map {
        order: 1;
    }
    
    .map-container {
        min-height: 450px;
    }
}

/* Mobile paysage */
@media (max-width: 768px) {
    .app-container {
        padding: 0.75rem;
    }
    
    .header-content {
        padding: 0.6rem 1rem;
    }
    
    .logo {
        gap: 0.5rem;
    }
    
    .fleur-icon {
        width: 32px;
        height: 32px;
    }
    
    .logo-text h1 {
        font-size: 1.2rem;
    }
    
    .logo-text .subtitle {
        font-size: 0.65rem;
    }
    
    .help-link {
        padding: 0.35rem 0.7rem;
        font-size: 0.75rem;
    }
    
    .header-badge {
        padding: 0.2rem 0.5rem;
        font-size: 0.6rem;
    }
    
    .import-box {
        padding: 1.5rem;
    }
    
    .drop-zone {
        padding: 3rem 1.5rem;
    }
    
    .drop-zone i {
        font-size: 3.5rem;
    }
    
    .drop-text-main {
        font-size: 1.2rem;
    }
    
    .drop-text-sub {
        font-size: 1rem;
    }
    
    .stats-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .sidebar-results {
        flex-direction: column;
    }
    
    .sidebar-results .card-stats,
    .sidebar-results .card-export {
        min-width: 100%;
    }
    
    .card-stats {
        max-height: 350px;
    }
    
    .map-container {
        min-height: 350px;
    }
    
    .preview-table-container {
        max-height: 220px;
    }
    
    .btn-large {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .app-container {
        padding: 0.5rem;
    }
    
    .header-content {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    
    .fleur-icon {
        width: 28px;
        height: 28px;
    }
    
    .logo-text h1 {
        font-size: 1rem;
    }
    
    .logo-text .subtitle {
        font-size: 0.6rem;
    }
    
    .header-nav {
        gap: 0.5rem;
    }
    
    .help-link span {
        display: none;
    }
    
    .help-link {
        padding: 0.4rem;
        font-size: 0.8rem;
    }
    
    .header-badge {
        padding: 0.15rem 0.4rem;
        font-size: 0.55rem;
    }
    
    .import-box {
        padding: 1rem;
    }
    
    .drop-zone {
        padding: 2rem 1rem;
    }
    
    .drop-zone i {
        font-size: 2.5rem;
        margin-bottom: 1rem;
    }
    
    .drop-text-main {
        font-size: 1rem;
    }
    
    .drop-text-sub {
        font-size: 0.85rem;
    }
    
    .drop-text-hint {
        font-size: 0.75rem;
    }
    
    .loaded-file-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .detected-tags {
        gap: 0.35rem;
    }
    
    .tag {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }
    
    .preview-table {
        font-size: 0.7rem;
    }
    
    .preview-table th,
    .preview-table td {
        padding: 0.35rem 0.4rem;
    }
    
    .stat-box {
        padding: 0.75rem;
    }
    
    .stat-number {
        font-size: 1.3rem;
    }
    
    .stat-box i {
        font-size: 1.3rem;
    }
    
    .card-head {
        padding: 0.6rem 0.75rem;
    }
    
    .card-head h3 {
        font-size: 0.8rem;
    }
    
    .tabs {
        flex-wrap: wrap;
    }
    
    .tab {
        padding: 0.5rem;
        font-size: 0.7rem;
    }
    
    .export-buttons {
        gap: 0.25rem;
    }
    
    .btn-export {
        padding: 3px 8px;
        font-size: 0.65rem;
    }
    
    .map-container {
        min-height: 300px;
    }
    
    .map-toolbar select {
        font-size: 0.65rem;
    }
    
    .conversion-toggle {
        padding: 0.75rem;
    }
    
    .toggle-label {
        font-size: 0.8rem;
    }
    
    .btn-convert {
        padding: 0.6rem;
        font-size: 0.8rem;
    }
    
    .notification {
        left: 10px;
        right: 10px;
        max-width: none;
    }
    
    .footer {
        padding: 1rem 0;
        font-size: 0.7rem;
    }
}
