/* Agents — feuille de style unique. Mobile d'abord, lisible au soleil, sombre la nuit. */

:root {
  --vert: #0f7b5a;
  --vert-clair: #14a074;
  --vert-pale: #e8f5f0;
  --accent: var(--vert);
  --accent-fg: #fff;

  --bg: #f6f7f6;
  --surface: #fff;
  --surface-2: #f0f2f1;
  --bord: #e2e6e4;
  --texte: #16211d;
  --muted: #667873;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: var(--vert);

  --radius: 16px;
  --radius-sm: 10px;
  --ombre: 0 1px 2px rgba(16, 33, 29, .06), 0 4px 16px rgba(16, 33, 29, .05);
  --ombre-forte: 0 4px 24px rgba(16, 33, 29, .14);
  --gutter: 16px;
  --topbar-h: 56px;
  --tabs-h: 60px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --transition: 160ms cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --vert-pale: #10241d;
    --bg: #0d1412;
    --surface: #141c1a;
    --surface-2: #1b2422;
    --bord: #263230;
    --texte: #e8efec;
    --muted: #8ba099;
    --danger: #ef6a5a;
    --warn: #e0a952;
    --ombre: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --ombre-forte: 0 4px 24px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --vert-pale: #10241d;
  --bg: #0d1412;
  --surface: #141c1a;
  --surface-2: #1b2422;
  --bord: #263230;
  --texte: #e8efec;
  --muted: #8ba099;
  --danger: #ef6a5a;
  --warn: #e0a952;
  --ombre: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --ombre-forte: 0 4px 24px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--texte);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  overscroll-behavior-y: none;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -.015em; }
h2 { font-size: 22px; margin: 4px 0 14px; }
h3 { font-size: 16px; margin: 22px 0 10px; }
p { margin: 0 0 10px; }
a { color: var(--vert-clair); }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0 0; }

/* ---------- connexion ---------- */
#login { display: grid; place-items: center; min-height: 100dvh; padding: var(--gutter); }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: 20px;
  padding: 32px 24px; box-shadow: var(--ombre-forte); text-align: center;
}
.login-logo { width: 64px; height: 64px; border-radius: 18px; }
.login-card h1 { font-size: 24px; margin: 14px 0 22px; }

input, textarea, select, button { font: inherit; color: inherit; }

input[type=password], input[type=text], textarea, select {
  width: 100%; padding: 13px 14px; border: 1px solid var(--bord); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--texte); transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--vert-clair); }

button { cursor: pointer; border: 0; background: none; }

.login-card button[type=submit], .btn {
  background: var(--accent); color: var(--accent-fg); border-radius: var(--radius-sm);
  padding: 13px 18px; font-weight: 600; transition: transform var(--transition), opacity var(--transition);
}
.login-card button[type=submit] { width: 100%; margin-top: 12px; }
.btn:active, .login-card button[type=submit]:active { transform: scale(.98); }
.btn.ghost { background: var(--surface-2); color: var(--texte); border: 1px solid var(--bord); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 14px; }

/* ---------- ossature ---------- */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-t) + 8px) var(--gutter) 8px;
  min-height: calc(var(--topbar-h) + var(--safe-t));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--bord);
}

.agent-pill {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--bord); border-radius: 999px; padding: 5px 12px 5px 5px;
  font-weight: 600; box-shadow: var(--ombre); transition: transform var(--transition);
}
.agent-pill:active { transform: scale(.97); }
.agent-pill img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.agent-pill .chev { color: var(--muted); font-size: 12px; }

.top-right { display: flex; align-items: center; gap: 8px; }
.budget { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget.warn { color: var(--warn); font-weight: 600; }
.badge-btn {
  background: var(--accent); color: var(--accent-fg); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
}

.view { flex: 1; padding: var(--gutter); padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 20px); }
#view-chat { display: flex; flex-direction: column; padding: 0; }

