/* Planning App — styles partagés (console & login).
   Identité visuelle reprise de l'application d'origine :
   police Outfit, bleu marine + accent cyan, écran de connexion sombre. */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3eb;
  --text: #1a2535;
  --text2: #4a5568;
  --muted: #8898aa;
  --navy: #0d1b2a;
  --navy2: #162032;
  --navy3: #1e2d40;
  --accent: #38bdf8;
  --accent2: #0ea5e9;
  --primary: #0ea5e9;
  --primary-d: #0284c7;
  --primary-l: #e0f2fe;
  --danger: #ef4444;
  --danger-d: #dc2626;
  --danger-l: #fee2e2;
  --success: #22c55e;
  --warn: #c2410c;
  --shadow: 0 2px 12px rgba(13,27,42,.08);
  --shadow-lg: 0 4px 24px rgba(13,27,42,.14);
  --radius: 12px;
  --rs: 8px;
  --mono: 'DM Mono', ui-monospace, SFMono-Regular, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Pastille d'état de la synchronisation temps réel (WebSocket) */
.ws-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; display: inline-block; vertical-align: middle; transition: background .3s, box-shadow .3s; }
.ws-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(34,197,94,.20); }
.ws-dot.off { background: var(--danger); }
.ws-dot.mid { background: #f59e0b; }
body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent2); }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 9px 15px; border-radius: var(--rs); border: 1px solid transparent;
  background: var(--primary); color: #fff; transition: background .15s, transform .05s, filter .15s;
}
.btn:hover { background: var(--primary-d); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text2); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-d); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover { background: var(--bg); color: var(--text); }

