:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7684;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --ok-bg: #e7f6ec;
  --warn: #b45309;
  --warn-bg: #fdf3e3;
  --todo: #64748b;
  --todo-bg: #eef1f5;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: #0f172a;
  color: #fff;
  flex-wrap: wrap;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.topbar .brand:hover { text-decoration: none; opacity: 0.9; }
.topnav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topnav a { color: #cbd5e1; font-size: 0.95rem; }
.topnav a:hover { color: #fff; text-decoration: none; }
.topnav .logout { color: #f8b4b4; }

.container {
  max-width: 960px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2rem 1rem;
}

/* ---- Headings ---- */
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.muted { color: var(--muted); }
.muted.intro { margin: 0.25rem 0 1rem; }
.big { font-size: 1.6rem; font-weight: 700; margin: 0.25rem 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0.6rem; }
.right { text-align: right; }

/* ---- Cards & grid ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.1rem;
}
.card.empty { text-align: center; padding: 2.5rem 1rem; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.1rem;
}

/* ---- Sub-navigation ---- */
.subnav {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.subnav a {
  padding: 0.55rem 0.85rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 0.95rem;
}
.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a.current {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.table tr:last-child td { border-bottom: none; }
.table.cles .cle-label { width: 46%; }
.table.cles .cle-input input { width: 100%; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.small { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Forms ---- */
.form label { display: block; font-weight: 600; margin: 0.75rem 0 0.25rem; }
.form input[type="text"],
.form input[type="password"],
.form select,
.form textarea,
.inline-form input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.form input:focus, .form select:focus, .form textarea:focus, .inline-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form-actions { display: flex; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: block; }
.cle-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; flex-wrap: wrap; }
textarea.mono, pre.preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
.mono { width: 100%; }
.preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  max-height: 420px;
  overflow: auto;
  margin: 0;
}

/* ---- Badges & chips ---- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.todo { background: var(--todo-bg); color: var(--todo); }
.badge.socle { background: #e0e7ff; color: #4338ca; margin-left: 0.4rem; }
.badge.inline { margin-left: 0.5rem; }

.chips { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: var(--todo-bg);
  color: var(--ink);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
}

/* ---- Alerts ---- */
.alert { padding: 0.7rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f4b4b4; }

/* ---- Test result inline ---- */
.test-result { font-size: 0.85rem; }
.test-result.ok { color: var(--ok); }
.test-result.ko { color: var(--danger); }
.test-result.na { color: var(--muted); }
.state { margin: 0.35rem 0; }

/* ---- Login ---- */
.login-wrap { max-width: 380px; margin: 3rem auto; }
.login-wrap h1 { text-align: center; }
.login-wrap .muted { text-align: center; }

/* =========================================================================
   Espace pro — compléments (réutilise le socle visuel de la console)
   ========================================================================= */

/* Marque : sous-titre métier dans la barre du haut */
.topbar .brand-sub { color: #94a3b8; font-weight: 400; font-size: 0.9rem; }
.topnav .who { color: #cbd5e1; font-size: 0.9rem; }
code { background: rgba(148, 163, 184, 0.18); padding: 0.05rem 0.35rem; border-radius: 6px; font-size: 0.9em; }

/* La sous-navigation reprend le style .subnav mais elle est hors du container :
   on lui redonne la largeur et le centrage. */
.subnav.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
}

/* ---- Grilles ---- */
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.9rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* ---- Cartes chiffres ---- */
.card.stat { text-align: center; padding: 1.1rem 0.75rem; }
.stat-num { font-size: 2rem; font-weight: 700; margin: 0; line-height: 1.1; }
.stat-num.accent-warn { color: var(--warn); }
.stat-num.accent-danger { color: var(--danger); }
.stat-label { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }

/* ---- Alertes complémentaires ---- */
.alert.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe6cb; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3d9a8; }
.alert a { font-weight: 600; }

/* ---- Filtres (chips cliquables + selects) ---- */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.chip-link {
  background: var(--todo-bg); color: var(--ink);
  padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.85rem;
}
.chip-link:hover { text-decoration: none; background: #e2e8f0; }
.chip-link.active { background: var(--primary); color: #fff; }
.filters-form { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters-form select {
  padding: 0.45rem 0.6rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: 0.9rem; font-family: inherit;
  background: #fff; color: var(--ink);
}

/* ---- Utilitaires table ---- */
.nowrap { white-space: nowrap; }
.table td.detail { font-size: 0.88rem; color: var(--muted); }

/* ---- Séjours & intervenants (cartes-fiches) ---- */
.sejour-head, .intervenant .sejour-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap;
}
.sejour-head h2 { margin: 0; }
.sejour-coords { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.card.intervenant.inactif { opacity: 0.72; }
.actif-form { margin-top: 0.6rem; }

/* Édition inline : lignes de champs alignées */
.field-row { display: flex; gap: 0.8rem; flex-wrap: wrap; align-items: flex-end; margin-top: 0.4rem; }
.field { display: flex; flex-direction: column; min-width: 140px; }
.field.grow { flex: 1 1 220px; }
.field label { font-weight: 600; margin: 0 0 0.25rem; font-size: 0.85rem; }
.field input, .field select {
  padding: 0.5rem 0.6rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: 0.92rem; font-family: inherit;
  background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.field-actions { display: flex; align-items: flex-end; }

/* ---- Planning : incidents ---- */
.resolve-form { display: flex; gap: 0.4rem; align-items: center; justify-content: flex-end; }
.cost-input { width: 90px; padding: 0.4rem 0.5rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.85rem; }
.photo-link { font-size: 0.85rem; }

/* ---- Validations (confirmations) ---- */
.card.confirm {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; border-left: 4px solid var(--warn);
}
.confirm-body { flex: 1 1 320px; }
.confirm-resume { font-weight: 600; margin: 0 0 0.25rem; }
.confirm-actions { display: flex; gap: 0.6rem; }

/* ---- Conversation (chat lecture seule) ---- */
.chat { display: flex; flex-direction: column; gap: 0.75rem; }
.msg { max-width: 82%; padding: 0.65rem 0.85rem; border-radius: 12px; }
.msg-user { align-self: flex-end; background: var(--primary); color: #fff; }
.msg-user .muted, .msg-user .msg-role { color: #dbe4ff; }
.msg-assistant { align-self: flex-start; background: var(--todo-bg); color: var(--ink); }
.msg-meta { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.75rem; margin-bottom: 0.2rem; }
.msg-role { font-weight: 600; }
.msg-body { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .table.cles .cle-label { width: auto; }
  .page-head { flex-direction: column; align-items: stretch; }
  .field-row { flex-direction: column; align-items: stretch; }
  .msg { max-width: 92%; }
}