/* ---------- navigation ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--bord);
  padding-bottom: var(--safe-b);
}
#tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 9px 2px 7px; color: var(--muted); font-size: 16px; min-height: var(--tabs-h);
  transition: color var(--transition);
}
#tabs button span { font-size: 10.5px; font-weight: 600; letter-spacing: .01em; }
#tabs button.active { color: var(--vert-clair); }
#tabs button .dot {
  position: absolute; transform: translate(14px, -10px);
  width: 7px; height: 7px; border-radius: 50%; background: var(--danger);
}

/* ---------- chat ---------- */
.messages { flex: 1; overflow-y: auto; padding: var(--gutter); display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--ombre); }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-fg); border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 5px; }
.msg .who { font-size: 11px; font-weight: 700; opacity: .65; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.msg.pending { opacity: .55; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 var(--gutter) 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: var(--surface); border: 1px solid var(--bord);
  border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 500; color: var(--texte);
}
.chip:active { background: var(--vert-pale); }

.composer {
  position: sticky; bottom: calc(var(--tabs-h) + var(--safe-b)); z-index: 20;
  display: flex; align-items: flex-end; gap: 8px; padding: 10px var(--gutter) 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--bord);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 11px 15px; line-height: 1.4;
}
.icon-btn {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; font-size: 19px;
  background: var(--surface-2); display: grid; place-items: center;
  transition: transform var(--transition), background var(--transition);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.primary { background: var(--accent); color: var(--accent-fg); }
.icon-btn.recording { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- cartes ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 15px;
  box-shadow: var(--ombre); margin-bottom: 12px;
}
.card h3, .card h4 { margin: 0 0 8px; font-size: 16px; }
.card .meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.card .btns { margin-top: 12px; }
.card details { margin-top: 10px; }
.card summary { color: var(--vert-clair); font-size: 14px; font-weight: 600; cursor: pointer; }
.card details pre, .card details .body {
  white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.55;
  margin: 10px 0 0; color: var(--texte); font-family: inherit;
}

.vide { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.vide .emoji { font-size: 34px; display: block; margin-bottom: 10px; opacity: .55; }

/* bandeau d'alerte / d'information */
.bandeau {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--vert-pale); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 14px; font-size: 14px; line-height: 1.45;
}
.bandeau.alerte { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.bandeau.erreur { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.bandeau b { display: block; margin-bottom: 2px; }

/* ---------- leads ---------- */
.lead-row {
  display: flex; gap: 12px; align-items: center; background: var(--surface);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 9px;
  box-shadow: var(--ombre); transition: transform var(--transition);
}
.lead-row:active { transform: scale(.99); }
.lead-row .flammes { font-size: 19px; flex: 0 0 auto; }
.lead-row .info { flex: 1; min-width: 0; }
.lead-row .nom { font-weight: 650; }
.lead-row .sous { font-size: 12.5px; color: var(--muted); }

.tag {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  text-transform: uppercase;
}
.tag.deterministic { background: var(--vert); color: #fff; }
.tag.probable { background: var(--vert-clair); color: #fff; }
.tag.influenced { background: var(--warn); color: #fff; }
.tag.unknown { background: var(--surface-2); color: var(--muted); }

.lead-card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--ombre); margin-bottom: 12px; }
.lead-card h2 { margin: 0 0 4px; }
.lead-card .section { margin-top: 16px; }
.lead-card .section-titre {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.timeline { font-size: 13px; line-height: 1.6; }
.timeline .quand { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- médias, veille, tunnel ---------- */
.upload-btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-fg);
  border-radius: var(--radius-sm); padding: 11px 16px; font-weight: 600; font-size: 14.5px; cursor: pointer;
}
.media-row, .compte-row {
  display: flex; gap: 12px; align-items: center; background: var(--surface);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 9px; box-shadow: var(--ombre);
}
.media-row .info, .compte-row .info { flex: 1; min-width: 0; }
.media-row .slug, .compte-row .nom { font-weight: 650; word-break: break-all; }
.media-row audio { width: 100%; margin-top: 8px; height: 34px; }
.media-row .del, .compte-row .del {
  background: none; color: var(--danger); font-size: 17px; flex: 0 0 auto;
  width: 34px; height: 34px; border-radius: 50%;
}
.media-row .del:active, .compte-row .del:active { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.media-row .used { font-size: 12px; color: var(--vert-clair); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 9px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; box-shadow: var(--ombre); }
.stat .valeur { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat .libelle { font-size: 11px; color: var(--muted); margin-top: 3px; }

.outlier-row { background: var(--surface); border-radius: var(--radius); padding: 13px 15px; margin-bottom: 9px; box-shadow: var(--ombre); }
.outlier-row .score { font-weight: 700; color: var(--vert-clair); }
.outlier-row .legende { font-size: 13.5px; color: var(--muted); margin-top: 5px; line-height: 1.45; }

/* ---------- markdown (brief, profil) ---------- */
.md { line-height: 1.65; }
.md h1 { font-size: 21px; margin: 18px 0 10px; }
.md h2 { font-size: 18px; margin: 20px 0 8px; }
.md h3 { font-size: 15.5px; margin: 16px 0 6px; }
.md ul, .md ol { padding-left: 21px; margin: 8px 0; }
.md li { margin: 4px 0; }
.md blockquote {
  border-left: 3px solid var(--vert-clair); margin: 12px 0; padding: 4px 0 4px 13px; color: var(--muted);
}
.md table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 12px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--bord); padding: 7px 9px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 650; }
.md code { font-size: 13px; }
.md hr { border: 0; border-top: 1px solid var(--bord); margin: 20px 0; }

textarea.editeur {
  width: 100%; min-height: 58vh; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  border-radius: var(--radius-sm); padding: 14px; resize: vertical;
}

/* ---------- feuille du bas ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 16, 14, .5); backdrop-filter: blur(3px); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px var(--gutter) calc(var(--safe-b) + 20px);
  max-height: 80vh; overflow-y: auto; box-shadow: var(--ombre-forte);
  animation: monte var(--transition);
}
@keyframes monte { from { transform: translateY(100%); } }
.sheet-body::before {
  content: ""; display: block; width: 38px; height: 4px; border-radius: 2px;
  background: var(--bord); margin: 4px auto 14px;
}
.sheet-close { font-size: 19px; color: var(--muted); width: 34px; height: 34px; border-radius: 50%; }

.agent-choix {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 9px;
}
.agent-choix img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.agent-choix .nom { font-weight: 650; }
.agent-choix .desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.agent-choix.actif { background: var(--vert-pale); box-shadow: inset 0 0 0 2px var(--vert-clair); }
.agent-choix .cmds { font-size: 11.5px; color: var(--vert-clair); margin-top: 3px; word-break: break-word; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + var(--safe-b) + 18px); z-index: 80;
  background: var(--texte); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500; box-shadow: var(--ombre-forte); max-width: calc(100vw - 32px);
  animation: monte-toast var(--transition);
}
@keyframes monte-toast { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
