:root {
  --bg: #070b14;
  --surface: #0e1424;
  --surface-2: #131c30;
  --border: rgba(255,255,255,0.07);
  --text: #e8edf5;
  --muted: #8a93a6;
  --accent: #4a6cf7;
  --accent-text: #ffffff;
  --accent-soft: rgba(74,108,247,0.15);
  --green: #2ecf86;
  --red: #ff5c79;
  --grid: rgba(255,255,255,0.04);
  --tick: #5c6577;
  --glow-1: rgba(74,108,247,0.12);
  --glow-2: rgba(46,207,134,0.06);
  --radius: 14px;
  --font-ui: 'Sora', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* Thème clair "Vanille" */
[data-theme="vanilla"] {
  --bg: #ece3cf;
  --surface: #f6efe0;
  --surface-2: #efe6d1;
  --border: rgba(0,0,0,0.10);
  --text: #2b2618;
  --muted: #837954;
  --accent: #b8923f;
  --accent-text: #ffffff;
  --accent-soft: rgba(184,146,63,0.18);
  --green: #1f7a4d;
  --red: #c0392b;
  --grid: rgba(0,0,0,0.10);
  --tick: #837954;
  --glow-1: rgba(184,146,63,0.22);
  --glow-2: rgba(47,158,99,0.10);
}


* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 85% -15%, var(--glow-1), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, var(--glow-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.logo { height: 38px; }

/* Buttons */
button {
  font-family: var(--font-ui); font-weight: 600; font-size: 14px;
  padding: 11px 18px; border: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-text, #fff); cursor: pointer;
  transition: transform .15s ease, filter .15s ease, border-color .15s ease, background .15s ease;
}
button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(0); }

.topbar button {
  background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 9px 16px;
}
.topbar button:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); filter: none; }

/* Stats */
.stats-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); padding: 18px; border-radius: var(--radius); }
.stat-card h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.stat-card p { margin: 0; font-family: var(--font-mono); font-size: 23px; font-weight: 700; letter-spacing: -0.02em; }
#gains { color: var(--green); }
#losses { color: var(--red); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  padding: 22px; border-radius: var(--radius);
  transition: border-color .2s ease, transform .2s ease;
}
.card h2 { margin: 0 0 16px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card > button { width: 100%; margin-top: 14px; }

/* Inputs */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
input, select {
  width: 100%; padding: 11px 12px; font-family: var(--font-ui); font-size: 14px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; margin: 5px 0;
}
input::placeholder { color: #5c6577; }
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* Layout */
.dashboard { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; margin-bottom: 18px; }
.side { display: flex; flex-direction: column; gap: 18px; }

#equityChart { height: 320px !important; }
#pieChart { height: 230px !important; }
.card canvas { margin-top: 6px; }

/* Table */
.table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  padding: 10px; text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 10px; border-bottom: 1px solid rgba(255,255,255,0.04); }
td.num { font-family: var(--font-mono); }
tbody tr:hover { background: rgba(255,255,255,0.025); }
tbody tr:last-child td { border-bottom: none; }
td button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 4px 9px; font-size: 12px; border-radius: 7px;
}
td button:hover { color: var(--red); border-color: var(--red); background: rgba(255,92,121,0.08); filter: none; transform: none; }

