/* QMsg — interface styling.
   Layout and colour follow WhatsApp closely so the app needs no explanation. */

:root {
  --green:        #00a884;
  --green-dark:   #008069;
  --tick-blue:    #53bdeb;

  --bg-app:       #f0f2f5;
  --bg-panel:     #ffffff;
  --bg-head:      #f0f2f5;
  --bg-convo:     #efeae2;
  --bubble-in:    #ffffff;
  --bubble-out:   #d9fdd3;
  --text:         #111b21;
  --text-soft:    #667781;
  --text-faint:   #8696a0;
  --divider:      #e9edef;
  --hover:        #f5f6f6;
  --active:       #e9edef;
  --danger:       #e34d4d;
  --shadow:       0 1px 0.5px rgba(11,20,26,.13);
  --meta-out:     #667781;
  --radius:       7.5px;

  --side-w:       min(420px, 38vw);
  --head-h:       59px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-app:       #0b141a;
  --bg-panel:     #111b21;
  --bg-head:      #202c33;
  --bg-convo:     #0b141a;
  --bubble-in:    #202c33;
  --bubble-out:   #005c4b;
  --text:         #e9edef;
  --text-soft:    #8696a0;
  --text-faint:   #667781;
  --divider:      #222d34;
  --hover:        #202c33;
  --active:       #2a3942;
  --shadow:       0 1px 0.5px rgba(0,0,0,.3);
  --meta-out:     rgba(233,237,239,.75);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app:     #0b141a;
    --bg-panel:   #111b21;
    --bg-head:    #202c33;
    --bg-convo:   #0b141a;
    --bubble-in:  #202c33;
    --bubble-out: #005c4b;
    --text:       #e9edef;
    --text-soft:  #8696a0;
    --text-faint: #667781;
    --divider:    #222d34;
    --hover:      #202c33;
    --active:     #2a3942;
    --shadow:     0 1px 0.5px rgba(0,0,0,.3);
    --meta-out:   rgba(233,237,239,.75);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Author-level display rules below would otherwise beat the UA's
   [hidden] { display: none }, leaving hidden panels stacked on screen. */
[hidden] { display: none !important; }

html, html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}
svg circle[cx] { fill: currentColor; stroke: none; }
svg .fg { stroke: var(--bg-head); }

/* ── boot ──────────────────────────────────────────────────────── */
.boot {
  position: fixed; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 22px;
  background: var(--bg-app); color: var(--text-soft); z-index: 100;
}
.boot-mark, .auth-logo, .empty-art {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--green);
  -webkit-mask: var(--lock-mask) center/32px no-repeat;
  mask: var(--lock-mask) center/32px no-repeat;
  background-image: linear-gradient(135deg, var(--green), var(--green-dark));
}
:root {
  --lock-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round"><rect x="4" y="10" width="16" height="11" rx="2.5"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>');
}
.boot-mark { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .45; } 50% { opacity: 1; } }

/* ── auth ──────────────────────────────────────────────────────── */
.auth {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    linear-gradient(var(--green-dark) 0 222px, transparent 222px 100%),
    var(--bg-app);
}
.auth-card {
  width: min(460px, 100%);
  background: var(--bg-panel);
  border-radius: 14px;
  padding: 28px 26px 22px;
  box-shadow: 0 8px 30px rgba(11,20,26,.18);
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo { margin: 0 auto 12px; }
.auth-brand h1 { margin: 0; font-size: 25px; font-weight: 600; letter-spacing: -.2px; }
.auth-tag { margin: 4px 0 0; color: var(--text-soft); font-size: 13.5px; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--divider); margin-bottom: 20px;
}
.tab {
  padding: 11px 6px; font-size: 14px; font-weight: 500;
  color: var(--text-soft); border-bottom: 2.5px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab.is-active { color: var(--green); border-bottom-color: var(--green); }

.auth-form { display: grid; gap: 15px; }
.auth-form label { display: grid; gap: 6px; font-size: 13px; color: var(--text-soft); font-weight: 500; }
.auth-form small { color: var(--text-faint); font-weight: 400; font-size: 11.8px; line-height: 1.4; }
.auth-form input, #new-chat-username {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--divider); border-radius: 8px;
  background: var(--bg-app); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus, #new-chat-username:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent);
}

