/* StockPilot — thème (sombre par défaut, clair optionnel) */
:root,
[data-bs-theme="dark"] {
    --sp-bg: #121417;
    --sp-surface: #1a1d22;
    --sp-surface-2: #20242a;
    --sp-border: #2a2f37;
    --sp-text: #e6e8eb;
    --sp-muted: #8b929c;
    --sp-accent: #5b8def;
    --sp-gain: #2fbf71;
    --sp-loss: #ef5350;
    --sp-warn: #f0b429;
    --sp-sidebar: #0f1114;
    --bs-body-bg: var(--sp-bg);
    --bs-body-color: var(--sp-text);
    --bs-border-color: var(--sp-border);
    --bs-secondary-color: var(--sp-muted);
    --bs-tertiary-bg: var(--sp-surface-2);
    --bs-primary: var(--sp-accent);
    --bs-primary-rgb: 91, 141, 239;
    --bs-link-color: #8fb1f5;
    --bs-link-hover-color: #b7cdfa;
    --bs-link-color-rgb: 143, 177, 245;
}

[data-bs-theme="light"] {
    --sp-bg: #f4f5f7;
    --sp-surface: #ffffff;
    --sp-surface-2: #f0f2f5;
    --sp-border: #e1e4e8;
    --sp-text: #1d2127;
    --sp-muted: #69707a;
    --sp-accent: #3466d6;
    --sp-gain: #13894a;
    --sp-loss: #d0342c;
    --sp-sidebar: #ffffff;
    --bs-body-bg: var(--sp-bg);
    --bs-body-color: var(--sp-text);
    --bs-border-color: var(--sp-border);
    --bs-secondary-color: var(--sp-muted);
    --bs-link-color: #2c5bc4;
    --bs-link-color-rgb: 44, 91, 196;
    --bs-link-hover-color: #1c3f8f;
}

html, body { background: var(--sp-bg); }
body {
    font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-feature-settings: "tnum" 1, "cv11" 1;
    font-size: .925rem;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; }
a:hover { text-decoration: underline; }

