/* Boîte à outils — UI web moderne (FastAPI). Palette héritée de la marque. */
:root {
    --gold: #D4AF37;
    --gold-soft: rgba(212, 175, 55, 0.12);
    --navy: #0E1A2B;
    --navy-2: #1B2D4A;
    --muted: #5B6B85;
    --bg: #F4F6FA;
    --border: #E5E9F0;
    --success: #28A745;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(14, 26, 43, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--navy);
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(212, 175, 55, 0.08), transparent),
        var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Top bar --- */
.topbar {
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
    color: #F4F6FA;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #F4F6FA; text-decoration: none; }
.brand-mark { font-size: 1.5rem; }
.brand-name { font-size: 1.1rem; letter-spacing: -0.01em; }

/* --- Navbar --- */
.topnav { display: flex; align-items: center; gap: 4px; flex: 1; justify-content: center; }
.nav-link, .nav-group-btn {
    color: #F4F6FA;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.92rem;
    font-family: inherit;
    padding: 8px 12px;
    border-radius: 10px;
    transition: background 0.2s ease;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.nav-link:hover, .nav-group-btn:hover { background: rgba(212, 175, 55, 0.18); }
.nav-link.active, .nav-group.active > .nav-group-btn { background: rgba(212, 175, 55, 0.28); color: #fff; }
.caret { font-size: 0.7rem; opacity: 0.8; transition: transform 0.2s ease; }

/* Dropdown */
.nav-group { position: relative; }
.nav-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 220px;
    background: #12233d;
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 20;
}
/* Ouverture au survol (desktop) ou au clic (classe .open, desktop + mobile) */
.nav-group:hover .nav-menu, .nav-group.open .nav-menu { display: flex; }
.nav-group:hover .caret, .nav-group.open .caret { transform: rotate(180deg); }
.nav-menu a {
    color: #F4F6FA;
    text-decoration: none;
    font-size: 0.9rem;
    padding: 9px 12px;
    border-radius: 8px;
    white-space: nowrap;
    transition: background 0.15s ease;
}
.nav-menu a:hover { background: rgba(212, 175, 55, 0.18); }
.nav-menu a.active { background: rgba(212, 175, 55, 0.28); color: #fff; font-weight: 600; }

/* Hamburger (caché en desktop) */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #F4F6FA;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}
.nav-toggle:hover { background: rgba(212, 175, 55, 0.18); }

/* User box (auth) */
.userbox { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.user-email { color: #F4F6FA; opacity: 0.85; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-action { color: var(--gold) !important; text-decoration: none; font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.user-action:hover { background: rgba(212, 175, 55, 0.2); }

/* --- Layout --- */
.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px 24px 48px;
    width: 100%;
    flex: 1;
}

/* --- Hero --- */
.hero { margin-bottom: 24px; }
.hero h1 { font-size: 2rem; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.hero-sub { color: var(--muted); margin: 6px 0 0; font-size: 1.05rem; }

/* --- Summary --- */
.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}
.summary-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow);
}
.summary-value { font-size: 1.8rem; font-weight: 800; color: var(--navy); }
.summary-label { color: var(--muted); font-size: 0.9rem; }

/* --- Goal grid --- */
.goal-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}
.goal-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.goal-card:hover { transform: translateY(-2px); border-color: var(--gold); }
.goal-card.is-done { border-color: var(--success); }

.goal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.goal-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1.05rem; }
.goal-icon { font-size: 1.4rem; }
.goal-badge { font-weight: 700; color: var(--gold); white-space: nowrap; }
.is-done .goal-badge { color: var(--success); }

.progress-track {
    background: var(--border);
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
    margin: 6px 0 10px;
}
.progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--gold), #e9c757);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.is-done .progress-fill { background: linear-gradient(90deg, var(--success), #34c759); }

.goal-figures {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.9rem;
}
.goal-figures strong { color: var(--navy); }

/* --- Inline edit --- */
.goal-edit { margin-top: 14px; }
.goal-edit summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.88rem;
    user-select: none;
}
.goal-edit summary:hover { color: var(--gold); }
.goal-edit form {
    margin-top: 12px;
    display: grid;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.goal-edit label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--muted);
}
.goal-edit input {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
}
.goal-edit input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.btn-primary {
    background: var(--gold);
    color: var(--navy);
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(212, 175, 55, 0.35); }

