:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1d2433;
  --ink-2: #5b6578;
  --line: #e2e6ee;
  --brand: #0f5c8c;
  --brand-2: #e6f0f7;
  --ok: #15803d;
  --ok-bg: #e8f6ed;
  --warn: #b45309;
  --warn-bg: #fdf3e2;
  --bad: #b91c1c;
  --bad-bg: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }

/* ---- Barre supérieure ---- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--brand); color: #fff; padding: 0 20px; height: 52px;
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.topbar .brand small { opacity: .75; font-weight: 400; margin-left: 6px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: #dbe9f4; text-decoration: none; padding: 8px 12px; border-radius: 6px;
}
.topbar nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.topbar nav a.active { background: rgba(255,255,255,.18); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .user button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---- Panneaux ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel + .panel { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.layout-side { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid-2, .layout-side { grid-template-columns: 1fr; } }

/* ---- Onglets ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  border: none; background: none; padding: 10px 16px; cursor: pointer; color: var(--ink-2);
  border-bottom: 2px solid transparent; border-radius: 0; font-size: 14px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tab { display: none; }
.tab.active { display: block; }

/* ---- Formulaires ---- */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 7px; padding: 7px 14px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #c4ccd9; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #0c4d76; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  font: inherit; padding: 6px 9px; border: 1px solid #cfd6e1; border-radius: 7px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #b8d4e8; border-color: var(--brand); }
input[type=number] { width: 72px; }
input[type=time] { width: 130px; }
input[type=color] { padding: 1px; width: 40px; height: 30px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---- Tableaux ---- */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { font-size: 12px; color: var(--ink-2); font-weight: 600; background: #fafbfd; position: sticky; top: 0; }
table.data tr:hover td { background: #fafcff; }
table.data td.num, table.data th.num { text-align: center; }
.scroll { max-height: 520px; overflow: auto; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--ink-2); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--brand-2); color: var(--brand); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }

/* ---- Liste latérale ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list li:hover { background: #f2f5f9; }
.list li.active { background: var(--brand-2); color: var(--brand); font-weight: 600; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--ink-2); }
.kpi.bad .v { color: var(--bad); }
.kpi.ok .v { color: var(--ok); }

/* ---- Modale ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 640px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: 900px; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px 18px; max-height: 70vh; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.close-x { border: none; background: none; font-size: 20px; padding: 2px 8px; }

/* ---- Toast ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; animation: fadein .2s; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---- Préférences ---- */
.seg { display: inline-flex; border: 1px solid #cfd6e1; border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; border-right: 1px solid #cfd6e1; padding: 6px 10px; font-size: 13px; }
.seg button:last-child { border-right: none; }
.seg button.on[data-v="-2"] { background: #fecaca; }
.seg button.on[data-v="-1"] { background: #fde2e2; }
.seg button.on[data-v="0"] { background: #e5e7eb; }
.seg button.on[data-v="1"] { background: #d1fae5; }
.seg button.on[data-v="2"] { background: #a7f3d0; }

/* ---- Calendrier ---- */
.fc { --fc-border-color: var(--line); --fc-today-bg-color: #f5f9fd; font-size: 13px; }
.fc .fc-event { cursor: pointer; border-radius: 5px; }
.fc .fc-timegrid-event .fc-event-main { padding: 2px 4px; }
.ev-title { font-weight: 600; font-size: 12px; line-height: 1.2; }
.ev-sub { font-size: 11px; opacity: .92; line-height: 1.25; }
.ev-docs { font-size: 11.5px; margin-top: 2px; line-height: 1.25; }
.ev-missing { background: #fff; color: var(--bad); border-radius: 3px; padding: 0 3px; font-weight: 700; font-size: 11px; display: inline-block; margin-top: 2px; }
.fc-event.manque { box-shadow: 0 0 0 2px var(--bad) inset; }
.fc-event.dim { opacity: .25; }
.fc-event.highlight { box-shadow: 0 0 0 3px #111827 inset; }

/* ---- Grille médecins x jours ---- */
.grille { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.grille th, .grille td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px; min-width: 64px; text-align: center; }
.grille th { background: #fafbfd; position: sticky; top: 0; z-index: 2; font-weight: 600; }
.grille td.nom, .grille th.nom { position: sticky; left: 0; background: #fff; text-align: left; min-width: 170px; z-index: 1; padding: 4px 8px; font-weight: 600; }
.grille th.nom { z-index: 3; background: #fafbfd; }
.grille .we { background: #f6f7f9; }
.grille .abs { background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 4px, #e5e7eb 4px, #e5e7eb 8px); color: var(--ink-2); }
.cell-act { display: block; color: #fff; border-radius: 4px; padding: 2px 3px; margin: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.grille th.sem-sep, .grille td.sem-sep { border-left: 2px solid #9aa5b8; }

.empty { text-align: center; color: var(--ink-2); padding: 40px; }
.hint { background: var(--brand-2); color: #1e4e6e; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert-list { margin: 0; padding-left: 18px; }
.alert-list li { margin: 3px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f5c8c, #12395a); }
.login-card { background: #fff; border-radius: 14px; padding: 32px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login-card input { width: 100%; padding: 9px 11px; }
.login-card .error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---- Tableau de planification par agenda ---- */
.planning-grid { width: 100%; }
.planning-grid th { min-width: 130px; }
.planning-grid td.cell-pl { vertical-align: top; text-align: left; padding: 4px; min-width: 130px; }
.planning-grid td.site-row { background: #eef2f7; text-align: left; font-weight: 700; color: var(--brand); padding: 6px 8px; position: sticky; left: 0; }
.planning-grid .bloc { border-left: 4px solid #888; border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; cursor: pointer; transition: box-shadow .1s; }
.planning-grid .bloc:hover { box-shadow: 0 0 0 1px #94a3b8; }
.planning-grid .bloc.manque { box-shadow: 0 0 0 2px var(--bad) inset; }
.planning-grid .bloc.dimmed { opacity: .3; }
.planning-grid .bloc .h { font-size: 11px; color: var(--ink-2); margin-bottom: 2px; }
.planning-grid .bloc .doc { font-size: 12.5px; font-weight: 600; line-height: 1.35; }
.planning-grid .bloc .doc.hl { background: #fde68a; border-radius: 3px; padding: 0 2px; }
