:root {
  --bg-0: #07080d;
  --bg-1: #0e1119;
  --fg: #e8ecf3;
  --muted: #8a93a8;
  --accent: #7c5cff;
  --accent-2: #19c2ff;
  --me: linear-gradient(135deg, #7c5cff, #19c2ff);
  --them: #1a1f2e;
  --danger: #ff5d6b;
  --radius: 18px;
  --shadow: 0 30px 80px -20px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--fg);
  background: radial-gradient(1200px 800px at 20% -10%, #1b1740 0%, transparent 60%),
              radial-gradient(900px 600px at 110% 110%, #052a3d 0%, transparent 55%),
              var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Landing ---------- */
.landing { display: grid; place-items: center; }
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }

.card {
  position: relative;
  z-index: 1;
  width: min(440px, 92vw);
  padding: 36px 30px 26px;
  background: rgba(14, 17, 25, 0.65);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

h1 {
  font-size: 38px;
  margin: 14px 0 4px;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff, #b9bee0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

form { text-align: left; }
label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.code-row {
  display: flex; gap: 8px;
  margin-top: 8px;
}
input[type="password"], input[type="text"] {
  flex: 1; min-width: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--fg);
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border .2s, background .2s, box-shadow .2s;
}
input:focus {
  border-color: rgba(124,92,255,0.7);
  box-shadow: 0 0 0 4px rgba(124,92,255,0.15);
}

#reveal {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--fg);
  width: 48px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 16px;
}
#reveal:hover { background: rgba(255,255,255,0.08); }

.actions { display: flex; gap: 10px; margin-top: 18px; }
button {
  font-family: inherit;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .08s, background .2s, border-color .2s;
}
button:active { transform: translateY(1px); }

.primary {
  flex: 1;
  background: var(--me);
  color: white;
  border: none;
  font-weight: 600;
  box-shadow: 0 10px 30px -10px rgba(124,92,255,0.7);
}
.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.12);
}
.ghost:hover { background: rgba(255,255,255,0.04); }

.err {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 12px 0 0;
}

.info {
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 14px;
  text-align: left;
}
.info summary { cursor: pointer; color: var(--fg); margin-bottom: 8px; }
.info ul { margin: 0; padding-left: 18px; line-height: 1.6; }
.info b { color: var(--fg); }

/* ---------- Orb ---------- */
.orb {
  width: 76px; height: 76px;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #7c5cff, #19c2ff, #7c5cff);
  display: grid; place-items: center;
  animation: spin 8s linear infinite;
  box-shadow: 0 0 60px -10px rgba(124,92,255,0.7);
}
.orb-inner {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff 0%, #b8c0ff 25%, #2b1f5a 70%);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
}
.orb.small { width: 36px; height: 36px; animation-duration: 12s; }
.orb.small .orb-inner { width: 30px; height: 30px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(7,8,13,0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 5;
}
.meta { flex: 1; min-width: 0; }
.title { font-weight: 600; letter-spacing: -0.01em; }
.status { font-size: 12px; color: var(--muted); }
.status.ok { color: #54e6a9; }
.status.warn { color: #ffc857; }
.status.err { color: var(--danger); }

.leave, button.small { padding: 8px 12px; font-size: 13px; }

.codebar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 10px 18px;
  background: rgba(124,92,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
}
.cb-left, .cb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cb-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
}
.cb-code, .cb-fp {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: rgba(255,255,255,0.05);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--fg);
  max-width: 50vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cb-fp {
  background: linear-gradient(135deg, rgba(124,92,255,0.18), rgba(25,194,255,0.18));
  border-color: rgba(124,92,255,0.35);
  letter-spacing: 0.06em;
}
.codebar button.small { padding: 4px 8px; font-size: 13px; }

.stream {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 8px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: min(560px, 78%);
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: pop .18s ease-out;
  position: relative;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.bubble.me {
  align-self: flex-end;
  background: var(--me);
  color: white;
  border-bottom-right-radius: 6px;
  box-shadow: 0 8px 22px -8px rgba(124,92,255,0.5);
}
.bubble.them {
  align-self: flex-start;
  background: var(--them);
  border-bottom-left-radius: 6px;
  border: 1px solid rgba(255,255,255,0.05);
}
.bubble.sys {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}
.bubble .ts {
  display: block;
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

.typing {
  display: flex; gap: 4px;
  padding: 0 22px 4px;
  height: 18px;
}
.typing[hidden] { display: none; }
.typing span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(7,8,13,0.7);
  backdrop-filter: blur(14px);
}
textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--fg);
  padding: 12px 14px;
  border-radius: 18px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
}
textarea:focus {
  border-color: rgba(124,92,255,0.7);
  box-shadow: 0 0 0 4px rgba(124,92,255,0.12);
}

.send {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--me);
  color: white;
  border: none;
  font-size: 18px;
  box-shadow: 0 10px 24px -10px rgba(124,92,255,0.7);
  flex: 0 0 auto;
}
.send:disabled { opacity: 0.4; cursor: not-allowed; }

/* scrollbar */
.stream::-webkit-scrollbar { width: 8px; }
.stream::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08); border-radius: 4px;
}

/* ---------- Reply / quote ---------- */
.reply-quote {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 10px;
  margin: -2px 0 8px;
  background: rgba(0,0,0,0.18);
  border-left: 3px solid rgba(255,255,255,0.5);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}
