/* =====================================================================
   Mamebot — design system
   Identité : vert nuit, ivoire, or. Surfaces tonales (jamais de dégradé
   décoratif ni de verre dépoli). Typographie : système pour l'interface,
   serif pour les moments de marque.
   ===================================================================== */

:root {
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;

  --night: #0f3d2e;
  --night-2: #17553f;
  --night-deep: #0a2a20;
  --ivory: #f6f1e7;
  --gold: #c8a24b;
  --gold-deep: #9a7a2c;
  --gold-ink: #33270a;

  --bg: #f1ebde;
  --surface: #fbf8f1;
  --surface-2: #f5f0e4;
  --surface-3: #ede6d6;
  --ink: #15241d;
  --ink-2: #435049;
  --muted: #76817a;
  --line: #e3dbc9;
  --line-2: #d6ccb6;

  --bub-in: #fffdf8;
  --bub-in-ink: #15241d;
  --bub-out: #0f3d2e;
  --bub-out-ink: #f6f1e7;
  --bub-agent: #e5eee1;
  --bub-agent-ink: #14291f;
  --bub-sys: #f6e9cf;
  --bub-sys-ink: #4a3410;

  --ok: #2f7d57;
  --danger: #b3402a;
  --focus: #1b7a58;

  --shadow-1: 0 1px 2px rgba(21, 36, 29, .06), 0 1px 1px rgba(21, 36, 29, .04);
  --shadow-2: 0 8px 24px rgba(21, 36, 29, .12), 0 2px 6px rgba(21, 36, 29, .06);
  --shadow-3: 0 24px 60px rgba(10, 42, 32, .28);

  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-bub: 18px;
  --side-w: 372px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(.2, .7, .2, 1);

  --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='%230f3d2e' fill-opacity='.055'%3E%3Cpath transform='translate(34 36) rotate(32)' d='M0 -12C8 -6 8 6 0 12C-8 6 -8 -6 0 -12Z'/%3E%3Cpath transform='translate(128 70) rotate(-48)' d='M0 -10C7 -5 7 5 0 10C-7 5 -7 -5 0 -10Z'/%3E%3Cpath transform='translate(70 128) rotate(78)' d='M0 -13C9 -6 9 6 0 13C-9 6 -9 -6 0 -13Z'/%3E%3Cpath transform='translate(150 150) rotate(12)' d='M0 -9C6 -4 6 4 0 9C-6 4 -6 -4 0 -9Z'/%3E%3Ccircle cx='96' cy='22' r='2'/%3E%3Ccircle cx='18' cy='104' r='2'/%3E%3Ccircle cx='160' cy='112' r='1.6'/%3E%3C/g%3E%3C/svg%3E");
}