.btn-primary {
  padding: 11px 18px; border-radius: 8px;
  background: var(--green); color: #fff; font-weight: 600;
  transition: background .15s, opacity .15s;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { padding: 11px 18px; border-radius: 8px; color: var(--text-soft); font-weight: 500; }
.btn-ghost:hover { background: var(--hover); }

.form-error { min-height: 1em; margin: 0; color: var(--danger); font-size: 13px; }
.auth-foot {
  margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--divider);
  color: var(--text-faint); font-size: 12.2px; text-align: center; line-height: 1.5;
}

/* ── app shell ─────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--divider);
  min-width: 0;
  overflow: hidden;
}
.side-head { flex: 0 0 var(--head-h); }
.search-row { flex: 0 0 auto; }
.chat-list { flex: 1 1 0%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.storage-bar { flex: 0 0 auto; }

.side-head {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--bg-head);
}
.side-head-title { flex: 1; min-width: 0; display: grid; }
.side-head-title strong { font-size: 15px; font-weight: 600; }
.side-head-title span { font-size: 12px; color: var(--text-soft); }
.side-head-title strong, .side-head-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-head-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--text-soft); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--active); color: var(--text); }
.icon-btn.danger { color: var(--danger); }

.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6d8ea0, #4a6572);
  color: #fff; font-weight: 600; font-size: 15px; letter-spacing: .3px;
  user-select: none; overflow: hidden;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }

.search-row { padding: 7px 12px; background: var(--bg-panel); border-bottom: 1px solid var(--divider); }
.search { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--text-faint); }
.search input {
  width: 100%; padding: 8px 12px 8px 40px;
  border: 0; border-radius: 8px; background: var(--bg-app); color: var(--text);
}
.search input:focus { outline: 2px solid var(--green); outline-offset: -2px; }

.chat-list { overflow-y: auto; overscroll-behavior: contain; }

.chat-row {
  display: grid; grid-template-columns: 49px 1fr; gap: 13px;
  align-items: center; padding: 10px 14px;
  cursor: pointer; border-bottom: 1px solid var(--divider);
  transition: background .12s;
}
.chat-row:hover { background: var(--hover); }
.chat-row.is-active { background: var(--active); }
.chat-row .avatar { width: 49px; height: 49px; font-size: 18px; }
.chat-meta { min-width: 0; display: grid; gap: 2px; }
.chat-meta-top, .chat-meta-bot { display: flex; align-items: center; gap: 8px; }
.chat-name { flex: 1; font-size: 15.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { font-size: 11.5px; color: var(--text-soft); flex: none; }
.chat-row.has-unread .chat-time { color: var(--green); font-weight: 600; }
.chat-preview {
  flex: 1; min-width: 0; font-size: 13.5px; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
.chat-preview svg { width: 15px; height: 15px; flex: none; }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--green); color: #fff;
  font-size: 11.5px; font-weight: 600; display: grid; place-items: center;
}
.presence-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  flex: none; box-shadow: 0 0 0 2px var(--bg-panel);
}

.storage-bar {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  padding: 9px 14px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  font-size: 11.5px; color: var(--text-soft);
}
.storage-track { height: 4px; border-radius: 2px; background: var(--divider); overflow: hidden; }
.storage-fill { height: 100%; width: 0; background: var(--green); transition: width .4s ease; }
.storage-fill.warn { background: #f0a742; }
.storage-fill.full { background: var(--danger); }

/* ── conversation ──────────────────────────────────────────────── */
.convo {
  position: relative;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  background: var(--bg-convo);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.empty-state {
  height: 100%; display: grid; place-content: center; justify-items: center;
  gap: 10px; text-align: center; padding: 40px; color: var(--text-soft);
  border-bottom: 6px solid var(--green);
}
.empty-art { width: 90px; height: 90px; opacity: .5; margin-bottom: 10px; }
.empty-state h2 { margin: 0; font-size: 30px; font-weight: 300; color: var(--text); }
.empty-state p { margin: 0; font-size: 13.5px; max-width: 420px; }
.empty-lock { display: flex; align-items: center; gap: 6px; margin-top: 26px !important; font-size: 12.5px; }
.mini-lock { width: 14px; height: 14px; stroke-width: 2.2; }

.convo-inner {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.convo-head {
  flex: 0 0 var(--head-h);
  height: var(--head-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-head);
  border-bottom: 1px solid var(--divider);
  z-index: 10;
}
.convo-title { flex: 1; min-width: 0; display: grid; cursor: pointer; }
.convo-title strong { font-size: 15.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-title span { font-size: 12.5px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { display: none; }

/* subtle paper texture, like the WhatsApp chat backdrop */
.messages {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  touch-action: pan-y;
  padding: 16px min(6%, 62px) 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,.022) 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(0,0,0,.022) 1px, transparent 1px);
  background-size: 42px 42px, 58px 58px;
}

.messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar,
.account-list::-webkit-scrollbar {
  width: 6px;
}
.messages::-webkit-scrollbar-track,
.chat-list::-webkit-scrollbar-track,
.account-list::-webkit-scrollbar-track {
  background: transparent;
}
.messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb,
.account-list::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.18);
  border-radius: 3px;
}
:root[data-theme="dark"] .messages::-webkit-scrollbar-thumb,
:root[data-theme="dark"] .chat-list::-webkit-scrollbar-thumb,
:root[data-theme="dark"] .account-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
}
:root[data-theme="dark"] .messages { background-image: none; }

