/* ---------- tokens ---------- */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #dde2ea;
  --ink: #17202b;
  --ink-2: #4b5768;
  --ink-3: #8a94a3;
  --accent: #2a4fd0;
  --accent-ink: #ffffff;
  --accent-soft: #e6ebfb;
  --danger: #c93a3a;
  --danger-soft: #fbe9e9;
  --ok: #1f8a5b;
  --ok-soft: #e3f4ec;
  --warn: #b7700f;
  --warn-soft: #fbf0dc;
  --note: #fff7d6;
  --note-line: #efd98a;
  --accent-line: #c9d3f2;   /* bord des éléments sur fond accent-soft */
  --ai-ink: #5b3aab;        /* texte des chips catégorie IA */

  --s-open: #d9a400;          /* jaune : jamais touché */
  --s-pending_agent: #d9a400; /* jaune : le client attend (le rouge est réservé à urgent / en retard) */
  --s-pending_client: #2a4fd0;/* bleu : on attend le client */
  --s-on_hold: #7048c9;       /* violet : en traitement, on attend un tiers (SAV) */
  --s-resolved: #1f8a5b;
  --s-archived: #8a94a3;
  --s-spam: #8a94a3;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  --nav-w: 200px;
  --list-w: 380px;
  --shadow: 0 1px 2px rgba(23, 32, 43, .06), 0 4px 16px rgba(23, 32, 43, .06);
}

/* Mode sombre : suit le réglage système. Palette choisie (pas une inversion) — les
   couleurs de statut et la couleur d'accent des Réglages restent identiques. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #182029;
    --surface-2: #212b37;
    --line: #2c3846;
    --ink: #e8edf4;
    --ink-2: #a9b4c3;
    --ink-3: #717d8d;
    --accent-soft: #1e2a4d;
    --danger-soft: #3a2020;
    --ok-soft: #163226;
    --warn-soft: #362a12;
    --note: #322c12;
    --note-line: #5a4d1e;
    --accent-line: #31437a;
    --ai-ink: #b7a1ec;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Pas de zoom au double-tap (le pincement reste possible) */
html, body { touch-action: manipulation; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
p { margin: 0 0 .6em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: .02em; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100dvh; }
.nav {
  position: sticky; top: 0; height: 100dvh; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; font-weight: 700; font-size: 16px; }
.nav-brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); flex: none;
  background-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);
  background-size: 14px 2.5px, 14px 2.5px, 8px 2.5px; background-position: 6px 7px, 6px 12px, 6px 17px; background-repeat: no-repeat; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
button.nav-item { background: none; border: 0; font: inherit; }
.nav-mobile { display: none; } /* flèches + « Plus » : barre du bas mobile uniquement */
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; font-size: 15px; }
.nav-badge { margin-left: auto; font-size: 12px; font-weight: 600; background: var(--danger); color: #fff; border-radius: 999px; padding: 1px 7px; }
.nav-filters { display: flex; flex-direction: column; gap: 1px; margin: 0 0 6px; padding-left: 26px; }
.nav-sub { display: flex; align-items: center; gap: 6px; text-align: left; padding: 5px 8px; border: 0; background: none; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.nav-count { font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 1px 6px; min-width: 20px; text-align: center; }
.nav-sub.active .nav-count { background: var(--surface); color: var(--accent); }
.nav-tags { display: flex; flex-direction: column; gap: 1px; margin: 0 0 6px; padding-left: 26px; overflow-y: auto; max-height: 40dvh; flex: none; }
.nav-tags-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 6px 8px 2px; border: 0; background: none; text-align: left; width: 100%; }
.nav-tags-title:hover { color: var(--ink-2); }
.nav-sub:hover { background: var(--surface-2); }
.nav-sub.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-me { padding: 8px 10px; font-size: 13px; color: var(--ink-2); border-top: 1px solid var(--line); }
.nav-me strong { display: block; color: var(--ink); }

.main { min-width: 0; display: flex; flex-direction: column; }
.page { padding: 20px 24px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { flex: 1; }

/* Tickets : liste + détail côte à côte */
.split { display: grid; grid-template-columns: var(--list-w) 1fr; min-height: 100dvh; }
.list-pane { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; height: 100dvh; position: sticky; top: 0; }
.list-resize { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 3; touch-action: none; }
.list-resize:hover, .list-resize:active { background: var(--accent-soft); }
@media (max-width: 900px) { .list-resize { display: none; } }
.detail-pane { min-width: 0; display: flex; min-height: 100dvh; } /* .tk-main + panneau module */
.tk-main { min-width: 0; flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.detail-empty { flex: 1; display: grid; place-items: center; color: var(--ink-3); text-align: center; padding: 40px; }
.detail-empty > div { max-width: 38ch; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: 14px; white-space: nowrap; min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #2242b3; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; min-height: 28px; font-size: 13px; }
/* Signature : zone d'édition riche (contenteditable) + aperçu dans Mon compte */
.sig-edit { min-height: 150px; max-height: 45vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 10px 12px; font-size: 14px; }
.sig-edit:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sig-edit img, .sig-preview img { max-width: 100%; height: auto; }
.sig-preview { border-left: 3px solid var(--line); padding-left: 10px; font-size: 14px; max-width: 100%; overflow-x: auto; }

.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; vertical-align: -2px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-icon { padding: 6px; width: 34px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-height: 36px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 90px; resize: vertical; }
.select { appearance: none; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%234b5768' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--ink-2); }
.chip-tag { background: var(--accent-soft); color: var(--accent); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-late { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
/* Catégorie IA : distincte des tags — fond lavande doux + étincelle */
.chip-ai {
  background: color-mix(in srgb, #7048c9 9%, var(--surface));
  border: 1px solid color-mix(in srgb, #7048c9 25%, transparent);
  color: var(--ai-ink);
}
.chip-ai::before { content: "✦"; font-size: 10px; opacity: .7; }
/* Dans les lignes de la liste : pilules sur une ligne, tronquées si trop longues */
.trow-meta .chip { display: inline-block; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Palette des tags (pastille .tag-dot et puces .chip-tag) */
.tagc-blue { --tc-bg: #e6ebfb; --tc-ink: #2a4fd0; } .tagc-green { --tc-bg: #e3f4ec; --tc-ink: #1f8a5b; }
.tagc-amber { --tc-bg: #fbf0dc; --tc-ink: #b7700f; } .tagc-red { --tc-bg: #fbe9e9; --tc-ink: #c93a3a; }
.tagc-violet { --tc-bg: #ede7f9; --tc-ink: #7048c9; } .tagc-teal { --tc-bg: #def4f2; --tc-ink: #0f766e; }
.tagc-pink { --tc-bg: #fbe7f1; --tc-ink: #c0397f; } .tagc-gray { --tc-bg: var(--surface-2); --tc-ink: var(--ink-2); }
.chip-tag[class*="tagc-"] { background: var(--tc-bg); color: var(--tc-ink); }
.nav-tag { padding: 3px 8px 3px 4px; gap: 5px; }
.nav-tag .nav-tag-name { border: 0; background: none; padding: 2px 0; text-align: left; font: inherit; color: inherit; min-width: 0; }
.tag-dot { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid var(--tc-bg); background: var(--tc-ink); padding: 0; }
.tag-dot:hover { transform: scale(1.15); }
.chip button { border: 0; background: none; padding: 0 0 0 2px; color: inherit; opacity: .6; }
.tag-pick { border: 0; cursor: pointer; }
.tag-pick:hover { filter: brightness(.95); }
.chip button:hover { opacity: 1; }
.ref { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--ink-3); }

/* statut */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--s, var(--ink-3)); }
.status.open { --s: var(--s-open); } .status.pending_agent { --s: var(--s-pending_agent); } .status.pending_client { --s: var(--s-pending_client); }
.status.on_hold { --s: var(--s-on_hold); }
.status.resolved { --s: var(--s-resolved); } .status.archived, .status.spam { --s: var(--s-archived); }
.prio { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; }
.prio.high { background: var(--warn-soft); color: var(--warn); } .prio.urgent { background: var(--danger-soft); color: var(--danger); } .prio.low { color: var(--ink-3); }

/* ---------- inbox list ---------- */
/* Bandeaux du haut : teinte légère de la couleur de marque (réglable) + liseré, texte normal. */
.list-head, .tk-head {
  background: var(--surface);
  background: color-mix(in srgb, var(--header-color, var(--accent)) 7%, var(--surface));
  border-bottom: 1px solid var(--line);
}
.list-head { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.list-head .row { height: 40px; }
.list-head .input {
  background: var(--surface); border-color: transparent; border-radius: 999px; box-shadow: 0 1px 2px rgba(23, 32, 43, .08);
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.5' fill='none' stroke='%238a94a3' stroke-width='1.6'/%3E%3Cpath d='M10.5 10.5L14 14' stroke='%238a94a3' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 11px center;
}
/* Sous la recherche : vue active + compteur + filtres actifs — équilibre le bandeau de droite */
.list-summary { display: flex; gap: 6px; align-items: center; min-height: 24px; font-size: 13px; color: var(--ink-2); padding-left: 4px; }
.list-head .btn-primary { border-radius: 999px; }
/* Filtres (marques/tags/catégories) : sur desktop ils vivent dans la nav de gauche —
   le bouton n'apparaît que quand celle-ci devient la barre du bas (mobile). */
.filters-btn { display: none; }
.filters-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 720px) { .filters-btn { display: inline-flex; } }
/* Desktop : les deux bandeaux font la même hauteur, bordures basses alignées. */
@media (min-width: 901px) { .list-head, .tk-head { min-height: 106px; } }
/* Les filtres sont dans la nav de gauche ; les tabs de la liste ne servent que sur mobile (nav = barre du bas). */
@media (min-width: 721px) { .list-pane .tabs { display: none; } }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink-2); border: 0; background: none; white-space: nowrap; }
.tab.active { background: var(--ink); color: var(--surface); }
.list-body { flex: 1; overflow-y: auto; padding: 16px 8px 8px; background: var(--bg); } /* respiration sous la barre */
/* Chaque ticket est une carte : coins arrondis, espacée, liseré de statut à gauche */
/* Effet d'envoi : petit avion qui décolle avant d'enchaîner sur le ticket suivant */
.sent-fx { position: fixed; inset: 0; display: grid; place-items: center; z-index: 60; pointer-events: none; }
.sent-fx-plane { font-size: 60px; animation: sent-fly .5s ease-in forwards; }
@keyframes sent-fly {
  0% { transform: translate(0, 36px) scale(.5) rotate(0); opacity: 0; }
  35% { transform: translate(0, 0) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(45vw, -45vh) scale(.4) rotate(14deg); opacity: 0; }
}

/* Balayage gauche (tactile) : la ligne glisse et découvre les actions rapides */
.trow-wrap { position: relative; margin-bottom: 8px; }
.trow-wrap .trow { margin-bottom: 0; transition: transform .16s ease; will-change: transform; }
.trow-actions { position: absolute; top: 0; bottom: 0; right: 0; width: 228px; display: flex;
  border-radius: 10px; overflow: hidden; }
.trow-actions button { flex: 1; border: 0; color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; }
.trow-actions .swipe-icon { font-size: 17px; }
.swipe-ok { background: var(--s-resolved); }
.swipe-hold { background: var(--s-on_hold); }
.swipe-prio { background: var(--warn); }

.trow { display: block; padding: 10px 12px 10px 16px; margin-bottom: 8px; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--s, var(--line)); border-radius: 10px;
  position: relative; box-shadow: 0 1px 2px rgba(23, 32, 43, .04); }
.trow:hover { box-shadow: var(--shadow); }
.trow.active { background: var(--accent-soft); border-color: var(--accent-line); border-left-color: var(--s, var(--accent)); }
.trow.open { --s: var(--s-open); } .trow.pending_agent { --s: var(--s-pending_agent); } .trow.pending_client { --s: var(--s-pending_client); }
.trow.on_hold { --s: var(--s-on_hold); }
.trow.resolved { --s: var(--s-resolved); } .trow.archived, .trow.spam { --s: var(--s-archived); }
/* Barre gauche = thermomètre pour les tickets qui attendent notre réponse :
   vert (récent) -> orange (ça date, seuil réglable) -> rouge (en retard).
   Les autres statuts gardent leur couleur de statut. */
.trow.heat-fresh { --s: var(--ok); }
.trow.heat-warm { --s: #e8850c; }
.trow.heat-late { --s: var(--danger); }
/* Urgents : épinglés en haut de liste, barre épaisse */
.trow.prio-urgent { border-left-width: 6px; padding-left: 13px; }
/* Bandeau « En retard » pleine largeur en tête de carte, coins hauts arrondis */
.trow-late { margin: -10px -12px 9px -16px; padding: 3px 16px; font-size: 12px; font-weight: 700; letter-spacing: .02em; border-radius: 9px 9px 0 0; background: var(--danger-soft); color: var(--danger); }
.trow.prio-urgent .trow-late { margin-left: -13px; padding-left: 13px; }
.trow-top { display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--ink-2); }
.trow-top .name { font-weight: 600; color: var(--ink); flex: 1; min-width: 0; }
.trow-subject { font-weight: 500; margin: 2px 0; }
.trow.pending_agent .trow-subject, .trow.open .trow-subject { font-weight: 650; }
.trow-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
.trow-meta .who { margin-left: auto; }
.trow-ai { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.list-empty { padding: 48px 20px; text-align: center; color: var(--ink-3); }
.list-empty b { display: block; color: var(--ink-2); font-size: 15px; }
.list-empty-icon { font-size: 34px; margin-bottom: 10px; }
.list-empty-icon.ok { color: var(--ok); font-weight: 800; letter-spacing: -8px; padding-right: 8px; }
.list-more { display: block; width: 100%; padding: 12px; border: 0; background: none; color: var(--accent); font-weight: 500; }

/* ---------- ticket detail ---------- */
.tk-head { padding: 12px 20px; position: sticky; top: 0; z-index: 2; }
.tk-title { display: flex; align-items: center; gap: 10px; height: 40px; }
.tk-title h1 { font-size: 19px; font-weight: 700; flex: 1; min-width: 0; }
.tk-rename { flex: none; padding: 2px 6px; font-size: 13px; opacity: .5; }
.tk-rename:hover { opacity: 1; }
.tk-title .ref { background: var(--surface); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; }
.tk-props { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
/* Desktop : les wrappers du panneau sont transparents (tout reste en ligne) */
.props-grid, .props-row, .props-actions, .prop-field { display: contents; }
.prop-label { display: none; }
.props-arrow, .props-more { display: none; } /* mobile seulement : flèche d'ouverture du panneau + actions dedans */
.tk-props .select { width: auto; min-height: 30px; padding: 3px 26px 3px 12px; font-size: 13px; border-radius: 999px; box-shadow: 0 1px 2px rgba(23, 32, 43, .05); }
.tk-props .btn-ghost { border-radius: 999px; }
.tk-collision { margin-top: 8px; font-size: 13px; color: var(--warn); background: var(--warn-soft); padding: 6px 10px; border-radius: 6px; }
.tk-late { margin-top: 8px; font-size: 13px; color: var(--danger); background: var(--danger-soft); padding: 6px 10px; border-radius: 6px; }
.tk-body { flex: 1; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.tk-body > * { flex-shrink: 0; } /* jamais compresser les messages quand le fil est plus haut que l'écran */
.tk-side { font-size: 13px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 14px; flex-wrap: wrap; }
.tk-side b { color: var(--ink); }

.evt { text-align: center; font-size: 12px; color: var(--ink-3); padding: 0 12px; }

.msg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.msg.agent { background: var(--accent-soft); border-color: var(--accent-line); }
.msg.note { background: var(--note); border-color: var(--note-line); }
.msg.auto { opacity: .7; }
.msg-head { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13px; color: var(--ink-2); border-bottom: 1px solid rgba(0,0,0,.05); }
.msg-head .who { font-weight: 600; color: var(--ink); }
.msg-head .when { margin-left: auto; white-space: nowrap; }
.msg-body { padding: 12px 14px; overflow-wrap: anywhere; }
/* Mail sans partie HTML : le corps texte est rendu en nœud texte, les retours à la ligne sont
   restitués ici et non par des <br> (voir message() dans ticket.js). */
.msg-body-text { white-space: pre-wrap; }
.msg-body img { max-width: 100%; height: auto; }
/* Les mails HTML embarquent souvent des tableaux à largeur fixe : on les contient. */
.msg-body table { display: block; max-width: 100%; overflow-x: auto; }
.msg-body blockquote { margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--ink-2); }
.msg-body pre { white-space: pre-wrap; }
.msg-atts { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 12px; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: var(--surface); }
.att .sz { color: var(--ink-3); font-size: 12px; }
.att-group { display: inline-flex; flex-direction: column; gap: 4px; }
.att-pages { display: flex; gap: 4px; flex-wrap: wrap; }
.att-unconverted { opacity: .55; cursor: default; }
/* Miniatures des photos jointes dans le composeur (croix de suppression par-dessus) */
.att-photo { position: relative; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.att-photo img { display: block; width: 64px; height: 64px; object-fit: cover; cursor: zoom-in; }
.att-del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; line-height: 1; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px; display: grid; place-items: center; }
.att-del:hover { background: rgba(0, 0, 0, .75); }
.msg-sched { font-size: 12px; color: var(--warn); padding: 0 14px 10px; }
.msg-translate { padding: 0 8px 8px; }
.msg-trad { margin: 0 14px 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-size: 14px; white-space: pre-wrap; }
.msg-trad .small { margin-bottom: 4px; }

/* Fond teinté de la couleur des Réglages, nettement plus saturé que les bandeaux (7%) :
   la zone de rédaction se distingue au premier coup d'œil. */
.composer { position: sticky; bottom: 0; background: color-mix(in srgb, var(--header-color, var(--accent)) 18%, var(--surface)); border-top: 1px solid var(--line); padding: 10px 20px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 20px rgba(0, 0, 0, .08); } /* détache la zone de saisie du fil */
.composer.note { background: var(--note); }
.composer-tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; } /* petit écran : « Réponse prédéfinie » passe à la ligne au lieu de sortir du cadre */
.composer .textarea { min-height: 170px; background: var(--surface); } /* ~7 lignes visibles */
.composer-bar { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.composer-bar .grow { flex: 1; }
.composer-atts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.composer-hint { font-size: 12px; color: var(--ink-3); }
.btn.rec { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }

/* ---------- statistiques ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.viz-box { position: relative; }
.viz-tip { position: absolute; top: 6px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 7px 10px; font-size: 13px; pointer-events: none; white-space: nowrap; z-index: 5; }
.viz-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- cards / tables ---------- */
/* max-width + overflow : un contenu large (signature HTML avec table fixe, long token…)
   défile DANS la carte au lieu d'élargir toute la page (surtout mobile). */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; max-width: 100%; overflow-x: auto; }
.card h2 { margin-bottom: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.clickable { cursor: pointer; } .clickable:hover { background: var(--surface-2); }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-box { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-box h1 { margin-bottom: 4px; }
.login-box .muted { margin-bottom: 20px; display: block; }
.login-err { color: var(--danger); font-size: 13px; margin: -4px 0 10px; }

/* ---------- popover (menu ancré) ---------- */
.popover { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 220px; max-width: 300px; animation: pop-in .12s ease-out; }
.popover > button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 7px; font-size: 14px; font-weight: 500; }
.popover > button:hover { background: var(--surface-2); }
.popover > button small { display: block; color: var(--ink-3); font-size: 12px; font-weight: 400; margin-top: 1px; }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px); } }
.popover-fit { min-width: 0; }
.swatches { display: grid; grid-template-columns: repeat(4, 30px); gap: 10px; padding: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--tc-bg); background: var(--tc-ink); padding: 0; cursor: pointer; }
.swatch:hover { transform: scale(1.12); }
.swatch.current { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- toasts / modal ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.modal { position: fixed; inset: 0; background: rgba(23,32,43,.45); display: grid; place-items: center; padding: 16px; z-index: 60; }
.modal-box { width: 100%; max-width: 520px; max-height: 90dvh; overflow-y: auto; background: var(--surface); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.modal-box h2 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.picker { max-height: min(48vh, 340px); overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.picker button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-bottom: 1px solid var(--line); }
.picker button:hover { background: var(--surface-2); }
/* Sections du picker (groupes de réponses prédéfinies) : en-têtes collants au scroll */
.picker-head { position: sticky; top: 0; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--ink-3); background: var(--surface-2); padding: 7px 10px 5px;
  border-bottom: 1px solid var(--line); }
/* Bascule en tête des menus IA/Dictée (cliquer ne ferme pas le menu) */
.pop-toggle { display: flex; align-items: flex-start; gap: 8px; padding: 8px 12px; font-size: 13px;
  border-bottom: 1px solid var(--line); cursor: pointer; }
.pop-toggle input { margin-top: 2px; }
.pop-toggle small { display: block; color: var(--ink-3); font-size: 11px; }
.picker-groups { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
/* Aperçu du corps sous le titre : on sait ce qu'on insère (2 lignes max) */
.picker-excerpt { margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.35; }
.picker-groups .chip { border: 0; cursor: pointer; }
.chip-on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.picker button small { display: block; color: var(--ink-3); }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .split.showing-detail .list-pane { display: none; }
  .split:not(.showing-detail) .detail-pane { display: none; }
  .list-pane { height: auto; min-height: calc(100dvh - 58px); position: static; border-right: 0; }
  .detail-pane { min-height: calc(100dvh - 58px); }
}
@media (max-width: 720px) {
  :root { --nav-w: 0px; }
  /* Cadre d'app verrouillé : le document ne défile jamais (fini le rebond iOS et les
     débordements horizontaux), chaque zone gère son propre scroll. */
  html, body { height: 100%; overflow: hidden; }
  /* --vvh = hauteur du viewport VISUEL (posée par app.js) : rétrécit quand le clavier iOS s'ouvre */
  .app { grid-template-columns: 1fr; padding-bottom: 0; height: var(--vvh, 100dvh); }
  .main { height: calc(var(--vvh, 100dvh) - 58px - env(safe-area-inset-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  /* Clavier ouvert : la barre du bas se masque, l'app occupe tout le viewport visible */
  :root.kb-open .nav { display: none; }
  :root.kb-open .main { height: var(--vvh, 100dvh); }
  .split { display: block; height: 100%; min-height: 0; } /* une seule colonne visible à la fois */
  .list-pane { height: 100%; min-height: 0; position: static; border-right: 0; }
  /* PWA iOS : la zone du geste d'accueil (safe-area) s'AJOUTE aux 58px, sinon elle
     mange l'intérieur de la barre et les boutons débordent de leur emplacement. */
  .nav { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: calc(58px + env(safe-area-inset-bottom)); flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 10; }
  .nav-brand, .nav-spacer, .nav-me, .nav-filters, .nav-tags { display: none; }
  /* Ticket OUVERT : barre de lecture Tickets | ◀ | ▶ | Plus (Contacts/Réponses/
     Stats/Réglages dans « Plus »). Sur la liste et les autres pages : barre standard. */
  :root.ticket-open .nav-item.nav-desktop { display: none; }
  :root.ticket-open .nav-mobile { display: flex; }
  .nav-item { flex: 1; flex-direction: column; gap: 2px; font-size: 11px; padding: 4px; justify-content: center; }
  .nav-icon { font-size: 18px; }
  .nav-badge { position: absolute; margin: 0; transform: translate(14px, -22px); }
  .nav-item { position: relative; }
  .page { padding: 14px; }
  .field-row { grid-template-columns: 1fr; }
  /* Vue ticket : colonne figée (en-tête / fil scrollable / composeur collé en bas). */
  .detail-pane { height: 100%; min-height: 0; }
  .tk-main { height: 100%; min-height: 0; }
  /* Statut, priorité, assignation, tags… : repliés derrière un bouton pour gagner de la place */
  .props-arrow { display: inline-flex; font-size: 22px; min-width: 44px; min-height: 40px; justify-content: center; align-items: center; padding: 0; }
  .props-more { display: inline-flex; }
  .tk-title .more-desktop { display: none; } /* les actions vivent dans le panneau déplié */
  .tk-title .ref { display: none; } /* la référence encombre la barre — visible dans le panneau des propriétés */
  /* Barre mobile épurée : ← / titre / ▾ — cibles généreuses, titre contenu sur une ligne */
  .tk-title { gap: 6px; height: 48px; }
  .tk-title h1 { font-size: 17px; line-height: 1.2; }
  .tk-title #backBtn { width: 40px; min-height: 40px; font-size: 19px; }
  .props-arrow { min-width: 48px; min-height: 42px; font-size: 26px; border: 1px solid var(--line);
    border-radius: 10px; background: var(--surface-2); color: var(--ink-2); }
  .props-arrow[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
  .tk-props { display: none; }
  /* Panneau déplié : carte structurée — menus étiquetés en grille, sections, actions */
  .tk-props.open { display: block; margin-top: 8px; background: var(--surface-2); border-radius: 12px; padding: 12px; }
  .props-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 8px; }
  .prop-field { display: block; min-width: 0; }
  .prop-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-3); margin-bottom: 3px; }
  .props-grid .select { width: 100%; background-color: var(--surface); }
  .props-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
  .props-row .prop-label { width: 100%; margin-bottom: 0; }
  .props-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
  .props-actions .props-more { flex: 1; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); justify-content: center; }
  .props-actions .ref { flex: none; }
  .tk-head { padding: 10px 12px; position: static; }
  .tk-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
  /* La nav du bas couvre déjà la safe-area : la re-compter ici créait un grand vide
     entre la barre de boutons du composeur et les onglets Tickets/Contacts. */
  .composer { position: static; padding: 8px 12px 8px; }
  /* Composeur replié tant qu'on n'écrit pas (~2 lignes) : le fil du ticket respire.
     Il reprend sa taille dès que le clavier s'ouvre / qu'un champ du composeur a le focus. */
  .composer .textarea { min-height: 0; height: 52px; overflow-y: hidden; transition: height .18s ease; }
  .composer:focus-within .textarea,
  :root.kb-open .composer .textarea { height: 165px; overflow-y: auto; } /* ~6-7 lignes */
  .input, .select, .textarea { font-size: 16px; } /* <16px : iOS zoome au focus et « dé-fixe » la page */
  .composer-hint { display: none; } /* raccourci clavier sans objet au doigt ; il écrasait la barre */
  .composer-bar { row-gap: 8px; }
  .composer-bar .btn { min-height: 40px; }
  .composer-bar .btn-primary { margin-left: auto; } /* Envoyer aligné à droite */
  .kv { grid-template-columns: 1fr; }
  .table th:nth-child(n+3):not(:last-child), .table td:nth-child(n+3):not(:last-child) { display: none; }
  .msg-head .when { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (min-width: 901px) { #backBtn { display: none; } }


/* ---------- panneau module métier (actions client) ---------- */
.mod-pane { width: 320px; flex: none; border-left: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; } /* le scroll reste DANS le panneau */
.mod-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; }
.mod-head h3 { margin: 0; }
.mod-body { padding: 0 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.mod-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.mod-card h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
/* Carte d'identité du client : teintée de la couleur d'accent, avatar à initiales */
.mod-id { background: color-mix(in srgb, var(--header-color, var(--accent)) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--header-color, var(--accent)) 25%, transparent); }
.mod-avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--header-color, var(--accent)); color: #fff; font-weight: 700; font-size: 15px; }
/* Teinte selon le sexe du client : bleu (H) / rose (F) — défaut : couleur d'accent */
.mod-id-m { --mod-id-c: #2a6bd0; }
.mod-id-f { --mod-id-c: #d0498f; }
.mod-id-m, .mod-id-f { background: color-mix(in srgb, var(--mod-id-c) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--mod-id-c) 28%, transparent); }
.mod-id-m .mod-avatar, .mod-id-f .mod-avatar { background: var(--mod-id-c); }
.mod-name { font-size: 16px; font-weight: 700; }
.mod-stats { display: flex; gap: 6px; margin-top: 8px; }
.mod-stat { flex: 1; text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 2px; font-size: 12px; }
.mod-stat b { display: block; font-size: 15px; }
.mod-actions-btn { border-radius: 999px; }
/* Notes de participation : mini-cartes étiquetées, cliquables pour éditer.
   Client = teinte accent ; interne = jaune « note », comme dans les tickets. */
.mod-note { display: block; width: 100%; text-align: left; border: 0; margin-top: 6px;
  border-radius: 8px; padding: 7px 10px 8px; border-left: 3px solid transparent; }
.mod-note-client { background: var(--note); border-left-color: var(--note-line); } /* jaune : note « normale » */
.mod-note-private { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-left-color: var(--danger); } /* rouge : interne, jamais montrée au client */
.mod-note-head { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin-bottom: 3px; }
.mod-note-head .chip { text-transform: none; letter-spacing: 0; font-weight: 600; }
.mod-note-done { color: var(--ok); text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 12px; }
.mod-note-edit { margin-left: auto; opacity: .45; font-size: 12px; }
.mod-note:hover .mod-note-edit { opacity: 1; }
.mod-note-text { display: block; font-size: 13px; line-height: 1.4; color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere; }
.mod-alert { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 30%, transparent); margin-bottom: 10px; }
.mod-collapse { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 0; border: 0; background: none;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); text-align: left; }
.mod-collapse .mod-count { background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 1px 8px;
  font-size: 12px; font-weight: 600; text-transform: none; }
.mod-collapse .muted { margin-left: auto; }
@media (max-width: 1100px) {
  .mod-actions-btn { flex: 1; min-height: 42px; margin-top: 2px; } /* cible de tap confortable */
}
.mod-part { padding: 8px 10px; margin: 6px 0; border-radius: 8px; border-left: 3px solid var(--line); background: var(--surface); }
.mp-future { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.mp-came { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 7%, var(--surface)); }
.mp-noshow { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.mp-cancelled { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
.mod-result { display: block; width: 100%; text-align: left; padding: 8px; border: 0; background: none; border-radius: 8px; }
.mod-result:hover { background: var(--surface-2); }
.mod-result small { display: block; color: var(--ink-3); }
.mod-busy { position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; background: var(--ink); color: var(--surface);
  border-radius: 999px; padding: 9px 16px; font-size: 13px; font-weight: 500; z-index: 70; box-shadow: var(--shadow); }
.mod-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 39; }
@media (min-width: 1101px) { .mod-close { display: none; } }
@media (max-width: 1100px) {
  .mod-pane { position: fixed; top: 0; right: 0; bottom: 0; height: auto; width: min(86vw, 360px); z-index: 40;
    transform: translateX(105%); transition: transform .22s ease; box-shadow: -8px 0 24px rgba(0, 0, 0, .18); }
  .mod-pane.open { transform: none; }
  /* Tiroir ouvert : la page derrière ne scrolle plus (le geste restait happé par le fil) */
  :root.drawer-open .main, :root.drawer-open .tk-body { overflow: hidden !important; }
}
