:root {
  --bg: #0e0f13;
  --panel: #181a22;
  --panel-2: #1f2230;
  --border: #2a2d3a;
  --text: #e8e9ee;
  --muted: #8b8f9c;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #4c8dff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  flex-wrap: wrap;
}

h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

/* ---- indices ---- */
.indices {
  display: flex;
  gap: 12px;
  flex: 1;
  flex-wrap: wrap;
}

.index {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 200px;
  flex: 1;
}

.index-info {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
}

.index-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.index-value { font-size: 16px; font-weight: 600; }
.index-change { font-size: 12px; font-weight: 600; }
.index-spark { flex: 1; height: 40px; min-width: 60px; }

/* ---- controls ---- */
.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px 12px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 460px;
}

#search {
  width: 100%;
  padding: 9px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
}
.search-results.open { display: block; }

.result {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.result:last-child { border-bottom: none; }
.result:hover { background: var(--panel-2); }
.r-sym { font-weight: 700; min-width: 64px; }
.r-name { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-exch { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---- period selector ---- */
.periods {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
}

.period-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.period-btn:hover { color: var(--text); }
.period-btn.active { background: var(--accent); color: #fff; }

/* ---- onglets de groupes ---- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  flex-wrap: wrap;
}

.tab {
  display: flex;
  align-items: center;
  border-radius: 6px;
  overflow: hidden;
}
.tab.active { background: var(--accent); }

.tab-name {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-name:hover { color: var(--text); }
.tab.active .tab-name { color: #fff; }

/* L'onglet « Tout » a sa couleur propre (violet) pour le démarquer
   du bleu des groupes — c'est la vue cumulée maître. */
.tab[data-tab="main"] .tab-name { color: #c4b5fd; }
.tab[data-tab="main"] .tab-name:hover { color: #ddd6fe; }
.tab[data-tab="main"].active { background: #a855f7; }
.tab[data-tab="main"].active .tab-name { color: #fff; }
.tab[data-tab="main"].tab-flash { animation-name: tab-flash-tout; }
@keyframes tab-flash-tout {
  0% { background: #a855f7; }
  100% { background: transparent; }
}

.tab-icon {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  font-size: 11px;
  padding: 7px 5px;
}
.tab-icon:hover { color: #fff; }

.tab-add {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 11px;
  border-radius: 6px;
}
.tab-add:hover { color: var(--text); background: var(--panel-2); }

/* glisser une carte vers un onglet */
.tabs.drag-active {
  outline: 1px dashed var(--accent);
  outline-offset: 3px;
}
.tab.drop-target {
  background: rgba(76, 141, 255, 0.25);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.tab-flash { animation: tab-flash 0.5s ease-out; }
@keyframes tab-flash {
  0% { background: var(--accent); }
  100% { background: transparent; }
}
.tab.active.tab-flash { animation: none; }

.card-fallback {
  pointer-events: none;
  opacity: 0.92;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  cursor: grabbing;
}

/* ---- main / grid ---- */
main { padding: 20px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.card-ghost { opacity: .4; }

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }

.card-title { display: flex; flex-direction: column; min-width: 0; }
.ticker { font-weight: 700; font-size: 15px; }
.name { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-quote {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  white-space: nowrap;
}
.price { font-weight: 600; font-size: 15px; }
.change { font-size: 12px; font-weight: 600; }

.remove {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
}
.remove:hover { color: var(--down); background: var(--panel-2); }

.chart-wrap { position: relative; }
.chart { height: 240px; width: 100%; }

/* Logo TradingView intrusif sur chaque graphique : masqué ici,
   l'attribution est conservée dans le pied de page. */
#tv-attr-logo,
a[id^="tv-attr-logo"] { display: none !important; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

/* ---- empty state ---- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}
.suggestions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.chip:hover { border-color: var(--accent); }

.options {
  display: flex;
  justify-content: center;
  padding: 20px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  user-select: none;
}
.opt:hover { border-color: var(--border); }
.opt input { cursor: pointer; accent-color: #f5a623; width: 15px; height: 15px; }
.opt strong { color: #f5a623; font-weight: 700; }

footer {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 8px 20px 32px;
  line-height: 1.6;
}

@media (max-width: 640px) {
  .bar { gap: 12px; }
  .index { min-width: 100%; }
  .controls { flex-direction: column; align-items: stretch; }
  .search-box { max-width: none; }
  .periods { justify-content: space-between; }
  .period-btn { flex: 1; padding: 8px 4px; }
}