.notice {
  align-self: center; max-width: 560px; margin: 6px 0 14px;
  padding: 7px 13px; border-radius: 8px;
  background: #fdf4c7; color: #54656f;
  font-size: 12.3px; text-align: center; line-height: 1.5;
  display: flex; align-items: center; gap: 7px; justify-content: center;
}
:root[data-theme="dark"] .notice { background: #182229; color: #ffd279; }

.day-sep { align-self: center; margin: 16px 0 10px; }
.day-sep span {
  padding: 5px 12px; border-radius: 8px; font-size: 12.2px; font-weight: 500;
  background: var(--bubble-in); color: var(--text-soft); box-shadow: var(--shadow);
  text-transform: uppercase; letter-spacing: .3px;
}

.msg {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
  position: relative;
}
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }
.msg.grouped { margin-top: 2px; }
.msg:not(.grouped) { margin-top: 14px; }

.bubble {
  position: relative;
  max-width: min(65ch, 78%);
  padding: 7px 11px 8px;
  border-radius: var(--radius);
  background: var(--bubble-in);
  box-shadow: var(--shadow);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg:not(.grouped) .bubble::after {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
  background: inherit;
}
.msg.in:not(.grouped) .bubble { border-top-left-radius: 0; }
.msg.in:not(.grouped) .bubble::after {
  left: -8px; clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.msg.out:not(.grouped) .bubble { border-top-right-radius: 0; }
.msg.out:not(.grouped) .bubble::after {
  right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%);
}

.bubble .sender { display: block; font-size: 12.8px; font-weight: 600; color: var(--green); margin-bottom: 2px; }
.bubble .body { white-space: pre-wrap; font-size: 14.6px; }
.bubble .body a { color: var(--green-dark); }
:root[data-theme="dark"] .bubble .body a { color: var(--tick-blue); }

.bubble .meta {
  float: right; display: inline-flex; align-items: center; gap: 3px;
  margin: 6px -2px -4px 10px; font-size: 11px; color: var(--text-faint);
  user-select: none; white-space: nowrap;
}
.msg.out .bubble .meta { color: var(--meta-out); }
.ticks { width: 16px; height: 15px; stroke-width: 2.1; }
.ticks.read { color: var(--tick-blue); }
.bubble.failed { outline: 1px solid var(--danger); }

.bubble.media { padding: 3px 3px 8px; max-width: min(330px, 78%); }
.bubble.media .body { padding: 4px 6px 0; }
.bubble.media .meta { margin-right: 6px; }
.media-frame {
  position: relative; border-radius: 6px; overflow: hidden;
  background: rgba(0,0,0,.05); min-height: 60px;
  display: grid; place-items: center;
}
.media-frame img, .media-frame video { display: block; width: 100%; height: auto; max-height: 340px; object-fit: cover; }
.media-frame img { cursor: zoom-in; }
.media-loading { padding: 40px; color: var(--text-faint); font-size: 12.5px; }

.audio-msg { display: flex; align-items: center; gap: 10px; padding: 5px 4px; min-width: 210px; }
.audio-msg audio { width: 100%; height: 34px; }
.file-msg {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; margin: 2px; border-radius: 6px;
  background: rgba(0,0,0,.05); min-width: 210px;
}
:root[data-theme="dark"] .file-msg { background: rgba(255,255,255,.05); }
.file-msg .file-icon { width: 34px; height: 34px; flex: none; color: var(--text-soft); }
.file-msg .file-meta { min-width: 0; display: grid; }
.file-msg .file-name { font-size: 13.8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-msg .file-size { font-size: 11.5px; color: var(--text-soft); }

.typing-row { display: flex; margin: 4px 0 8px; }
.bubble.typing { display: flex; gap: 4px; padding: 12px 13px; }
.bubble.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
  animation: blink 1.3s infinite;
}
.bubble.typing span:nth-child(2) { animation-delay: .18s; }
.bubble.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.load-more { align-self: center; margin-bottom: 10px; }
.chip {
  padding: 6px 14px; border-radius: 14px; font-size: 12.5px;
  background: var(--bubble-in); color: var(--text-soft); box-shadow: var(--shadow);
}

/* ── composer ──────────────────────────────────────────────────── */
.composer-wrap {
  flex: 0 0 auto;
  background: var(--bg-head);
  padding-bottom: env(safe-area-inset-bottom);
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  border-top: 1px solid var(--divider);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.03);
}

