/* Portofolium : poste de suivi de courtier. Chiffres denses et alignés, gain/perte colorés et marqués, rail encre.
   CSP style-src 'self' : aucun style en ligne ; les largeurs de barres passent par des attributs SVG. */

/* ---- Jetons ---- */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --hover: #eef2f7;
  --text: #111a27;
  --muted: #566376;
  --border: #dce2ea;
  --rule: #e8ecf1;
  --accent: #1f5fd6;
  --accent-hover: #184cb0;
  --accent-soft: #e6eefc;
  --accent-contrast: #ffffff;
  --gain: #0b7a43;
  --gain-soft: #e2f4ea;
  --loss: #c42a1f;
  --loss-soft: #fde8e6;
  --danger: var(--loss);
  --loss-fill: #c42a1f;
  --warning-bg: #fff3d1;
  --warning-text: #5e4100;
  --warning-line: #e7c35c;
  --success-bg: #e2f4ea;
  --success-text: #0d4f2e;
  --danger-bg: #fde8e6;
  --rail: #0e1828;
  --rail-2: #16233a;
  --rail-text: #b9c4d6;
  --rail-muted: #7d8aa1;
  --rail-active: #ffffff;
  --rail-accent: #6ea0ff;
  --s1: #1f5fd6; --s2: #12a39a; --s3: #e08a1e; --s4: #8b5bd6; --s5: #d4466f; --s6: #6b7a90;
  --focus: #1f5fd6;
  --radius: 8px;
  --radius-sm: 6px;
  --gutter: 16px;
  --rail-width: 15rem;
  --shadow-pop: 0 8px 24px rgba(14, 24, 40, .14), 0 2px 6px rgba(14, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1114; --surface: #16191e; --surface-2: #1b1f25; --hover: #21262e;
    --text: #e6e9ee; --muted: #9aa3b0; --border: #2b313a; --rule: #23282f;
    --accent: #5b93ff; --accent-hover: #7aa8ff; --accent-soft: #172a4a; --accent-contrast: #08111f;
    --gain: #3fcf8e; --gain-soft: #10291e; --loss: #ff6f63; --loss-soft: #33171a; --loss-fill: #d6372b;
    --warning-bg: #33290e; --warning-text: #ffd98a; --warning-line: #8a6a1d;
    --success-bg: #10291e; --success-text: #a9ecc8; --danger-bg: #33171a;
    --rail: #0e1828; --rail-2: #17243a; --rail-text: #aeb9cb; --rail-muted: #6f7c92; --rail-accent: #7aa8ff;
    --s1: #5b93ff; --s2: #2cc4b8; --s3: #f0a240; --s4: #a582f0; --s5: #f06a90; --s6: #8796ab;
    --focus: #7aa8ff;
    --shadow-pop: 0 10px 28px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1114; --surface: #16191e; --surface-2: #1b1f25; --hover: #21262e;
  --text: #e6e9ee; --muted: #9aa3b0; --border: #2b313a; --rule: #23282f;
  --accent: #5b93ff; --accent-hover: #7aa8ff; --accent-soft: #172a4a; --accent-contrast: #08111f;
  --gain: #3fcf8e; --gain-soft: #10291e; --loss: #ff6f63; --loss-soft: #33171a; --loss-fill: #d6372b;
  --warning-bg: #33290e; --warning-text: #ffd98a; --warning-line: #8a6a1d;
  --success-bg: #10291e; --success-text: #a9ecc8; --danger-bg: #33171a;
  --rail: #0e1828; --rail-2: #17243a; --rail-text: #aeb9cb; --rail-muted: #6f7c92; --rail-accent: #7aa8ff;
  --s1: #5b93ff; --s2: #2cc4b8; --s3: #f0a240; --s4: #a582f0; --s5: #f06a90; --s6: #8796ab;
  --focus: #7aa8ff;
  --shadow-pop: 0 10px 28px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* ---- Base ---- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--border) transparent; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); color: var(--text); }