.btn-primary { --bs-btn-bg: var(--sp-accent); --bs-btn-border-color: var(--sp-accent); --bs-btn-hover-bg: #4a7bdc; --bs-btn-hover-border-color: #4a7bdc; --bs-btn-active-bg: #3f6dcb; }
.btn-outline-primary { --bs-btn-color: var(--sp-accent); --bs-btn-border-color: var(--sp-accent); --bs-btn-hover-bg: var(--sp-accent); --bs-btn-hover-border-color: var(--sp-accent); }

.text-gain { color: var(--sp-gain) !important; }
.text-loss { color: var(--sp-loss) !important; }

/* --- Structure ---------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar { background: var(--sp-sidebar); border-right: 1px solid var(--sp-border); }
@media (min-width: 992px) {
    .app-sidebar { width: 248px; flex: 0 0 248px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
.app-main { flex: 1; min-width: 0; overflow-x: clip; display: flex; flex-direction: column; }
.app-content { padding: 1.5rem clamp(1rem, 2.5vw, 2.25rem) 2.5rem; max-width: 1600px; width: 100%; }
@media (max-width: 991.98px) { .app-content { padding-bottom: 5.5rem; } }

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; font-size: 1.1rem; color: var(--sp-text); padding: 1.25rem 1.25rem 1rem; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; color: var(--sp-text); }
.brand i, .brand-sm i { color: var(--sp-accent); }
.brand-sm { font-weight: 650; }

.app-nav { padding: .25rem .65rem; gap: 2px; }
.app-nav .nav-link { display: flex; align-items: center; gap: .7rem; color: var(--sp-muted); border-radius: .5rem; padding: .5rem .7rem; font-size: .9rem; transition: background .15s, color .15s; }
.app-nav .nav-link i { font-size: 1.05rem; width: 1.1rem; text-align: center; }
.app-nav .nav-link:hover { background: var(--sp-surface-2); color: var(--sp-text); text-decoration: none; }
.app-nav .nav-link.active { background: rgba(91, 141, 239, .14); color: var(--sp-text); font-weight: 550; }
.app-nav .nav-link.active i { color: var(--sp-accent); }
.app-nav .nav-link.disabled { opacity: .45; cursor: not-allowed; }
.badge-phase { margin-left: auto; font-size: .65rem; border: 1px solid var(--sp-border); border-radius: 999px; padding: .05rem .45rem; color: var(--sp-muted); }
.sidebar-foot { border-top: 1px solid var(--sp-border); }

.app-topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; background: var(--sp-sidebar); border-bottom: 1px solid var(--sp-border); }
.app-bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 1020; display: flex; background: var(--sp-sidebar); border-top: 1px solid var(--sp-border); padding-bottom: env(safe-area-inset-bottom); }
.app-bottomnav a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .5rem; font-size: .68rem; color: var(--sp-muted); }
.app-bottomnav a i { font-size: 1.2rem; }
.app-bottomnav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.app-bottomnav a.active { color: var(--sp-accent); }
.app-bottomnav a:hover { text-decoration: none; }

/* --- En-têtes ------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.55rem; font-weight: 650; letter-spacing: -.02em; margin: 0; }
.section-title { font-size: 1rem; font-weight: 620; margin-bottom: .75rem; letter-spacing: -.005em; }
.panel-title { font-size: .8rem; font-weight: 600; color: var(--sp-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem; }

/* --- Cartes --------------------------------------------------------- */
.card-panel { background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: .85rem; padding: 1rem 1.1rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .85rem; }
.kpi-grid-4 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.kpi { background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: .85rem; padding: .95rem 1.05rem; animation: rise .35s ease both; }
.kpi-label { color: var(--sp-muted); font-size: .78rem; font-weight: 550; text-transform: uppercase; letter-spacing: .035em; }
.kpi-value { font-size: 1.4rem; font-weight: 650; letter-spacing: -.02em; margin-top: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: .8rem; margin-top: .15rem; }
.kpi-main { background: linear-gradient(135deg, rgba(91, 141, 239, .16), rgba(91, 141, 239, .03)) , var(--sp-surface); border-color: rgba(91, 141, 239, .35); }
.kpi-main .kpi-value { font-size: 1.75rem; }
@media (min-width: 1200px) { .kpi-perf { grid-row: span 2; } }
.perf-list { margin-top: .4rem; font-size: .85rem; }
.perf-row { display: flex; justify-content: space-between; padding: .14rem 0; }
/* Animation de transformation uniquement : le contenu reste visible même si l'animation ne s'exécute pas. */
@keyframes rise { from { transform: translateY(4px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .kpi { animation: none; } }

.account-card { display: block; color: inherit; background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: .85rem; padding: 1rem 1.1rem; transition: border-color .15s, transform .15s; }
.account-card:hover { text-decoration: none; color: inherit; border-color: var(--sp-accent); transform: translateY(-1px); }
.account-card.is-archived { opacity: .6; }
.account-value { font-size: 1.5rem; font-weight: 650; letter-spacing: -.02em; }

/* --- Graphiques ----------------------------------------------------- */
.chart-box { position: relative; height: 300px; }
.chart-box-sm { height: 260px; }
@media (max-width: 575.98px) { .chart-box { height: 240px; } .chart-box-sm { height: 220px; } }
.period-picker { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.period-picker .btn { --bs-btn-padding-x: .55rem; font-size: .78rem; flex: 0 0 auto; }
@media (max-width: 575.98px) { .period-picker .btn { --bs-btn-padding-x: .38rem; font-size: .72rem; } }
.period-picker .btn.active { background: var(--sp-accent); border-color: var(--sp-accent); color: #fff; }

.market-strip { display: flex; flex-wrap: wrap; gap: .5rem; }
.market-chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: 999px; padding: .2rem .65rem; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; display: inline-block; }
.dot-open { background: var(--sp-gain); box-shadow: 0 0 0 3px rgba(47, 191, 113, .18); }
.dot-closed { background: var(--sp-muted); }

/* --- Tableaux ------------------------------------------------------- */
.data-table { --bs-table-bg: transparent; --bs-table-hover-bg: var(--sp-surface-2); font-size: .85rem; }
.data-table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--sp-muted); font-weight: 600; border-bottom-color: var(--sp-border); white-space: nowrap; padding-top: .6rem; padding-bottom: .6rem; }
.data-table td { border-color: var(--sp-border); padding-top: .5rem; padding-bottom: .5rem; }
.data-table td:first-child, .data-table th:first-child { padding-left: 1rem; }
.data-table td:last-child, .data-table th:last-child { padding-right: 1rem; }
.js-sortable th[data-sort] { cursor: pointer; user-select: none; }
.js-sortable th[data-sort]::after { content: " ↕"; opacity: .35; font-size: .7rem; }
.js-sortable th.sorted-asc::after { content: " ↑"; opacity: .9; }
.js-sortable th.sorted-desc::after { content: " ↓"; opacity: .9; }

.badge-soft-info { background: rgba(91, 141, 239, .15); color: #8fb1f5; }
.badge-soft-warning { background: rgba(240, 180, 41, .15); color: #e8b53a; }
.badge-soft-success { background: rgba(47, 191, 113, .15); color: var(--sp-gain); }
.badge-soft-danger { background: rgba(239, 83, 80, .15); color: var(--sp-loss); }
.badge-soft-secondary { background: var(--sp-surface-2); color: var(--sp-muted); }
[data-bs-theme="light"] .badge-soft-info { color: #2c5bc4; }
[data-bs-theme="light"] .badge-soft-warning { color: #8a6100; }

/* --- Formulaires ---------------------------------------------------- */
.form-control, .form-select { background-color: var(--sp-surface-2); border-color: var(--sp-border); }
.form-control:focus, .form-select:focus { border-color: var(--sp-accent); box-shadow: 0 0 0 .2rem rgba(91, 141, 239, .2); background-color: var(--sp-surface-2); }
.form-narrow { max-width: 760px; }
.form-wide { max-width: 1100px; }
.search-narrow { max-width: 380px; }
.tx-preview { background: var(--sp-surface-2); border: 1px dashed var(--sp-border); border-radius: .6rem; padding: .6rem .85rem; font-size: .85rem; }
.tx-preview:empty { display: none; }
.filter-bar { padding: .75rem 1rem; }
.settings-nav { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; }

/* --- États ---------------------------------------------------------- */
.empty-state { text-align: center; padding: 3rem 1rem; background: var(--sp-surface); border: 1px dashed var(--sp-border); border-radius: 1rem; }
.empty-state > i { font-size: 2.4rem; color: var(--sp-accent); display: block; margin-bottom: .75rem; }
.empty-inline { color: var(--sp-muted); font-size: .85rem; padding: .9rem 1rem; background: var(--sp-surface); border: 1px dashed var(--sp-border); border-radius: .75rem; }
.demo-banner { background: repeating-linear-gradient(-45deg, rgba(240, 180, 41, .12), rgba(240, 180, 41, .12) 10px, rgba(240, 180, 41, .06) 10px, rgba(240, 180, 41, .06) 20px); border: 1px solid rgba(240, 180, 41, .35); border-radius: .6rem; padding: .45rem .8rem; font-size: .8rem; margin-bottom: 1rem; }
.data-warnings { background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: .75rem; padding: .6rem .9rem; font-size: .85rem; }
.data-warnings summary { cursor: pointer; }
.alert { border-radius: .65rem; }

/* --- Pages publiques -------------------------------------------- */
.public-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 20% -10%, rgba(91, 141, 239, .16), transparent), var(--sp-bg); }
.public-main { width: 100%; padding: 1rem; }
.login-card { max-width: 400px; margin: 0 auto; background: var(--sp-surface); border: 1px solid var(--sp-border); border-radius: 1rem; padding: 2rem 1.75rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.login-logo { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto; display: grid; place-items: center; font-size: 1.6rem; color: #fff; background: linear-gradient(135deg, #5b8def, #3d63c9); }

.offcanvas-lg.app-sidebar { --bs-offcanvas-bg: var(--sp-sidebar); --bs-offcanvas-width: 270px; }

/* --- Mobile : KPI sur deux colonnes ------------------------------ */
@media (max-width: 575.98px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: .6rem; }
    .kpi-main, .kpi-perf { grid-column: 1 / -1; }
    .kpi { padding: .7rem .8rem; }
    .kpi-label { font-size: .68rem; }
    .kpi-value { font-size: 1.08rem; }
    .kpi-main .kpi-value { font-size: 1.5rem; }
    .kpi-sub { font-size: .72rem; }
    .page-title { font-size: 1.3rem; }
}

/* Import CSV */
.import-remark { min-width: 14rem; }

/* Alertes */
.alert-events .is-unread { border-left: 3px solid var(--bs-warning); }
[data-field][hidden] { display: none !important; }
.universe-filters { max-width: 100%; scrollbar-width: none; }
.universe-filters .nav-link { font-size: .875rem; }
.score-bar { width: 4.5rem; height: .4rem; border-radius: 1rem; background: var(--bs-secondary-bg); overflow: hidden; }
.score-bar > span { display: block; height: 100%; background: var(--bs-primary); border-radius: 1rem; }
.score-bar-wide { width: auto; height: .55rem; }
.component-label { width: 11rem; }
.component-value { width: 6.5rem; }
.reasons-cell { min-width: 16rem; }
.reason-list li + li { border-top: 1px solid var(--bs-border-color-translucent); }
.chart-box-lg { height: 340px; }
.chart-box-xs { height: 110px; }
.reco-bar { display: flex; height: .6rem; border-radius: 1rem; overflow: hidden; background: var(--bs-secondary-bg); }
.reco-bar > span { display: block; height: 100%; }
.reco-strong_buy { background: #1f9d5c; } .reco-buy { background: var(--sp-gain); } .reco-hold { background: var(--sp-muted); }
.reco-sell { background: #f78c6b; } .reco-strong_sell { background: var(--sp-loss); }
.news-list li + li { border-top: 1px solid var(--bs-border-color-translucent); }
.news-summary { color: var(--bs-secondary-color); }
@media (max-width: 575.98px) { .chart-box-lg { height: 260px; } .chart-box-xs { height: 90px; } }