.attach-preview {
  display: flex; gap: 9px; padding: 10px 14px 2px; overflow-x: auto;
  border-top: 1px solid var(--divider);
}
.attach-chip {
  position: relative; flex: none;
  width: 74px; height: 74px; border-radius: 8px; overflow: hidden;
  background: var(--bg-panel); display: grid; place-items: center;
  font-size: 10.5px; color: var(--text-soft); text-align: center; padding: 4px;
}
.attach-chip img, .attach-chip video { width: 100%; height: 100%; object-fit: cover; }
.attach-chip button {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.62); color: #fff; display: grid; place-items: center;
}
.attach-chip button svg { width: 13px; height: 13px; stroke-width: 2.6; }

.composer, .recording-bar {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 7px 12px 9px;
}
.recording-bar { align-items: center; gap: 12px; }
.input-shell { flex: 1; background: var(--bg-panel); border-radius: 9px; padding: 8px 12px; }
.input-shell textarea {
  width: 100%; max-height: 130px; border: 0; resize: none; background: none;
  font-size: 14.8px; line-height: 1.4; outline: none; display: block;
}
.send-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--green); color: #fff;
  transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--green-dark); }
.send-btn:active { transform: scale(.93); }
.send-btn svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }

.mic-btn.is-recording { color: var(--danger); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-hint { flex: 1; font-size: 13px; color: var(--text-soft); }
#rec-time { font-variant-numeric: tabular-nums; font-size: 14px; }

/* ── dialogs, lightbox, toast ──────────────────────────────────── */
.dlg { border: 0; border-radius: 14px; padding: 0; background: var(--bg-panel); color: var(--text); max-width: 92vw; width: 420px; }
.dlg::backdrop { background: rgba(11,20,26,.55); backdrop-filter: blur(2px); }
.dlg-body { padding: 24px; display: grid; gap: 13px; }
.dlg-body h3 { margin: 0; font-size: 18px; font-weight: 600; }
.dlg-sub { margin: 0; color: var(--text-soft); font-size: 13.2px; line-height: 1.5; }
.dlg menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 14px; }
.setting-row.column { flex-direction: column; align-items: stretch; gap: 6px; }
.setting-row select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--divider); background: var(--bg-app); }

.safety-number {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16.5px; letter-spacing: 1.4px; line-height: 2;
  text-align: center; padding: 18px 12px; border-radius: 10px;
  background: var(--bg-app); word-spacing: 6px;
}

.lightbox {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(11,20,26,.94);
  display: grid; place-items: center; padding: 30px;
}
.lightbox-content img, .lightbox-content video { max-width: 92vw; max-height: 88vh; border-radius: 6px; }
.lightbox-close {
  position: absolute; top: 18px; right: 20px;
  width: 42px; height: 42px; border-radius: 50%; color: #fff;
  display: grid; place-items: center; background: rgba(255,255,255,.12);
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 120; padding: 11px 20px; border-radius: 22px;
  background: #202c33; color: #e9edef; font-size: 13.5px;
  box-shadow: 0 4px 18px rgba(0,0,0,.3); max-width: 90vw; text-align: center;
  animation: rise .22s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ── mobile ────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .convo { display: none; }
  .app.show-convo .sidebar { display: none; }
  .app.show-convo .convo { display: flex; flex-direction: column; height: 100%; }
  .back-btn { display: grid; }
  .messages { padding-left: 10px; padding-right: 10px; }
  .bubble { max-width: 85%; }
  .empty-state { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── account key entry ─────────────────────────────────────────── */
#account-id {
  width: 100%; padding: 11px 13px; resize: vertical;
  border: 1px solid var(--divider); border-radius: 8px;
  background: var(--bg-app); color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.5; word-break: break-all;
}
#account-id:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent);
}

