:root {
  --bg: #f8fafc; --surface: #ffffff; --surface-2: #f1f5f9; --border: #e2e8f0;
  --text: #0f172a; --muted: #64748b; --accent: #0369a1; --accent-text: #ffffff;
  --ok: #047857; --ok-bg: #d1fae5; --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --info: #1d4ed8; --info-bg: #dbeafe;
  --radius: 12px; --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 4px 12px rgb(15 23 42 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #1e293b; --border: #263244;
    --text: #e2e8f0; --muted: #94a3b8; --accent: #38bdf8; --accent-text: #0b1120;
    --ok: #34d399; --ok-bg: #064e3b; --warn: #fbbf24; --warn-bg: #451a03;
    --bad: #f87171; --bad-bg: #450a0a; --info: #93c5fd; --info-bg: #1e3a8a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { display: grid; place-items: center; min-height: 60vh; text-align: center; padding: 16px; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.top-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: 1280px; margin: 0 auto; }
.top-row h1 { font-size: 17px; margin: 0 auto 0 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }
.sub { font-size: 13px; color: var(--muted); max-width: 1280px; margin: 4px auto 0; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner .grow { flex: 1 1 200px; }

/* Kanban : colonnes défilantes sur téléphone, grille sur grand écran */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(82%, 1fr); gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; }
@media (min-width: 768px) { .board { grid-auto-columns: minmax(300px, 1fr); } }
@media (min-width: 1280px) { .board { grid-auto-flow: row; grid-template-columns: repeat(5, 1fr); overflow: visible; } }
.col { scroll-snap-align: start; background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 2px 4px 10px; display: flex; justify-content: space-between; }
.card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; }
.card:hover { border-color: var(--accent); }
.card .t { font-weight: 600; margin: 4px 0; overflow-wrap: anywhere; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 6px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 768px) { .grid2 { grid-template-columns: 1fr 1fr; } }

label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=url], select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 44px; }
textarea { min-height: 110px; resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.bad { background: var(--bad); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { min-height: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); }
.rec { color: var(--bad); font-weight: 700; }
.error { color: var(--bad); margin-top: 8px; }

/* Fil de discussion du ticket */
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { border-radius: 12px; padding: 8px 12px; max-width: 92%; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--info-bg); }
.msg .who { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.waiting { border: 2px solid var(--warn); background: var(--warn-bg); color: var(--text); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.waiting strong { color: var(--warn); }
.attach img, .attach video { max-width: 100%; border-radius: 8px; margin-top: 6px; }
.attach audio { width: 100%; margin-top: 6px; }

.agent { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.agent:last-child { border-bottom: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }

nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
nav.tabs button { min-height: 60px; border: 0; background: none; cursor: pointer; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; }
nav.tabs button .ico { font-size: 20px; }
nav.tabs button[aria-current=page] { color: var(--accent); font-weight: 700; }
.badge { position: absolute; top: 6px; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; }
.login { max-width: 380px; margin: 12vh auto; padding: 16px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: calc(100% - 32px); }

/* Icônes SVG (remplacent les emojis, 28/10) */
.ico { flex: none; vertical-align: -3px; }
.with-ico { display: inline-flex; align-items: center; gap: 6px; }
.btn, .seg button, .pill { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.avatar .ico { color: #fff; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.chip button { display: inline-flex; padding: 0; }

/* Bouton afficher / masquer le mot de passe (Chrome mobile n'en a pas) */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; }
.pw-eye:hover, .pw-eye[aria-pressed=true] { color: var(--accent); }

/* Rendu Markdown des tickets et des rapports */
.md { overflow-wrap: anywhere; line-height: 1.5; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; line-height: 1.3; }
.md h3 { font-size: 16px; } .md h4 { font-size: 15px; } .md h5, .md h6 { font-size: 14px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md li > .md { margin-top: 4px; }
.md li.task { list-style: none; margin-left: -20px; display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.md .box { flex: none; width: 16px; height: 16px; margin-top: 3px; border: 1.5px solid var(--muted); border-radius: 4px; display: grid; place-items: center; }
.md .box.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.md code { font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0 0 8px; }
.md pre code { background: none; padding: 0; white-space: pre; }
.md blockquote { margin: 0 0 8px; padding: 4px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md .md-table { overflow-x: auto; margin: 0 0 8px; }
.md table { font-size: 13px; min-width: 100%; }
.md th { background: var(--surface-2); }
.msg .md { white-space: normal; }

/* En-tête de message : qui parle, clairement */
.msg { border-left: 3px solid var(--who, var(--border)); }
.msg.me { border-left: 0; border-right: 3px solid var(--who, var(--accent)); }
.msg .who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.msg .who strong { font-weight: 700; }
.who-avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; flex: none; }
.who-role { color: var(--muted); font-size: 12px; }
.who-time { color: var(--muted); font-size: 12px; margin-left: auto; }

/* Suivi en direct de l'agent */
.live { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; margin-top: 6px; color: var(--text); overflow-wrap: anywhere; }
.live-dot { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 1.6s infinite; }
.live.quiet .live-dot { background: var(--warn); animation: none; }
.live.quiet { color: var(--warn); }
.live-time { color: var(--muted); }
.live-panel { padding: 10px 14px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(4 120 87 / .45); } 70% { box-shadow: 0 0 0 7px rgb(4 120 87 / 0); } 100% { box-shadow: 0 0 0 0 rgb(4 120 87 / 0); } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
