/* main.css — Marchés Publics (design tokens + thème sombre automatique) */

/* ===== Tokens ===== */
:root {
    --brand: #1a2a6c;            /* navy de marque (fonds navbar/boutons, 2 thèmes) */
    --brand-hover: #2d4373;
    --primary: #1a2a6c;          /* titres/accents sur surface (s'éclaircit en sombre) */
    --accent: #3388ff;           /* liens */
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f0f3fa;        /* fonds subtils : th, sig, hover */
    --surface-3: #eef2ff;        /* chips */
    --text: #333333;
    --muted: #777f8f;
    --border: #dde1ec;
    --border-subtle: #f0f0f0;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --success: #047857;
    --success-bg: #ecfdf5;
    --success-strong: #166534;
    --success-strong-bg: #dcfce7;
    --note-text: #92400e;
    --note-bg: #fffbeb;
    --note-border: #fde68a;
    --warn: #b45309;
    --info-text: #1a4480;
    --info-bg: #f0f7ff;
    --info-border: #cfe2ff;
    --shadow-1: 0 2px 10px rgba(0,0,0,.06);
    --shadow-2: 0 8px 22px rgba(0,0,0,.12);
    --radius-s: 6px;
    --radius-m: 10px;
    --radius-l: 12px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --primary: #9db1ff;
        --accent: #6ba3ff;
        --bg: #11141c;
        --surface: #1b2030;
        --surface-2: #232a3d;
        --surface-3: #262e48;
        --text: #d6dae3;
        --muted: #98a0b3;
        --border: #313a52;
        --border-subtle: #262e44;
        --danger: #f87171;
        --danger-bg: #35191d;
        --danger-border: #5f2529;
        --success: #4ade80;
        --success-bg: #143024;
        --success-strong: #86efac;
        --success-strong-bg: #14532d;
        --note-text: #fcd34d;
        --note-bg: #2c2410;
        --note-border: #57431a;
        --warn: #fbbf24;
        --info-text: #a8c7ff;
        --info-bg: #1a2438;
        --info-border: #2c3c5c;
        --shadow-1: 0 2px 10px rgba(0,0,0,.35);
        --shadow-2: 0 8px 22px rgba(0,0,0,.5);
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }

/* Navbar (navy de marque, identique dans les deux thèmes) */
.navbar { background: linear-gradient(135deg, var(--brand), var(--brand-hover)); box-shadow: 0 2px 10px rgba(0,0,0,.15);
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000; height: 60px; }
.navbar-container { max-width: 1400px; margin: 0 auto; display: flex; align-items: center;
    justify-content: space-between; height: 100%; padding: 0 1.5rem; }
.navbar-brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand-icon { font-size: 1.4rem; }
.navbar-btn { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); border-radius: 50%;
    color: #fff; text-decoration: none; }
.nav-item.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: 110%; right: 0; list-style: none; background: var(--surface);
    border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.25); min-width: 210px; padding: .4rem 0;
    opacity: 0; visibility: hidden; transform: translateY(-10px); transition: all .2s ease; }
.dropdown-menu.show { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-header { padding: .5rem 1rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--border-subtle); }
.dropdown-item { display: block; width: 100%; text-align: left; padding: .6rem 1rem; background: none;
    border: none; color: var(--text); text-decoration: none; cursor: pointer; font-size: .95rem; }
.dropdown-item:hover { background: var(--surface-2); color: var(--primary); }
.navbar-link { color: rgba(255,255,255,.88); text-decoration: none; margin-right: 1.2rem; font-size: .92rem;
    padding-bottom: .15rem; border-bottom: 2px solid transparent; }
.navbar-link:hover { color: #fff; }
.navbar-link--active { color: #fff; font-weight: 600; border-bottom-color: #fff; }
.navbar-actions { display: flex; align-items: center; }

/* Barre de chargement HTMX */
#loading-bar { position: fixed; top: 60px; left: 0; right: 0; height: 3px; z-index: 1500;
    background: linear-gradient(90deg, var(--accent), var(--brand)); opacity: 0; transition: opacity .2s; }
#loading-bar.htmx-request { opacity: 1; animation: loading-slide 1s linear infinite; }
@keyframes loading-slide { from { background-position: 0 0; } to { background-position: 240px 0; } }

/* Layout */
.main-content { margin-top: 60px; padding: 2rem; min-height: calc(100vh - 60px - 60px); }
.container { max-width: 1400px; margin: 0 auto; }
.footer { background: var(--brand); color: #fff; text-align: center; padding: 1.2rem; font-size: .85rem; }

/* Hero + features */
.hero { text-align: center; padding: 3rem 1rem; background: linear-gradient(135deg, var(--info-bg), var(--surface-3));
    border-radius: var(--radius-l); margin-bottom: 2rem; }
.hero h1 { color: var(--primary); font-size: 2rem; margin-bottom: 1rem; }
.hero p { max-width: 720px; margin: 0 auto; color: var(--muted); line-height: 1.6; }
.hero-actions { margin-top: 1.4rem; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }
.feature-card { background: var(--surface); border-radius: var(--radius-l); padding: 1.5rem; box-shadow: var(--shadow-1);
    transition: transform .2s, box-shadow .2s; }
.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-2); }
.feature-icon { font-size: 2rem; margin-bottom: .5rem; }
.feature-card h3 { color: var(--primary); margin-bottom: .4rem; }
.feature-card p { color: var(--muted); font-size: .95rem; line-height: 1.5; }