/* Entrance animation */
.stat-card, .card { animation: rise .5s ease both; }
.stat-card:nth-child(2) { animation-delay: .04s; }
.stat-card:nth-child(3) { animation-delay: .08s; }
.stat-card:nth-child(4) { animation-delay: .12s; }
.stat-card:nth-child(5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Auth page */
.auth-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card h2 { margin: 0 0 18px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.auth-logo { height: 50px; width: auto; display: block; margin: 0 auto 14px; }
.auth-card input { margin: 8px 0; }
.auth-card button { width: 100%; margin-top: 8px; }
.error { color: var(--red); min-height: 18px; font-size: 13px; margin: 8px 0; }
.switch { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* Responsive */
@media (max-width: 860px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .dashboard { grid-template-columns: 1fr; }
}

/* === Ajouts : ligne de stats sous le graphique === */
#equityChart { height: 360px !important; }
#pieChart { height: 200px !important; }
#monthlyChart { height: 200px !important; }

.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 18px; align-items: start; margin-bottom: 18px;
}

.metrics { list-style: none; margin: 0; padding: 0; }
.metrics li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.metrics li:last-child { border-bottom: none; }
.metrics li span { color: var(--muted); }
.metrics li b { font-family: var(--font-mono); font-weight: 700; }

@media (max-width: 860px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* === Aligner la hauteur de l'Equity Curve sur le formulaire === */
.dashboard { align-items: stretch; }
.card.hero { display: flex; flex-direction: column; }
.chart-fill { flex: 1; min-height: 0; position: relative; margin-top: 6px; }
.chart-fill canvas { position: absolute; inset: 0; }
#equityChart { height: 100% !important; }

/* === Aligner les 3 blocs du bas à la même hauteur === */
.stats-row { align-items: stretch; }
.stats-row .card { display: flex; flex-direction: column; }
#pieChart, #monthlyChart { height: 100% !important; }

/* === Titre centré + nom de l'utilisateur === */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; }
.topbar .logo { justify-self: start; }
.topbar h1 { justify-self: center; text-align: center; }
.topbar button { justify-self: end; }
.dash-name { color: var(--muted); font-weight: 500; margin-left: 4px; }

/* === Pied de page === */
.footer {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.footer p { margin: 4px 0; }
.footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.footer a:hover { text-decoration: underline; }
.footer-copy { font-size: 12px; color: #5c6577; }

/* === Pied de page (page connexion) === */
.auth-container { position: relative; }
.auth-footer {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.auth-footer p { margin: 3px 0; }
.auth-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; }

/* === Filtre par année === */
.year-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.yf-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  padding: 5px 13px; font-size: 12px; font-weight: 600; border-radius: 8px;
  font-family: var(--font-mono); transition: all .15s ease;
}
.yf-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); filter: none; transform: none; }
.yf-btn.active { background: var(--accent); color: var(--accent-text, #fff); border-color: var(--accent); }
.yf-btn.active:hover { background: var(--accent); }

/* === Ligne Total de l'historique === */
tfoot .total-row td { border-top: 1px solid var(--border); border-bottom: none; padding-top: 14px; }
tfoot .total-row td:first-child {
  color: var(--muted); text-transform: uppercase; font-size: 11px;
  letter-spacing: .06em; font-weight: 600;
}
#histTotal { font-family: var(--font-mono); font-weight: 700; }

/* === Bouton thème dans la barre du haut === */
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }

/* === En-tête historique + bouton export === */
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.table-head h2 { margin: 0; }
.export-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 8px 14px; font-size: 13px; }
.export-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); filter: none; transform: none; }

/* === Barre de filtre (menus déroulants sur une ligne) === */
.filter-bar {
  display: flex; flex-direction: row; flex-wrap: nowrap; gap: 14px;
  align-items: flex-end; margin-bottom: 22px; overflow-x: auto; padding-bottom: 4px;
}
.filter-item { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.filter-item label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin: 0;
}
.filter-item select { width: auto; min-width: 140px; margin: 0; cursor: pointer; padding: 9px 12px; }
.filter-item select:disabled { opacity: .5; cursor: not-allowed; }

/* === Formulaire "Ajouter un trade" sur une ligne === */
.trade-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}
.trade-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 120px;   /* chaque champ prend sa place, et passe à la ligne seulement si vraiment trop serré */
  min-width: 110px;
}
.trade-form .field.field-wide { flex: 2 1 220px; }   /* Notes et Lien un peu plus larges */
.trade-form .field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0;
}
.trade-form .field input,
.trade-form .field select {
  margin: 0;
  width: 100%;
}
.trade-form .field.rr-field input { border-color: var(--accent); }  /* met en valeur les cases RR */
#rr { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }

.trade-form-actions { display: flex; gap: 10px; }
.trade-form-actions button { width: auto; }

/* === Hauteur de l'Equity Curve (pleine largeur) === */
.card.hero .chart-fill { height: 360px; }
.card.hero #equityChart { height: 100% !important; }

/* === Hauteur de l'Equity Curve (pleine largeur) === */
.card.hero { display: block; }
.card.hero .chart-fill {
  height: 360px !important;
  min-height: 360px;
  position: relative;
}
.card.hero #equityChart { height: 100% !important; width: 100% !important; }