a { color: var(--accent); text-decoration: none; text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 650; letter-spacing: -.01em; margin: 0 0 1rem; text-wrap: balance; }
h2 { font-size: 1rem; line-height: 1.3; font-weight: 650; margin: 1.75rem 0 .6rem; }
h3 { font-size: .875rem; font-weight: 650; margin: 1rem 0 .4rem; }
section > h2:first-child, .card > h2:first-child, .card > h3:first-child { margin-top: 0; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .9em; word-break: break-all; }
small { font-size: .8125rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .8125rem; font-weight: 400; }
.link { font-weight: 600; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: var(--gutter); top: var(--gutter); background: var(--surface); padding: .5rem .75rem; border-radius: var(--radius); z-index: 50; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- Coquille : rail encre + colonne de travail ---- */
.app { min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-text); }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem var(--gutter); }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: -.01em; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.nav-toggle-label { display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: 0 .7rem; border: 1px solid var(--rail-2); border-radius: var(--radius); color: var(--rail-text); cursor: pointer; font-weight: 600; }
.nav-toggle:focus-visible + .rail-head .nav-toggle-label { outline: 2px solid var(--rail-accent); outline-offset: 2px; }
.rail-body { display: none; padding: 0 .6rem .8rem; }
.nav-toggle:checked ~ .rail-body { display: block; }
.site-nav ul { list-style: none; margin: 0; padding: 0; }
.nav-group { margin-top: .9rem; }
.nav-group-title { padding: 0 .65rem .3rem; color: var(--rail-muted); font-size: .75rem; font-weight: 600; }
.site-nav a, .site-nav .soon { display: flex; align-items: center; gap: .65rem; min-height: 36px; padding: .35rem .65rem; border-radius: var(--radius-sm); color: var(--rail-text); font-weight: 550; text-decoration: none; }
.site-nav a:hover { background: var(--rail-2); color: #fff; }
.site-nav a[aria-current="page"] { background: var(--rail-2); color: var(--rail-active); }
.site-nav a[aria-current="page"] .icon { color: var(--rail-accent); }
.site-nav .soon { opacity: .55; cursor: not-allowed; }
.site-nav a:focus-visible { outline-color: var(--rail-accent); }
.count-badge { display: inline-block; margin-left: auto; min-width: 1.35rem; padding: 0 .4rem; border-radius: 999px; background: var(--loss-fill); color: #fff; font-size: .75rem; font-weight: 700; line-height: 1.35rem; text-align: center; }
.rail-foot { margin-top: 1rem; padding: .75rem .65rem 0; border-top: 1px solid var(--rail-2); display: flex; flex-direction: column; gap: .35rem; }
.rail-user { color: var(--rail-muted); font-size: .8125rem; overflow-wrap: anywhere; }
.logout { margin: 0; }
.rail .link-button { color: var(--rail-text); text-decoration: none; display: inline-flex; align-items: center; gap: .5rem; }
.rail .link-button:hover { color: #fff; }

.workspace { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: relative; z-index: 20; display: flex; align-items: center; justify-content: flex-end; gap: .5rem; padding: .55rem var(--gutter); background: color-mix(in srgb, var(--bg) 88%, transparent); border-bottom: 1px solid var(--rule); backdrop-filter: saturate(1.4) blur(8px); }
.topbar-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.container { flex: 1; width: 100%; max-width: 92rem; margin: 0 auto; padding: 1.25rem var(--gutter) 2.5rem; }
.site-footer { padding: .9rem var(--gutter); color: var(--muted); font-size: .75rem; border-top: 1px solid var(--rule); }

/* Menu déroulant natif (details/summary) : « + Opération » */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 14rem; padding: .35rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop); }
.menu-panel a { display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--text); font-weight: 550; }
.menu-panel a:hover { background: var(--hover); text-decoration: none; }
.menu-panel hr { border: 0; border-top: 1px solid var(--rule); margin: .3rem 0; }
.menu-panel .hint { display: block; padding: .3rem .65rem .1rem; }
.theme-toggle .when-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .when-dark { display: inline; }
:root[data-theme="dark"] .theme-toggle .when-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .when-dark { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .when-light { display: none; }
}

.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem var(--gutter); }
.auth-shell .brand { color: var(--text); margin-bottom: 1.25rem; font-size: 1.15rem; }
.auth-shell .container { flex: none; max-width: 30rem; padding: 0; }

