:root {
  --bg: #edf1ef;
  --surface: #ffffff;
  --sunken: #f5f8f6;
  --ink: #1a2622;
  --muted: #5f6d68;
  --line: #d3dcd8;
  --accent: #0b6b58;
  --accent-hover: #095a4a;
  --accent-soft: #dcebe6;
  --on-accent: #ffffff;
  --signal: #b57712;
  --signal-soft: #f6ead3;
  --danger: #a93a2e;
  --danger-soft: #f6e1de;
  --focus: #1f8f74;

  --font: 'Hanken Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111916;
    --surface: #18221e;
    --sunken: #141d1a;
    --ink: #e3ebe7;
    --muted: #93a39d;
    --line: #2b3934;
    --accent: #3fb396;
    --accent-hover: #5cc6aa;
    --accent-soft: #1d3730;
    --on-accent: #0c1a16;
    --signal: #e0a94a;
    --signal-soft: #3a2f1a;
    --danger: #e3826f;
    --danger-soft: #3b211d;
    --focus: #5cc6aa;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
code, pre { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.85em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.rail {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; padding: 0 10px 20px; display: flex; gap: 10px; align-items: center; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 14px; height: 14px; }
.org-pick { padding: 0 10px 18px; display: grid; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.org-name { padding: 0 10px 18px; font-weight: 600; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--sunken); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; }
.rail-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; font-size: 0.875rem; }
.rail-foot .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; }

main { padding: 36px 44px 80px; max-width: 1180px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 62ch; }
.back { display: inline-block; margin-bottom: 10px; font-size: 0.875rem; }

.section { margin-top: 36px; }
.section > h2 { margin-bottom: 4px; }
.section > .hint { color: var(--muted); margin-bottom: 14px; max-width: 70ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ---------- Boutons et formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 0.925rem;
  padding: 9px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.55; cursor: progress; }

