/* =====================================================================
   CAC 40 Market Cap — feuille de style
   Design sobre & financier, thèmes clair / sombre.
   ===================================================================== */

:root {
    --accent:        #0a4d8c;   /* bleu CAC */
    --accent-soft:   #e7f0fa;
    --pos:           #138a52;   /* vert hausse */
    --neg:           #c0392b;   /* rouge baisse */

    --bg:            #f4f6f9;
    --surface:       #ffffff;
    --surface-2:     #fafbfc;
    --border:        #e3e7ee;
    --text:          #1a2533;
    --text-soft:     #5a6b80;
    --text-faint:    #8b98a9;
    --row-hover:     #f3f7fc;
    --shadow:        0 1px 3px rgba(18, 38, 63, .06), 0 8px 24px rgba(18, 38, 63, .05);
}

html[data-theme="dark"] {
    --accent:        #4c9fff;
    --accent-soft:   #14263c;
    --pos:           #3ed68a;
    --neg:           #ff6b5e;

    --bg:            #0d1420;
    --surface:       #151e2e;
    --surface-2:     #1a2536;
    --border:        #26334a;
    --text:          #e8edf4;
    --text-soft:     #9aa9bd;
    --text-faint:    #6b7b92;
    --row-hover:     #1c2840;
    --shadow:        0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ---------- Header ---------- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 64px;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
    font-weight: 800;
    letter-spacing: .5px;
    color: var(--accent);
    font-size: 22px;
}
.brand-num {
    font-weight: 800;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    padding: 1px 7px;
    font-size: 18px;
}
.brand-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-soft);
    margin: 0 0 0 6px;
}
@media (max-width: 640px) { .brand-title { display: none; } }

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

.currency-switch {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}
.cur-btn {
    border: 0;
    background: transparent;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s ease;
}
.cur-btn.is-active {
    background: var(--accent);
    color: #fff;
}

.icon-btn {
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 8px;
    cursor: pointer;
    display: grid; place-items: center;
    color: var(--text-soft);
    transition: all .15s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-icon { width: 18px; height: 18px; display: block; position: relative; }
/* soleil (clair) */
.theme-icon::before {
    content: "";
    position: absolute; inset: 0;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 -7px 0 -5px, 0 7px 0 -5px, -7px 0 0 -5px, 7px 0 0 -5px,
                5px 5px 0 -5px, -5px -5px 0 -5px, 5px -5px 0 -5px, -5px 5px 0 -5px;
    transform: scale(.62);
}
html[data-theme="dark"] .theme-icon::before {
    /* lune */
    box-shadow: 5px 1px 0 0 var(--surface-2);
    transform: scale(.85);
    background: currentColor;
}

/* ---------- Carte de synthèse ---------- */
.summary {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    align-items: flex-end;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 26px 28px;
    margin: 28px 0 22px;
    box-shadow: var(--shadow);
}
.summary-label {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-faint);
    font-weight: 600;
}
.summary-value {
    font-size: clamp(30px, 6vw, 46px);
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1.1;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}
.summary-sub { font-size: 13px; color: var(--text-soft); margin-top: 6px; }

.summary-side { display: flex; gap: 28px; flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-faint); font-weight: 600;
}
.kpi-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Contrôles ---------- */
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.search-wrap {
    position: relative;
    flex: 1 1 240px;
    min-width: 200px;
}
.search-ico {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 18px; height: 18px; color: var(--text-faint); pointer-events: none;
}
#search {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

#sectorFilter {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    max-width: 220px;
}
#sectorFilter:focus { border-color: var(--accent); }

.sort-group { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.sort-label { font-size: 13px; color: var(--text-soft); margin-right: 2px; }
.sort-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s ease;
}
.sort-btn:hover { border-color: var(--accent); color: var(--accent); }
.sort-btn.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Tableau ---------- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.cac-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.cac-table thead th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-faint);
    font-weight: 700;
    padding: 14px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.col-price, .col-change, .col-cap, .col-weight { text-align: right; }
.col-rank { width: 44px; text-align: center; }

.cac-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.cac-table tbody tr:last-child td { border-bottom: 0; }
.cac-table tbody tr { transition: background-color .12s ease; }
.cac-table tbody tr:hover { background: var(--row-hover); }

.cell-rank { text-align: center; color: var(--text-faint); font-variant-numeric: tabular-nums; font-weight: 600; }