/* === Historique : ~10 lignes visibles, le reste scrolle === */
.card.table table { display: block; }
.card.table thead, .card.table tfoot { display: table; width: 100%; table-layout: fixed; }
.card.table tbody {
  display: block;
  max-height: 520px;        /* ~10 lignes ; ajuste si besoin */
  overflow-y: auto;
}
.card.table tbody tr { display: table; width: 100%; table-layout: fixed; }


/* === Case à cocher Break even === */
.field-check { justify-content: center; flex: 0 0 auto; }
.check-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text);
  cursor: pointer; white-space: nowrap;
  text-transform: none; letter-spacing: 0;
}
.check-label input[type="checkbox"] {
  width: 18px; height: 18px; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}

/* === Badge BE dans l'historique === */
.be-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent);
}

/* Compteur de BE en bas (ligne Total) */
#histBE { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }

/* === Barres de défilement assorties au thème === */
* {
  scrollbar-width: thin;                         /* Firefox */
  scrollbar-color: var(--surface-2) transparent; /* Firefox : poignée / piste */
}
*::-webkit-scrollbar {                            /* Chrome, Edge, Safari */
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 8px;
  border: 2px solid var(--bg);                   /* petit liseré couleur du fond */
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* === Espacement vertical uniforme entre les grands blocs === */
.container > .card.hero,
.container > .card,
.container > .stats-row,
.container > .dashboard,
.container > .card.table {
  margin-bottom: 22px;
}

/* === Largeurs de colonnes : un max de place pour Notes === */
.card.table table { table-layout: fixed; width: 100%; }
.card.table th, .card.table td {
  overflow: hidden; text-overflow: ellipsis;
}
.card.table th:nth-child(1),  .card.table td:nth-child(1)  { width: 92px; }   /* Date */
.card.table th:nth-child(2),  .card.table td:nth-child(2)  { width: 80px; }   /* Actif */
.card.table th:nth-child(3),  .card.table td:nth-child(3)  { width: 64px; }   /* Type */
.card.table th:nth-child(4),  .card.table td:nth-child(4)  { width: 72px; }   /* Entrée */
.card.table th:nth-child(5),  .card.table td:nth-child(5)  { width: 72px; }   /* Sortie */
.card.table th:nth-child(6),  .card.table td:nth-child(6)  { width: 72px; }   /* PnL */
.card.table th:nth-child(7),  .card.table td:nth-child(7)  { width: 70px; }   /* RR */
.card.table th:nth-child(8),  .card.table td:nth-child(8)  { width: 48px; }   /* BE */
.card.table th:nth-child(9),  .card.table td:nth-child(9)  { width: 110px; }  /* Modèle */
.card.table th:nth-child(10), .card.table td:nth-child(10) { width: auto; }   /* Notes = tout le reste */
.card.table th:nth-child(11), .card.table td:nth-child(11) { width: 64px; }   /* Lien */
.card.table th:nth-child(12), .card.table td:nth-child(12) { width: 78px; }   /* Actions */
.card.table td:nth-child(10) { white-space: normal; }   /* Notes peut aller à la ligne */

/* Filtre par actif à côté du titre Historique */
.table-head-left { display: flex; align-items: center; gap: 14px; }
.asset-filter { width: auto; min-width: 130px; margin: 0; padding: 7px 12px; cursor: pointer; }
#histRR { font-family: var(--font-mono); font-weight: 700; }

/* Total RR sur 2 lignes (somme au-dessus, moyenne en dessous) */
#histRR { line-height: 1.25; }
#histRR .rr-sum { display: block; font-family: var(--font-mono); font-weight: 700; }
#histRR .rr-avg {
  display: block;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
}


/* Ligne Total : rien n'est rogné, RR/BE alignés sur leurs colonnes */
.total-row td { overflow: visible; white-space: nowrap; }
.total-row .total-label b { margin-left: 10px; font-family: var(--font-mono); font-weight: 700; }
#histRR .rr-sum { display: block; font-family: var(--font-mono); font-weight: 700; }
#histRR .rr-avg { display: block; font-family: var(--font-mono); font-weight: 500; font-size: 11px; color: var(--muted); white-space: nowrap; }


/* "Total" + montant collés à gauche, dans une seule cellule large */
.total-row .total-cell { text-align: left; white-space: nowrap; }
.total-row .total-word { font-weight: 600; }
.total-row .total-cell .num { margin-left: 12px; font-family: var(--font-mono); font-weight: 700; }