@media (min-width: 64rem) {
  .app { display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr); }
  .rail { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; scrollbar-color: var(--rail-2) transparent; }
  .rail-head { padding: 1.1rem 1.15rem .4rem; }
  .nav-toggle-label { display: none; }
  .rail-body { display: flex; flex-direction: column; flex: 1; padding: 0 .65rem 1rem; }
  .rail-foot { margin-top: auto; }
  .topbar { position: sticky; top: 0; padding: .6rem 1.75rem; }
  .container { padding: 1.5rem 1.75rem 3rem; }
  .site-footer { padding: .9rem 1.75rem; }
  h1 { font-size: 1.75rem; }
}

/* ---- Boutons et liens d'action ---- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 38px; padding: .45rem .95rem; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-contrast); font: inherit; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap; transition: background-color .12s ease-out, border-color .12s ease-out;
}
.button:hover { background: var(--accent-hover); text-decoration: none; }
.button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.button.secondary:hover { background: var(--hover); border-color: var(--muted); }
.button.ghost { background: transparent; color: var(--text); border-color: transparent; }
.button.ghost:hover { background: var(--hover); }
.button.danger { background: var(--loss-fill); color: #fff; }
.button.danger:hover { background: color-mix(in srgb, var(--loss-fill) 85%, #000); }
.button[disabled], .button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.button .icon { width: 16px; height: 16px; }
.link-button { background: none; border: 0; padding: .25rem 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .75rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.chip { display: inline-flex; align-items: center; min-height: 34px; padding: .3rem .8rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 550; text-decoration: none; }
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.inline-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .35rem 0 0; }
.big-actions { gap: .75rem; }
.big-actions .button { min-height: 44px; }

/* ---- Surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; }
.card.attention { border-color: var(--loss); }
.auth-card { width: 100%; max-width: 30rem; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head h1, .page-head h2 { margin: 0; }
.page-head p { margin: .25rem 0 0; }
section + section { margin-top: 1.5rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin: 1.75rem 0 .6rem; }
.section-head h2 { margin: 0; }

/* Bandeau de chiffres (tuiles) : une surface, séparateurs fins, chiffres tabulaires. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 1px; margin: 0 0 1rem; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tile { background: var(--surface); padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.tile-label { color: var(--muted); font-size: .75rem; font-weight: 600; }
.tile-value { font-size: 1.25rem; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tile-value.small { font-size: 1rem; }
.tile-sub { color: var(--muted); font-size: .8125rem; }
.unavailable { color: var(--muted); font-style: italic; font-weight: 500; }

/* Accueil : chiffre de tête et répartition */
.overview { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem; }
.headline { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; display: grid; grid-template-columns: 1fr; gap: 1rem; }
.headline-main { display: flex; flex-direction: column; gap: .2rem; }
.headline-label { color: var(--muted); font-size: .8125rem; font-weight: 600; }
.headline-value { font-size: 2.25rem; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.headline-delta { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .9375rem; font-weight: 600; }
.headline-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1.25rem; margin: 0; }
.headline-stats div { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.headline-stats dt { color: var(--muted); font-size: .75rem; font-weight: 600; }
.headline-stats dd { margin: 0; font-size: 1.0625rem; font-weight: 650; }
.headline .badge { margin-left: .25rem; }
@media (min-width: 48rem) {
  .headline { grid-template-columns: minmax(16rem, 1.1fr) 2fr; align-items: center; }
  .headline-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); padding-left: 1.25rem; border-left: 1px solid var(--rule); }
}

.allocation { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.allocation-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin-bottom: .6rem; }
.allocation-head h2 { margin: 0; }
.alloc-bar { display: block; width: 100%; height: 14px; border-radius: 4px; overflow: hidden; }
.alloc-bar rect { stroke: var(--surface); stroke-width: .35; vector-effect: non-scaling-stroke; }
.alloc-legend { list-style: none; margin: .75rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: .1rem 1.5rem; }
.alloc-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: .55rem; padding: .35rem 0; border-bottom: 1px solid var(--rule); font-size: .8125rem; }
.alloc-legend .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-legend .pct { color: var(--muted); min-width: 3.4rem; text-align: right; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }
.seg-1 { fill: var(--s1); } .seg-2 { fill: var(--s2); } .seg-3 { fill: var(--s3); } .seg-4 { fill: var(--s4); } .seg-5 { fill: var(--s5); } .seg-6 { fill: var(--s6); }
.seg-cash { fill: var(--border); }