.btn-secondary {
    background: transparent;
    color: var(--gold);
    border: 1px solid var(--gold);
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
}
.btn-secondary:hover { background: rgba(212, 175, 55, 0.12); }
.btn-secondary:disabled { opacity: 0.5; cursor: progress; }
.ocr-btn { margin-top: 8px; align-self: flex-start; }

/* --- Footer --- */
.site-footer {
    text-align: center;
    color: #9AA5BC;
    font-size: 0.85rem;
    padding: 24px;
}

/* --- Panels (outils portés) --- */
.panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.panel h2 { margin: 0 0 16px; font-size: 1.2rem; }
.form-section { grid-column: 1 / -1; margin: 8px 0 0; font-size: 1.05rem; color: var(--navy); }

/* Forms */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; }
.inline-form input { flex: 1 1 160px; }
.grid-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-form label, .inline-form label {
    display: flex; flex-direction: column; gap: 5px;
    font-size: 0.82rem; color: var(--muted);
}
.grid-form label.checkbox { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--navy); }
.form-actions { grid-column: 1 / -1; }
input, select {
    padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
    font-size: 0.95rem; font-family: inherit; background: #fff; color: var(--navy);
}
input:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.form-error { color: var(--error); font-weight: 600; }

/* Liens */
.link-category { margin-bottom: 18px; }
.link-category h3 { margin: 0 0 8px; font-size: 1rem; }
.link-category .count { color: var(--muted); font-weight: 400; }
.link-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.link-items li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--bg); border-radius: 10px; }
.link-items a { color: var(--navy); text-decoration: none; font-weight: 500; }
.link-items a:hover { color: var(--gold); text-decoration: underline; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px; border-radius: 8px; }
.btn-icon:hover { background: rgba(220, 53, 69, 0.12); }
.empty-state { padding: 24px; text-align: center; color: var(--muted); background: var(--bg); border-radius: 12px; }

/* Résultats calculateurs */
.result-block { margin-top: 4px; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.result-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.result-card.highlight { border-color: var(--gold); }
.result-value { font-size: 1.7rem; font-weight: 800; }
.result-label { color: var(--muted); font-size: 0.9rem; }
.result-note { color: var(--muted); font-size: 0.85rem; margin-top: 12px; }

.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.metric { background: var(--bg); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.m-value { font-size: 1.35rem; font-weight: 700; }
.m-value.pos { color: var(--success); }
.m-value.neg { color: var(--error); }
.m-label { color: var(--muted); font-size: 0.82rem; }
.acq-line { margin-top: 16px; color: var(--muted); font-size: 0.9rem; }
.acq-line strong { color: var(--navy); }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table thead th { color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--border); }
.data-table tbody tr:hover { background: var(--bg); }
.data-table .pos { color: var(--success); }
.data-table .neg { color: var(--error); }

/* Dossier bancaire */
.dossier-list { display: flex; flex-wrap: wrap; gap: 10px; }
.dossier-chip { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--bg); border-radius: 999px; }
.dossier-chip.active { background: var(--gold-soft); border: 1px solid var(--gold); }
.dossier-chip a { color: var(--navy); text-decoration: none; font-weight: 500; }
.dossier-chip form { display: inline; }
.doc-section { margin-bottom: 18px; }
.doc-section h3 { font-size: 1rem; margin: 0 0 8px; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--bg); border-radius: 10px; flex-wrap: wrap; }
.doc-info { display: flex; align-items: center; gap: 10px; }
.doc-name { font-weight: 600; font-size: 0.9rem; }
.doc-desc { color: var(--muted); font-size: 0.8rem; }
.doc-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-meta { color: var(--muted); font-size: 0.8rem; }
.upload-mini { display: flex; align-items: center; gap: 6px; }
.upload-mini input[type=file] { font-size: 0.8rem; max-width: 180px; }