/* Auth */
.auth-wrapper { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 60px - 60px - 4rem); }
.auth-card { background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-2); padding: 2.5rem; width: 100%; max-width: 420px; }
.auth-card h1 { color: var(--primary); margin-bottom: 1.5rem; text-align: center; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .3rem; font-weight: 600; font-size: .9rem; }
.form-group input { width: 100%; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-s); font-size: 1rem; background: var(--surface); color: var(--text); }
.form-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(51,136,255,.15); }
.form-help { color: var(--muted); font-size: .78rem; }
.btn-submit { width: 100%; background: var(--brand); color: #fff; border: none; border-radius: var(--radius-s);
    padding: .7rem; font-weight: 600; font-size: 1rem; cursor: pointer; margin-top: .5rem; }
.btn-submit:hover { background: var(--brand-hover); }
.auth-link { text-align: center; margin-top: 1.2rem; font-size: .9rem; }
.auth-link a { color: var(--accent); }
.auth-errors { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); border-radius: var(--radius-s); padding: .5rem .8rem; margin-top: .4rem; }
.auth-errors ul { list-style: none; font-size: .85rem; }

/* Dashboard, entreprises */
.dashboard-header { margin-bottom: 1.5rem; }
.dashboard-header h1 { color: var(--primary); }
.dashboard-header p { color: var(--muted); margin-top: .3rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); border-radius: var(--radius-l); padding: 1.5rem; box-shadow: var(--shadow-1); text-align: center; }
.stat-card--muted { opacity: .7; }
.stat-value { font-size: 2.2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); margin-top: .3rem; font-size: .9rem; }
.badge { display: inline-block; background: var(--surface-3); color: var(--primary); border-radius: 10px; padding: 0 .5rem; font-size: .7rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 1.5rem 0 1rem; gap: 1rem; }
.section-head h1, .section-head h2 { color: var(--primary); }

.btn-primary { background: var(--brand); color: #fff; border: none; border-radius: var(--radius-s); padding: .55rem 1rem;
    font-weight: 600; cursor: pointer; text-decoration: none; font-size: .92rem; display: inline-block; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary[disabled], .htmx-request .btn-primary[type=submit] { opacity: .6; pointer-events: none; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: .9rem; text-decoration: none; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.btn-link--danger { color: var(--danger); }

.enterprise-card { display: flex; flex-direction: column; }
.muted { color: var(--muted); } .small { font-size: .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .6rem 0; }
.chip { background: var(--surface-3); color: var(--primary); border-radius: 12px; padding: .15rem .6rem; font-size: .75rem; }
.chip--alt { background: var(--success-bg); color: var(--success); }
.chip--off { background: var(--danger-bg); color: var(--danger); }
.card-actions { display: flex; gap: 1rem; margin-top: auto; padding-top: .8rem; }

.empty-state { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-l); padding: 2rem; text-align: center; color: var(--muted); }
.empty-state .btn-primary { margin-top: 1rem; }
.empty-state a { color: var(--accent); }

.info-banner { background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-text); border-radius: 8px; padding: .9rem 1rem; margin: .8rem 0; font-size: .9rem; }

/* Detail */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.2rem; }
.detail-card { background: var(--surface); border-radius: var(--radius-l); padding: 1.3rem; box-shadow: var(--shadow-1); }
.detail-card--wide { grid-column: 1 / -1; }
.detail-card h3 { color: var(--primary); margin-bottom: .7rem; font-size: 1rem; }
.detail-card dl { display: grid; grid-template-columns: 130px 1fr; row-gap: .4rem; font-size: .9rem; }
.detail-card dt { color: var(--muted); } .detail-card dd { color: var(--text); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none;
    align-items: center; justify-content: center; z-index: 2000; padding: 1rem; }
.modal-box { background: var(--surface); border-radius: var(--radius-l); padding: 1.8rem; width: 100%; max-width: 560px;
    max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.modal-title { color: var(--primary); margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1rem; }
.form-group textarea, .form-group select { width: 100%; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-s); font-size: 1rem; font-family: inherit; background: var(--surface); color: var(--text); }