.bubble.them .reply-quote {
  background: rgba(255,255,255,0.05);
  border-left-color: var(--accent);
  color: var(--muted);
}
.reply-quote:hover { filter: brightness(1.15); }
.reply-ico { opacity: 0.7; }
.reply-text {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.bubble { position: relative; }
.bubble.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0%   { box-shadow: 0 0 0 3px rgba(124,92,255,0.7); }
  100% { box-shadow: 0 0 0 0 rgba(124,92,255,0); }
}

/* Rangée bulle + bouton répondre (hover continu, plus de trou) */
.bubble-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}
.bubble-row.me { align-self: flex-end; flex-direction: row; justify-content: flex-end; }
.bubble-row.them { align-self: flex-start; }

/* la bulle dans la rangée n'a plus besoin de align-self */
.bubble-row .bubble { align-self: auto; }

.bubble-reply {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  padding: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(14,17,25,0.92);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, background .15s, border-color .15s, transform .15s;
  box-shadow: 0 6px 14px -6px rgba(0,0,0,0.5);
}
.bubble-row:hover .bubble-reply,
.bubble-row:focus-within .bubble-reply {
  opacity: 1;
  pointer-events: auto;
}
.bubble-reply:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.08);
}
@media (hover: none) {
  .bubble-reply { opacity: 0.6; pointer-events: auto; }
}

/* ---------- Reply composer bar ---------- */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: rgba(124,92,255,0.10);
  border-top: 1px solid rgba(124,92,255,0.25);
  border-bottom: 1px solid rgba(124,92,255,0.15);
  font-size: 13px;
}
.reply-bar[hidden] { display: none; }
.reply-chev { color: var(--accent); font-size: 16px; }
.reply-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.reply-to { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.reply-snippet {
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Links / embeds ---------- */
.msg-text { word-break: break-word; }
.msg-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(255,255,255,0.4);
  text-underline-offset: 2px;
}
.bubble.them .msg-link { color: var(--accent-2); text-decoration-color: rgba(25,194,255,0.4); }
.msg-link:hover { text-decoration-color: currentColor; }

.embed {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0,0,0,0.3);
  max-width: 100%;
}
.embed-yt, .embed-vimeo {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(480px, 100%);
}
.embed-yt iframe, .embed-vimeo iframe {
  width: 100%; height: 100%; border: 0;
}
.embed-img img {
  display: block;
  max-width: min(420px, 100%);
  max-height: 360px;
  cursor: zoom-in;
  object-fit: contain;
}
.embed-img.attach img { max-height: 420px; }

/* ---------- Link preview card ---------- */
.preview-card {
  display: flex;
  margin-top: 8px;
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.08);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  max-width: min(460px, 100%);
  transition: background .2s, border-color .2s, transform .08s;
}
.bubble.them .preview-card { background: rgba(255,255,255,0.04); }
.preview-card:hover { background: rgba(124,92,255,0.10); border-left-color: var(--accent-2); }
.preview-card:active { transform: translateY(1px); }

.pv-img {
  flex: 0 0 96px;
  align-self: stretch;
  background: rgba(0,0,0,0.4);
  display: grid; place-items: center;
}
.pv-img img {
  width: 100%; height: 100%;
  max-height: 140px;
  object-fit: cover;
  display: block;
}
.pv-body {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px;
  line-height: 1.4;
}
.pv-site {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pv-title {
  color: var(--fg);
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pv-desc {
  color: var(--muted);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- GIF panel ---------- */
.gif-panel {
  position: relative;
  background: rgba(7,8,13,0.95);
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  max-height: 340px;
  display: flex;
  flex-direction: column;
  z-index: 4;
}
.gif-panel[hidden] { display: none; }
.gif-head {
  display: flex; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.gif-head input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.gif-head input:focus {
  border-color: rgba(124,92,255,0.5);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.12);
}
.gif-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
  padding: 10px;
}
.gif-cell {
  padding: 0;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
  cursor: pointer;
  aspect-ratio: 1 / 1;
  transition: transform .1s, border-color .15s;
}
.gif-cell:hover {
  transform: scale(1.03);
  border-color: var(--accent);
}
.gif-cell img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.gif-status {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 30px 10px;
  font-size: 13px;
}
.gif-status.err { color: var(--danger); }
.gif-foot {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  padding: 4px 0 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.gif-btn {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* ---------- CTA notifs ---------- */
.bubble.sys.cta {
  background: rgba(124,92,255,0.10);
  border: 1px solid rgba(124,92,255,0.25);
  color: var(--fg);
  font-style: normal;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: min(560px, 92%);
  display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px;
}
.cta-btn {
  background: var(--me);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
}
.cta-btn:hover { filter: brightness(1.1); }

/* ---------- Call button ---------- */
#call-btn { font-size: 16px; }
#call-btn.busy {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  animation: ringshake 0.5s ease-in-out 0s 3;
}
@keyframes ringshake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-10deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(6deg); }
}

/* ---------- Composer attach ---------- */
.attach {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--fg);
  font-size: 18px;
  padding: 0;
  flex: 0 0 auto;
  cursor: pointer;
}
.attach:hover { background: rgba(124,92,255,0.15); border-color: rgba(124,92,255,0.4); }

/* ---------- Drag overlay ---------- */
body.dragging::after {
  content: "Déposer l'image ici";
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(7,8,13,0.7);
  color: var(--fg);
  font-size: 22px;
  border: 3px dashed rgba(124,92,255,0.6);
  z-index: 100;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: grid; place-items: center;
  z-index: 200;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: white;
  font-size: 16px;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }
