:root {
  --fond: #f6f7fb;
  --surface: #ffffff;
  --texte: #0f172a;
  --doux: #64748b;
  --trait: #e2e8f0;
  --accent: #4f46e5;
  --accent-texte: #ffffff;
  --accent-doux: #eef2ff;
  --urgent: #dc2626;
  --urgent-doux: #fef2f2;
  --or: #b45309;
  --or-doux: #fffbeb;
  --vert: #16a34a;
  --bulle-agent: #eef2ff;
  --bulle-appelant: #f1f5f9;
  --rayon: 14px;
  --ombre: 0 1px 2px rgb(15 23 42 / 0.06), 0 1px 1px rgb(15 23 42 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0b1020;
    --surface: #131a2e;
    --texte: #e2e8f0;
    --doux: #94a3b8;
    --trait: #24304d;
    --accent: #818cf8;
    --accent-texte: #0b1020;
    --accent-doux: #1e2350;
    --urgent: #f87171;
    --urgent-doux: #2a1418;
    --or: #fbbf24;
    --or-doux: #2a210e;
    --vert: #4ade80;
    --bulle-agent: #1e2350;
    --bulle-appelant: #1b2440;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: 8px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--doux); margin: 24px 0 8px; }
a { color: inherit; }

/* En-tête */
.entete {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--fond) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--trait);
}
.marque { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; }
.marque.grande { font-size: 1.6rem; margin-bottom: 8px; }
.pastille { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-doux); }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; color: var(--doux); padding: 6px 10px; border-radius: 999px; font-size: 0.95rem; }
nav a[aria-current] { color: var(--texte); background: var(--surface); box-shadow: var(--ombre); font-weight: 600; }

/* Éléments communs */
.carte { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre); }
.meta, .aide, .vide { color: var(--doux); font-size: 0.9rem; }
.vide { text-align: center; padding: 48px 0; }
.alerte { background: var(--urgent-doux); color: var(--urgent); padding: 10px 14px; border-radius: 10px; }
.etiquette {
  font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-doux); color: var(--accent); white-space: nowrap;
}
.etiquette.urgent { background: var(--urgent-doux); color: var(--urgent); }
.etiquette.prioritaire { background: var(--or-doux); color: var(--or); }
.etiquette.discret { background: var(--bulle-appelant); color: var(--doux); }

.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--trait); background: var(--surface); color: var(--texte);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.bouton.danger { color: var(--urgent); }
.bouton.lien { border: none; background: none; min-height: 36px; padding: 0; color: var(--doux); font-weight: 500; text-decoration: underline; }
.bouton.lien.danger { color: var(--urgent); }
input {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--trait); border-radius: 12px; min-height: 44px; padding: 0 14px; width: 100%;
}
input:focus-visible, .bouton:focus-visible, a:focus-visible { outline: 3px solid var(--accent-doux); outline-offset: 1px; border-color: var(--accent); }

/* Connexion */
.connexion { max-width: 360px; margin: 18vh auto 0; text-align: center; display: grid; gap: 12px; }
.connexion form { display: grid; gap: 10px; }
.code { text-align: center; font-size: 1.6rem; letter-spacing: 0.5em; padding-left: 0.5em; }

/* Liste des appels */
.barre { display: grid; gap: 10px; margin-bottom: 12px; }
.filtres { display: flex; gap: 6px; }
.filtres a { text-decoration: none; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--trait); color: var(--doux); font-size: 0.9rem; }
.filtres a[aria-current] { background: var(--texte); color: var(--fond); border-color: var(--texte); }
.appels, .contacts, .voyants, .chiffres, .conversation { list-style: none; margin: 0; padding: 0; }
.appels { display: grid; gap: 8px; }
.appel {
  display: block; text-decoration: none; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre);
  border-left: 4px solid var(--accent);
}
.appel:hover { border-color: var(--accent); }
.appel.urgent { border-left-color: var(--urgent); }
.ligne-haut { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ligne-haut time { margin-left: auto; color: var(--doux); font-size: 0.85rem; white-space: nowrap; }
.objet { margin: 4px 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ligne-bas { display: flex; gap: 6px; color: var(--doux); font-size: 0.85rem; }
.audio-dispo { margin-left: auto; color: var(--accent); }

/* Fiche d'un appel */
.retour { display: inline-block; color: var(--doux); text-decoration: none; margin-bottom: 8px; }
.fiche header { padding-bottom: 8px; }
.fiche.urgent h1::after { content: "Urgent"; font-size: 0.75rem; vertical-align: middle; margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--urgent-doux); color: var(--urgent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
audio { width: 100%; }
.compte-rendu { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; padding: 16px; background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); }
.compte-rendu dt { color: var(--doux); }
.compte-rendu dd { margin: 0; font-weight: 500; }
.conversation { display: grid; gap: 6px; }
.conversation li { display: flex; }
.conversation span { max-width: 85%; padding: 8px 12px; border-radius: 16px; }
.conversation .agent span { background: var(--bulle-agent); border-bottom-left-radius: 4px; }
.conversation .appelant { justify-content: flex-end; }
.conversation .appelant span { background: var(--bulle-appelant); border-bottom-right-radius: 4px; }
.fiche > form { margin-top: 32px; }

/* Contacts */
.ajout { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; margin: 16px 0; }
.ajout .case { display: flex; align-items: center; gap: 8px; color: var(--doux); }
.ajout .case input { width: auto; min-height: 0; }
.contacts { display: grid; gap: 8px; }
.contacts li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }

/* État */
.voyants { display: grid; gap: 8px; margin: 16px 0; }
.voyants li { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.voyant { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--doux); }
.voyant.vert { background: var(--vert); box-shadow: 0 0 0 4px color-mix(in srgb, var(--vert) 20%, transparent); }
.voyant.rouge { background: var(--urgent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--urgent) 20%, transparent); }
.voyant.bleu { background: var(--accent); }
.chiffres { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 24px; }
.chiffres li { padding: 14px; text-align: center; display: grid; }
.chiffres strong { font-size: 1.6rem; }
.chiffres span { color: var(--doux); font-size: 0.85rem; }