/* Recherche (layout partagé DECP + opportunités) */
.search-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.5rem; align-items: start; }
.search-filters { background: var(--surface); border-radius: var(--radius-l); padding: 1.2rem; box-shadow: var(--shadow-1); position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; }
.search-filters .fg { margin-bottom: .7rem; }
.search-filters label { font-size: .82rem; font-weight: 600; color: var(--text); display: block; margin-bottom: .2rem; }
.search-filters input[type=text], .search-filters input[type=date], .search-filters input[type=number],
.search-filters select { width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius-s); font-size: .9rem; background: var(--surface); color: var(--text); }
.fg-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.search-filters fieldset { border: 1px solid var(--border-subtle); border-radius: 8px; padding: .5rem .7rem; margin-bottom: .7rem; }
.search-filters legend { font-size: .78rem; color: var(--muted); padding: 0 .3rem; }
.search-filters fieldset label { font-weight: 400; display: inline-flex; align-items: center; gap: .3rem; margin: .15rem 0; }
.search-filters .chk { font-weight: 400; display: flex; align-items: center; gap: .4rem; margin: .3rem 0; }
.search-filters .btn-primary { width: 100%; margin-top: .6rem; }
.btn-reset { display: block; text-align: center; margin-top: .5rem; font-size: .82rem; color: var(--muted); }

.results-head { margin-bottom: .8rem; color: var(--muted); }
.results-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-m); overflow: hidden; box-shadow: var(--shadow-1); font-size: .88rem; }
.results-table th, .results-table td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
.results-table th { background: var(--surface-2); color: var(--primary); font-size: .8rem; }
.results-table td.num, .results-table th.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 1rem; color: var(--muted); }
ul.plain { list-style: none; } ul.plain li { padding: .2rem 0; }

/* Opportunités (cartes) */
.opp-list { display: grid; gap: .9rem; }
.opp-card { display: block; background: var(--surface); border-radius: var(--radius-m); padding: 1rem 1.2rem; box-shadow: var(--shadow-1); text-decoration: none; color: inherit; border-left: 4px solid var(--brand); transition: box-shadow .2s, transform .2s; }
.opp-card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.opp-card h3 { color: var(--primary); font-size: 1.02rem; margin: .3rem 0; }
.opp-card-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.opp-card-head .opp-deadline { margin-left: auto; }
.opp-deadline { font-size: .8rem; color: var(--warn); font-weight: 600; }
.opp-meta { color: var(--muted); font-size: .85rem; margin-bottom: .3rem; }
.chip--boamp { background: var(--surface-3); color: var(--primary); }
.chip--ted { background: var(--note-bg); color: var(--note-text); }

/* Matching */
.match-score { font-weight: 700; color: var(--primary); font-size: .9rem; }
.match-signals { display: flex; flex-wrap: wrap; gap: .4rem; margin: .35rem 0; }
.sig { background: var(--surface-2); color: var(--muted); border-radius: 6px; padding: .1rem .45rem; font-size: .72rem; font-family: ui-monospace, monospace; }
.sig--ok { background: var(--success-bg); color: var(--success); }

