:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1a2233;
  --muted: #7b859c;
  --border: #e2e7f0;
  --primary: #4f6ef2;
  --primary-ink: #ffffff;
  --shadow: 0 6px 24px rgba(30, 41, 82, .10);
  --radius: 14px;
  --must_reply: #E24B4A;
  --followup: #EF9F27;
  --news: #378ADD;
  --ok: #639922;
  --me: #534AB7;
}
[data-theme="dark"] {
  --bg: #0e1220;
  --surface: #171d2e;
  --surface-2: #1f2740;
  --text: #e8ecf6;
  --muted: #8b96b3;
  --border: #28324e;
  --primary: #6d86ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .85em; }

/* ---- Login ---- */
.login-page { display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #2a3566, var(--bg)); }
.login-card {
  background: var(--surface); padding: 40px 36px; border-radius: 20px; box-shadow: var(--shadow);
  width: 320px; text-align: center; border: 1px solid var(--border);
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 2px; letter-spacing: .5px; }
.login-card input { width: 100%; margin: 18px 0 10px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 15px; }
.login-card button { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--primary);
  color: var(--primary-ink); font-size: 15px; font-weight: 600; cursor: pointer; }
.login-error { color: var(--must_reply); font-size: 13px; margin-bottom: 8px; }

/* ---- Topbar ---- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 18px; display: flex; gap: 6px; align-items: center; }
.brand span { letter-spacing: .3px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 10px;
  cursor: pointer; font-size: 14px; font-weight: 600; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary); color: var(--primary-ink); }
.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--must_reply); color: #fff; font-size: 11px; margin-left: 4px; }

.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 8px 12px;
  border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger:hover { border-color: var(--must_reply); color: var(--must_reply); }

.view { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* ---- Orbites (plein espace) ---- */
#view-orbites { padding: 0; max-width: none; margin: 0; }
.orbit-wrap { position: relative; overflow: hidden; }
#orbit-canvas { width: 100%; display: block; cursor: grab; }
#orbit-canvas.grabbing { cursor: grabbing; }
.orbit-overlay { position: absolute; top: 10px; right: 10px; display: flex; gap: 5px; }
.orbit-overlay button { background: rgba(255,255,255,.9); border: .5px solid #D3D1C7; color: var(--me);
  border-radius: 6px; font-size: 12px; font-weight: 600; height: 28px; padding: 0 10px; cursor: pointer; }
[data-theme="dark"] .orbit-overlay button { background: rgba(38,36,44,.9); border-color: #3D3B45; color: #B7AEFF; }
.orbit-overlay button:hover { filter: brightness(1.06); }
.orbit-legend { position: absolute; bottom: 12px; left: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; box-shadow: var(--shadow);
  font-size: 12px; display: flex; gap: 14px; flex-wrap: wrap; }
.orbit-legend .lg { display: flex; align-items: center; gap: 6px; }
.orbit-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* Menu contextuel de la carte */
.ctx-menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 5px; box-shadow: var(--shadow); min-width: 190px; font-size: 13px; }
.ctx-menu .ctx-title { font-weight: 700; padding: 6px 10px 8px; border-bottom: 1px solid var(--border);
  margin-bottom: 4px; }
.ctx-menu button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: 0; padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--text);
  font-size: 13px; }
.ctx-menu button:hover { background: var(--surface-2); }
.ctx-menu .ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.ctx-menu .sw { width: 9px; height: 9px; border-radius: 50%; }

/* ---- Toolbar / table ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar select { padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }

.table-scroll { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; box-shadow: var(--shadow); }
.contacts-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.contacts-table th { text-align: left; padding: 12px 14px; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap; position: sticky; top: 0;
  background: var(--surface); }
.contacts-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.contacts-table tr:last-child td { border-bottom: 0; }
.contacts-table tr:hover td { background: var(--surface-2); }
.name-cell { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 700; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.st-must_reply { background: rgba(226,75,74,.14); color: var(--must_reply); }
.st-followup { background: rgba(239,159,39,.16); color: var(--followup); }
.st-news { background: rgba(55,138,221,.14); color: var(--news); }
.st-ok { background: rgba(99,153,34,.16); color: var(--ok); }
.days-hot { color: var(--must_reply); font-weight: 700; }
.row-actions { display: flex; gap: 6px; }
.muted-row td { opacity: .5; }

/* ---- Todo ---- */
.todo-list { display: grid; gap: 10px; }
.todo-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.todo-item .grow { flex: 1; }
.todo-item .sub { color: var(--muted); font-size: 12.5px; }
.todo-item.left-bar { border-left: 4px solid var(--border); }

/* ---- Settings ---- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.cat-row, .tag-row { display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--border); }
.cat-row:last-child, .tag-row:last-child { border-bottom: 0; }
.swatch { width: 16px; height: 16px; border-radius: 5px; flex: none; }
.cat-row .grow, .tag-row .grow { flex: 1; }

/* ---- Modal / form ---- */
.modal { position: fixed; inset: 0; background: rgba(10,15,30,.5); display: grid; place-items: center;
  z-index: 50; padding: 20px; }
.modal-card { background: var(--surface); border-radius: 18px; width: 640px; max-width: 100%;
  max-height: 90vh; overflow: auto; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px;
  font-family: inherit; }
.field textarea { min-height: 70px; resize: vertical; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  margin: 18px 0 8px; }
.history-item, .interaction-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border);
  color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 9px; border-radius: 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); }
.chip.on { color: #fff; border-color: transparent; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text);
  color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: 14px; z-index: 100;
  box-shadow: var(--shadow); }

/* ---- Champ Cercle mis en évidence (fin du formulaire) ---- */
.cercle-field { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; margin-top: 4px; }
.cercle-field .req { color: var(--must_reply); }
.cat-chip { display: inline-flex; align-items: center; gap: 7px; }
.cat-chip .chip-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.cat-chip { padding: 5px 11px; }
.cat-chip.on { color: var(--text); border-width: 2px; font-weight: 700; background: var(--surface); }
#cat-chips.invalid { outline: 2px solid var(--must_reply); outline-offset: 3px; border-radius: 10px; }

/* ---- Recherche globale (spotlight) ---- */
.spotlight { position: fixed; inset: 0; background: rgba(10,15,30,.42);
  display: grid; justify-items: center; align-items: start; padding: 90px 20px 20px;
  z-index: 90; }
.spotlight-card { width: 560px; max-width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.spotlight-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); }
.spotlight-input .spot-icon { font-size: 16px; }
.spotlight-input input { flex: 1; border: 0; background: transparent; color: var(--text);
  font-size: 16px; outline: none; }
.spotlight-input kbd { font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 6px; }
.spotlight-results { max-height: 420px; overflow-y: auto; padding: 6px; }
.spot-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border-radius: 10px; cursor: pointer; }
.spot-item.active, .spot-item:hover { background: var(--surface-2); }
.spot-item .grow { min-width: 0; flex: 1; }
.spot-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spot-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spot-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.spot-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 22px; }

@media (max-width: 720px) {
  .tabs .tab { padding: 8px 10px; font-size: 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .spotlight { padding-top: 60px; }
}
