/* TMKAsk — interface de @TMKAskBot */
:root {
    --bg: #f4f6f9; --surface: #fff; --surface-2: #eef2f6; --text: #18212b; --muted: #637083; --border: #dde3ea;
    --accent: #1e88d6; --accent-ink: #fff; --accent-soft: #e3f1fc; --danger: #c93a3a; --danger-soft: #fdeaea;
    --ok: #1f8a4c; --ok-soft: #e4f5ea; --warn: #b26a00; --warn-soft: #fff3df;
    --bubble-in: #fff; --bubble-out: #d9efff; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --radius: 12px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1419; --surface: #182029; --surface-2: #1f2a35; --text: #e6edf3; --muted: #93a1b0; --border: #2b3744;
        --accent: #3aa5f0; --accent-ink: #0b1620; --accent-soft: #15324a; --danger: #f07070; --danger-soft: #3a1d1f;
        --ok: #5cc98a; --ok-soft: #173326; --warn: #f0b04a; --warn-soft: #3a2c14;
        --bubble-in: #1f2a35; --bubble-out: #1b4466; --shadow: none;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0f1419; --surface: #182029; --surface-2: #1f2a35; --text: #e6edf3; --muted: #93a1b0; --border: #2b3744;
    --accent: #3aa5f0; --accent-ink: #0b1620; --accent-soft: #15324a; --danger: #f07070; --danger-soft: #3a1d1f;
    --ok: #5cc98a; --ok-soft: #173326; --warn: #f0b04a; --warn-soft: #3a2c14;
    --bubble-in: #1f2a35; --bubble-out: #1b4466; --shadow: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: .05em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: var(--muted); padding: .4rem .75rem; border-radius: 8px; white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-logout { margin-left: auto; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* Messages flash */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-small { padding: .35rem .7rem; font-size: .85rem; }
.btn-icon { min-width: 2.2rem; }
.btn-block { width: 100%; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.pill { display: inline-flex; min-width: 1.35rem; height: 1.35rem; padding: 0 .4rem; align-items: center; justify-content: center; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.board { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.empty { padding: 2.5rem 1rem; text-align: center; }
.empty p { margin: .25rem 0; }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-warn .kpi-value { color: var(--accent); }

/* Liste des conversations */
.board-tools { display: flex; gap: .75rem; padding: .75rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.board-tools input[type=search] { flex: 1; min-width: 200px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: .55rem .75rem; width: 100%; }
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
.board-tools input { width: auto; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.segmented button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .88rem; padding: .35rem .8rem; border-radius: 7px; cursor: pointer; }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list li + li { border-top: 1px solid var(--border); }
.conv { display: flex; gap: .85rem; align-items: center; padding: .8rem 1rem; color: var(--text); }
.conv:hover { background: var(--surface-2); text-decoration: none; }
.conv.is-blocked { opacity: .6; }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .95rem; color: #fff; background: hsl(var(--hue, 205) 55% 50%); }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.conv-top, .conv-bottom { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-name .muted { font-weight: 400; }
.conv-date { flex: none; }
.conv-preview { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.conv.is-unread .conv-name, .conv.is-unread .conv-preview { color: var(--text); font-weight: 700; }
.conv.is-unread .conv-date { color: var(--accent); font-weight: 600; }

/* Conversation */
.page-chat { max-width: 1200px; padding-bottom: 1rem; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; align-items: start; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 7rem); min-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.chat-title { display: flex; flex-direction: column; min-width: 0; }
.back { font-size: 1.3rem; color: var(--muted); padding: 0 .25rem; }
.back:hover { text-decoration: none; color: var(--text); }
.thread { flex: 1; overflow-y: auto; padding: 1rem; background: var(--bg); display: flex; flex-direction: column; gap: .35rem; }
.day { text-align: center; margin: .75rem 0 .35rem; }
.day span { font-size: .78rem; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: .15rem .65rem; border-radius: 999px; }
.msg { display: flex; flex-direction: column; max-width: min(78%, 620px); }
.msg-in { align-self: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }
.bubble { background: var(--bubble-in); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: .5rem .75rem; overflow-wrap: anywhere; }
.msg-out .bubble { background: var(--bubble-out); border-color: transparent; border-radius: 14px 14px 4px 14px; }
.msg-failed .bubble { border: 1px dashed var(--danger); }
.msg-meta { font-size: .74rem; color: var(--muted); margin: .1rem .35rem 0; }
.msg-error { color: var(--danger); }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; }
.bubble audio, .bubble video { max-width: 100%; display: block; }
.bubble video { max-height: 320px; border-radius: 8px; }
.msg-kind { font-size: .85rem; color: var(--muted); font-style: italic; }
.msg-file { font-weight: 600; }
.msg-text + .msg-text, .msg-img + .msg-text { margin-top: .35rem; }

.composer { border-top: 1px solid var(--border); padding: .65rem .75rem .75rem; display: flex; flex-direction: column; gap: .5rem; background: var(--surface); }
.quick { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: .3rem .75rem; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.chip:hover { text-decoration: none; filter: brightness(.97); }
.chip-off { opacity: .6; }
.chip-ghost { background: transparent; }
.composer-row { display: flex; gap: .5rem; align-items: flex-end; }
.composer-row textarea { resize: vertical; min-height: 2.8rem; max-height: 40vh; }
.composer-hint { margin: 0; }

.side { display: flex; flex-direction: column; gap: 1rem; }
.side textarea { margin-bottom: .5rem; resize: vertical; }
.card-actions { display: flex; flex-direction: column; gap: .5rem; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; margin: 0; font-size: .92rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Réponses toutes prêtes */
.replies { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.reply.is-off { opacity: .7; }
.reply-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.reply-usage { margin-left: auto; }
.reply-text { white-space: normal; background: var(--surface-2); border-radius: 9px; padding: .6rem .8rem; margin-bottom: .75rem; font-size: .93rem; }
.reply-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.reply-actions form { margin: 0; }
.tg-button { display: inline-block; background: color-mix(in srgb, #5b8fb9 22%, var(--surface)); color: var(--text); border-radius: 8px; padding: .35rem .9rem; font-weight: 600; font-size: .9rem; text-align: center; }
.tg-button-wide { display: block; margin-top: .3rem; }

.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.form { display: flex; flex-direction: column; }
.form label { font-weight: 600; margin-top: .9rem; margin-bottom: .3rem; }
.form label:first-of-type { margin-top: 0; }
.form .help { margin: .3rem 0 0; color: var(--muted); font-size: .85rem; }
.form .error { margin: .3rem 0 0; color: var(--danger); font-size: .88rem; font-weight: 600; }
.form .check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-top: 1rem; }
.form .check input { width: auto; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }
.form textarea { resize: vertical; }
.tg-preview { background: #8fb5d6 linear-gradient(160deg, #a6c8e4, #7fa7c9); border-radius: 10px; padding: .9rem; display: flex; flex-direction: column; gap: .3rem; }
.tg-msg { background: #fff; color: #111; border-radius: 12px 12px 12px 4px; padding: .45rem .7rem; font-size: .9rem; max-width: 92%; white-space: pre-line; }
.tg-msg-out { align-self: flex-end; background: #e1ffc7; border-radius: 12px 12px 4px 12px; margin-top: .5rem; }
.tg-preview .tg-button { background: rgba(255, 255, 255, .55); color: #13324b; max-width: 92%; }
.status { margin-bottom: 1rem; border-left: 4px solid var(--ok); }
.status-warn { border-left-color: var(--warn); }

/* Connexion */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem 1.5rem; text-align: center; box-shadow: var(--shadow); }
.auth-card h1 { margin-top: .6rem; }
.auth-card form { margin: 1.25rem 0 1rem; }
.auth .flash { width: 100%; max-width: 380px; text-align: left; }
.auth-card .flash { max-width: none; margin-top: 1rem; }

@media (max-width: 860px) {
    .chat-layout, .form-layout { grid-template-columns: 1fr; }
    .chat { height: calc(100vh - 6.5rem); }
    .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    .topbar { gap: .75rem; padding: .5rem 1rem; flex-wrap: wrap; }
    .nav { order: 3; flex-basis: 100%; flex-wrap: wrap; overflow: visible; }
    .nav a { padding: .35rem .55rem; font-size: .9rem; }
    .page { padding: 1rem 1rem 2rem; }
    .msg { max-width: 90%; }
    .reply-usage { margin-left: 0; flex-basis: 100%; }
}