/* Factures */
.supplier-config { background: var(--bg); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.supplier-config summary { cursor: pointer; font-weight: 500; }
.badge-on { color: var(--success); font-size: 0.8rem; font-weight: 600; }
.import-badge { font-weight: 600; padding: 8px 0; }
.import-badge.running { color: var(--gold); }
.import-badge.done { color: var(--success); }
.log-box { background: var(--navy); color: #d6e0f0; padding: 12px; border-radius: 10px; font-size: 0.8rem; max-height: 280px; overflow: auto; white-space: pre-wrap; }

/* Justificatifs d'achat */
.scan-field { grid-column: 1 / -1; }
.scan-hint { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.receipt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.receipt-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow); transition: transform 0.2s ease, border-color 0.2s ease; }
.receipt-card:hover { transform: translateY(-2px); border-color: var(--gold); }
.receipt-thumb { display: flex; align-items: center; justify-content: center; height: 150px; background: var(--bg); overflow: hidden; }
.receipt-thumb img { width: 100%; height: 100%; object-fit: cover; }
.receipt-pdf { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.receipt-body { padding: 12px 14px; }
.receipt-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.receipt-amount { font-weight: 700; color: var(--navy); white-space: nowrap; }
.receipt-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.pill { background: var(--gold-soft); color: var(--navy); border-radius: 999px; padding: 2px 10px; font-weight: 600; }
.receipt-note { color: var(--muted); font-size: 0.82rem; margin-top: 6px; }
.receipt-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* Blocs biens fonciers (fiscalité avancée) */
.foncier-block { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; align-items: end; padding: 12px; background: var(--bg); border-radius: 12px; }
.foncier-block strong { grid-column: 1 / -1; font-size: 0.9rem; }

/* Mini bar-chart (comparatif fiscal) */
.barchart { display: grid; gap: 8px; }
.barrow { display: grid; grid-template-columns: 180px 1fr 110px; align-items: center; gap: 12px; font-size: 0.85rem; }
.bartrack { background: var(--bg); border-radius: 999px; height: 18px; overflow: hidden; }
.barfill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold), #e9c757); transition: width .5s ease; }
.barfill.best { background: linear-gradient(90deg, var(--success), #34c759); }
.barvalue { text-align: right; font-weight: 600; }
.data-table tr.row-best { background: rgba(40, 167, 69, 0.08); }
.data-table tr.row-best td { font-weight: 600; }

/* Alertes véhicules */
.alert-group { margin-bottom: 16px; }
.alert-group h3 { margin: 0 0 8px; font-size: 1rem; }
.alert-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.alert-items li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; font-size: 0.88rem; border-left: 4px solid var(--border); background: var(--bg); }
.alert-items .alert-op { font-weight: 600; min-width: 180px; }
.alert-items .alert-msg { color: var(--muted); }
.alert-ok { border-left-color: var(--success) !important; }
.alert-warn { border-left-color: var(--warning) !important; }
.alert-alert { border-left-color: var(--error) !important; background: rgba(220,53,69,0.06) !important; }
.alert-info { border-left-color: var(--muted) !important; }

/* --- Responsive --- */
@media (max-width: 860px) {
    .topbar-inner { flex-wrap: wrap; }
    .nav-toggle { display: block; order: 3; margin-left: auto; }
    .userbox { order: 2; }
    /* Nav repliée par défaut ; dépliée quand .topbar a la classe .nav-open */
    .topnav {
        display: none;
        order: 4;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin-top: 10px;
        justify-content: flex-start;
    }
    .nav-open .topnav { display: flex; }
    .nav-group { width: 100%; }
    .nav-group-btn { width: 100%; justify-content: space-between; }
    /* En mobile, les sous-menus s'affichent en accordéon (au clic uniquement) */
    .nav-menu { position: static; min-width: 0; box-shadow: none; margin: 2px 0 2px 12px; }
    .nav-group:hover .nav-menu { display: none; }
    .nav-group.open .nav-menu { display: flex; }
    .nav-link { width: 100%; }
}

@media (max-width: 720px) {
    .summary { grid-template-columns: 1fr; }
    .goal-grid { grid-template-columns: 1fr; }
    .grid-form { grid-template-columns: 1fr; }
    .result-grid, .metrics-grid { grid-template-columns: 1fr; }
    .hero h1 { font-size: 1.6rem; }
    .user-email { max-width: 120px; }
}
