/* Cahier de garde – feuille de style */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1b2734;
  --ink-2: #4c5b6d;
  --muted: #6c7a8b;
  --line: #dfe5ec;
  --line-2: #eef1f5;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --brand-soft: #e5edf6;
  --accent: #0f7b6c;
  --warn: #a35b00;
  --warn-soft: #fff3e0;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #1d7a3e;
  --ok-soft: #e6f4ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 35, 55, .06), 0 2px 8px rgba(20, 35, 55, .04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #1a212b; --ink: #e6ebf1; --ink-2: #b8c3cf; --muted: #8f9cab;
    --line: #2c3643; --line-2: #222b36; --brand: #4f8fcf; --brand-ink: #0c1520; --brand-soft: #1f3247;
    --accent: #3fb8a5; --warn: #f0a548; --warn-soft: #3a2a14; --danger: #ef6b62; --danger-soft: #3d1c1a;
    --ok: #5cc27e; --ok-soft: #173322; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand); }
h1 { font-size: 1.55rem; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: 0 0 .6rem; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
code.big { font-size: 1.25rem; padding: .2rem .5rem; background: var(--brand-soft); border-radius: 6px; user-select: all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.text { white-space: pre-line; overflow-wrap: anywhere; }
.center { text-align: center; }
.warn { color: var(--warn); }

/* ---- barre du haut ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .55rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); font-size: .78rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand); color: var(--brand-ink); font-weight: 700;
}
.brand-mark.big { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 13px; margin: 0 auto .8rem; }
.nav { display: flex; align-items: center; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav > a {
  padding: .45rem .7rem; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.nav > a:hover { background: var(--line-2); }
.nav > a.active { background: var(--brand-soft); color: var(--brand); }
.nav > a.nav-cta { background: var(--brand); color: var(--brand-ink); margin-right: .4rem; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: .8rem; font-size: .88rem; color: var(--muted); }
.nav-user form { margin: 0; }
.nav-toggle, .nav-burger { display: none; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }

/* ---- page ---- */
.page { max-width: 1280px; margin: 0 auto; padding: 1.25rem; padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
.narrow { max-width: 760px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-actions, .actions, .filter-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.stack { display: flex; flex-direction: column; gap: .9rem; }
.stack-tight { display: flex; flex-direction: column; gap: .35rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.1rem; }

/* ---- formulaires ---- */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.optional, .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%;
  font-weight: 400; min-height: 42px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip input:focus-visible + span {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--brand); }
.input-row { display: flex; gap: .4rem; }
.input-row input { flex: 1; }
.check-inline { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips legend { width: 100%; }
.chip { flex-direction: row; font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer; background: var(--surface); user-select: none;
}
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip-2 input:checked + span, .chip-3 input:checked + span { background: var(--warn); border-color: var(--warn); color: #fff; }
.followup { display: none; }
.followup.show { display: flex; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .95rem; min-height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--brand); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-small { padding: .3rem .65rem; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; }

/* ---- messages ---- */
.flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .65rem .9rem; border-radius: 8px; border-left: 4px solid var(--brand); background: var(--brand-soft); }
.flash-success { border-color: var(--ok); background: var(--ok-soft); }
.flash-error { border-color: var(--danger); background: var(--danger-soft); }
.flash-warning { border-color: var(--warn); background: var(--warn-soft); }

/* ---- étiquettes ---- */
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .8rem; font-weight: 600; }
.tag-urgent { background: var(--danger); color: #fff; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); text-decoration: none; }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-err { background: var(--danger-soft); color: var(--danger); }

/* ---- filtres ---- */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; padding: .9rem 1rem; }
.filters label { flex: 0 1 160px; }
.filters label.grow { flex: 1 1 220px; }

.filter-box > summary { list-style: none; margin-bottom: .6rem; }
.filter-box > summary::-webkit-details-marker { display: none; }
@media (min-width: 861px) { .filter-box > summary { display: none; } }

/* ---- tableaux ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--line-2); }
th, td { padding: .6rem .75rem; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
table.calls td.text { min-width: 220px; max-width: 420px; }
table.calls tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
tr.is-urgent td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
tr.is-open td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
tr.is-urgent.is-open td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
tr.is-inactive td { opacity: .55; }
.row-link a { text-decoration: none; font-size: 1.3rem; color: var(--muted); }
.pending { margin-top: .35rem; color: var(--warn); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; }
.empty { text-align: center; padding: 2.5rem 1rem; }

/* ---- fiche appel ---- */
.details { display: grid; grid-template-columns: 210px 1fr; gap: .55rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-weight: 600; font-size: .88rem; }
.details dd { margin: 0; }
.trace { margin: 1rem 0 0; padding-top: .7rem; border-top: 1px solid var(--line-2); }
.danger-zone { text-align: right; }

/* ---- statistiques ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.kpi strong { display: block; font-size: 1.9rem; line-height: 1.1; color: var(--brand); }
.kpi span { color: var(--muted); font-size: .88rem; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.bars li { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 3ch; align-items: center; gap: .6rem; font-size: .9rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
progress { appearance: none; -webkit-appearance: none; width: 100%; height: 12px; border: 0; border-radius: 4px; background: var(--line-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line-2); border-radius: 4px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 4px; }

/* ---- rapport ---- */
.report-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--brand); padding-bottom: .8rem; margin-bottom: .8rem; }
.report-kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--muted); margin: 0; }
.report-kpis { display: flex; gap: 1.4rem; }
.report-kpis div { text-align: center; }
.report-kpis strong { display: block; font-size: 1.6rem; color: var(--brand); line-height: 1.1; }
.report-kpis span { font-size: .8rem; color: var(--muted); }
.report-summary .tag { margin: 0 .2rem .3rem 0; }
.report-open { background: var(--warn-soft); border-radius: 8px; padding: .5rem 1rem; margin: .8rem 0; }
.report-open h3 { color: var(--warn); margin-top: .4rem; }
.report-day h3 { border-bottom: 1px solid var(--line); padding-bottom: .25rem; margin-top: 1.4rem; }
.report-table { font-size: .9rem; }
.report-table th { background: transparent; }
.report-foot { margin-top: 1.5rem; padding-top: .6rem; border-top: 1px solid var(--line); }

