/* ─────────────────────────────────────────────────────────────────────────────
   TradingStocksBot — Styles globaux (dark theme)
───────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:          #0f172a;
  --bg-card:     #1e293b;
  --bg-card-alt: #263044;
  --border:      #334155;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --accent:      #3b82f6;
  --accent-h:    #2563eb;
  --retain:      #22c55e;
  --borderline:  #f59e0b;
  --reject:      #ef4444;
  --running:     #3b82f6;
  --failed:      #6b7280;
  --positive:    #22c55e;
  --negative:    #ef4444;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */

.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.3px;
}

.nav-brand:hover { color: var(--accent); }

.nav-sub {
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Page header ───────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.back-link {
  display: inline-block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 4px;
}

.back-link:hover { color: var(--text); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.card-error { border-color: var(--reject); }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

/* ── Formulaire d'évaluation ───────────────────────────────────────────────── */

.eval-form .form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 140px;
}

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.label-hint {
  font-weight: 400;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  opacity: 0.7;
}

.form-group input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus { border-color: var(--accent); }

.form-submit { flex: 0 0 auto; min-width: unset; }

/* ── Boutons ───────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg-card-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm:hover { border-color: var(--accent); color: var(--accent); }

/* ── Badges verdict ─────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.badge-lg {
  padding: 6px 18px;
  font-size: 14px;
  border-radius: var(--radius);
}

.badge-retain    { background: rgba(34,197,94,.15);  color: var(--retain);    border: 1px solid rgba(34,197,94,.3); }
.badge-borderline{ background: rgba(245,158,11,.15); color: var(--borderline);border: 1px solid rgba(245,158,11,.3);}
.badge-reject    { background: rgba(239,68,68,.15);  color: var(--reject);    border: 1px solid rgba(239,68,68,.3); }
.badge-running   { background: rgba(59,130,246,.15); color: var(--running);   border: 1px solid rgba(59,130,246,.3);}
.badge-failed    { background: rgba(107,114,128,.15);color: var(--failed);    border: 1px solid rgba(107,114,128,.3);}
.badge-unknown   { color: var(--text-muted); }

/* ── Tableau ────────────────────────────────────────────────────────────────── */

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.table-header h2 { margin-bottom: 0; }

.table-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input, .filter-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.search-input:focus, .filter-select:focus { border-color: var(--accent); }
.filter-select { cursor: pointer; }

.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text); }
.sort-icon { font-size: 10px; opacity: 0.5; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-card-alt); }

td {
  padding: 10px 12px;
  vertical-align: middle;
}