.company {
    display: flex; align-items: center; gap: 12px;
}
.logo {
    width: 34px; height: 34px;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    padding: 3px;
    flex-shrink: 0;
}
.logo-fallback {
    width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 13px;
}
.company-name { font-weight: 600; }
.company-ticker { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.col-sector, .cell-sector { color: var(--text-soft); }
.sector-tag {
    display: inline-block;
    font-size: 12px;
    color: var(--text-soft);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    white-space: nowrap;
}

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-cap { font-weight: 700; }
.cell-price { color: var(--text-soft); }

.chg { font-weight: 600; font-variant-numeric: tabular-nums; }
.chg.pos { color: var(--pos); }
.chg.neg { color: var(--neg); }
.chg .arrow { font-size: 11px; }

/* barre de poids dans l'indice */
.weight-cell { min-width: 120px; }
.weight-inner { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.weight-pct { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 46px; text-align: right; }
.weight-bar {
    flex: 1;
    max-width: 70px;
    height: 6px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.weight-fill { height: 100%; background: var(--accent); border-radius: 4px; }

.empty-row td { text-align: center; color: var(--text-faint); padding: 40px 16px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Divers ---------- */
.disclaimer {
    font-size: 12px;
    color: var(--text-faint);
    margin: 18px 2px 40px;
    line-height: 1.6;
}
.site-footer {
    border-top: 1px solid var(--border);
    padding: 22px 0;
    color: var(--text-faint);
    font-size: 13px;
    text-align: center;
}

/* highlight de recherche */
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- Panneaux (graphique + mouvements) ---------- */
.insights {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 18px;
    margin: 4px 0 22px;
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px 20px;
    box-shadow: var(--shadow);
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.panel-title { font-size: 15px; font-weight: 700; margin: 0; }

/* Contrôle segmenté (période) */
.seg {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}
.seg-btn {
    border: 0;
    background: transparent;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s ease;
}
.seg-btn.is-active { background: var(--accent); color: #fff; }

/* ---------- Graphique en courbe ---------- */
.chart { color: var(--accent); position: relative; }
.chart-host { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-line { stroke: currentColor; }
.chart-area { color: var(--accent); }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-ylab { fill: var(--text-faint); font-size: 11px; text-anchor: end; font-variant-numeric: tabular-nums; }
.chart-xlab { fill: var(--text-faint); font-size: 11px; text-anchor: middle; }
.chart-cursor { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-hit { cursor: crosshair; }
.chart-tip {
    position: absolute;
    top: 6px;
    pointer-events: none;
    background: var(--text);
    color: var(--surface);
    border-radius: 8px;
    padding: 6px 9px;
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
    z-index: 2;
}
.chart-tip .tip-val { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-tip .tip-lab { display: block; opacity: .7; font-size: 11px; }
.chart-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 300px; text-align: center;
    color: var(--text-faint); font-size: 14px; line-height: 1.6;
}

/* ---------- Mouvements ---------- */
.movers { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.movers-head {
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
    margin-bottom: 8px;
}
.movers-head.pos { color: var(--pos); }
.movers-head.neg { color: var(--neg); }
.movers-list { list-style: none; margin: 0; padding: 0; }
.movers-list li { border-bottom: 1px solid var(--border); }
.movers-list li:last-child { border-bottom: 0; }
.movers-list a {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 7px 0; text-decoration: none; color: var(--text);
}
.movers-list a:hover .mover-name { color: var(--accent); }
.mover-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mover-pct { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.movers-empty { color: var(--text-faint); font-size: 13px; padding: 7px 0; }

/* ---------- Sparkline (colonne tendance) ---------- */
.col-spark { text-align: right; }
.cell-spark { text-align: right; white-space: nowrap; }
.spark { display: inline-block; vertical-align: middle; }
.spark-pos { color: var(--pos); }
.spark-neg { color: var(--neg); }
.spark-empty { color: var(--text-faint); }

/* ---------- Lignes cliquables ---------- */
tr.is-clickable { cursor: pointer; }
a.company-name { color: inherit; text-decoration: none; }
tr.is-clickable:hover a.company-name { color: var(--accent); }

/* ---------- Page détail ---------- */
.brand-link { text-decoration: none; }
.back-link {
    display: inline-block;
    margin: 22px 0 6px;
    color: var(--text-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}
.back-link:hover { color: var(--accent); }

.co-hero {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 24px;
    margin: 10px 0 18px;
    box-shadow: var(--shadow);
}
.co-id { display: flex; align-items: center; gap: 16px; }
.co-logo { display: inline-flex; }
.co-logo .logo, .co-logo .logo-fallback { width: 52px; height: 52px; border-radius: 12px; font-size: 18px; }
.co-name { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.co-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; color: var(--text-faint); font-size: 13px; }
.co-meta .sector-tag { margin-left: 0; }
.co-price-block { text-align: right; }
.co-price { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.co-change { font-size: 14px; font-weight: 600; margin-top: 2px; }
.co-change.pos { color: var(--pos); }
.co-change.neg { color: var(--neg); }

.co-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.stat-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); font-weight: 600; }
.stat-value { display: block; font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.chart-panel { margin-bottom: 18px; }

/* ---------- Lien de navigation (en-tête) ---------- */
.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 13px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 8px;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s ease;
}
.nav-link:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 600px) {
    .nav-label { display: none; }
    .nav-link { padding: 0 11px; }
    .header-actions { gap: 8px; }
}

/* ---------- Carte de marché (heatmap) ---------- */
.hm-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin: 26px 0 14px;
}
.hm-title { font-size: 20px; font-weight: 800; margin: 0; letter-spacing: -.3px; }
.hm-sub { font-size: 13px; color: var(--text-soft); margin: 4px 0 0; }

.hm-legend { display: flex; align-items: center; gap: 10px; }
.hm-legend-lab { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hm-legend-bar {
    width: 160px; height: 10px; border-radius: 5px;
    background: linear-gradient(90deg, rgb(208,57,43) 0%, rgb(71,79,92) 50%, rgb(38,166,91) 100%);
}

.heatmap-wrap { position: relative; margin-bottom: 18px; }
.heatmap {
    position: relative;
    width: 100%;
    min-height: 440px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.hm-loading {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-faint); font-size: 14px; line-height: 1.6; text-align: center;
}

.hm-tile {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 3px;
    color: #fff;
    text-decoration: none;
    text-align: center;
    line-height: 1.15;
    text-shadow: 0 1px 2px rgba(0,0,0,.35);
    transition: outline-color .1s ease;
    outline: 2px solid transparent;
    outline-offset: -2px;
}
.hm-tile:hover { outline-color: rgba(255,255,255,.85); z-index: 3; }
.hm-tile > * { pointer-events: none; }
.hm-pct {
    margin-top: 4px;
    font-weight: 600;
    opacity: .95;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0,0,0,.35);
}

/* Logo dans la tuile : encart blanc pour rester lisible sur tout fond. */
.hm-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
    overflow: hidden;
}
.hm-logo img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    display: block;
}
.hm-logo.is-mono {
    color: #fff;
    font-weight: 800;
    text-shadow: none;
    border-radius: 50%;
}

.hm-tip {
    position: absolute;
    pointer-events: none;
    background: var(--text);
    color: var(--surface);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.3);
    z-index: 10;
}

/* ---------- Responsive : passage en cartes sur mobile ---------- */
@media (max-width: 900px) {
    .insights { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .summary { flex-direction: column; align-items: flex-start; }
    .summary-side { gap: 20px; }

    .cac-table thead { display: none; }
    .cac-table, .cac-table tbody, .cac-table tr, .cac-table td { display: block; width: 100%; }
    .cac-table tbody tr {
        padding: 12px 14px;
        border-bottom: 1px solid var(--border);
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 4px 12px;
        align-items: center;
    }
    .cac-table tbody td { padding: 2px 0; border: 0; }
    .cell-rank { display: none; }
    .cell-company { grid-column: 1; grid-row: 1; }
    .cell-cap { grid-column: 2; grid-row: 1; text-align: right; font-size: 15px; }
    .cell-sector { grid-column: 1; grid-row: 2; }
    .cell-change { grid-column: 2; grid-row: 2; text-align: right; }
    .cell-price { display: none; }
    .weight-cell { grid-column: 1 / -1; grid-row: 3; }
    .weight-inner { justify-content: flex-start; }
    .weight-bar { max-width: none; }
    .sort-group { margin-left: 0; width: 100%; flex-wrap: wrap; }

    /* La sparkline est masquée en vue carte (peu lisible) ; la tendance
       reste disponible sur la page détail de chaque société. */
    .col-spark, .cell-spark { display: none; }

    .movers { gap: 14px; }
    .chart-svg, .chart-empty { height: 240px; }

    .co-hero { flex-direction: column; align-items: flex-start; }
    .co-price-block { text-align: left; }
    .co-stats { grid-template-columns: 1fr 1fr; }
}