.known-row { display: flex; align-items: center; gap: 11px; }
.known-meta { display: grid; min-width: 0; }
.known-meta strong { font-size: 15px; }
.known-meta span { font-size: 12px; color: var(--text-soft); }
.link-btn {
  margin-top: 8px; padding: 0; font-size: 12.5px;
  color: var(--green); text-decoration: underline; text-underline-offset: 2px;
}

/* ── directory ─────────────────────────────────────────────────── */
.people-list, .account-list {
  max-height: min(46vh, 380px); overflow-y: auto;
  border: 1px solid var(--divider); border-radius: 10px;
}
.people-list:empty::after, .account-list:empty::after {
  content: "Nobody here yet."; display: block;
  padding: 22px; text-align: center; color: var(--text-faint); font-size: 13px;
}
.person-row, .account-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 13px; border-bottom: 1px solid var(--divider);
}
.person-row:last-child, .account-row:last-child { border-bottom: 0; }
.person-row { cursor: pointer; transition: background .12s; }
.person-row:hover { background: var(--hover); }
.person-meta, .account-meta { flex: 1; min-width: 0; display: grid; }
.person-meta strong, .account-meta strong { font-size: 14.5px; font-weight: 500; }
.person-meta span, .account-meta span { font-size: 12px; color: var(--text-soft); }