@media (max-width: 480px) {
  .ajout { grid-template-columns: 1fr; }
  .compte-rendu { grid-template-columns: 1fr; gap: 2px; }
  .compte-rendu dd { margin-bottom: 8px; }
}

/* ---------------------------------------------------------------------------
   Boîte : liste + fiche. Téléphone : l'une OU l'autre. Ordinateur : côte à côte.
   --------------------------------------------------------------------------- */
.boite.avec-fiche .colonne-liste { display: none; }
.boite:not(.avec-fiche) .colonne-fiche { display: none; }
.invite { display: grid; place-items: center; gap: 12px; text-align: center; color: var(--doux); padding: 64px 24px; }
.appel[aria-current] { border-color: var(--accent); background: var(--accent-doux); }

@media (min-width: 960px) {
  main { max-width: 1280px; padding: 24px; }
  .entete { padding-left: 24px; padding-right: 24px; }
  .boite { display: grid; grid-template-columns: minmax(340px, 400px) 1fr; gap: 24px; align-items: start; }
  .boite .colonne-liste, .boite .colonne-fiche { display: block !important; }
  .colonne-liste {
    position: sticky; top: 80px;
    max-height: calc(100vh - 104px); overflow-y: auto;
    padding-right: 4px; scrollbar-width: thin;
  }
  .colonne-fiche {
    background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon);
    box-shadow: var(--ombre); padding: 8px 32px 32px; min-height: calc(100vh - 104px);
  }
  .colonne-fiche .retour { display: none; }
  .colonne-fiche .compte-rendu { background: var(--fond); }
  .fiche h1 { font-size: 1.8rem; margin-top: 16px; }

  /* Contacts : formulaire en ligne, cartes sur plusieurs colonnes */
  .ajout { grid-template-columns: 2fr 2fr auto auto; align-items: center; }
  .contacts { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

  /* État : voyants et chiffres sur une ligne */
  .voyants { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .chiffres { max-width: 720px; }
}

/* ---------------------------------------------------------------------------
   Suivi, direct, réglages
   --------------------------------------------------------------------------- */
.etiquette.or { background: var(--or-doux); color: var(--or); }
.etiquette.ok { background: color-mix(in srgb, var(--vert) 15%, transparent); color: var(--vert); }
.appel.traite { opacity: 0.6; border-left-color: var(--trait); }
.succes { background: color-mix(in srgb, var(--vert) 12%, transparent); color: var(--vert); padding: 10px 14px; border-radius: 10px; }
textarea, select {
  font: inherit; color: inherit; background: var(--surface); width: 100%;
  border: 1px solid var(--trait); border-radius: 12px; padding: 10px 14px;
}
select { min-height: 44px; }
textarea { resize: vertical; line-height: 1.5; }
label { display: grid; gap: 4px; color: var(--doux); font-size: 0.9rem; }
label.case { display: flex; align-items: center; gap: 8px; color: var(--texte); font-size: 0.95rem; }
label.case input { width: auto; min-height: 0; }

.suivi .statuts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.suivi .bouton.actif { background: var(--texte); color: var(--fond); border-color: var(--texte); }
.suivi .note { display: grid; gap: 6px; justify-items: start; }

.ligne-formulaire { display: flex; gap: 8px; }
.ligne-formulaire input, .ligne-formulaire select { flex: 1; }
.appeler { padding: 4px 16px 16px; margin: 16px 0; }
.console { padding: 16px; margin: 16px 0; border-color: var(--accent); }
.console header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.console #console-duree { margin-left: auto; }
.console .conversation { max-height: 50vh; overflow-y: auto; padding: 4px 0; }
.appel.en-direct { border-left-color: var(--vert); }
.appel .actions { margin-top: 8px; }
.voyant.clignote { animation: clignote 1.4s ease-in-out infinite; }
@keyframes clignote { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .voyant.clignote { animation: none; } }

.reglages { display: grid; gap: 12px; }
.reglages .carte { padding: 4px 16px 16px; display: grid; gap: 10px; }
.horaires, .jours { display: flex; flex-wrap: wrap; gap: 12px; }
.horaires input { width: auto; }
.barre-enregistrer { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--fond) 30%); }
.barre-enregistrer .bouton { width: 100%; }

@media (min-width: 960px) {
  .reglages { grid-template-columns: 1fr 1fr; align-items: start; }
  .reglages .carte:nth-child(3) { grid-row: span 2; }
  .barre-enregistrer { grid-column: 1 / -1; }
  .barre-enregistrer .bouton { width: auto; min-width: 240px; }
  .console .conversation { max-height: 60vh; }
}

/* Téléphone : 5 onglets → le menu défile, la marque se réduit à sa pastille */
@media (max-width: 560px) {
  .entete { gap: 8px; }
  .entete .marque { font-size: 0; gap: 0; }
  nav { overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; padding: 6px 9px; }
}