/* ---- administration ---- */
.subnav { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; }
.subnav a { padding: .55rem .9rem; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.subnav a.active { color: var(--brand); border-color: var(--brand); }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; align-items: start; }
.admin-grid > .stack { gap: 0; }
.motif-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input[name=label] { flex: 1; }
.log { list-style: none; padding: 0; margin: 0; font-size: .85rem; display: flex; flex-direction: column; gap: .3rem; }
.smtp-info { border-top: 1px solid var(--line-2); padding-top: .7rem; }
.warn-box { background: var(--warn-soft); border-radius: 8px; padding: .6rem 1rem; }
.warn-box summary { cursor: pointer; font-weight: 600; color: var(--warn); }

.merge-table td:first-child { min-width: 220px; }
.merge-table input { min-width: 240px; }
.merge-table tr.is-changed td { background: color-mix(in srgb, var(--warn-soft) 70%, transparent); }

.brand-logo { height: 46px; width: auto; max-width: 140px; object-fit: contain; }
.login-logo { display: block; max-width: 200px; max-height: 150px; width: auto; height: auto; margin: 0 auto 1rem; }
.logo-preview img { max-width: 200px; max-height: 150px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.garde-nav { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }

.rcpt-table td:first-child { white-space: nowrap; }
.rcpt-table input { min-width: 260px; }

/* ---- bandeau, OTP ---- */
.banner { background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); padding: .55rem 1.25rem; font-size: .9rem; text-align: center; }
.qr { display: flex; justify-content: center; padding: .5rem; }
.qr img { background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--line); max-width: 100%; height: auto; }
.otp-input { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.login-note { background: var(--brand-soft); border-radius: 8px; padding: .5rem .75rem; text-align: left; }
.details.compact { grid-template-columns: 190px 1fr; font-size: .9rem; }
.details code { overflow-wrap: anywhere; }
body.is-external .topbar { border-top: 3px solid var(--accent); }

/* ---- connexion / erreurs ---- */
.login-page .page { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.75rem; text-align: center; box-shadow: var(--shadow); }
.login-card form { text-align: left; margin: 1.2rem 0; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--brand); margin: 0; }

/* ---- mobile ---- */
@media (max-width: 860px) {
  .page { padding: .9rem; }
  .topbar { padding: .5rem .9rem; }
  .nav-burger { display: block; margin-left: auto; width: 40px; height: 40px; cursor: pointer; position: relative; }
  .nav-burger span, .nav-burger span::before, .nav-burger span::after {
    position: absolute; left: 9px; width: 22px; height: 2px; background: var(--ink); content: ""; border-radius: 2px;
  }
  .nav-burger span { top: 19px; }
  .nav-burger span::before { top: -7px; left: 0; }
  .nav-burger span::after { top: 7px; left: 0; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: .5rem; }
  .nav-toggle:checked ~ .nav { display: flex; }
  .nav > a.nav-cta { margin: 0 0 .3rem; text-align: center; }
  .nav-user { margin: .5rem 0 0; padding-top: .6rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
  .grid-2, .admin-grid, .stat-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .details { grid-template-columns: 1fr; gap: .1rem; }
  .details dd { margin-bottom: .6rem; }
  .filters label { flex: 1 1 140px; }
  .actions .btn { flex: 1; }

  /* tableaux en cartes */
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  table.calls, table.simple, table.calls tbody, table.simple tbody, table.calls tr, table.simple tr { display: block; }
  table.calls thead, table.simple thead { display: none; }
  table.calls tr, table.simple tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    margin-bottom: .6rem; padding: .5rem .8rem; position: relative;
  }
  table.calls td, table.simple td { display: block; border: 0; padding: .2rem 0; max-width: none; min-width: 0; }
  table.calls td[data-label]::before, table.simple td[data-label]::before {
    content: attr(data-label); display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  }
  table.calls td:first-child::before { display: none; }
  table.calls td:first-child { box-shadow: none !important; font-size: 1.05rem; }
  table.calls tr.is-urgent { border-left: 4px solid var(--danger); }
  table.calls tr.is-open { border-left: 4px solid var(--warn); }
  .row-link { position: absolute; top: .4rem; right: .8rem; }
  table.calls td.is-empty { display: none; }
}

/* ---- impression ---- */
@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #444; --line: #bbb; --line-2: #ddd; --brand: #1f4e79; color-scheme: light; }
  @page { size: A4 landscape; margin: 12mm; }
  body { font-size: 10.5pt; }
  .no-print, .topbar { display: none !important; }
  .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .report-day { break-inside: auto; }
  .report-table tr { break-inside: avoid; }
  .report-open { border: 1px solid #e0b06a; }
  a { color: inherit; text-decoration: none; }
}