.form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: 0.9rem; }
.field .help { color: var(--muted); font-size: 0.85rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="url"],
input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 11px; width: 100%;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
textarea.tall { min-height: 360px; font-size: 0.925rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input[readonly] { background: var(--sunken); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > input, .inline > select { flex: 1; min-width: 160px; }
fieldset { border: 0; padding: 0; margin: 0; }

.form-section { padding: 24px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section > header h2 { font-size: 1rem; }
.form-section > header p { color: var(--muted); font-size: 0.875rem; margin-top: 4px; }
.savebar {
  position: sticky; bottom: 0; margin-top: 12px;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.hours { display: grid; grid-template-columns: 110px 1fr; gap: 8px 14px; align-items: center; }
.hours label { font-weight: 500; }

/* ---------- Listes ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.list-row {
  display: grid; align-items: center; gap: 16px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.list-row:first-child { border-top: 0; }
a.list-row:hover { background: var(--sunken); }
.list-row .title { font-weight: 700; }
.list-row .sub { color: var(--muted); font-size: 0.875rem; }
.calls-row { grid-template-columns: 150px 170px minmax(0, 1fr) 90px 110px; }
.calls-row .summary { color: var(--muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bots-row { grid-template-columns: minmax(0, 1fr) 90px 110px 110px; }
.numbers-row { grid-template-columns: minmax(0, 1fr) 240px auto; }
.big-number { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.simple-row { grid-template-columns: minmax(0, 1fr) auto; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  background: var(--sunken); color: var(--muted); border: 1px solid var(--line);
}
.chip.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warn { background: var(--signal-soft); color: var(--signal); border-color: transparent; }
.chip.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 8px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.stats div { padding: 18px 22px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats dt { color: var(--muted); font-size: 0.875rem; }
.stats dd { margin: 4px 0 0; font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.steps { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 12px; counter-reset: step; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: start; }
.steps li::before {
  content: counter(step); width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 0.875rem;
  background: var(--accent-soft); color: var(--accent);
}

.empty { padding: 48px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty p { color: var(--muted); max-width: 52ch; }
.loading { color: var(--muted); }

/* ---------- Fiche d'appel : la bande de conversation ---------- */
.call-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: flex-end; }
.call-number { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.call-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); margin-top: 6px; }
.summary-box { margin-top: 22px; padding: 18px 22px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--r-md); max-width: 75ch; }
.summary-box h2 { font-size: 0.95rem; margin-bottom: 6px; }
audio { width: 100%; max-width: 560px; margin-top: 20px; }

.strip { position: relative; margin-top: 28px; padding-left: 0; list-style: none; display: grid; gap: 0; max-width: 820px; }
.strip::before { content: ''; position: absolute; left: 71px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.turn { display: grid; grid-template-columns: 56px 32px minmax(0, 1fr); gap: 0; padding: 10px 0; position: relative; }
.turn time { text-align: right; padding-right: 12px; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; padding-top: 3px; }
.turn .dot { width: 12px; height: 12px; border-radius: 50%; margin: 6px auto 0; background: var(--surface); border: 2px solid var(--muted); position: relative; z-index: 1; }
.turn.agent .dot { background: var(--accent); border-color: var(--accent); }
.turn .who { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.turn.agent .who { color: var(--accent); }
.turn .msg { max-width: 68ch; }
.turn.user .msg { font-weight: 500; }

/* ---------- Agenda ---------- */
.day { margin-top: 26px; }
.day h3 { margin-bottom: 10px; text-transform: none; }
.appt-row { grid-template-columns: 80px minmax(0, 1fr) auto; }
.appt-time { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.slots { display: flex; flex-wrap: wrap; gap: 8px; }
.slots label { cursor: pointer; }
.slots input { position: absolute; opacity: 0; pointer-events: none; }
.slots span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); font-variant-numeric: tabular-nums; font-weight: 600; }
.slots input:checked + span { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.slots input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Divers ---------- */
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
pre.code { background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; overflow-x: auto; line-height: 1.6; margin: 0; }
.callout { padding: 14px 18px; border-radius: var(--r-md); background: var(--signal-soft); color: var(--ink); border: 1px solid transparent; }
.callout strong { color: var(--signal); }
.secret-box { padding: 14px 18px; border-radius: var(--r-md); background: var(--accent-soft); display: grid; gap: 8px; }
table.logs { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.logs th, table.logs td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); }
table.logs th { color: var(--muted); font-weight: 600; border-top: 0; }
.table-wrap { overflow-x: auto; }

dialog {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgb(10 20 17 / 0.45); }
dialog .dlg-head { padding: 20px 24px 0; display: flex; justify-content: space-between; align-items: center; }
dialog .dlg-body { padding: 18px 24px 24px; overflow-y: auto; }
dialog .dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.close-x { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: var(--r-sm); }
.close-x:hover { background: var(--sunken); }

#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r-md); max-width: 380px; font-weight: 500; box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-side { background: var(--accent); color: var(--on-accent); padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-side h1 { font-size: clamp(2rem, 4vw, 3.25rem); max-width: 14ch; letter-spacing: -0.03em; }
.login-side p { opacity: 0.85; max-width: 40ch; margin-top: 14px; }
.wave { display: flex; gap: 5px; align-items: center; height: 64px; }
.wave i { display: block; width: 6px; border-radius: 3px; background: currentColor; opacity: 0.75; }
.login-form { display: grid; place-items: center; padding: 40px 24px; }
.login-form form { width: min(360px, 100%); }

@media (prefers-reduced-motion: no-preference) {
  .wave i { animation: pulse 1.6s ease-in-out infinite; transform-origin: center; }
  @keyframes pulse { 50% { transform: scaleY(0.45); } }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail, main { min-width: 0; }
  .rail { position: static; height: auto; padding: 14px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding-bottom: 10px; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .rail-foot { display: none; }
  main { padding: 24px 18px 80px; }
  .cols, .form-section { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats div:nth-child(3) { border-left: 0; }
  .stats div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .calls-row { grid-template-columns: 1fr auto; }
  .calls-row > :nth-child(3), .calls-row > :nth-child(4) { display: none; }
  .bots-row { grid-template-columns: 1fr auto; }
  .bots-row > :nth-child(2), .bots-row > :nth-child(3) { display: none; }
  .numbers-row { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-side { padding: 32px 24px; gap: 24px; }
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