/* ====== Ligne Total — version finale, RR/BE ne bougent plus ====== */
.card.table tfoot td.total-cell {
  overflow: visible;       /* le montant déborde sur les cases vides à droite */
  white-space: nowrap;
}
.card.table tfoot td.total-cell b {
  margin-left: 10px;
  font-size: 14px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text);
}

/* === Boutons modifier/supprimer côte à côte === */
.card.table td.actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
}
.card.table td.actions button { flex: 0 0 auto; }

/* un peu plus de place pour la colonne Actions */
.card.table th:nth-child(12), .card.table td:nth-child(12) { width: 92px; }


/* ====== BOUTONS ✎ ✕ DE L'HISTORIQUE — CORRECTIF FINAL ====== */
.card.table td.actions {
  display: table-cell !important;   /* annule le flex qui cassait tout */
  white-space: nowrap !important;
  text-align: right !important;
  width: 96px !important;
}
.card.table td.actions .icon-btn {
  display: inline-block !important;
  width: auto !important;
  padding: 5px 9px !important;
  font-size: 13px !important;
  margin: 0 0 0 5px !important;
  background: transparent !important;
  border: 1px solid var(--border) !important;
  color: var(--muted) !important;
  border-radius: 7px !important;
  vertical-align: middle !important;
}
.card.table td.actions .icon-btn:hover {
  color: var(--text) !important;
  border-color: var(--accent) !important;
  background: var(--accent-soft) !important;
  transform: none !important;
  filter: none !important;
}
.card.table td.actions .icon-btn.del:hover {
  color: var(--red) !important;
  border-color: var(--red) !important;
  background: rgba(255,92,121,0.08) !important;
}

/* S'assurer que les boutons ✎ ✕ sont bien cliquables */
.card.table td.actions { position: relative; z-index: 2; }
.card.table td.actions .icon-btn {
  position: relative;
  z-index: 3;
  pointer-events: auto !important;
  cursor: pointer !important;
}

/* ===== ✕ réapparaît : on enlève le rognage + on élargit la colonne ===== */
.card.table th:nth-child(12),
.card.table td:nth-child(12) { width: 112px !important; }

.card.table td.actions {
  overflow: visible !important;     /* ne plus couper le 2e bouton */
  text-overflow: clip !important;
  text-align: right !important;
  white-space: nowrap !important;
}
.card.table td.actions .icon-btn {
  display: inline-block !important;
  width: auto !important;
  min-width: 0 !important;
}


.auth-theme-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: auto;
  z-index: 100;
}

/* --- Bouton discret : suppression de compte --- */
.delete-account-row {
  text-align: center;
  margin: 8px 0;
}
.btn-delete-account {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-ui);
  text-decoration: underline;
  width: auto;
}
.btn-delete-account:hover {
  color: var(--red);
}
/* Bouton rouge conservé pour la fenêtre de confirmation */
.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
}
.btn-danger:hover {
  opacity: 0.9;
}

/* --- Fenêtre de confirmation (modal) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  max-width: 440px;
  width: 90%;
}
.modal-box h2 {
  color: var(--red);
  margin-top: 0;
}
.modal-box p {
  color: var(--text);
  line-height: 1.5;
  margin: 10px 0;
}
.modal-box input {
  width: 100%;
  margin: 8px 0;
  box-sizing: border-box;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ============================================
   ADAPTATION MOBILE — DASHBOARD (index.html)
   ============================================ */
@media (max-width: 640px) {
  /* En-tête : logo en haut, puis titre, puis boutons */
  .topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
    text-align: center;
  }
  .topbar .logo { justify-self: center; }
  .topbar h1 { justify-self: center; font-size: 22px; }
  .topbar-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  .topbar button { justify-self: center; }

  /* Barre de filtres : 2 colonnes au lieu de 4 */
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Cartes de stats : 2 colonnes */
  .stats-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Les rangées de graphiques : 1 colonne (empilées) */
  .stats-row {
    grid-template-columns: 1fr;
  }

  /* Formulaire d'ajout : champs en 1 colonne */
  .trade-form {
    grid-template-columns: 1fr;
  }
  .trade-form .field-wide { grid-column: auto; }

  /* Tableau d'historique : scroll horizontal pour ne pas déborder */
  .card.table table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* En-tête du tableau (titre + filtre + export) empilé */
  .table-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}