/* Champs */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .2px; }
input[type=text], input[type=password], input[type=number], input[type=color], select {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--rs); background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(14,165,233,.18); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.role-super_admin { background: #fef3c7; color: #92400e; }
.badge.role-super_admin_adjoint { background: #ffedd5; color: #9a3412; }
.badge.role-admin { background: var(--primary-l); color: #0369a1; }
.badge.role-agent { background: #dcfce7; color: #15803d; }
.badge.off { background: #eef2f7; color: var(--muted); }

/* Pastille de compteur dans la navigation (messages non lus) */
.nav-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; flex-shrink: 0; }

/* Messagerie — discussions (planning.html + console.html, module messages.js) */
.chat { max-width: 760px; }
.chat-bar { margin-bottom: 14px; }
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--rs); padding: 11px 13px; cursor: pointer; font: inherit; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.unread { border-left: 3px solid var(--accent2); background: #f0f9ff; }
.chat-av { width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: var(--navy); color: #fff; font-weight: 700; font-size: 14px; }
.chat-row-main { flex: 1; min-width: 0; }
.chat-row-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.chat-title { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--text2); font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.chat-row-sub { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-top: 2px; }
.chat-prev { color: var(--text2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-unread { background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
  line-height: 18px; text-align: center; border-radius: 999px; padding: 0 5px; flex-shrink: 0; }

.chat-thread, .chat-compose { display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-thead { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-thead-t { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-msgs { padding: 16px; display: flex; flex-direction: column; gap: 12px; max-height: 56vh; overflow-y: auto; background: var(--bg); }
.chat-msg { max-width: 78%; align-self: flex-start; display: flex; flex-direction: column; }
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.chat-msg-from { font-size: 12px; color: var(--text2); margin: 0 2px 3px; }
.chat-msg-from small { color: var(--accent2); }
.chat-bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 9px 13px;
  font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.chat-msg.me .chat-bubble { background: var(--navy); color: #fff; border-color: var(--navy); }
.chat-msg-time { font-size: 11px; color: var(--text2); margin: 3px 4px 0; }
.chat-reply { display: flex; gap: 8px; align-items: flex-end; padding: 12px 14px; border-top: 1px solid var(--border); }
.chat-reply textarea { flex: 1; font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--rs);
  background: #fff; color: var(--text); outline: none; resize: vertical; }
.chat-reply textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(14,165,233,.18); }

.compose-body { padding: 16px; }
.compose-lbl { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 4px 0 8px; letter-spacing: .2px; }
.compose-body textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--rs); background: #fff; color: var(--text); outline: none; resize: vertical; }
.compose-body textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(14,165,233,.18); }
.compose-actions { margin-top: 12px; display: flex; justify-content: flex-end; }
.pick { border: 1px solid var(--border); border-radius: var(--rs); max-height: 320px; overflow-y: auto; margin-bottom: 8px; }
.pick-g { border-bottom: 1px solid var(--border); padding: 8px 10px; }
.pick-g:last-child { border-bottom: 0; }
.pick-gh { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.pick-gh b { font-weight: 700; }
.pick-m { display: flex; flex-direction: column; gap: 2px; margin: 6px 0 2px 22px; }
.pick-i { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; padding: 2px 0; }
.pick-i small { color: var(--text2); font-size: 12px; }

/* Cartes & divers */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 200; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; max-width: 90vw; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: var(--danger); }

/* Modale */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(13,27,42,.55); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 90vh; overflow: auto;
}
.modal-h { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 22px; }
.modal-f { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Login (écran sombre) ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1100px 600px at 50% -15%, #16263b 0%, var(--navy) 60%); }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { text-align: center; margin-bottom: 24px; }
.login-card .brand .logo { width: 60px; height: 60px; border-radius: 16px; background: var(--accent2);
  color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 28px; box-shadow: 0 10px 30px rgba(14,165,233,.35); }
.login-card .brand h1 { font-size: 26px; margin-top: 14px; color: #fff; font-weight: 800; }
.login-card .brand p { color: #94a3b8; margin: 4px 0 0; font-size: 13px; letter-spacing: .4px; text-transform: uppercase; }
.login-box { padding: 30px 28px; background: var(--navy2); border: 1px solid var(--navy3);
  border-radius: 20px; box-shadow: 0 24px 60px rgba(0,0,0,.5); }
.login-box h2 { font-size: 19px; margin-bottom: 4px; color: #fff; }
.login-box .sub { color: #94a3b8; font-size: 14px; margin-bottom: 20px; }
.login-box label.field > span { color: #94a3b8; text-transform: uppercase; letter-spacing: .4px; font-size: 12.5px; }
.login-box input { background: var(--navy3); border-color: #1e3a5f; color: #e2e8f0; }
.login-box input::placeholder { color: #475569; }
.login-box input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(14,165,233,.25); }
.login-box .btn { padding: 13px; font-size: 15px; }
.err-box { background: #3b0a0a; color: #fca5a5; border: 1px solid #991b1b;
  padding: 10px 12px; border-radius: var(--rs); font-size: 14px; margin-bottom: 14px; display: none; }
.err-box.show { display: block; }
.qr-box { text-align: center; margin: 6px 0 14px; }
.qr-box img { border: 4px solid #fff; border-radius: 12px; background: #fff; }
.secret { font-family: var(--mono); background: var(--navy3); border: 1px solid #1e3a5f; color: #cbd5e1;
  border-radius: var(--rs); padding: 8px 10px; word-break: break-all; font-size: 13px; margin-top: 8px; }
.login-box details summary { color: #94a3b8; }
.otp-input input { text-align: center; font-size: 22px; letter-spacing: 8px; font-family: var(--mono); }
.policy { font-size: 12.5px; color: #94a3b8; margin-top: 6px; }

/* Pages légales (CGU/CGV/confidentialité) : même habillage que login-wrap, en plus large. */
.legal-wrap { min-height: 100vh; display: flex; justify-content: center; padding: 40px 20px;
  background: radial-gradient(1100px 600px at 50% -15%, #16263b 0%, var(--navy) 60%); }
.legal-box { width: 100%; max-width: 720px; padding: 36px 40px; background: var(--navy2);
  border: 1px solid var(--navy3); border-radius: 20px; box-shadow: 0 24px 60px rgba(0,0,0,.5);
  color: #cbd5e1; line-height: 1.65; }
.legal-box h1 { font-size: 24px; color: #fff; margin-bottom: 4px; }
.legal-box .updated { color: #94a3b8; font-size: 13px; margin-bottom: 24px; }
.legal-box h2 { font-size: 16px; color: #fff; margin: 26px 0 8px; }
.legal-box p, .legal-box li { font-size: 14.5px; }
.legal-box ul { padding-left: 22px; margin: 8px 0; }
.legal-box a { color: var(--accent); }
.legal-box .back { display: inline-block; margin-bottom: 24px; }
.legal-box .placeholder { background: #3b0a0a; color: #fca5a5; border: 1px solid #991b1b;
  border-radius: 8px; padding: 2px 6px; font-family: var(--mono); font-size: 13px; }
.legal-nav { display: flex; gap: 16px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--navy3); font-size: 13px; }

/* ── Console layout ── */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #94a3b8; padding: 16px 12px; display: flex; flex-direction: column; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; border-bottom: 1px solid var(--navy3); margin-bottom: 8px; }
.sidebar .brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.sidebar .brand b { color: #fff; font-size: 16px; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav button { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: transparent; border: 0; color: #94a3b8; font: inherit; font-weight: 500; font-size: 15px;
  padding: 9px 12px; border-radius: var(--rs); cursor: pointer; transition: all .15s; }
.nav button .ic { width: 20px; text-align: center; }
.nav button:hover { background: var(--navy3); color: #e2e8f0; }
.nav button.active { background: var(--navy3); color: var(--accent); }
.sidebar .foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--navy3); font-size: 13px; }
.sidebar .foot .who { color: #fff; font-weight: 600; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 8px rgba(13,27,42,.04); }
.topbar h1 { font-size: 18px; }
.content { padding: 24px 28px; }
.page-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }

/* Grille de plannings */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.plan-card { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.plan-card .ic { width: 50px; height: 50px; border-radius: 14px; background: var(--navy); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 26px; overflow: hidden; }
.plan-card .ic img { width: 100%; height: 100%; object-fit: cover; }
.plan-card .pname { font-weight: 700; font-size: 16px; }
.plan-card .pmeta { color: var(--muted); font-size: 13px; }
.plan-card .row { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.tbl th, table.tbl td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.tbl th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Icon picker */
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 6px; }
.icon-grid button { font-size: 22px; padding: 6px; border: 1px solid var(--border); border-radius: var(--rs); background: #fff; cursor: pointer; transition: all .15s; }
.icon-grid button:hover { border-color: var(--accent2); }
.icon-grid button.sel { border-color: var(--accent2); background: var(--primary-l); }

/* Matrice (droits, habilitations, stats) */
.rights-head { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.rights-head label.field { margin-bottom: 0; min-width: 280px; }
.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; min-width: 520px; width: 100%; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.matrix th, table.matrix td { padding: 10px 12px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: center; }
table.matrix th:first-child, table.matrix td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-2); font-weight: 600; width: 1%; white-space: nowrap; }
table.matrix thead th { background: var(--navy); color: #e2e8f0; font-size: 13px; }
table.matrix thead th:first-child { background: var(--navy); color: #e2e8f0; }
table.matrix .grp td { background: var(--surface-2); font-weight: 700; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; }
table.matrix input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent2); }
.cred-box { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 14px; margin-top: 8px; }
.cred-box code { font-family: var(--mono); font-size: 15px; background: #fff; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* Tiroir de navigation mobile (off-canvas) — masqués sur PC */
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hamburger { display: none; background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: var(--rs); }
.hamburger:hover { background: var(--surface-2); }
.sb-close { display: none; margin-left: auto; background: none; border: 0; color: #94a3b8; font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.sb-close:hover { color: #fff; background: var(--navy3); }
.sb-ov { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 900; opacity: 0; pointer-events: none; transition: opacity .25s; }
.sb-ov.vis { opacity: 1; pointer-events: auto; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; width: 260px; max-width: 84vw;
    z-index: 1000; transform: translateX(-100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
    flex-direction: column; overflow-y: auto; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 30px rgba(0,0,0,.4); }
  .nav { flex-direction: column; }
  .sidebar .foot { display: block; }
  .hamburger { display: flex; align-items: center; }
  .sb-close { display: block; }
}
