/* ============================================================
   Pilotage Franchise - design soigne, themes clair & sombre.
   Les couleurs sont des variables surchargees par [data-theme].
   ============================================================ */

/* ---------- THEME CLAIR (defaut) ---------- */
:root {
  --bg: #eef1f6;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #e6ecff 0%, transparent 60%), var(--bg);
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #1b2030;
  --ink-soft: #3a4256;
  --muted: #707a8f;
  --line: #e4e8ef;
  --line-strong: #d3d9e3;
  --accent: #4f46e5;
  --accent-2: #6d5cf6;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --shadow: 0 1px 2px rgba(20,28,50,.04), 0 8px 24px rgba(20,28,50,.06);
  --shadow-lg: 0 20px 50px rgba(20,28,50,.18);
  /* statuts */
  --s-afaire: #94a0b3; --s-afaire-bg: #eef1f6;
  --s-encours: #3b82f6; --s-encours-bg: #e7f0ff;
  --s-fait: #16a34a;    --s-fait-bg: #e4f7ec;
  --s-bloque: #e11d48;  --s-bloque-bg: #fde7ec;
  /* priorites */
  --p-critique: #e11d48; --p-important: #ea580c; --p-scalabilite: #8a93a6;
}

/* ---------- THEME SOMBRE ---------- */
[data-theme="dark"] {
  --bg: #0d0f15;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #1a1f3a 0%, transparent 55%), var(--bg);
  --surface: #161922;
  --surface-2: #1c2029;
  --ink: #e8ebf2;
  --ink-soft: #c2c8d6;
  --muted: #8b93a7;
  --line: #262b37;
  --line-strong: #313847;
  --accent: #6d6af8;
  --accent-2: #8b7bff;
  --accent-ink: #ffffff;
  --accent-soft: #20223a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55);
  --s-afaire: #8b93a7; --s-afaire-bg: #242a36;
  --s-encours: #5b9dff; --s-encours-bg: #18253c;
  --s-fait: #34d27e;    --s-fait-bg: #14301f;
  --s-bloque: #fb5e7f;  --s-bloque-bg: #361720;
  --p-critique: #fb5e7f; --p-important: #fb9a4b; --p-scalabilite: #8b93a7;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--s-bloque); min-height: 1em; font-size: 13px; }
.spacer { flex: 1; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: 1px solid var(--line); }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-dot { width: 14px; height: 14px; border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 2px 8px var(--accent-soft); }

/* ---------- Overlays / cartes modales ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,14,25,.5);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.login-card, .modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 26px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.login-card .brand { margin-bottom: 6px; }
.modal { max-width: 560px; max-height: 88vh; overflow: auto; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }

label { display: block; margin: 14px 0 5px; font-weight: 600; font-size: 13px; color: var(--ink-soft); }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong);
  border-radius: 10px; font-family: inherit; font-size: 14px;
  background: var(--surface-2); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 76px; resize: vertical; }
input[type=range] { padding: 0; accent-color: var(--accent); }

/* ---------- Boutons ---------- */
.primary {
  margin-top: 16px; width: 100%; padding: 12px; border: 0; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
  font-weight: 700; font-size: 15px; box-shadow: var(--shadow); transition: transform .08s, filter .15s;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.ghost {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft);
  padding: 8px 13px; border-radius: 10px; font-weight: 600; transition: background .15s, border-color .15s;
}
.ghost:hover { background: var(--surface-2); border-color: var(--accent); color: var(--ink); }
.mini { font-size: 12.5px; padding: 6px 11px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-soft); font-weight: 600; }
.mini:hover { border-color: var(--accent); color: var(--ink); }
.mini.primary { width: auto; margin-top: 0; color: var(--accent-ink); border: 0; }

/* ---------- Header ---------- */
header {
  display: flex; align-items: center; gap: 12px; padding: 11px 20px;
  background: var(--surface); /* fallback si color-mix non supporte */
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
#tabs { display: flex; gap: 3px; flex-wrap: wrap; }
#tabs button {
  border: 0; background: transparent; padding: 8px 13px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 13.5px; transition: background .15s, color .15s;
}
#tabs button:hover { background: var(--surface-2); color: var(--ink); }
#tabs button.active { background: var(--accent-soft); color: var(--accent); }
.user-chip {
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line); padding: 5px 11px; border-radius: 99px;
}

main { padding: 22px; max-width: 1300px; margin: 0 auto; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(var(--accent), var(--accent-2)); opacity: .85; }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px;
  margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 14.5px; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- Barres d'avancement ---------- */
.bar-row { display: grid; grid-template-columns: 150px 1fr 52px; align-items: center; gap: 12px; margin: 8px 0; font-size: 13px; }
.bar { background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; height: 12px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.bar-row small { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Toolbar process ---------- */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select, .toolbar input { width: auto; min-width: 130px; padding: 8px 11px; }
.view-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.view-switch button { border: 0; background: var(--surface); padding: 8px 14px; color: var(--muted); font-weight: 600; }
.view-switch button + button { border-left: 1px solid var(--line); }
.view-switch button.active { background: var(--accent); color: var(--accent-ink); }

/* ---------- Tableau ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--surface); min-width: 720px; }
.finance-table, #view-journal table { min-width: 0; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none; white-space: nowrap; }
th:hover { color: var(--ink); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.code { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 99px; background: currentColor; opacity: .9; }
.st-a_faire { color: var(--s-afaire); background: var(--s-afaire-bg); }
.st-en_cours { color: var(--s-encours); background: var(--s-encours-bg); }
.st-fait { color: var(--s-fait); background: var(--s-fait-bg); }
.st-bloque { color: var(--s-bloque); background: var(--s-bloque-bg); }
.statut-btn { cursor: pointer; transition: filter .15s; }
.statut-btn:hover { filter: brightness(.97); }
.pr-critique { color: var(--p-critique); font-weight: 700; }
.pr-important { color: var(--p-important); font-weight: 600; }
.pr-scalabilite { color: var(--p-scalabilite); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 980px) { .kanban { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .kanban { grid-template-columns: 1fr; } }
.kcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-height: 140px; transition: outline .12s; }
.kcol h3 { margin: 0 0 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.kcol h3 > span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; margin-bottom: 9px; cursor: grab; box-shadow: var(--shadow); transition: transform .1s, box-shadow .15s; }
.kcard:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.kcard.drag { opacity: .45; }
.kcol.over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.kcard .c { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- Roadmap ---------- */
.phase-block h2 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.phase-block h2 .bar { display: inline-block; }
.seq { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }

/* ---------- Listes ---------- */
ul.clean { list-style: none; margin: 0; padding: 0; }
ul.clean li { padding: 9px 0; border-bottom: 1px solid var(--line); }
ul.clean li:last-child { border-bottom: 0; }
.row-flex { display: flex; gap: 10px; align-items: center; justify-content: space-between; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 11px; font-weight: 600;
  z-index: 200; opacity: 0; pointer-events: none; box-shadow: var(--shadow-lg); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Etats : en retard, archivé, case à cocher ---------- */
.overdue { color: var(--s-bloque); font-weight: 700; }
tr.archived { opacity: .5; font-style: italic; }
.kcard.archived { opacity: .55; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.inline-check input { width: auto; margin: 0; accent-color: var(--accent); }
.code a { color: var(--accent); text-decoration: none; font-weight: 700; }
.code a:hover { text-decoration: underline; }

/* ---------- Notifications ---------- */
.notif-banner { max-width: 1300px; margin: 14px auto -4px; padding: 10px 18px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; font-size: 13.5px; box-shadow: var(--shadow); }
.notif-banner .n-bad { color: var(--s-bloque); font-weight: 700; }
.notif-banner .n-warn { color: var(--p-important); font-weight: 700; }

/* ---------- Chips (indicateurs ligne) ---------- */
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip-ok { color: var(--s-fait); border-color: var(--s-fait); }
.chip-bad { color: var(--s-bloque); border-color: var(--s-bloque); }

/* ---------- Detail modal : checklist + commentaires ---------- */
.detail-section { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.detail-section h3 { margin: 0 0 8px; font-size: 13px; }
.form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-2 label { margin-top: 8px; }
.item-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-row .done { text-decoration: line-through; color: var(--muted); }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.row-flex > input { flex: 1; }
.danger { color: var(--s-bloque); border-color: var(--s-bloque); }
.danger:hover { background: var(--s-bloque); color: #fff; }

/* ---------- Timeline / planning ---------- */
.timeline { margin-top: 6px; }
.tl-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.tl-row { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 8px; margin: 8px 0; }
.tl-label { font-weight: 700; font-size: 12px; color: var(--muted); }
.tl-track { position: relative; height: 16px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; }
.tl-dot { position: absolute; top: 1px; width: 12px; height: 12px; border-radius: 99px; transform: translateX(-50%); border: 2px solid var(--surface); }
.tl-dot.st-a_faire { background: var(--s-afaire); } .tl-dot.st-en_cours { background: var(--s-encours); }
.tl-dot.st-fait { background: var(--s-fait); } .tl-dot.st-bloque { background: var(--s-bloque); }
.tl-dot.overdue-dot { box-shadow: 0 0 0 2px var(--s-bloque); }

/* ---------- Calendrier ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid > b { font-size: 11px; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-cell { min-height: 76px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: var(--surface-2); }
.cal-cell.empty { background: transparent; border: 0; }
.cal-cell.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cal-d { font-size: 11px; color: var(--muted); font-weight: 700; }
.cal-ev { display: block; font-size: 11px; font-weight: 700; padding: 1px 5px; border-radius: 5px; margin-top: 2px; color: #fff; text-decoration: none; }
.cal-ev.st-a_faire { background: var(--s-afaire); } .cal-ev.st-en_cours { background: var(--s-encours); }
.cal-ev.st-fait { background: var(--s-fait); } .cal-ev.st-bloque { background: var(--s-bloque); }
.cal-ev.overdue { outline: 2px solid var(--s-bloque); }
@media (max-width: 640px) { .cal-cell { min-height: 56px; } }

/* ---------- Kanban clavier ---------- */
.kmove { display: flex; gap: 4px; margin-top: 6px; }
.kbtn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; width: 26px; height: 22px; line-height: 1; color: var(--ink-soft); font-weight: 700; }
.kbtn:hover { border-color: var(--accent); color: var(--accent); }
.kcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- États ---------- */
.overdue { color: var(--s-bloque); font-weight: 700; }
tr.archived { opacity: .5; font-style: italic; }
.kcard.archived { opacity: .55; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.inline-check input { width: auto; margin: 0; accent-color: var(--accent); }
.code a { color: var(--accent); text-decoration: none; font-weight: 700; }
.code a:hover { text-decoration: underline; }
.link-proc { font-weight: 700; }

/* ---------- Impression / PDF ---------- */
@media print {
  header, #tabs, .toolbar, #theme-toggle, #logout, #menu-account, #notif-banner, .view-switch, #new-process, .statut-btn .kmove, .kbtn { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  main { padding: 0; max-width: none; }
  a { color: #000; text-decoration: none; }
}

/* ---------- Responsive header ---------- */
@media (max-width: 720px) {
  .brand-txt { display: none; }
  main { padding: 16px; }
  #tabs button { padding: 7px 10px; font-size: 13px; }
}