/* ---- Gain / perte ---- */
.gain { color: var(--gain); }
.loss, .negative { color: var(--loss); }
.delta { white-space: nowrap; font-weight: 600; }
.delta.gain::before, .delta.loss::before { content: ""; display: inline-block; width: 0; height: 0; margin-right: .3em; vertical-align: .12em; border-left: .32em solid transparent; border-right: .32em solid transparent; }
.delta.gain::before { border-bottom: .42em solid currentColor; }
.delta.loss::before { border-top: .42em solid currentColor; }
.pill { display: inline-block; padding: .05rem .4rem; border-radius: 4px; font-size: .75rem; font-weight: 650; }
.pill.gain { background: var(--gain-soft); }
.pill.loss { background: var(--loss-soft); }

/* ---- Formulaires ---- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; min-width: 0; }
label, .label { font-weight: 600; font-size: .8125rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], input[type="url"], select, textarea {
  width: 100%; font: inherit; padding: .45rem .65rem; min-height: 38px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  transition: border-color .12s ease-out, box-shadow .12s ease-out;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--muted) 60%, var(--border)); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly] { background: var(--surface-2); }
textarea { min-height: 6rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.field.check { flex-direction: row; align-items: center; gap: .55rem; }
.field.check input[type="checkbox"], .field.check input[type="radio"] { flex: none; }
.field.check label { font-size: .875rem; font-weight: 550; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
fieldset.field { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; margin-inline: 0; }
fieldset.field legend { padding: 0 .35rem; font-weight: 600; font-size: .8125rem; }
.form-card { max-width: 46rem; }
.form-error, .field-error { color: var(--loss); }
.form-error:not(:empty) { margin-bottom: .75rem; }
.validation-summary-valid { display: none; } /* CSP style-src 'self' : le style="display:none" en ligne du résumé vide est ignoré */
.form-error ul { margin: 0; padding-left: 1.1rem; }
.inline-form { display: grid; grid-template-columns: 1fr; gap: 0 1rem; margin-top: 1rem; }
.inline-form.wrap { flex-wrap: wrap; }
.filters { display: grid; grid-template-columns: 1fr; gap: 0 .75rem; align-items: end; padding: .75rem .9rem .1rem; }
.filters .field { margin-bottom: .65rem; }
.split-cards { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.split-cards.allocations { gap: 1rem; margin-bottom: .5rem; }
.split-cards.allocations > section { margin-top: 0; }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }

/* ---- Messages ---- */
.notice { padding: .65rem .85rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid transparent; }
.notice.success { background: var(--success-bg); color: var(--success-text); border-color: color-mix(in srgb, var(--gain) 30%, transparent); }
.warning { background: var(--warning-bg); color: var(--warning-text); padding: .65rem .85rem; border-radius: var(--radius); border: 1px solid var(--warning-line); margin: 0 0 1rem; }
.notice ul, .warning ul, .form-error ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.inline-warning { display: block; color: var(--warning-text); background: var(--warning-bg); border-radius: var(--radius-sm); padding: .15rem .45rem; margin-top: .25rem; font-size: .8125rem; }
.outcome h3 { font-size: .9375rem; margin: 1rem 0 .25rem; }
.outcome .form-error { background: var(--danger-bg); padding: .65rem .85rem; border-radius: var(--radius); }
.status { min-height: 1.5rem; margin: .5rem 0 0; }
.htmx-request .status, .htmx-request.status { opacity: .6; }
.htmx-request { transition: opacity .15s ease-out; }

