:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --accent: #c9a96e;
  --accent-ink: #1a1a19;
  --up: #0ca30c;
  --down: #e66767;
  --error: #e66767;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  --other: #5c5b57;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --accent: #8a6a2f;
  --accent-ink: #ffffff;
  --up: #006300;
  --down: #d03b3b;
  --error: #d03b3b;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #4a3aa7;
  --s8: #e34948;
  --other: #c3c2b7;
}

* { box-sizing: border-box; }
/* Aucun glissement horizontal de la page, même si un élément déborde. */
html, body { overflow-x: hidden; overflow-x: clip; max-width: 100%; }
.show-sm { display: none; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.error { color: var(--error); font-size: 13px; margin: 8px 0 0; }

/* Connexion */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(360px, 100%); display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px;
}
.auth-card .brand { font-size: 20px; }
.auth-card p { margin: 0; }
.auth-card input {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--page);
}
.auth-card .btn { justify-content: center; padding: 11px; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap; }
.logo { width: 24px; height: 24px; vertical-align: -6px; border-radius: 6px; }
.wordmark { font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif; font-weight: 600; font-size: 20px; letter-spacing: 0.28em; margin-left: 4px; }
.actions { display: flex; align-items: center; gap: 6px; position: relative; }

.tabs { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; color: var(--text-2); padding: 6px 14px; border-radius: 9px;
  cursor: pointer; font-size: 14px; white-space: nowrap;
}
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--up); animation: pulse 2s infinite; }
.live.err i { background: var(--down); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); display: grid;
}
.menu button, .menu label {
  text-align: left; background: transparent; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.menu button:hover, .menu label:hover { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { padding: 8px 10px; }
.btn.danger { color: var(--down); background: transparent; }

.ticker { min-height: 46px; border-bottom: 1px solid var(--border); }
.ticker:empty { display: none; }

.container { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }
.foot { text-align: center; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px 22px; min-width: 0; }
.card h2 { margin: 0 0 16px; font-size: 15px; font-weight: 600; color: var(--text-2); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* Chiffre héros */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 28px; }
.hero-label { color: var(--text-2); font-size: 14px; }
.hero-value { font-size: 44px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0 6px; }
.hero-deltas { display: flex; gap: 18px; flex-wrap: wrap; font-size: 15px; font-weight: 550; }
.hero-deltas > span:empty { display: none; }
.hero-deltas .lbl { color: var(--muted); font-weight: 400; font-size: 13px; }
.hero-sub { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* Répartition */
.stack { display: flex; height: 14px; gap: 2px; margin-bottom: 16px; }
.stack span { display: block; min-width: 3px; height: 100%; }
.stack span:first-child { border-radius: 4px 0 0 4px; }
.stack span:last-child { border-radius: 0 4px 4px 0; }
.stack span:only-child { border-radius: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 10px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.legend .val { font-variant-numeric: tabular-nums; color: var(--text-2); }
.legend .pct { font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; font-weight: 600; white-space: nowrap; }

/* Historique */
.history { position: relative; height: 240px; }
.history svg { width: 100%; height: 100%; display: block; overflow: visible; }
.history .placeholder { height: 100%; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 0 16px; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; cursor: pointer; font-size: 13px; color: var(--text-2);
}
.chip.active { background: var(--text); color: var(--page); border-color: transparent; }

/* Tableau */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.positions { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.positions th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
.positions td { padding: 12px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.positions tr:last-child td { border-bottom: 0; }
.positions tbody tr { cursor: pointer; }
.positions tbody tr:hover { background: var(--surface-2); }
.positions .num { text-align: right; }
.asset { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff;
}
.asset-name { font-weight: 550; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.asset-sym { font-size: 12px; color: var(--muted); }
.sub { font-size: 12px; }
.flash-up { animation: flashUp 1.2s; }
.flash-down { animation: flashDown 1.2s; }
@keyframes flashUp { from { background: color-mix(in srgb, var(--up) 25%, transparent); } }
@keyframes flashDown { from { background: color-mix(in srgb, var(--down) 25%, transparent); } }

.empty { text-align: center; padding: 28px 0 8px; color: var(--text-2); }
.empty p { margin: 0 0 14px; }

/* Modales */
.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 22px;
  background: var(--surface); color: var(--text);
  width: min(580px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
.modal.wide { width: min(1000px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; gap: 8px; margin-top: 20px; }
.spacer { flex: 1; }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 2px; background: var(--page); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg button { border: 0; background: transparent; padding: 7px; border-radius: 8px; cursor: pointer; color: var(--text-2); }
.seg button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); align-content: start; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select {
  padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--page); color: var(--text); width: 100%;
}
.search { position: relative; }
.suggest {
  margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); max-height: 280px; overflow-y: auto;
}
.suggest button {
  display: flex; width: 100%; justify-content: space-between; gap: 12px; text-align: left;
  background: transparent; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text);
}
.suggest button:hover, .suggest button.focus { background: var(--surface-2); }
.suggest .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.picked {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
}
.picked b { display: block; }
.picked .price { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }

.detail-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.detail-stats div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.detail-stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.detail-stats span { font-size: 12px; color: var(--muted); }
.tv-chart { height: 480px; border-radius: 10px; overflow: hidden; }
.tv-chart .placeholder { height: 100%; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); text-align: center; padding: 16px; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); overflow: visible; }
  .tabs button { padding: 7px 4px; }
  .container { padding: 16px; gap: 16px; }
  .grid { grid-template-columns: 1fr; gap: 16px; }
  .hero { padding: 22px; }
  .hero-value { font-size: 34px; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  /* Le tableau tient exactement dans la carte ; les noms trop longs sont tronqués. */
  .table-wrap { overflow-x: hidden; margin: 0; padding: 0; }
  .positions { table-layout: fixed; }
  .positions th.num:not(.hide-sm) { width: 32%; }
  .positions td, .positions th { padding-left: 4px; padding-right: 4px; }
  .positions td:first-child { overflow: hidden; }
  .asset > div { min-width: 0; }
  .asset-name, .asset-sym { max-width: none; overflow: hidden; text-overflow: ellipsis; }
  /* 16 px minimum : sinon Safari iOS zoome sur le champ et la page glisse sur le côté. */
  input, select, textarea { font-size: 16px !important; }
  .detail-stats { grid-template-columns: 1fr 1fr; }
  .tv-chart { height: 360px; }
  .form-grid { grid-template-columns: 1fr; }
  .live #live-text { display: none; }
}

/* Le widget TradingView ne reste transparent que si l'iframe garde le jeu de couleurs par défaut. */
.tradingview-widget-container iframe { color-scheme: light; }