/* Triage des opportunités (interactions) */
.opp-card h3 a { color: inherit; text-decoration: none; }
.opp-card h3 a:hover { text-decoration: underline; }
.opp-card--dismissed { opacity: .55; border-left-color: var(--muted); }
.interaction { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .55rem; padding-top: .55rem; border-top: 1px solid var(--border-subtle); }
.int-btn { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: .18rem .65rem; font-size: .78rem; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.int-btn:hover { border-color: var(--primary); color: var(--primary); }
.int-btn--on { background: var(--brand); border-color: var(--brand); color: #fff; }
.int-btn--danger:hover { border-color: var(--danger); color: var(--danger); }
.int-btn--danger.int-btn--on { background: var(--danger); border-color: var(--danger); color: #fff; }
.int-btn--noted { border-color: var(--warn); color: var(--warn); }
.opp-note { background: var(--note-bg); border: 1px solid var(--note-border); color: var(--note-text); border-radius: 8px; padding: .4rem .6rem; font-size: .82rem; margin: .45rem 0 0; white-space: pre-line; }
.suivi-section { margin-bottom: 1.6rem; }
.suivi-section h2 { color: var(--primary); font-size: 1.05rem; margin-bottom: .6rem; }
.suivi-section--dismissed .opp-card { opacity: .6; }
.chip--new { background: var(--success-strong-bg); color: var(--success-strong); font-weight: 700; }

/* Pertinence humanisée */
.match-badge { font-size: .78rem; font-weight: 700; border-radius: 999px; padding: .15rem .6rem; }
.match-badge--3 { background: var(--success-strong-bg); color: var(--success-strong); }
.match-badge--2 { background: var(--surface-3); color: var(--primary); }
.match-badge--1 { background: var(--surface-2); color: var(--muted); }
.match-why { color: var(--muted); font-size: .82rem; margin: .3rem 0 0; }
.form-group textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; font: inherit; }

/* Veilles (SavedSearch) */
.saved-searches { background: var(--surface); border-radius: var(--radius-m); padding: .7rem .8rem; box-shadow: var(--shadow-1); margin-bottom: .9rem; }
.saved-title { font-size: .78rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .45rem; }
.saved-chip { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: .18rem 0; }
.saved-chip a { color: var(--primary); text-decoration: none; font-size: .86rem; display: inline-flex; align-items: center; gap: .4rem; }
.saved-chip a:hover { text-decoration: underline; }
.saved-chip--active a { font-weight: 700; }
.saved-count { background: var(--danger); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700; padding: .05rem .45rem; }
.saved-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: .8rem; }
.saved-del:hover { color: var(--danger); }
.btn-save-search { width: 100%; margin-top: .4rem; text-align: center; }
.veilles-list { display: grid; gap: .5rem; margin-bottom: 1.4rem; }
.veille-card { display: flex; align-items: center; gap: .8rem; background: var(--surface); border-radius: var(--radius-m); padding: .6rem .9rem; box-shadow: var(--shadow-1); text-decoration: none; color: inherit; }
.veille-card:hover { box-shadow: var(--shadow-2); }
.veille-name { font-weight: 600; color: var(--primary); }

/* Recherche sémantique + pertinence profil */
.fg-mode ul { list-style: none; display: flex; gap: 1rem; padding: 0; margin: .2rem 0 0; }
.fg-mode li label { font-weight: 400; display: inline-flex; align-items: center; gap: .35rem; font-size: .86rem; }
.sim-bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin: .35rem 0 .15rem; overflow: hidden; }
.sim-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--brand)); border-radius: 2px; }
.match-filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; background: var(--surface); border-radius: var(--radius-m); padding: .6rem .8rem; box-shadow: var(--shadow-1); margin-bottom: .9rem; }
.match-filters select, .match-filters input { border: 1px solid var(--border); border-radius: 8px; padding: .3rem .5rem; font: inherit; font-size: .85rem; background: var(--surface); color: var(--text); }
.chip-toggle { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: .25rem .6rem; cursor: pointer; }
.chip-toggle input { accent-color: var(--primary); }
.cpv-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: -.4rem 0 .9rem; font-size: .82rem; }
.cpv-chips .chip { text-decoration: none; }

/* Urgence des échéances */
.deadline--critical { color: var(--danger); font-weight: 700; }
.deadline--soon { color: #b45309; font-weight: 600; }
@media (prefers-color-scheme: dark) { .deadline--soon { color: #fbbf24; } }

/* Dashboard multi-entreprises */
.dash-companies { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .9rem; }
.dash-company { background: var(--surface); border-radius: var(--radius-m); padding: .8rem 1rem; box-shadow: var(--shadow-1); display: flex; flex-direction: column; }
.dash-company-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.dash-company-head h3 { font-size: 1rem; color: var(--primary); }
.dash-matches { list-style: none; padding: 0; margin: 0 0 .6rem; flex: 1; }
.dash-matches li { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; padding: .25rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.dash-matches li:last-child { border-bottom: none; }
.dash-matches a { color: var(--text); text-decoration: none; }
.dash-matches a:hover { color: var(--primary); }
.dash-matches .muted { white-space: nowrap; }

/* Digest « Nouveautés du jour » */
.digest-block { background: var(--surface); border-radius: var(--radius-m); padding: .8rem 1rem; box-shadow: var(--shadow-1); margin-bottom: 1rem; }
.digest-block h2 { color: var(--primary); font-size: 1.05rem; margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; }
.digest-list { list-style: none; padding: 0; margin: 0 0 .5rem; }
.digest-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; }
.digest-list li:last-child { border-bottom: none; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .search-layout { grid-template-columns: 1fr; }
    .search-filters { position: static; max-height: none; }
}
@media (max-width: 700px) {
    /* La navbar redevient statique et peut passer sur plusieurs lignes. */
    .navbar { position: static; height: auto; }
    .navbar-container { flex-wrap: wrap; padding: .5rem 1rem; gap: .3rem; }
    .navbar-actions { flex-wrap: wrap; }
    .navbar-link { margin-right: .8rem; font-size: .85rem; }
    .main-content { margin-top: 0; padding: 1rem; }
    #loading-bar { top: 0; }
    .detail-card dl { grid-template-columns: 1fr; }
}
