:root {
  --bg: #0f172a;
  --card: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --warn: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: #60a5fa; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
code { background: rgba(148,163,184,.15); padding: 1px 5px; border-radius: 4px; }

/* Auth pages */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-wrap .card { width: 100%; max-width: 380px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

h1 { margin-top: 0; font-size: 1.5rem; }
h2 { margin-top: 0; font-size: 1.15rem; }

label {
  display: block;
  margin-bottom: 14px;
  font-size: .9rem;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .95rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }

.link-btn {
  background: none;
  color: #60a5fa;
  padding: 0;
}
.link-btn:hover { background: none; text-decoration: underline; }
.inline { display: inline; }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } }

/* Bloc identité du bot */
.bot-id {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  border-color: var(--accent);
}
.bot-id h2 { margin-bottom: 4px; }
.bot-id p { margin: 0; }
.bot-id-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.bot-handle {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  background: #0b1220;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  user-select: all;
}
.copy-btn { white-space: nowrap; }
.copy-btn.copied { background: var(--success); }
.link-out {
  font-size: .88rem;
  white-space: nowrap;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: .9rem;
}
.alert.success { background: rgba(22,163,74,.15); border: 1px solid var(--success); }
.alert.error   { background: rgba(220,38,38,.15); border: 1px solid var(--error); }
.alert.warn    { background: rgba(217,119,6,.15); border: 1px solid var(--warn); }

/* Fil de messages */
.thread-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.thread-head h2 { margin: 0; }
.thread-filter select { width: auto; min-width: 180px; margin-top: 0; }

.thread {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 4px 2px;
  margin-top: 10px;
}
.msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
}
.msg-in  { align-self: flex-start; align-items: flex-start; }
.msg-out { align-self: flex-end;   align-items: flex-end; }

/* Méta compacte, collée à la bulle */
.msg-meta {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: .68rem;
  line-height: 1.2;
  color: var(--muted);
  padding: 0 4px;
}
.msg-who { font-weight: 600; color: #cbd5e1; }
.msg-group {
  background: rgba(148,163,184,.15);
  padding: 0 5px;
  border-radius: 999px;
}
.msg-time { opacity: .75; }

.msg-body {
  padding: 3px 9px;
  border-radius: 10px;
  font-size: .85rem;
  line-height: 1.3;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-in .msg-body {
  background: #0b1220;
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.msg-out .msg-body {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.msg-doc { font-weight: 600; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .78rem;
  text-transform: capitalize;
}
.badge.sent    { background: rgba(22,163,74,.2);  color: #4ade80; }
.badge.failed  { background: rgba(220,38,38,.2);  color: #f87171; }
.badge.pending { background: rgba(217,119,6,.2);  color: #fbbf24; }
