:root {
  color-scheme: dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --bg: #000;
  --panel: #191919;
  --surface: #242424;
  --surface-alt: #2c2c2c;
  --border: #303030;
  --border-bright: #444;
  --text: #f5f5f5;
  --muted: #9b9b9b;
  --accent: #3366ff;
  --accent-soft: rgba(51, 102, 255, 0.18);
  --accent-text: #5b8cff;
  --error: #ef4f5a;
  --success: #34d39e;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-weight: 600; margin: 0 0 14px; }
h2 { font-size: 18px; padding-right: 28px; }

button {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
button:hover:not(:disabled) { background: #4a7aff; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
button.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: var(--text); }
button.small-btn { padding: 4px 12px; }

input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.2); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error-text { color: var(--error); font-size: 13px; }

/* Connexion */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 360px; max-width: 100%; background: var(--surface); border-radius: 16px; padding: 28px; }
.login-card h1 { font-size: 22px; margin-bottom: 20px; }
.login-card button { width: 100%; margin-top: 4px; }

/* Barre du haut + légende */
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 24px; background: var(--bg); }
.brand { font-weight: 700; font-size: 18px; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 18%, #151515); }
.legend-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.legend-item .tg { font-weight: 400; color: var(--text); }

.tabs { display: flex; gap: 6px; padding: 0 24px 10px; background: var(--bg); }
.tab { background: transparent; color: var(--muted); border-radius: 10px; padding: 9px 16px; }
.tab:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.tab.active { background: #1f1f1f; color: var(--text); font-weight: 600; }

main { background: var(--panel); border-radius: 16px; margin: 0 12px 12px; padding: 24px; min-height: calc(100vh - 140px); }

/* Pastilles de modèle */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--c); background: color-mix(in srgb, var(--c) 18%, #151515); white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.toast { background: color-mix(in srgb, var(--success) 18%, #151515); color: var(--success); padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; font-size: 14px; }

.section-label { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar p { margin: 0; }

/* Délégations récentes (annulables 2 min) */
.recent-box { background: var(--surface); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recent-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.recent-list .undo { margin-left: auto; padding: 3px 10px; font-size: 12px; }

/* Tableaux */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.03); }
.col-check { width: 40px; }
td .username { font-weight: 600; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* VA */
.va-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.va-card { background: var(--surface); border-radius: 14px; padding: 18px; cursor: pointer; text-align: left; border: 1px solid transparent; transition: border-color 0.15s, background 0.15s; }
.va-card:hover { background: var(--surface-alt); border-color: var(--border-bright); }
.va-card h3 { margin: 0 0 10px; font-size: 16px; }
.va-card .gain { font-size: 13px; margin-top: 10px; }
.gain-positive { color: var(--success); font-weight: 600; }
.gain-negative { color: var(--error); font-weight: 600; }

/* Fenêtres */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-content { background: var(--surface); border-radius: 14px; padding: 24px; width: 640px; max-width: 95vw; max-height: 90vh; overflow: auto; position: relative; }
.modal-small { width: 460px; }
.modal-wide { width: 820px; }
.modal-close { position: absolute; top: 10px; right: 14px; background: transparent; color: var(--muted); border: none; font-size: 22px; padding: 4px 8px; }
.modal-close:hover:not(:disabled) { background: transparent; color: var(--text); }

/* Emails */
.email-list { list-style: none; margin: 12px 0 0; padding: 0; }
.email-list li { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.email-list li:hover { background: rgba(255, 255, 255, 0.03); }
.email-list .subj { font-weight: 600; font-size: 14px; }
.email-list .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.email-subject { font-size: 16px; font-weight: 600; margin: 14px 0 4px; }
.email-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.6; background: var(--panel); border-radius: 10px; padding: 14px; margin-top: 12px; max-height: 55vh; overflow: auto; }
.email-body a { color: var(--accent-text); }

/* Graphique */
.chart-block { margin: 6px 0 4px; padding: 14px; background: var(--panel); border-radius: 12px; }
.period-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.period-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.period-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.period-btn.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.week-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.custom-range { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.custom-range .field { margin: 0; }
.chart-wrap { position: relative; }
#va-chart { width: 100%; height: auto; display: block; }
.chart-tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-bright); border-radius: 6px; padding: 4px 9px; font-size: 12px; color: var(--text); white-space: nowrap; transform: translate(-50%, -130%); z-index: 10; }

@media (max-width: 640px) {
  .topbar { padding: 12px 14px; }
  .tabs { padding: 0 14px 10px; }
  main { margin: 0 6px 6px; padding: 14px; }
}

.addva-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.addva-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel); font-size: 14px; }
.addva-list label { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; flex-wrap: wrap; }