/* ---- Badges ---- */
.badge { display: inline-block; margin-left: .3rem; padding: 0 .4rem; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: .6875rem; font-weight: 650; line-height: 1.5; vertical-align: .1em; white-space: nowrap; }
.badge.big { font-size: .875rem; padding: .2rem .7rem; margin-left: 0; }
.badge.stale, .badge.cycle-missing, .badge.suspect, .badge.llm, .badge.no-snapshot { border-color: var(--warning-line); color: var(--warning-text); background: var(--warning-bg); }
.badge.alt { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); background: var(--accent-soft); }
.badge.manual { border-color: var(--border); color: var(--muted); }
.badge.incomplete, .badge.open { border-color: color-mix(in srgb, var(--loss) 45%, transparent); color: var(--loss); background: var(--loss-soft); }
.badge.ok { border-color: color-mix(in srgb, var(--gain) 45%, transparent); color: var(--gain); background: var(--gain-soft); }
.badge.decision { color: var(--text); }
.decision-buy { border-color: color-mix(in srgb, var(--gain) 45%, transparent); color: var(--gain); background: var(--gain-soft); }
.decision-sell { border-color: color-mix(in srgb, var(--loss) 45%, transparent); color: var(--loss); background: var(--loss-soft); }
.decision-hold, .decision-wait, .decision-skip { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); background: var(--accent-soft); }

/* ---- Tableaux denses ---- */
.table-wrap { overflow-x: auto; margin: 0 0 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .8125rem; }
.table-wrap > table.data { border: 0; }
table.data th, table.data td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data thead th { background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 600; white-space: nowrap; border-bottom-color: var(--border); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--hover); }
table.data .num { text-align: right; white-space: nowrap; }
table.data td.num strong { font-weight: 650; }
table.data tr.closed td, table.data tr.deleted td { color: var(--muted); }
table.data tr.deleted td:not(.row-actions) { text-decoration: line-through; }
table.data.compact th, table.data.compact td { padding: .35rem .6rem; }
table.data td > a:first-child { font-weight: 600; }
.cell-sub { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; }
.row-actions { white-space: nowrap; }
.row-actions a { margin-right: .75rem; }
.plain-list { list-style: none; padding: 0; margin: .5rem 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--rule); }
.plain-list form { margin: 0; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .4rem 0; border-bottom: 1px solid var(--rule); }
.status-list { display: grid; grid-template-columns: 1fr; gap: .15rem 1rem; margin: 0 0 1rem; }
.status-list dt { color: var(--muted); font-weight: 600; margin-top: .5rem; }
.status-list dd { margin: 0; }
.cycles { margin-top: .2rem; font-size: .75rem; color: var(--muted); }
.cycles ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.cycles summary { cursor: pointer; min-height: 22px; width: max-content; }
.quote-cell strong { font-weight: 650; }
.quote-cell small { display: block; color: var(--muted); font-size: .75rem; white-space: normal; }
.weight { display: inline-flex; align-items: center; gap: .45rem; justify-content: flex-end; }
.weight svg { width: 36px; height: 6px; border-radius: 3px; overflow: hidden; }
.weight .track { fill: var(--rule); }
.weight .fill { fill: var(--accent); }

@media (max-width: 47.99rem) {
  /* Tableaux en cartes sur mobile : une ligne par champ, libellé issu de data-label. */
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  table.data, table.data tbody, table.data tfoot, table.data tr, table.data td, table.data tfoot th { display: block; }
  table.data td.empty { display: none; }
  table.data { background: transparent; }
  table.data thead { position: absolute; left: -999px; }
  table.data tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem 0; margin-bottom: .6rem; }
  table.data tbody tr:hover td { background: transparent; }
  table.data td { border: 0; padding: .2rem .8rem; text-align: left !important; white-space: normal !important; }
  table.data td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: .75rem; }
  table.data td.row-actions { padding-top: .5rem; }
}

/* ---- Journal ---- */
.timeline { list-style: none; margin: .5rem 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; overflow-wrap: anywhere; }
.note-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; font-size: .8125rem; color: var(--muted); }
.note-head .badge { margin-left: 0; }
.note-instrument { font-weight: 650; color: var(--text); }
.note-meta { display: flex; flex-wrap: wrap; gap: .15rem 1rem; margin: .5rem 0 0; font-size: .8125rem; }
.note-meta .superseded { font-style: italic; }
.note-links { margin: .5rem 0 0; padding-left: 1.1rem; }
.markdown { margin-top: .5rem; max-width: 75ch; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { font-size: 1rem; margin: .75rem 0 .25rem; }
.markdown pre, .markdown code { background: var(--surface-2); border-radius: var(--radius-sm); }
.markdown pre { padding: .5rem; overflow-x: auto; }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: .2rem .5rem; }
.markdown blockquote { margin: .5rem 0; padding-left: .75rem; border-left: 1px solid var(--border); color: var(--muted); }
.pager { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0; }

/* ---- Courbes ---- */
.chart { margin: 0 0 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem .6rem; }
.chart h3 { margin: 0 0 .4rem; font-size: .875rem; }
.chart-canvas { width: 100%; min-height: 260px; }
.chart .u-legend { font-size: .75rem; text-align: left; color: var(--muted); }
.chart .u-legend .u-value { color: var(--text); font-weight: 600; }
.perf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: .75rem; }
.perf-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.perf-card h3 { margin: 0 0 .5rem; font-size: .875rem; }
.perf-card dl { margin: 0 0 .5rem; display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; font-size: .8125rem; }
.perf-card dt { color: var(--muted); }
.perf-card dd { margin: 0; text-align: right; font-weight: 600; }
.perf-card .hint { font-size: .75rem; margin: 0; }

/* ---- Authentification, accès LLM ---- */
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .5rem; }
.codes li { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .4rem .6rem; text-align: center; font-family: var(--mono); }
.qr { text-align: center; }
.qr img { max-width: 100%; height: auto; background: #fff; padding: 8px; border-radius: var(--radius); }
.secret { display: block; padding: .6rem .75rem; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: var(--radius-sm); user-select: all; word-break: break-all; font-family: var(--mono); }
.snippet { margin: .25rem 0 1rem; padding: .6rem .75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; font-size: .8125rem; }
.snippet code { word-break: normal; white-space: pre; }
.snapshot-json { max-height: 32rem; overflow: auto; padding: .6rem .75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .75rem; }
.snapshot-json code { word-break: normal; white-space: pre; }
#clients td code { display: inline-block; word-break: normal; overflow-wrap: anywhere; margin: 0 .25rem .15rem 0; }
.consent-facts dd { margin: 0 0 .5rem; }

/* ---- Saisie d'opération : formulaire + aperçu latéral ---- */
.entry-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
.entry-layout > .card { margin-bottom: 0; }
.entry-aside { display: flex; flex-direction: column; gap: 1rem; }
@media (min-width: 80rem) {
  .entry-layout { grid-template-columns: minmax(0, 46rem) minmax(18rem, 1fr); }
  .entry-aside { position: sticky; top: 4.25rem; }
}

@media (min-width: 48rem) {
  .field-row { grid-template-columns: 1fr 1fr; }
  .inline-form { grid-template-columns: repeat(4, 1fr); align-items: end; }
  .inline-form .button { grid-column: 1 / -1; justify-self: start; }
  .filters { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
  .split-cards { grid-template-columns: 1fr 1fr; }
  .status-list { grid-template-columns: 12rem 1fr; }
  .status-list dt { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.entry-preview-title { font-size: .875rem; margin: 0 0 .6rem; }
.entry-preview .actions { border-top: 1px solid var(--rule); padding-top: .85rem; margin-top: .85rem; }
.entry-preview .outcome h3:first-child { margin-top: 0; }

/* Accueil : courbes valeur et gain côte à côte, sans le détail (disponible dans Courbes). */
#home-curve > #curve-performance, #home-curve > details { display: none; }
@media (min-width: 80rem) {
  #home-curve { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1rem; }
  #home-curve > :not(.chart) { grid-column: 1 / -1; }
}

/* Recherche d'instrument : liste de choix compacte et défilante, ligne choisie surlignée. */
.instrument-results { max-height: 17rem; overflow-y: auto; margin: .35rem 0 .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.instrument-results > .hint { padding: .5rem .65rem; margin: 0; }
.instrument-results .field.check { margin: 0; padding: .35rem .65rem; border-bottom: 1px solid var(--rule); }
.instrument-results .field.check:last-child { border-bottom: 0; }
.instrument-results .field.check:hover { background: var(--hover); }
.instrument-results .field.check:has(input:checked) { background: var(--accent-soft); }
.instrument-results label { font-weight: 500; cursor: pointer; }

/* Positions : colonnes stables, cours libellé (le montant en gras de la cellule est la valeur). */
#positions td:first-child { min-width: 11.5rem; max-width: 20rem; }
#positions td:first-child > a:first-child { display: block; max-width: 16rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#positions td:first-child .cell-sub { display: inline; margin-right: .5rem; }
#positions .cycles { display: inline-block; margin-top: 0; }
#positions th, #positions td { padding-left: .5rem; padding-right: .5rem; }
#positions thead th { white-space: normal; vertical-align: bottom; }
#positions td[data-label="Compte"] { min-width: 7rem; }
#positions td[data-label="Compte"] .link { display: block; font-size: .75rem; font-weight: 500; }
#positions .quote-cell small { max-width: 11.5rem; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#positions .quote-cell { display: block; margin-top: .15rem; }
#positions .quote-cell > strong { font-weight: 550; }
#positions .quote-cell > strong::before { content: "Cours "; color: var(--muted); font-weight: 400; }
.filters.compact { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; padding: .7rem .9rem; }
.filters.compact .field { margin: 0; min-width: 13rem; }

/* Méthodes de calcul repliées : la règle reste lisible sans peser sur la page. */
details.method { max-width: 75ch; margin: .25rem 0 1rem; color: var(--muted); font-size: .8125rem; }
details.method summary { cursor: pointer; width: max-content; font-weight: 600; }
details.method p { margin: .35rem 0 0; }

/* Tri par en-tête (liens serveur, sans script) : flèche CSS sur la colonne active. */
table.data thead a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: .3em; }
table.data thead a.sort:hover { color: var(--text); }
table.data thead a.sort.asc, table.data thead a.sort.desc { color: var(--accent); }
table.data thead a.sort.asc::after, table.data thead a.sort.desc::after { content: ""; border-left: .3em solid transparent; border-right: .3em solid transparent; }
table.data thead a.sort.asc::after { border-bottom: .38em solid currentColor; }
table.data thead a.sort.desc::after { border-top: .38em solid currentColor; }
.sort-group { display: inline-flex; gap: .55rem; justify-content: flex-end; }
table.data thead .cell-sub { font-size: .6875rem; font-weight: 500; }

/* Ligne de totaux : même grille, séparée par un filet fort. */
table.data tfoot th, table.data tfoot td { background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; font-weight: 650; text-align: left; }
table.data tfoot th { color: var(--text); }
table.data tfoot .num { text-align: right; }
table.data tfoot .cell-sub { font-weight: 400; }
@media (max-width: 47.99rem) {
  #positions .quote-cell small { margin-left: 0; max-width: 100%; }
  table.data tfoot tr { background: var(--surface-2); }
  table.data tfoot th, table.data tfoot td { border-top: 0; background: transparent; }
}

/* Tableau à en-tête fixe : le cadre défile dans les deux sens (hauteur de l'écran moins la barre haute),
   l'en-tête reste en haut et les totaux en bas. Les filets passent en ombres internes : une bordure de cellule collante disparaît au défilement. */
@media (min-width: 48rem) {
  .table-wrap.scroll { max-height: calc(100vh - 4.5rem); overflow: auto; }
  .table-wrap.scroll thead th { position: sticky; top: 0; z-index: 2; border-bottom: 0; box-shadow: inset 0 -1px 0 var(--border); }
  .table-wrap.scroll tfoot th, .table-wrap.scroll tfoot td { position: sticky; bottom: 0; z-index: 2; border-top: 0; box-shadow: inset 0 1px 0 var(--border); }
}
@media (max-width: 89.99rem) {
  /* Écrans de portable : le poids se lit en %, la mini-barre disparaît pour garder toutes les colonnes visibles. */
  #positions .weight svg { display: none; }
  #positions { font-size: .78rem; }
  #positions td:first-child > a:first-child { max-width: 11.5rem; }
  #positions td[data-label="Compte"] { min-width: 4.5rem; }
}

/* Filtre segmenté (liens) : ouvertes / clôturées / toutes. */
.segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.segmented a { padding: .3rem .75rem; border-radius: var(--radius-sm); color: var(--muted); font-size: .8125rem; font-weight: 600; text-decoration: none; }
.segmented a:hover { color: var(--text); }
.segmented a[aria-current] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(14, 24, 40, .12); }

/* Ancres (#positions-title…) : le titre visé ne passe pas sous la barre haute collante. */
h2[id] { scroll-margin-top: 4.5rem; }
