:root {
  --bg: #f7f4f1;
  --surface: #ffffff;
  --sidebar: #efeae5;
  --hover: rgba(40, 20, 50, 0.05);
  --active: rgba(107, 63, 143, 0.12);
  --border: rgba(40, 20, 50, 0.09);
  --text: #231d27;
  --muted: #7a7180;
  --faint: #a69fab;
  --accent: #6b3f8f;
  --accent-strong: #57307a;
  --accent-soft: rgba(107, 63, 143, 0.1);
  --on-accent: #ffffff;
  --danger: #c2413b;
  --online: #3fa66b;
  --shadow: 0 1px 2px rgba(30, 15, 40, 0.06), 0 8px 24px rgba(30, 15, 40, 0.08);
  --shadow-lg: 0 12px 48px rgba(30, 15, 40, 0.18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --sidebar-w: 264px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16131a;
    --surface: #1d1922;
    --sidebar: #120f15;
    --hover: rgba(255, 245, 255, 0.05);
    --active: rgba(176, 132, 214, 0.16);
    --border: rgba(255, 245, 255, 0.08);
    --text: #ece6f0;
    --muted: #9b91a3;
    --faint: #6d6475;
    --accent: #b084d6;
    --accent-strong: #c39be3;
    --accent-soft: rgba(176, 132, 214, 0.14);
    --on-accent: #1a1220;
    --danger: #ef6b62;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

/* ---------- botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 24px; height: 24px; border-radius: 7px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn.send { background: var(--accent); color: var(--on-accent); }
.icon-btn.send:hover { background: var(--accent-strong); color: var(--on-accent); }
.icon-btn.send:disabled { background: var(--hover); color: var(--faint); cursor: default; }

/* ---------- boot & auth ---------- */

.boot { position: fixed; inset: 0; display: grid; place-items: center; font-size: 40px; opacity: .6; }

.auth {
  position: fixed; inset: 0; overflow-y: auto;
  display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(ellipse at 20% 0%, var(--accent-soft), transparent 55%),
    radial-gradient(ellipse at 90% 100%, var(--accent-soft), transparent 50%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 30px 30px;
  box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.auth-card h1 { margin: 0; font-size: 48px; line-height: 1; text-align: center; }
.auth-sub { margin: -6px 0 8px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 11px; padding: 4px; margin-bottom: 4px; }
.auth-tabs button { border: 0; background: transparent; padding: 7px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.auth-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input:not([type]), textarea.field {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { margin: 0; min-height: 1em; color: var(--danger); font-size: 13px; }
.form-error:empty { display: none; }

/* ---------- layout ---------- */

.app { display: flex; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.sidebar-head { padding: 18px 20px 10px; font-size: 28px; line-height: 1; }
.sidebar-head a { text-decoration: none; }
.nav-section.compact { margin-top: 1px !important; }
.nav-item .hash svg { width: 16px; height: 16px; vertical-align: -3px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 10px; }
.nav-section + .nav-section { margin-top: 18px; }
.nav-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 4px 10px;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--faint);
}
.nav-list { list-style: none; margin: 2px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: 0; background: transparent; text-align: left;
  padding: 6px 10px; border-radius: 9px;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--active); color: var(--text); font-weight: 500; }
.nav-item.unread { color: var(--text); font-weight: 600; }
.nav-item .hash { width: 22px; text-align: center; color: var(--faint); font-weight: 500; }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-list li { position: relative; }
.nav-close {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  opacity: 0; transition: opacity .12s;
}
.closable:hover .nav-close, .nav-close:focus-visible { opacity: 1; }
.closable:hover .badge { visibility: hidden; }
@media (hover: none) { .nav-close { opacity: .6; } .closable .badge { margin-right: 26px; } }
.closable .nav-item .label { padding-right: 18px; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 600; display: grid; place-items: center;
}

.me-card {
  display: flex; align-items: center; gap: 10px;
  margin: 8px; padding: 10px; border: 0; border-radius: 12px;
  background: transparent; text-align: left;
  margin-bottom: calc(8px + env(safe-area-inset-bottom));
}
.me-card:hover { background: var(--hover); }
.me-card .who { min-width: 0; line-height: 1.25; }
.me-card .who strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-card .who span { font-size: 12px; color: var(--muted); }

.avatar {
  --size: 32px;
  position: relative; flex-shrink: 0;
  width: var(--size); height: var(--size);
  border-radius: calc(var(--size) * 0.3);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-size: calc(var(--size) * 0.42); font-weight: 600;
  text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar.sm { --size: 22px; }
.avatar.lg { --size: 96px; }
.avatar .dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--faint); border: 2px solid var(--sidebar);
}
.avatar .dot.on { background: var(--online); }

.scrim { display: none; }

.chat { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}
.chat-title { flex: 1; min-width: 0; padding-left: 8px; }
.chat-title h2 { margin: 0; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-title p { margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title p:empty { display: none; }
.menu-btn { display: none; }

/* ---------- mensajes ---------- */

.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 0 8px; }
.load-more { display: flex; justify-content: center; padding: 8px; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty .wordmark { display: block; font-size: 36px; margin-bottom: 6px; }

.day {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 20px 8px; font-size: 12px; font-weight: 600; color: var(--faint);
}
.day::before, .day::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg {
  position: relative;
  display: grid; grid-template-columns: 40px 1fr; column-gap: 12px;
  padding: 6px 20px 4px;
}
.msg.cont { padding-top: 1px; }
.msg:hover { background: var(--hover); }
.msg .avatar { --size: 40px; grid-row: span 2; margin-top: 2px; }
.msg .gutter-time {
  grid-row: span 2; font-size: 11px; color: var(--faint);
  text-align: right; padding-top: 4px; opacity: 0; white-space: nowrap;
}
.msg.cont:hover .gutter-time { opacity: 1; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-meta strong { font-weight: 600; }
.msg-meta time { font-size: 12px; color: var(--faint); }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-body.jumbo { font-size: 36px; line-height: 1.25; }
.msg-content { min-width: 0; }

.msg-actions {
  position: absolute; top: -14px; right: 16px;
  display: none; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.msg:hover .msg-actions, .msg.menu-open .msg-actions { display: flex; }
.msg-actions .icon-btn { width: 30px; height: 30px; border-radius: 7px; }
.msg-actions .icon-btn svg { width: 17px; height: 17px; }
.msg-actions .quick { font-size: 16px; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 13px;
  background: var(--bg); font-size: 13px;
  transition: border-color .12s, background .12s;
}
.reaction:hover { border-color: var(--faint); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.reaction .count { font-size: 12px; font-weight: 600; }
.reaction.add { color: var(--faint); padding: 0 6px; }
.reaction.add svg { width: 15px; height: 15px; }

/* ---------- adjuntos ---------- */

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att { position: relative; max-width: min(420px, 100%); }
.att-media {
  display: block; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg);
}
.att-media img { display: block; max-width: 100%; max-height: 340px; object-fit: contain; cursor: zoom-in; }
.att-media video { display: block; max-width: 100%; max-height: 360px; background: #000; }
.att audio { display: block; width: min(360px, 100%); margin-top: 2px; }
.att-tools {
  position: absolute; top: 6px; right: 6px; display: none; gap: 4px;
}
.att:hover .att-tools { display: flex; }
.att-tools .icon-btn { width: 28px; height: 28px; background: rgba(20, 10, 25, .6); color: #fff; backdrop-filter: blur(6px); }
.att-tools .icon-btn svg { width: 15px; height: 15px; }
.att.audio .att-tools { position: static; display: flex; margin-top: 4px; }
.att.audio .att-tools .icon-btn { background: transparent; color: var(--muted); }

.file-card {
  display: flex; align-items: center; gap: 12px;
  width: min(340px, 100%); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
}
.file-icon {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 700; letter-spacing: .03em;
}
.file-info { flex: 1; min-width: 0; line-height: 1.3; }
.file-info strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info span { font-size: 12px; color: var(--muted); }
.file-card .icon-btn { width: 32px; height: 32px; }

/* ---------- inicio ---------- */

.home { max-width: 720px; margin: 0 auto; padding: 12px 20px 24px; }
.home-title {
  margin: 8px 4px 10px; font-size: 12px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--faint);
}
.home-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin-bottom: 8px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); text-align: left;
  transition: border-color .12s, background .12s, transform .1s;
}
.home-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--hover); }
.home-card:active { transform: scale(0.99); }
.home-card .lead {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 18px;
}
.home-card .avatar { --size: 40px; }
.home-card .text { flex: 1; min-width: 0; line-height: 1.35; }
.home-card .text strong { display: block; font-weight: 600; }
.home-card .text span {
  display: block; color: var(--muted); font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.home-card .meta { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--faint); }

.home-empty { display: grid; justify-items: center; text-align: center; padding: 72px 24px 40px; }
.home-check {
  width: 72px; height: 72px; border-radius: 24px; margin-bottom: 18px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.home-check svg { width: 34px; height: 34px; }
.home-empty h3 { margin: 0 0 4px; font-family: var(--font-display); font-style: italic; font-weight: 600; font-size: 30px; color: var(--text); }
.home-empty p { margin: 0; color: var(--muted); }

/* En el celular la barra lateral está oculta: el inicio muestra también todas las conversaciones. */
.home-all { display: none; }
@media (max-width: 760px) {
  .home-all { display: block; margin-top: 18px; }
  .home-empty { padding-top: 40px; }
}

/* ---------- menciones ---------- */

.mention {
  padding: 0 3px; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
.mention.me { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-strong); font-weight: 600; }

.mention-menu {
  position: absolute; left: 8px; right: 8px; bottom: calc(100% + 6px); z-index: 7;
  max-width: 340px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
}
.mention-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 8px;
  background: transparent; text-align: left;
}
.mention-menu button.active { background: var(--active); }
.mention-menu small { color: var(--muted); }
.mention-menu .hash { width: 22px; text-align: center; color: var(--faint); font-weight: 600; }
.composer { position: relative; }

.mention-item { margin: 4px 12px 10px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.mention-item.unseen { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: inset 3px 0 0 var(--accent); }
.mention-context {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 8px 14px; border: 0; border-bottom: 1px solid var(--border);
  background: var(--bg); text-align: left; font-size: 13px; color: var(--muted);
}
.mention-context:hover { color: var(--accent); }
.mention-context strong { color: var(--text); font-weight: 600; }
.mention-context:hover strong { color: var(--accent); }
.mention-context .go { margin-left: auto; font-size: 12px; }
.mention-item .msg { padding-top: 8px; padding-bottom: 8px; }
.mention-item .msg:hover { background: transparent; }

@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.msg.flash { animation: flash 2.4s ease-out; }

/* ---------- hilos ---------- */

.thread-summary {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 3px 10px 3px 4px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; font-size: 13px;
  transition: background .12s, border-color .12s;
}
.thread-summary:hover { background: var(--surface); border-color: var(--border); }
.thread-summary .avatars { display: flex; }
.thread-summary .avatars .avatar { --size: 22px; border: 2px solid var(--surface); box-sizing: content-box; }
.thread-summary .avatars .avatar + .avatar { margin-left: -8px; }
.thread-summary strong { color: var(--accent); font-weight: 600; }
.thread-summary span { color: var(--faint); }
.thread-summary[hidden] { display: none; }

.reply-label {
  display: block; margin-bottom: 2px;
  border: 0; background: none; padding: 0;
  font-size: 12px; color: var(--muted); text-align: left;
}
.reply-label:hover { color: var(--accent); text-decoration: underline; }

.thread {
  position: relative;
  width: 400px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.thread .messages { padding-top: 8px; }
.thread .thread-parent { padding-bottom: 6px; }
.thread .replies-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 20px 6px; font-size: 12px; color: var(--faint);
}
.thread .replies-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.thread .msg { padding-left: 16px; padding-right: 16px; }
.broadcast-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px 10px; margin-top: -2px;
  font-size: 12px; font-weight: 400; color: var(--muted); cursor: pointer;
}
.broadcast-opt input { accent-color: var(--accent); margin: 0; }

/* ---------- composer ---------- */

.typing { height: 20px; padding: 0 22px; font-size: 12px; color: var(--muted); }
.composer {
  margin: 0 16px calc(16px + env(safe-area-inset-bottom));
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; padding: 6px; }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  padding: 7px 4px; max-height: 40vh; line-height: 1.45; font-size: 15px;
}
.pending { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 10px 0; }
.chip {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 30px 0 6px; max-width: 220px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font-size: 13px;
}
.chip img, .chip .file-icon { width: 42px; height: 42px; border-radius: 7px; object-fit: cover; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .name small { display: block; color: var(--muted); font-size: 11px; }
.chip .icon-btn { position: absolute; top: 2px; right: 2px; }
.upload-progress { height: 3px; margin: 8px 10px 0; background: var(--hover); border-radius: 2px; overflow: hidden; }
.upload-progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.drop-zone {
  position: absolute; inset: 8px; z-index: 6;
  display: none; place-items: center;
  border: 2px dashed var(--accent); border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  font-weight: 600; color: var(--accent);
  pointer-events: none;
}
.drop-zone.on { display: grid; }

/* ---------- popovers & modales ---------- */

.emoji-picker {
  position: fixed; z-index: 30;
  width: 312px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 10px;
}
.emoji-picker h4 { margin: 4px 4px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 240px; overflow-y: auto; }
.emoji-grid button {
  border: 0; background: transparent; border-radius: 8px;
  font-size: 22px; line-height: 1; aspect-ratio: 1;
}
.emoji-grid button:hover { background: var(--hover); }

.modal {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--border); border-radius: 20px;
  padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(15, 8, 20, .45); backdrop-filter: blur(3px); }
.modal form { display: grid; gap: 16px; padding: 24px; }
.modal h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal .actions .spacer { flex: 1; }
.modal hr { border: 0; border-top: 1px solid var(--border); margin: 0; width: 100%; }
.avatar-edit { display: flex; align-items: center; gap: 16px; }
.avatar-edit .stack { display: grid; gap: 6px; justify-items: start; }
.user-pick { display: grid; gap: 2px; max-height: 320px; overflow-y: auto; }
.user-pick button {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border: 0; border-radius: 10px;
  background: transparent; text-align: left;
}
.user-pick button:hover { background: var(--hover); }
.user-pick small { color: var(--muted); }
details summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 500; }
details[open] summary { margin-bottom: 12px; }
details .grid { display: grid; gap: 12px; }

.lightbox {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(10, 5, 15, .88); padding: 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: var(--shadow-lg); }
.lightbox .icon-btn { position: absolute; top: 16px; color: #fff; background: rgba(255, 255, 255, .1); }
.lightbox .close { right: 16px; }
.lightbox .download { right: 60px; }

.toast {
  position: fixed; inset: auto auto 24px 50%; z-index: 50; transform: translateX(-50%);
  margin: 0; border: 0;
  padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
}

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .thread {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 18;
    width: min(420px, 100vw);
    box-shadow: var(--shadow-lg);
  }
}


@media (max-width: 760px) {
  .menu-btn { display: inline-grid; }
  .chat-title { padding-left: 0; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20;
    width: min(300px, 85vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(15, 8, 20, .4); }
  .msg { padding-left: 16px; padding-right: 16px; column-gap: 10px; grid-template-columns: 36px 1fr; }
  .msg .avatar { --size: 36px; }
  .msg-actions { right: 10px; }
  .composer { margin-left: 10px; margin-right: 10px; margin-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .composer textarea { font-size: 16px; }
  .thread { width: 100vw; border-left: 0; }
}
