:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1b2430; --muted: #5d6b7c; --line: #dfe4ea;
  --brand: #1e3a5f; --brand-2: #2b5283; --accent: #f97316; --focus: #2563eb;
  --ok: #15803d; --ok-bg: #dcfce7; --good: #2563eb; --good-bg: #dbeafe;
  --warn: #b45309; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--brand-2); }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.25; }
h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .86rem; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- En-tête & navigation ---------- */
header.top { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 18px; height: 56px; position: sticky; top: 0; z-index: 50; }
header.top .brand { font-weight: 700; font-size: 1.02rem; white-space: nowrap; display: flex; align-items: center; gap: 10px; }
header.top .brand img { width: 28px; height: 28px; }
nav.main { display: flex; gap: 2px; flex: 1; }
nav.main a { color: #cfe0f5; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
nav.main a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.main a.active { background: rgba(255,255,255,.16); color: #fff; }
.syncbox { display: flex; align-items: center; gap: 8px; font-size: .84rem; color: #cfe0f5; white-space: nowrap; }
.syncbox button { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: .84rem; }
.syncbox button:hover { background: rgba(255,255,255,.22); }
main { padding: 18px; max-width: 1400px; margin: 0 auto; }

/* ---------- Éléments ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
label.f { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .02em; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=time], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #c9d1db; border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
input.big { font-size: 1.1rem; padding: 12px 14px; }
button, .btn { font: inherit; border: 1px solid #c9d1db; background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: #f1f4f8; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-2); }
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.accent:hover { filter: brightness(1.05); }
button.danger { color: var(--bad); border-color: #f1b4b4; }
button.link { border: 0; background: none; padding: 0; color: var(--brand-2); text-decoration: underline; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.huge { width: 100%; justify-content: center; font-size: 1.05rem; padding: 14px; letter-spacing: .02em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #c9d1db; background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; user-select: none; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.lv-excellent { background: var(--ok-bg); color: var(--ok); }
.lv-bon { background: var(--good-bg); color: var(--good); }
.lv-acceptable { background: var(--warn-bg); color: var(--warn); }
.lv-a_eviter { background: var(--bad-bg); color: var(--bad); }
.lv-nouvelle { background: #ede9fe; color: #6d28d9; }
.newtour { border: 2px solid #c4b5fd; background: #faf8ff; }
.newtour-banner { border-left: 4px solid #7c3aed; background: #f5f3ff; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.b-warn { background: var(--warn-bg); color: var(--warn); } .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: #eef2f7; color: var(--muted); } .b-ok { background: var(--ok-bg); color: var(--ok); }
.notice { border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.notice.warn { background: var(--warn-bg); color: #7c4a03; border: 1px solid #f6d58b; }
.notice.bad { background: var(--bad-bg); color: #7f1d1d; border: 1px solid #f5b5b5; }
.notice.info { background: #eef4fb; color: #1e3a5f; border: 1px solid #cbdcf0; }
.notice.ok { background: var(--ok-bg); color: #14532d; border: 1px solid #a7e3bc; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #f7f9fc; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.spinner { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: #cbd5e1; border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Nouveau RDV ---------- */
.newrdv { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
.newrdv .form { position: sticky; top: 74px; }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); margin-top: 4px; max-height: 280px; overflow: auto; }
.ac-item { padding: 9px 12px; cursor: pointer; font-size: .93rem; }
.ac-item:hover, .ac-item.sel { background: #eef4fb; }
.ac-item .muted { font-size: .8rem; }
.addr-ok { font-size: .82rem; color: var(--ok); margin-top: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 9px 12px; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.prop { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 14px 16px; box-shadow: var(--shadow); }
.prop + .prop { margin-top: 10px; }
.prop.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(30,58,95,.25); }
.prop .when { font-size: 1.08rem; font-weight: 800; letter-spacing: .01em; text-transform: uppercase; }
.prop .impact { display: flex; gap: 18px; flex-wrap: wrap; margin: 8px 0 6px; }
.prop .impact .big { font-size: 1.25rem; font-weight: 800; }
.prop .impact .lbl { font-size: .78rem; color: var(--muted); }
.prop .meta { font-size: .88rem; color: var(--muted); }
.prop .why { margin-top: 8px; font-size: .9rem; background: #f7f9fc; border-radius: 8px; padding: 10px 12px; }
.prop .why p { margin: 0 0 4px; }
.prop .expl { font-size: .9rem; margin-top: 6px; }
.confirm-panel { border: 2px solid var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- Planning ---------- */
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-col { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 220px; padding: 6px; }
.cal-col.today { border-color: var(--brand); }
.cal-col.off { background: #f0f2f5; }
.cal-col h4 { margin: 2px 2px 6px; font-size: .82rem; text-transform: capitalize; color: var(--muted); }
.ev { border-left: 4px solid var(--brand); background: #f6f8fb; border-radius: 6px; padding: 5px 7px; margin-bottom: 5px; cursor: pointer; font-size: .82rem; }
.ev:hover { background: #eaf0f7; }
.ev.cancel { opacity: .5; text-decoration: line-through; }
.ev .t { font-weight: 700; }
.ev .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-month .dh { font-size: .75rem; text-transform: uppercase; color: var(--muted); padding: 4px; font-weight: 700; }
.cal-month .cell { background: #fff; border: 1px solid var(--line); border-radius: 6px; min-height: 92px; padding: 4px; cursor: pointer; font-size: .78rem; }
.cal-month .cell.other { opacity: .45; } .cal-month .cell.today { border-color: var(--brand); }
.cal-month .cell .d { font-weight: 700; margin-bottom: 2px; }
.cal-month .cell .mini { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-list .item { display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; padding: 10px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.day-list .item:hover { background: #f7f9fc; }

/* ---------- Tournée ---------- */
.tour { display: grid; grid-template-columns: minmax(300px, 460px) minmax(0, 1fr); gap: 16px; align-items: start; }
.tl { position: relative; }
.tl .stop { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.tl .stop.depot { background: #eef4fb; border-color: #cbdcf0; }
.tl .leg { padding: 6px 0 6px 22px; color: var(--muted); font-size: .85rem; border-left: 3px dashed #c3cfdd; margin-left: 14px; }
.tl .num { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; margin-right: 6px; }
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.totals .k { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.totals .k b { display: block; font-size: 1.25rem; }
.totals .k > span.small:last-child:not(:first-child) { display: block; }
.map-num { background: var(--brand); color: #fff; border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); font-size: 12px; }
.map-num.depot { background: var(--accent); }

/* ---------- Modale, toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .close { float: right; border: 0; font-size: 1.3rem; line-height: 1; padding: 4px 8px; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: #1b2430; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: .92rem; }
.toast.err { background: #991b1b; } .toast.ok { background: #166534; }

/* ---------- Connexion ---------- */
.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 26px; }
.login h1 { font-size: 1.3rem; }

/* ---------- Paramètres ---------- */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: start; }
.settings nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.settings nav a.on, .settings nav a:hover { background: #e8eef6; }
.settings nav { position: sticky; top: 74px; }
.checklist li { margin: 3px 0; }
.checklist .done { color: var(--ok); } .checklist .todo { color: var(--bad); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .newrdv, .tour, .settings { grid-template-columns: 1fr; }
  .newrdv .form, .settings nav { position: static; }
  .cal-week { grid-template-columns: 1fr; }
  .cal-col { min-height: 0; }
  #map { height: 380px; }
}
@media (max-width: 760px) {
  header.top { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  nav.main { order: 3; flex: 1 1 100%; overflow-x: auto; }
  .syncbox { margin-left: auto; font-size: .78rem; }
  nav.main a { padding: 7px 9px; font-size: .9rem; }
  main { padding: 12px; }
  .grid2, .grid3 { grid-template-columns: 1fr 1fr; }
  .totals { grid-template-columns: 1fr 1fr; }
  .cal-month .cell { min-height: 60px; }
  .cal-month .cell .mini { display: none; }
  .day-list .item { grid-template-columns: 70px 1fr; }
  .day-list .item > :last-child { grid-column: 1 / -1; }
}
@media print { header.top, .no-print { display: none !important; } }

/* ---------- À rappeler ---------- */
.rp-phones { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.rp-phones a { font-size: 1.1rem; font-weight: 700; text-decoration: none; color: var(--brand); white-space: nowrap; }
.rp-item .num { display: inline-flex; }

/* ---------- Pourquoi cette note ? ---------- */
.diag summary { cursor: pointer; }
.diag-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.diag-split > div { background: #f6f8fb; border-radius: 8px; padding: 10px 12px; }
.diag .bar { height: 8px; background: #e5e9ef; border-radius: 4px; margin: 6px 0 3px; }
.diag .bar span { display: block; height: 8px; background: #ea580c; border-radius: 4px; }
@media (max-width: 760px) { .diag-split { grid-template-columns: 1fr; } }