:root[data-theme="dark"] {
  --bg: #0a1410;
  --surface: #0f1c17;
  --surface-2: #13241d;
  --surface-3: #183029;
  --ink: #e8efe9;
  --ink-2: #b6c4ba;
  --muted: #7d8d84;
  --line: #1c3027;
  --line-2: #25402f;
  --bub-in: #15261f;
  --bub-in-ink: #e8efe9;
  --bub-out: #1a5c43;
  --bub-out-ink: #f4f7f1;
  --bub-agent: #1b3a2d;
  --bub-agent-ink: #e6f0e8;
  --bub-sys: #3b2f14;
  --bub-sys-ink: #f1e3c2;
  --focus: #5fc79b;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .45);
  --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='%23ffffff' fill-opacity='.028'%3E%3Cpath transform='translate(34 36) rotate(32)' d='M0 -12C8 -6 8 6 0 12C-8 6 -8 -6 0 -12Z'/%3E%3Cpath transform='translate(128 70) rotate(-48)' d='M0 -10C7 -5 7 5 0 10C-7 5 -7 -5 0 -10Z'/%3E%3Cpath transform='translate(70 128) rotate(78)' d='M0 -13C9 -6 9 6 0 13C-9 6 -9 -6 0 -13Z'/%3E%3Cpath transform='translate(150 150) rotate(12)' d='M0 -9C6 -4 6 4 0 9C-6 4 -6 -4 0 -9Z'/%3E%3Ccircle cx='96' cy='22' r='2'/%3E%3Ccircle cx='18' cy='104' r='2'/%3E%3Ccircle cx='160' cy='112' r='1.6'/%3E%3C/g%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1410; --surface: #0f1c17; --surface-2: #13241d; --surface-3: #183029;
    --ink: #e8efe9; --ink-2: #b6c4ba; --muted: #7d8d84; --line: #1c3027; --line-2: #25402f;
    --bub-in: #15261f; --bub-in-ink: #e8efe9; --bub-out: #1a5c43; --bub-out-ink: #f4f7f1;
    --bub-agent: #1b3a2d; --bub-agent-ink: #e6f0e8; --bub-sys: #3b2f14; --bub-sys-ink: #f1e3c2;
    --focus: #5fc79b; --shadow-1: 0 1px 2px rgba(0, 0, 0, .35); --shadow-2: 0 8px 24px rgba(0, 0, 0, .45);
    --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='%23ffffff' fill-opacity='.028'%3E%3Cpath transform='translate(34 36) rotate(32)' d='M0 -12C8 -6 8 6 0 12C-8 6 -8 -6 0 -12Z'/%3E%3Cpath transform='translate(128 70) rotate(-48)' d='M0 -10C7 -5 7 5 0 10C-7 5 -7 -5 0 -10Z'/%3E%3Cpath transform='translate(70 128) rotate(78)' d='M0 -13C9 -6 9 6 0 13C-9 6 -9 -6 0 -13Z'/%3E%3Cpath transform='translate(150 150) rotate(12)' d='M0 -9C6 -4 6 4 0 9C-6 4 -6 -4 0 -9Z'/%3E%3Ccircle cx='96' cy='22' r='2'/%3E%3Ccircle cx='18' cy='104' r='2'/%3E%3Ccircle cx='160' cy='112' r='1.6'/%3E%3C/g%3E%3C/svg%3E");
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--night-2); }
:root[data-theme="dark"] a { color: #7fd1aa; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#app { height: 100dvh; }
.boot { display: grid; place-items: center; background: var(--night); }
.boot-mark svg { animation: bootpulse 1.6s var(--ease) infinite; border-radius: 16px; }
@keyframes bootpulse { 0%, 100% { transform: scale(1); opacity: .9 } 50% { transform: scale(1.06); opacity: 1 } }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; font-weight: 600; font-size: 15px;
  transition: transform .15s var(--ease), background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }
.btn-primary { background: var(--night); color: var(--ivory); box-shadow: var(--shadow-1); }
.btn-primary:hover:not([disabled]) { background: var(--night-2); box-shadow: var(--shadow-2); }
:root[data-theme="dark"] .btn-primary { background: var(--night-2); }
.btn-gold { background: var(--gold); color: var(--gold-ink); }
.btn-gold:hover:not([disabled]) { background: #d4b05c; }
.btn-ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover:not([disabled]) { background: var(--surface-3); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover:not([disabled]) { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }
.iconbtn {
  width: 42px; height: 42px; border-radius: 50%; display: inline-grid; place-items: center;
  color: var(--ink-2); transition: background .15s, color .15s, transform .15s var(--ease); position: relative;
}
.iconbtn:hover { background: var(--surface-3); color: var(--ink); }
.iconbtn:active { transform: scale(.92); }
.iconbtn.on { color: var(--night-2); background: var(--surface-3); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label small { font-weight: 400; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1.5px solid var(--line-2); transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--night-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--night-2) 20%, transparent); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }
.err-text { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; cursor: pointer; }
.switch .sw-text b { display: block; font-weight: 600; }
.switch .sw-text span { font-size: 13px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 46px; height: 28px; border-radius: 999px; background: var(--line-2); position: relative; flex: none; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform .2s var(--ease); }
.switch input:checked + .track { background: var(--night-2); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: 999px; gap: 2px; }
.seg button { padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- Marque ---------- */
.wm { font-family: var(--font-serif); font-size: 22px; letter-spacing: -.01em; font-weight: 600; color: var(--ink); line-height: 1; }
.wm i { font-style: italic; color: var(--night-2); }
:root[data-theme="dark"] .wm i { color: #7fd1aa; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: block; }

/* ---------- Avatars ---------- */
.avatar {
  --size: 46px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; position: relative;
  display: grid; place-items: center; font-weight: 700; font-size: calc(var(--size) * .38); letter-spacing: .02em;
  color: #f6f1e7; background: hsl(var(--hue, 150) 36% 30%);
  user-select: none;
}
.avatar.sm { --size: 32px; }
.avatar.lg { --size: 56px; }
.avatar.mame { background: none; border-radius: 28%; overflow: hidden; }
.avatar.mame svg { width: 100%; height: 100%; display: block; }
.avatar.group { background: var(--night-2); }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2.5px solid var(--surface); }

/* ---------- Ecrans d'accès ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-art {
  background: var(--night); color: var(--ivory); padding: 56px 56px 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art::before { content: ""; position: absolute; inset: 0; background-image: var(--wall); background-size: 180px; opacity: 1; filter: invert(1) brightness(2); mix-blend-mode: soft-light; opacity: .55; pointer-events: none; }
.auth-art > * { position: relative; }
.auth-art .wm { color: var(--ivory); font-size: 30px; }
.auth-art .wm i { color: var(--gold); }
.auth-quote { font-family: var(--font-serif); font-size: clamp(28px, 3.2vw, 44px); line-height: 1.12; letter-spacing: -.015em; max-width: 14em; }
.auth-quote em { color: var(--gold); font-style: italic; }
.auth-foot { font-size: 14px; color: color-mix(in srgb, var(--ivory) 70%, transparent); max-width: 30em; }
.auth-panel { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-family: var(--font-serif); font-size: 32px; letter-spacing: -.015em; margin: 0 0 6px; font-weight: 600; }
.auth-card p.lead { margin: 0 0 26px; color: var(--ink-2); }
.auth-card .brandline { display: none; align-items: center; gap: 10px; margin-bottom: 28px; }
.pw-wrap { position: relative; }
.pw-wrap .iconbtn { position: absolute; right: 2px; top: 2px; width: 42px; height: 42px; }
.pw-wrap .input { padding-right: 48px; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-card .brandline { display: flex; }
}

/* ---------- Coque de l'application ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); background: var(--surface); overflow: hidden; position: relative; }

.side { position: relative; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: var(--surface); height: 100dvh; }
.side-top { display: flex; align-items: center; gap: 10px; padding: calc(14px + var(--safe-t)) 14px 8px 16px; }
.side-top .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-btn { border-radius: 50%; }
.search { margin: 4px 14px 10px; position: relative; }
.search .i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; pointer-events: none; }
.search input { width: 100%; height: 42px; border-radius: 999px; border: 0; background: var(--surface-3); padding: 0 16px 0 40px; }
.search input:focus { outline: 2px solid var(--focus); }
.filters { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { padding: 6px 14px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.on { background: var(--night); color: var(--ivory); border-color: var(--night); }
:root[data-theme="dark"] .chip.on { background: var(--night-2); border-color: var(--night-2); }
.chip .n { margin-left: 6px; font-size: 12px; opacity: .8; }

.tlist { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 96px; }
.titem { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 10px 10px; border-radius: var(--r-md); position: relative; transition: background .12s; }
.titem:hover { background: var(--surface-2); }
.titem.on { background: color-mix(in srgb, var(--night) 10%, var(--surface)); }
.titem.on::before { content: ""; position: absolute; left: -8px; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--gold); }
.tbody { flex: 1; min-width: 0; }
.trow { display: flex; align-items: baseline; gap: 8px; }
.tname { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ttime { font-size: 12px; color: var(--muted); flex: none; }
.titem.unread .ttime { color: var(--night-2); font-weight: 700; }
.tprev { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.titem.unread .tprev { color: var(--ink-2); }
.tprev .who { color: var(--ink-2); font-weight: 600; }
.tprev .typing-txt { color: var(--night-2); font-weight: 600; }
.tbadge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-size: 12.5px; font-weight: 800; display: grid; place-items: center; flex: none; }
.tbadge.muted { background: var(--line-2); color: var(--ink-2); }
.tsub { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.tmute { width: 14px; height: 14px; color: var(--muted); }
.tsec { padding: 14px 12px 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.fab {
  position: absolute; right: 18px; bottom: calc(18px + var(--safe-b)); width: 58px; height: 58px; border-radius: 50%; background: var(--night); color: var(--ivory);
  display: grid; place-items: center; box-shadow: var(--shadow-2); transition: transform .15s var(--ease), background .15s; z-index: 5;
}
.fab:hover { background: var(--night-2); transform: translateY(-2px); }
.fab:active { transform: scale(.94); }
.fab .i { width: 24px; height: 24px; }
:root[data-theme="dark"] .fab { background: var(--night-2); }

/* ---------- Volet de conversation ---------- */
.pane { display: flex; flex-direction: column; min-width: 0; height: 100dvh; background: var(--bg); position: relative; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: calc(10px + var(--safe-t)) 14px 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 3; min-height: 66px; }
.chat-head .back { display: none; }
.chat-head .hmain { flex: 1; min-width: 0; text-align: left; }
.htitle { font-weight: 700; font-size: 16.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsub.live { color: var(--night-2); font-weight: 600; }
:root[data-theme="dark"] .hsub.live { color: #7fd1aa; }

.stream { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 0 8px; background-image: var(--wall); background-size: 180px; position: relative; scroll-behavior: auto; }
.msgs { max-width: 860px; margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; }
.more { align-self: center; margin: 4px 0 12px; }
.dayline { align-self: center; margin: 14px 0 8px; padding: 4px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 650; background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--ink-2); border: 1px solid var(--line); box-shadow: var(--shadow-1); position: sticky; top: 4px; z-index: 1; }

.row { display: flex; gap: 8px; margin-top: 2px; max-width: 100%; align-items: flex-end; }
.row.first { margin-top: 10px; }
.row.out { justify-content: flex-end; }
.row .rav { width: 32px; flex: none; }
.row .col { display: flex; flex-direction: column; min-width: 0; max-width: min(78%, 620px); }
.row.out .col { align-items: flex-end; }
.sender { font-size: 12.5px; font-weight: 700; margin: 0 12px 3px; color: hsl(var(--hue, 150) 42% 34%); }
:root[data-theme="dark"] .sender { color: hsl(var(--hue, 150) 45% 68%); }
.sender small { font-weight: 500; color: var(--muted); margin-left: 6px; }

.bub {
  position: relative; padding: 8px 12px 6px; border-radius: var(--r-bub); background: var(--bub-in); color: var(--bub-in-ink);
  box-shadow: var(--shadow-1); word-wrap: break-word; overflow-wrap: anywhere; min-width: 0; max-width: 100%;
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.row.in .bub { border-bottom-left-radius: 6px; }
.row.in:not(.last) .bub { border-bottom-left-radius: var(--r-bub); }
.row.in:not(.first) .bub { border-top-left-radius: 8px; }
.row.out .bub { background: var(--bub-out); color: var(--bub-out-ink); border-bottom-right-radius: 6px; }
.row.out:not(.last) .bub { border-bottom-right-radius: var(--r-bub); }
.row.out:not(.first) .bub { border-top-right-radius: 8px; }
.bub.agent { background: var(--bub-agent); color: var(--bub-agent-ink); }
.bub.event { border-left: 4px solid var(--gold); padding-left: 11px; }
.bub.system { background: var(--bub-sys); color: var(--bub-sys-ink); }
.bub.err { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--ink); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.bub.sending { opacity: .72; }
.tag-event { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 3px; }
:root[data-theme="dark"] .tag-event { color: var(--gold); }
.tag-event .i { width: 13px; height: 13px; stroke-width: 2.2; }

.txt { white-space: pre-wrap; }
.txt p { margin: 0 0 .55em; white-space: pre-wrap; }
.txt p:last-child { margin-bottom: 0; }
.txt strong { font-weight: 700; }
.txt code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, currentColor 11%, transparent); }
.txt pre { margin: .4em 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, currentColor 9%, transparent); overflow-x: auto; white-space: pre; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; }
.txt ul, .txt ol { margin: .3em 0 .6em; padding-left: 1.3em; white-space: normal; }
.txt li { margin: .12em 0; }
.txt a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.row.out .txt a { color: #ffe9a8; }
.txt h4 { margin: .5em 0 .25em; font-size: 1em; font-weight: 750; }
.txt blockquote { margin: .4em 0; padding-left: 10px; border-left: 3px solid color-mix(in srgb, currentColor 30%, transparent); opacity: .9; }

.bub { padding-bottom: 7px; }
.txt > :last-child::after { content: ""; display: inline-block; width: 58px; height: 1px; }
.meta { position: absolute; right: 11px; bottom: 5px; display: flex; align-items: center; gap: 4px; font-size: 11.5px; opacity: .62; line-height: 1; }
.meta .i { width: 15px; height: 15px; stroke-width: 2.2; }
.meta .read { color: #8ee0bd; opacity: 1; display: inline-flex; }
.meta .read .i { color: #8ee0bd; }
.row.in .meta .read, .bub.agent .meta .read { color: var(--night-2); }
.meta .fail { color: #ff9a85; opacity: 1; display: inline-flex; }
.bub .voice, .bub .filecard { padding-bottom: 14px; }
.bub:has(> .voice, > .filecard) { min-width: 240px; }
.bub.mediaonly { padding: 0; background: transparent; box-shadow: none; }
.bub.mediaonly .media { margin: 0; }
.bub.mediaonly .meta { right: 10px; bottom: 10px; background: rgba(10, 22, 17, .55); color: #fff; opacity: 1; padding: 3px 8px; border-radius: 999px; }
.media + .txt { margin-top: 6px; }
.unreadline { align-self: stretch; text-align: center; margin: 14px 0 6px; font-size: 12.5px; font-weight: 800; color: var(--gold-deep); letter-spacing: .05em; text-transform: uppercase; display: flex; align-items: center; gap: 12px; }
.unreadline::before, .unreadline::after { content: ""; height: 1px; flex: 1; background: color-mix(in srgb, var(--gold) 55%, transparent); }
.row .rav .avatar { visibility: hidden; }
.row.last .rav .avatar { visibility: visible; }
.typing-row .rav .avatar { visibility: visible; }

.media { display: block; margin: -4px -8px 4px; border-radius: 14px; overflow: hidden; background: var(--surface-3); position: relative; cursor: zoom-in; max-width: 320px; }
.media img { display: block; max-width: 100%; max-height: 360px; width: auto; height: auto; min-width: 180px; object-fit: cover; }
.filecard { display: flex; align-items: center; gap: 12px; padding: 4px 2px 2px; min-width: 210px; text-decoration: none; color: inherit; }
.filecard .fico { width: 42px; height: 48px; border-radius: 9px; background: color-mix(in srgb, currentColor 13%, transparent); display: grid; place-items: center; flex: none; font-size: 11px; font-weight: 800; letter-spacing: .05em; }
.filecard .fname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.filecard .fsub { font-size: 12.5px; opacity: .7; }

.voice { display: flex; align-items: center; gap: 10px; min-width: 230px; padding: 2px 0; }
.voice .play { width: 40px; height: 40px; border-radius: 50%; background: var(--night); color: var(--ivory); display: grid; place-items: center; flex: none; transition: transform .12s var(--ease); }
.voice .play:active { transform: scale(.9); }
.row.out .voice .play { background: var(--ivory); color: var(--night); }
.voice .wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; }
.voice .wave i { flex: 1; min-width: 2px; border-radius: 2px; background: currentColor; opacity: .3; height: var(--h, 40%); transition: opacity .15s; }
.voice .wave i.on { opacity: .95; }
.voice .dur { font-size: 12px; font-variant-numeric: tabular-nums; opacity: .75; min-width: 34px; text-align: right; }
.voice .spd { font-size: 11.5px; font-weight: 800; padding: 3px 7px; border-radius: 999px; background: color-mix(in srgb, currentColor 14%, transparent); }

.bubbtn { display: inline-flex; margin-top: 8px; font-weight: 700; font-size: 13.5px; padding: 6px 14px; border-radius: 999px; background: var(--night); color: var(--ivory); }
.copyhint { position: absolute; top: 4px; right: -34px; opacity: 0; transition: opacity .15s; }
.row.out .copyhint { right: auto; left: -34px; }
.bub:hover .copyhint { opacity: 1; }
.copyhint .iconbtn { width: 30px; height: 30px; background: var(--surface); box-shadow: var(--shadow-1); }
.copyhint .i { width: 15px; height: 15px; }
@media (hover: none) { .copyhint { display: none; } }

.typing { display: inline-flex; align-items: center; gap: 5px; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--night-2); opacity: .45; animation: bounce 1.2s infinite var(--ease); }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .35 } 30% { transform: translateY(-5px); opacity: 1 } }
.typing-label { font-size: 12.5px; color: var(--muted); margin-left: 4px; }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 2px 40px; }
.qbtn { padding: 9px 18px; border-radius: 999px; font-weight: 700; font-size: 14px; border: 1.5px solid var(--night-2); color: var(--night-2); background: var(--surface); transition: background .12s, color .12s, transform .12s var(--ease); }
.qbtn:hover { background: var(--night); color: var(--ivory); }
.qbtn:active { transform: scale(.95); }
.qbtn.ok { background: var(--night); color: var(--ivory); border-color: var(--night); }
.qbtn.no { border-color: var(--line-2); color: var(--ink-2); }
.qbtn.no:hover { background: var(--surface-3); color: var(--ink); }
:root[data-theme="dark"] .qbtn { border-color: #5fc79b; color: #7fd1aa; }
:root[data-theme="dark"] .qbtn.ok { background: var(--night-2); color: #fff; border-color: var(--night-2); }

.jump { position: absolute; right: 16px; bottom: 14px; z-index: 4; width: 44px; height: 44px; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); display: grid; place-items: center; border: 1px solid var(--line); }
.jump .n { position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-size: 12px; font-weight: 800; display: grid; place-items: center; }

.emptychat { margin: auto; text-align: center; padding: 40px 24px; max-width: 360px; color: var(--ink-2); }
.emptychat .avatar { margin: 0 auto 14px; }
.emptychat h3 { font-family: var(--font-serif); font-size: 24px; margin: 0 0 6px; color: var(--ink); font-weight: 600; }
.nochat { display: grid; place-items: center; height: 100%; text-align: center; padding: 24px; background-image: var(--wall); background-size: 180px; }
.nochat .card { max-width: 420px; }
.nochat .logo-big { width: 96px; height: 96px; margin: 0 auto 18px; border-radius: 24px; box-shadow: var(--shadow-2); }
.nochat h2 { font-family: var(--font-serif); font-size: 30px; margin: 0 0 8px; letter-spacing: -.01em; font-weight: 600; }
.nochat p { color: var(--ink-2); margin: 0; }

/* ---------- Composeur ---------- */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-b)); z-index: 3; }
.cin { max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.cbox { flex: 1; display: flex; align-items: flex-end; background: var(--surface-3); border-radius: 24px; padding: 2px 4px 2px 4px; border: 1.5px solid transparent; transition: border-color .15s, background .15s; min-width: 0; }
.cbox:focus-within { border-color: var(--night-2); background: var(--surface); }
.cbox textarea { flex: 1; resize: none; border: 0; background: none; padding: 11px 6px; max-height: 148px; min-height: 44px; line-height: 1.4; outline: none; min-width: 0; }
.cbox textarea::placeholder { color: var(--muted); }
.cbox .iconbtn { width: 40px; height: 40px; flex: none; }
.send { width: 48px; height: 48px; border-radius: 50%; background: var(--night); color: var(--ivory); display: grid; place-items: center; flex: none; transition: transform .15s var(--ease), background .15s; box-shadow: var(--shadow-1); }
.send:hover { background: var(--night-2); }
.send:active { transform: scale(.9); }
.send.mic { background: var(--gold); color: var(--gold-ink); }
.send.mic:hover { background: #d4b05c; }
:root[data-theme="dark"] .send:not(.mic) { background: var(--night-2); }
.tray { max-width: 860px; margin: 0 auto 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.att { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; background: var(--surface-3); border-radius: 14px; max-width: 280px; }
.att img { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; flex: none; }
.att .fico { width: 44px; height: 44px; border-radius: 9px; background: var(--surface); display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: none; }
.att .an { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .as { font-size: 12px; color: var(--muted); }
.att .iconbtn { width: 30px; height: 30px; }
.att .iconbtn .i { width: 16px; height: 16px; }

.rec { max-width: 860px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.rec .pill { flex: 1; display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; border-radius: 24px; background: var(--surface-3); min-width: 0; }
.rec .rdot { width: 11px; height: 11px; border-radius: 50%; background: #d64533; animation: blink 1.1s infinite; flex: none; }
@keyframes blink { 50% { opacity: .25; } }
.rec .rtime { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 44px; }
.rec .rlevel { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; overflow: hidden; }
.rec .rlevel i { width: 3px; border-radius: 2px; background: var(--night-2); flex: none; height: 4px; }
.rec .rhint { font-size: 13px; color: var(--muted); }

.dropveil { position: absolute; inset: 0; z-index: 20; background: color-mix(in srgb, var(--night) 82%, transparent); color: var(--ivory); display: grid; place-items: center; font-family: var(--font-serif); font-size: 26px; pointer-events: none; border: 3px dashed var(--gold); margin: 10px; border-radius: 22px; }

/* ---------- Feuilles (modales) ---------- */
.veil { position: fixed; inset: 0; background: rgba(10, 22, 17, .5); z-index: 50; display: grid; place-items: center; padding: 20px; animation: fade .18s; }
@keyframes fade { from { opacity: 0 } }
.sheet { background: var(--surface); width: 100%; max-width: 520px; max-height: min(90dvh, 760px); border-radius: 24px; box-shadow: var(--shadow-3); display: flex; flex-direction: column; overflow: hidden; animation: rise .26s var(--ease); }
.sheet.wide { max-width: 760px; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 12px 12px 22px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; font-family: var(--font-serif); font-weight: 650; }
.sheet-body { padding: 18px 22px 22px; overflow-y: auto; }
.sheet-foot { padding: 14px 22px calc(16px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.sheet .sec { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--muted); margin: 22px 0 8px; }
.sheet .sec:first-child { margin-top: 0; }

.plist { display: grid; }
.pitem { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: var(--r-md); width: 100%; text-align: left; }
.pitem:hover { background: var(--surface-2); }
.pitem .pn { font-weight: 650; }
.pitem .ps { font-size: 13px; color: var(--muted); }
.pitem .pbody { flex: 1; min-width: 0; }
.pitem input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--night-2); }
.pitem.big { padding: 12px 8px; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.mcard { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 10px; background: var(--surface); }
.mcard.off { opacity: .6; }
.mcard .mmain { flex: 1; min-width: 0; }
.mcard .mname { font-weight: 700; }
.mcard .msub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.mcard .mtags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); }
.tag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.tag.warn { background: color-mix(in srgb, var(--gold) 24%, transparent); color: var(--gold-deep); }
.tag.off { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
:root[data-theme="dark"] .tag.warn { color: var(--gold); }

.linkbox { display: flex; gap: 8px; align-items: stretch; }
.linkbox input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.callout { padding: 12px 14px; border-radius: var(--r-md); background: color-mix(in srgb, var(--gold) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); font-size: 14px; margin: 12px 0; }
.callout.bad { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.statusline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.statusline .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.statusline .dot.ok { background: var(--ok); } .statusline .dot.bad { background: var(--danger); }

/* ---------- Divers ---------- */
.banner { position: fixed; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: var(--night-deep); color: var(--ivory); padding: 8px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 70; box-shadow: var(--shadow-2); display: flex; align-items: center; gap: 10px; }
.banner .spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--ivory) 30%, transparent); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(24px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 80; pointer-events: none; padding: 0 16px; }
.toast { background: var(--night-deep); color: var(--ivory); padding: 11px 18px; border-radius: 14px; font-size: 14.5px; box-shadow: var(--shadow-2); animation: rise .25s var(--ease); max-width: 440px; pointer-events: auto; }
.toast.bad { background: var(--danger); color: #fff; }
.lightbox { position: fixed; inset: 0; background: rgba(6, 14, 10, .94); z-index: 90; display: grid; place-items: center; animation: fade .15s; }
.lightbox img { max-width: 94vw; max-height: 86dvh; border-radius: 6px; box-shadow: var(--shadow-3); }
.lightbox .lb-top { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; display: flex; gap: 6px; }
.lightbox .iconbtn { color: #fff; background: rgba(255, 255, 255, .12); }
.lightbox .iconbtn:hover { background: rgba(255, 255, 255, .22); }
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty b { display: block; color: var(--ink-2); margin-bottom: 4px; font-size: 16px; }
.skel { height: 64px; margin: 6px 8px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .app { display: block; }
  .side, .pane { position: absolute; inset: 0; width: 100%; transition: transform .32s var(--ease); }
  .side { z-index: 2; border-right: 0; }
  .pane { z-index: 3; transform: translateX(100%); }
  .app[data-view="chat"] .pane { transform: none; }
  .app[data-view="chat"] .side { transform: translateX(-24%); }
  .chat-head .back { display: inline-grid; margin-left: -6px; }
  .row .col { max-width: 84%; }
  .msgs { padding: 0 10px; }
  .quick { margin-left: 0; }
  .sheet { max-height: 92dvh; border-radius: 24px 24px 0 0; align-self: end; }
  .veil { padding: 0; align-items: end; }
  .sheet.wide { max-width: none; }
}
@media (min-width: 901px) {
  .nochat-pane .chat-head { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