.muted { color: var(--text-muted); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.date-cell { font-size: 12px; color: var(--text-muted); }

/* ── Métriques grid ──────────────────────────────────────────────────────────── */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.metric-card.positive { border-color: rgba(34,197,94,.3); }
.metric-card.negative { border-color: rgba(239,68,68,.3); }

.metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.metric-card.positive .metric-value { color: var(--positive); }
.metric-card.negative .metric-value { color: var(--negative); }

/* ── Sous-périodes ───────────────────────────────────────────────────────────── */

.subperiod-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.subperiod-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.subperiod-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.mini-table {
  width: 100%;
  font-size: 13px;
}

.mini-table td {
  padding: 4px 6px;
  color: var(--text);
}

.mini-table td:first-child { color: var(--text-muted); }
.mini-table td:last-child  { text-align: right; font-weight: 500; }
.mini-table tr.positive td:last-child { color: var(--positive); }
.mini-table tr.negative td:last-child { color: var(--negative); }

/* ── Chart ───────────────────────────────────────────────────────────────────── */

.chart-container {
  position: relative;
  height: 300px;
}

/* ── Raisons ─────────────────────────────────────────────────────────────────── */

.reasons-card { border-left: 3px solid; }
.reasons-retain     { border-left-color: var(--retain);     background: rgba(34,197,94,.05); }
.reasons-borderline { border-left-color: var(--borderline); background: rgba(245,158,11,.05); }
.reasons-reject     { border-left-color: var(--reject);     background: rgba(239,68,68,.05); }

.reasons-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reasons-list li {
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
  font-size: 13px;
}

/* ── Error trace ──────────────────────────────────────────────────────────────── */

.error-trace {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  font-size: 12px;
  color: var(--reject);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
}

/* ── Running indicator ────────────────────────────────────────────────────────── */

.running-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── History table ────────────────────────────────────────────────────────────── */

.history-table thead th { font-size: 11px; }
.row-current { background: var(--bg-card-alt); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .subperiod-grid { grid-template-columns: 1fr; }
  .metrics-grid   { grid-template-columns: repeat(2, 1fr); }
  .form-row       { flex-direction: column; }
  .page-header    { flex-direction: column; }
}

/* ── Score badge ─────────────────────────────────────────────────────────────── */

.score-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.score-high { background: rgba(34,197,94,.18);  color: var(--retain);    }
.score-mid  { background: rgba(245,158,11,.18); color: var(--borderline);}
.score-low  { background: rgba(239,68,68,.18);  color: var(--reject);    }

/* ── Profil badge ────────────────────────────────────────────────────────────── */

.profile-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.profile-momentum    { background: rgba(59,130,246,.18);  color: #60a5fa; }
.profile-trend-propre{ background: rgba(34,197,94,.14);   color: #4ade80; }
.profile-volatile    { background: rgba(245,158,11,.18);  color: #fbbf24; }
.profile-chaotique   { background: rgba(239,68,68,.14);   color: #f87171; }

/* ── Badge "En cours" avec progress bar ─────────────────────────────────────── */

.badge-running-wrap {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}

.running-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--running);
}

.elapsed-time {
  font-weight: 400;
  opacity: 0.8;
  letter-spacing: 0;
}

.progress-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(59,130,246,.2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--running);
  border-radius: 2px;
  transition: width 0.8s ease;
}

.progress-fill.stuck {
  background: var(--borderline);
  animation: pulse-bar 1.5s ease-in-out infinite;
}

@keyframes pulse-bar {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Spinner inline (dans badge ou bouton) ────────────────────────────────────── */

.spinner-inline {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}

/* ── Tooltip sur badge failed ─────────────────────────────────────────────────── */

.has-tooltip {
  position: relative;
  cursor: help;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  max-width: 320px;
  white-space: normal;
  text-align: left;
}

.has-tooltip:hover::after { opacity: 1; }

/* ── Profils daily ────────────────────────────────────────────────────────────── */

.profile-momentum      { background: rgba(59,130,246,.14);  color: #60a5fa; }
.profile-trend-propre  { background: rgba(34,197,94,.12);   color: #4ade80; }
.profile-volatile      { background: rgba(245,158,11,.14);  color: #fbbf24; }
.profile-chaotique     { background: rgba(239,68,68,.10);   color: #f87171; }

/* ── Profils intraday ─────────────────────────────────────────────────────────── */

.profile-orb-solide   { background: rgba(34,197,94,.14);  color: #4ade80; }
.profile-orb-marginal { background: rgba(245,158,11,.14); color: #fbbf24; }
.profile-sans-edge    { background: rgba(239,68,68,.10);  color: #f87171; }

/* ── Coloring FC% ────────────────────────────────────────────────────────────── */

.fc-warn { color: #fbbf24; }

/* ── Intraday table — colonnes compactes ─────────────────────────────────────
   Le tableau intraday a 3 colonnes extra (FC%/Stop%/BE%) par rapport au daily.
   On réduit le padding sur toutes les colonnes intraday pour conserver le
   même rendu global sans scroll horizontal.
─────────────────────────────────────────────────────────────────────────────── */

#intradayTable th,
#intradayTable td {
  padding-left:  8px;
  padding-right: 8px;
}

/* Colonnes purement numériques : largeur fixe pour éviter l'élargissement */
#intradayTable th:nth-child(3),  /* Score   */
#intradayTable td:nth-child(3)  { width: 50px;  }

#intradayTable th:nth-child(5),  /* Trades  */
#intradayTable td:nth-child(5)  { width: 52px;  }

#intradayTable th:nth-child(7),  /* PF      */
#intradayTable td:nth-child(7)  { width: 44px;  }

#intradayTable th:nth-child(8),  /* WR      */
#intradayTable td:nth-child(8)  { width: 44px;  }

#intradayTable th:nth-child(9),  /* Max DD  */
#intradayTable td:nth-child(9)  { width: 54px;  }

#intradayTable th:nth-child(10), /* FC%     */
#intradayTable td:nth-child(10) { width: 42px;  }

#intradayTable th:nth-child(11), /* Stop%   */
#intradayTable td:nth-child(11) { width: 44px;  }

#intradayTable th:nth-child(12), /* BE%     */
#intradayTable td:nth-child(12) { width: 40px;  }

#intradayTable th:nth-child(14), /* Détail  */
#intradayTable td:nth-child(14) { width: 44px;  }

#intradayTable th:nth-child(16), /* ✕       */
#intradayTable td:nth-child(16) { width: 28px; padding-left: 4px; padding-right: 4px; }

/* ── Bouton "Ajouter au bot" ──────────────────────────────────────────────────── */

.btn-add-universe {
  background: rgba(59,130,246,.15);
  border-color: rgba(59,130,246,.4);
  color: #60a5fa;
  transition: background 0.15s, color 0.15s;
}

.btn-add-universe:hover {
  background: rgba(59,130,246,.3);
  color: #fff;
}

.btn-added {
  background: rgba(34,197,94,.12);
  border-color: rgba(34,197,94,.3);
  color: var(--retain);
  cursor: default;
  opacity: 0.8;
}

.btn-delete {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  opacity: 0.4;
  transition: opacity 0.15s, color 0.15s;
}

.btn-delete:hover {
  color: var(--reject);
  border-color: rgba(239,68,68,.3);
  opacity: 1;
}

/* ── Toggle de vue global ─────────────────────────────────────────────────── */

.view-toggle-bar {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
}

.view-btn {
  padding: 8px 28px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}

.view-btn:hover:not(.active) {
  background: var(--bg-card-alt);
  color: var(--text);
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Intraday detail page ─────────────────────────────────────────────────── */

.strategy-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  vertical-align: middle;
  margin-left: 8px;
}

/* Exit reasons breakdown */

.exits-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.exit-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exit-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.exit-label {
  min-width: 160px;
  font-weight: 500;
}

.exit-count {
  color: var(--text-muted);
  font-size: 12px;
  min-width: 70px;
}

.exit-pct {
  font-size: 12px;
  min-width: 40px;
  text-align: right;
}

.exit-bar-track {
  height: 6px;
  background: var(--bg-card-alt);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
  max-width: 400px;
}

.exit-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.exit-bar-fc   { background: rgba(239,68,68,.6); }
.exit-bar-stop { background: rgba(245,158,11,.6); }
.exit-bar-be   { background: rgba(34,197,94,.6); }