.pill {
  flex: none; padding: 2px 9px; border-radius: 11px;
  font-size: 11px; font-weight: 600; letter-spacing: .2px;
  background: var(--active); color: var(--text-soft);
}
.pill.active    { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.pill.pending   { background: color-mix(in srgb, #f0a742 22%, transparent); color: #c07d19; }
.pill.suspended { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.pill.owner     { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
:root[data-theme="dark"] .pill.pending { color: #f0a742; }

.account-actions { display: flex; gap: 4px; flex: none; }
.account-actions .icon-btn { width: 34px; height: 34px; }
.account-actions .icon-btn svg { width: 18px; height: 18px; }

/* ── admin + credentials ───────────────────────────────────────── */
.dlg-wide { width: 620px; }
.create-row { display: flex; gap: 8px; }
.create-row input {
  flex: 1; padding: 10px 13px;
  border: 1px solid var(--divider); border-radius: 8px;
  background: var(--bg-app); color: var(--text);
}
.create-row input:focus { outline: none; border-color: var(--green); }
.create-row .btn-primary { flex: none; white-space: nowrap; }

.warn-text { color: #c07d19; font-weight: 500; }
:root[data-theme="dark"] .warn-text { color: #f0a742; }

.cred-grid { display: grid; gap: 13px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.cred-block { display: grid; gap: 6px; }
.cred-block.center { justify-items: center; }
.cred-label { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.cred-label small { font-weight: 400; color: var(--text-faint); }
.cred-value {
  padding: 10px 12px; border-radius: 8px;
  background: var(--bg-app); border: 1px solid var(--divider);
  font-size: 14px; word-break: break-all;
}
.cred-value.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.cred-value.small { font-size: 11.5px; }
.cred-value.tiny  { font-size: 10.5px; line-height: 1.5; }
.cred-value.scroll { max-height: 92px; overflow-y: auto; }
.copy-btn { justify-self: start; padding: 6px 12px; font-size: 12.5px; border: 1px solid var(--divider); }

.qr-box { padding: 12px; background: #fff; border-radius: 10px; line-height: 0; }
.qr-box img { width: 210px; height: 210px; image-rendering: pixelated; }

@media (max-width: 700px) {
  .dlg-wide { width: 92vw; }
  .create-row { flex-direction: column; }
  .create-row .btn-primary { width: 100%; }
}


/* ── reply preview bar in composer ─────────────────────────────── */
.reply-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; margin: 6px 12px 2px;
  background: var(--bg-panel); border-radius: 8px;
  border-left: 4px solid var(--green);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  animation: slideUp .15s ease-out;
}
.reply-preview-content { flex: 1; min-width: 0; display: grid; gap: 2px; }
.reply-preview-content strong { font-size: 12.8px; color: var(--green); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview-content span { font-size: 12px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview .close-btn { flex: none; width: 28px; height: 28px; color: var(--text-soft); }

/* ── quote box inside bubble ────────────────────────────────────── */
.quote-box {
  display: grid; gap: 2px;
  padding: 5px 8px 6px; margin: 2px 2px 5px;
  border-radius: 6px; border-left: 3.5px solid var(--green);
  background: rgba(0,0,0,.04); cursor: pointer;
  transition: background .12s, opacity .12s;
  user-select: none;
}
:root[data-theme="dark"] .quote-box { background: rgba(255,255,255,.06); }
.msg.out .quote-box { border-left-color: var(--green-dark); }
.quote-box:hover { background: rgba(0,0,0,.08); }
:root[data-theme="dark"] .quote-box:hover { background: rgba(255,255,255,.1); }
.quote-sender { font-size: 12px; font-weight: 600; color: var(--green); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.out .quote-sender { color: var(--green-dark); }
:root[data-theme="dark"] .msg.out .quote-sender { color: var(--green); }
.quote-text { font-size: 12px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── message hover actions ──────────────────────────────────────── */
.msg-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-panel);
  border-radius: 18px;
  box-shadow: 0 1px 5px rgba(0,0,0,.12);
  border: 1px solid var(--divider);
  padding: 2px 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
  transform: scale(0.92);
  flex-shrink: 0;
  z-index: 15;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg.has-open-picker .msg-actions {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.msg-act-btn {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-soft); transition: background .12s, color .12s;
  padding: 0;
}
.msg-act-btn:hover { background: var(--hover); color: var(--text); }
.msg-act-btn svg { width: 15px; height: 15px; }

/* ── floating reaction picker ────────────────────────────────────── */
.reaction-picker {
  position: absolute; bottom: 100%; margin-bottom: 6px;
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 24px;
  background: var(--bg-panel); box-shadow: 0 4px 18px rgba(0,0,0,.22);
  border: 1px solid var(--divider);
  z-index: 60; animation: popIn .15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.msg.in .reaction-picker { left: 0; }
.msg.out .reaction-picker { right: 0; }
.emoji-btn {
  width: 32px; height: 32px; font-size: 19px; line-height: 1;
  display: grid; place-items: center; border-radius: 50%;
  transition: transform .12s, background .12s;
  cursor: pointer;
}
.emoji-btn:hover { transform: scale(1.28); background: var(--hover); }

/* ── reaction badges on bubbles ──────────────────────────────────── */
.reaction-badges {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px; margin-bottom: -2px;
}
.reaction-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 12px;
  background: var(--bg-app); border: 1px solid var(--divider);
  font-size: 11.5px; cursor: pointer; user-select: none;
  transition: transform .1s, background .1s, border-color .1s;
}
.reaction-pill:hover { transform: scale(1.08); background: var(--hover); }
.reaction-pill.mine {
  background: color-mix(in srgb, var(--green) 16%, var(--bg-app));
  border-color: var(--green);
}
.reaction-pill .emoji { font-size: 13.5px; line-height: 1; }
.reaction-pill .count { font-size: 11px; font-weight: 500; color: var(--text-soft); }

/* ── quote jump pulse ────────────────────────────────────────────── */
.highlight-pulse {
  animation: pulseFlash 1.4s ease-out;
}
@keyframes pulseFlash {
  0% { transform: scale(1.02); filter: brightness(1.22); }
  50% { transform: scale(1.02); filter: brightness(1.22); }
  100% { transform: scale(1); filter: brightness(1); }
}
@keyframes slideUp {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}


/* ── disappearing messages retention dialog ───────────────────── */
.retention-options {
  display: grid; gap: 8px; margin: 14px 0 20px;
}
.radio-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--divider);
  background: var(--bg-app); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.radio-card:hover {
  border-color: var(--green); background: var(--hover);
}
.radio-card input[type="radio"] {
  margin-top: 3px; accent-color: var(--green); cursor: pointer;
}
.radio-meta {
  display: grid; gap: 2px;
}
.radio-meta strong {
  font-size: 13.5px; display: flex; align-items: center; gap: 6px;
}
.radio-meta span {
  font-size: 12px; color: var(--text-soft);
}
.badge-tag {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  padding: 1px 6px; border-radius: 4px;
  background: color-mix(in srgb, var(--green) 18%, var(--bg-app));
  color: var(--green-dark);
}
:root[data-theme="dark"] .badge-tag {
  color: var(--green);
}
