/* ============================================================
   Ripple chat app. Fusion of Discord (rail), WhatsApp (chat),
   Instagram (stories). Dark default + light theme.
   Radius system: cards 16px, rows 14px, inputs pill, elements 10-12px.
   ============================================================ */

/* ---------- Tokens: dark ---------- */
:root {
  color-scheme: dark;
  --bg: #0e0e13;
  --rail: #12131a;
  --rail-hover: #1b1c26;
  --rail-active-bg: #ffffff;
  --rail-active-icon: #5865f2;
  --pane: #12131a;
  --chat-bg: #0e0e13;
  --surface: #1b1b25;
  --surface-2: #242530;
  --surface-3: #2d2e3a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f4f6;
  --text-2: #a2a6b4;
  --text-3: #8b90a0; /* was #6d7180 — 3.99:1 on bg, below AA; 8b90a0 = 6.07:1 */
  --dot: rgba(255, 255, 255, 0.07);
  --accent: #5865f2;
  --accent-hover: #4f5bd5;
  --accent-soft: rgba(88, 101, 242, 0.16);
  --accent-text: #8b96ff;
  --accent-ring: #8b96ff; /* focus rings: brighter than --accent on dark bg */
  --danger: #f87171;
  --online: #23c55a;
  --out-from: #24ab5f; /* was #2bbd6e — white text 2.45:1 at the light end */
  --out-to: #168a4a;   /* deepened the gradient for AA on bubble text */
  --in-bubble: #1b1b25;
  --in-text: #eef0f4;
  --tick: rgba(255, 255, 255, 0.55);
  --tick-read: #4fc3f7;
  --ring-ig: linear-gradient(45deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5);
  --story-badge: var(--accent);
  --shadow-pop: 0 12px 34px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
  --bubble-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  --scroll-thumb: rgba(255, 255, 255, 0.16);
  --scroll-thumb-hover: rgba(255, 255, 255, 0.3);

  --font-display: "Space Grotesk", "Manrope", system-ui, sans-serif;
  --font-body: "Manrope", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ---------- Tokens: light ---------- */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #edeff2;
  --rail: #1b1c26;
  --rail-active-bg: #f4f4f6;
  --rail-active-icon: #4f5bd5;
  --pane: #f4f5f7;
  --chat-bg: #efe9e0;
  --surface: #ffffff;
  --surface-2: #e9e7df;
  --surface-3: #e0ded4;
  --border: rgba(9, 9, 11, 0.09);
  --border-strong: rgba(9, 9, 11, 0.18);
  --text: #15161b;
  --text-2: #5c5d68;
  --text-3: #63646f; /* was #90919c — 2.8:1 on pane/white, below AA; 63646f = 5.2:1 */
  --dot: rgba(9, 9, 11, 0.09);
  --accent: #5865f2;
  --accent-hover: #4f5bd5;
  --accent-soft: rgba(88, 101, 242, 0.13);
  --accent-text: #3d4acb;
  --accent-ring: #3d4acb; /* focus rings: deeper blurple reads on light bg */
  --danger: #c73b3b;
  --online: #1fa04e;
  --out-from: #24ab5f; /* same deepened gradient as dark */
  --out-to: #168a4a;
  --in-bubble: #ffffff;
  --in-text: #212126;
  --tick: rgba(0, 0, 0, 0.45);
  --tick-read: #039be5;
  --shadow-pop: 0 14px 40px rgba(9, 9, 11, 0.22);
  --shadow-card: 0 8px 28px rgba(9, 9, 11, 0.14);
  --bubble-shadow: 0 1px 1px rgba(9, 9, 11, 0.08);
  --scroll-thumb: rgba(9, 9, 11, 0.2);
  --scroll-thumb-hover: rgba(9, 9, 11, 0.35);
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

h1,
h2,
h3,
p,
figure,
blockquote,
ul,
ol {
  margin: 0;
}

ul,
ol {
  list-style: none;
  padding: 0;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

input,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

input,
textarea {
  caret-color: var(--accent);
}

.text-clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ============================================================
   App frame
   ============================================================ */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================================
   Rail (Discord)
   ============================================================ */
.rail {
  width: 76px;
  flex-shrink: 0;
  background: var(--rail);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 14px;
  border-right: 1px solid var(--border);
}

.rail-top,
.rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.rail-sentinel {
}

.rail-brand {
  width: 46px;
  height: 46px;
  border-radius: 26px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-radius 0.2s ease;
}

.rail-brand:hover {
  border-radius: 16px;
}

.rail-sep {
  width: 28px;
  height: 2px;
  background: var(--border-strong);
  border-radius: 2px;
}

.rail-item {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--rail-hover);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-radius 0.2s ease, background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.rail-item svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.rail-item:hover {
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}

.rail-item:active {
  transform: scale(0.95);
}

.rail-item.is-active {
  background: var(--rail-active-bg);
  color: var(--rail-active-icon);
  border-radius: 15px;
  box-shadow: 0 2px 10px rgba(88, 101, 242, 0.45);
}

.rail-item.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  width: 4px;
  height: 22px;
  margin-top: -11px;
  background: var(--accent);
  border-radius: 4px;
}

.rail-sm {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--rail-hover);
}

.rail-me {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--rail-hover);
  color: var(--accent-text);
  transition: border-radius 0.2s ease;
}

.rail-me:hover {
  border-radius: 15px;
}

.rail-item.has-dot::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--online);
  border: 3px solid var(--rail);
}

.theme-toggle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease, border-radius 0.2s ease;
}

.theme-toggle:hover {
  background: var(--rail-hover);
  color: var(--text);
  border-radius: 15px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

html[data-theme="dark"] .icon-sun {
  display: none;
}

html[data-theme="light"] .icon-moon {
  display: none;
}

/* ============================================================
   Sidebar (WhatsApp + Instagram)
   ============================================================ */
.sidebar {
  width: 348px;
  flex-shrink: 0;
  background: var(--pane);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 10px;
}

.side-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.side-head-actions {
  display: flex;
  gap: 4px;
}

.side-head-actions button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.side-head-actions button svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.side-head-actions button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 14px 12px;
  padding: 0 14px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--pill, 999px);
  color: var(--text-3);
}

.search svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  fill: none;
  flex-shrink: 0;
}

.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: 0.88rem;
  color: var(--text);
}

.search input::placeholder {
  color: var(--text-3);
}

.stories {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 6px 14px 14px;
  scrollbar-width: none;
}

.stories::-webkit-scrollbar {
  display: none;
}

.story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  width: 62px;
}

.story-item .ring-box {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.story-item .ring-inner {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: var(--pane);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
}

.story-item.has-story .ring-box {
  background: var(--ring-ig);
  padding: 2px;
}

.story-item.seen .ring-box {
  background: var(--surface-3);
}

.story-item.you .ring-box {
  background: var(--accent);
}

.story-item.you.has-story .ring-box {
  background: var(--ring-ig);
}

.story-item.you .ring-inner {
  position: relative;
}

.story-item.you .add-badge {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--pane);
}

.story-item .story-name {
  font-size: 0.66rem;
  color: var(--text-2);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-tabs {
  display: flex;
  gap: 6px;
  margin: 0 14px 10px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.side-tabs button {
  flex: 1;
  padding: 7px 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-3);
  border-radius: 999px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.side-tabs button.is-active {
  color: var(--text);
  background: var(--surface-2);
}

.convo-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 12px;
}

.convo-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.convo-row:hover {
  background: var(--surface);
}

.convo-row.is-active {
  background: var(--accent-soft);
}

.convo-row .row-bar {
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 3px;
  background: transparent;
}

.convo-row.is-active .row-bar {
  background: var(--accent);
}

.convo-avatar {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
  position: relative;
}

.convo-avatar.group {
  border-radius: 30% 44% 30% 44%;
}

.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--online);
  flex-shrink: 0;
}

.convo-avatar .status-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  border: 2.5px solid var(--pane);
}

.convo-avatar.has-story .status-dot {
  right: 2px;
  bottom: 2px;
}

.convo-avatar.has-story {
  padding: 2px;
  border: 2px solid transparent;
  background:
    linear-gradient(var(--pane) 0 0) padding-box,
    var(--ring-ig) border-box;
}

.convo-row-main {
  flex: 1;
  min-width: 0;
}

.convo-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.convo-name {
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-time {
  font-size: 0.7rem;
  color: var(--text-3);
  flex-shrink: 0;
}

.convo-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.convo-preview {
  font-size: 0.8rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.convo-preview .muted-ic {
  width: 13px;
  height: 13px;
  color: var(--text-3);
  flex-shrink: 0;
}

.convo-preview .muted-ic svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 1.7;
}

.convo-row .unread-badge {
  background: var(--online);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

/* Muted conversations get a neutral gray counter (WhatsApp). */
.convo-row.muted .unread-badge {
  background: var(--text-3);
  box-shadow: none;
}

.convo-row.unread .convo-name,
.convo-row.unread .convo-preview {
  color: var(--text);
  font-weight: 700;
}

/* ============================================================
   Chat pane (WhatsApp)
   ============================================================ */
.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  position: relative;
}

.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px);
  background-size: 22px 22px;
  opacity: 0.45;
}

.chat > * {
  position: relative;
  z-index: 1;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  min-height: 62px;
  background: var(--pane);
  border-bottom: 1px solid var(--border);
}

.back-btn {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--text-2);
  align-items: center;
  justify-content: center;
}

.back-btn svg {
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.back-btn:hover {
  background: var(--surface-2);
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-peer .ring {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
}

.chat-peer .ring.has-story {
  padding: 2px;
  cursor: pointer;
}

.chat-peer .ring .ring-inner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
}

.chat-peer-meta {
  min-width: 0;
}

.chat-peer-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-status {
  font-size: 0.74rem;
  color: var(--online);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-status.off {
  color: var(--text-3);
}

.chat-actions {
  display: flex;
  gap: 2px;
}

.chat-actions button,
.ci-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.chat-actions button:hover,
.ci-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: scale(1.06);
}

.chat-actions button:active,
.ci-btn:active {
  transform: scale(0.94);
}

.chat-actions svg,
.ci-btn svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.chat-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 0.7rem;
  color: var(--text-3);
  background: var(--pane);
  border-bottom: 1px solid var(--border);
}

.chat-note svg {
  stroke: currentColor;
  stroke-width: 1.7;
  flex-shrink: 0;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 10px;
  display: flex;
  flex-direction: column;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
}

.day-sep {
  align-self: center;
  margin: 10px 0 14px;
  padding: 5px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* ---------- Messages ---------- */
.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  position: relative; /* containing block for the floating action bar */
}

.msg-avatar {
  display: none;
}

.msg-body {
  display: flex;
  flex-direction: column;
  max-width: min(76%, 620px);
}

.msg-in .msg-body {
  align-items: flex-start;
}

.msg-me .msg-body {
  align-items: flex-end;
  margin-left: auto;
}

.msg-attrib {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 4px 2px;
}

.msg-author {
  font-size: 0.78rem;
  font-weight: 700;
}

.msg-dt {
  font-size: 0.66rem;
  color: var(--text-3);
}

.bubble {
  position: relative;
  padding: 8px 12px 9px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: var(--bubble-shadow);
}

.bubble b {
  font-weight: 700;
}

.msg-in .bubble {
  background: var(--in-bubble);
  color: var(--in-text);
  border-top-left-radius: 6px;
}

.msg-me .bubble {
  background: linear-gradient(180deg, var(--out-from), var(--out-to));
  color: #fff;
  border-top-right-radius: 6px;
}

.msg-grouped-in {
  margin-top: 2px;
}

.bubble-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}

.file-ic {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-text, var(--accent));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-ic svg {
  stroke: currentColor;
  stroke-width: 1.7;
  fill: none;
}

.file-meta {
  min-width: 0;
}

.file-name {
  font-weight: 700;
  font-size: 0.84rem;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 0.7rem;
  opacity: 0.72;
}

.bubble-voice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 190px;
  padding: 9px 14px;
}

.play-ic {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.play-ic svg {
  fill: currentColor;
  stroke: none;
}

.waveform {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 22px;
  flex-shrink: 0;
}

.waveform i {
  width: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.85;
}

.voice-dur {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  opacity: 0.8;
  margin-left: auto;
}

/* ---------- Read receipt ticks ---------- */
.ticks {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  color: var(--tick);
  margin-top: 2px;
  margin-right: 6px;
  align-self: flex-end;
}

.ticks.read {
  color: var(--tick-read);
}

.ticks .tick {
  font-family: var(--font-body);
  font-weight: 700;
}

/* ticks rendered inside a bubble foot (time row) */
.bubble-foot .ticks {
  margin: 0;
  font-size: 0.62rem;
}

.msg-me .bubble-foot .ticks.read {
  color: #8ef0c0;
}

/* ---------- Reactions ---------- */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.r-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.r-chip:hover {
  transform: translateY(-1px);
}

.r-chip.mine {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.r-chip .r-count {
  color: var(--text-2);
  font-weight: 700;
}

.r-chip.mine .r-count {
  color: var(--accent-text);
}

/* ---------- Typing indicator ---------- */
.typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  background: var(--in-bubble);
  padding: 12px 16px;
  border-radius: 16px;
  border-top-left-radius: 6px;
  box-shadow: var(--bubble-shadow);
}

.tdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: tdot 1.1s infinite ease-in-out;
}

.tdot:nth-child(2) {
  animation-delay: 0.15s;
}

.tdot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes tdot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.typing-label {
  font-size: 0.74rem;
  color: var(--text-3);
}

/* ---------- Input ---------- */
.chat-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  background: var(--pane);
  border-top: 1px solid var(--border);
}

.ci-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 6px 4px 10px;
  transition: border-color 0.15s ease;
}

.input-wrap:focus-within {
  border-color: var(--accent);
}

.input-wrap textarea {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--text);
  padding: 8px 2px;
  height: 40px;
  min-height: 40px;
  max-height: 120px;
}

.input-wrap textarea::placeholder {
  color: var(--text-3);
}

.send-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.4);
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.send-btn svg {
  fill: currentColor;
  stroke: none;
}

.send-btn:hover {
  transform: scale(1.07);
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.5);
}

.send-btn:active {
  transform: scale(0.96);
}

/* ============================================================
   Story modal (Instagram)
   ============================================================ */
.story-modal {
  position: fixed;
  inset: 0;
  z-index: 310;
  background: rgba(6, 6, 12, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-frame {
  position: relative;
  width: min(430px, 94vw);
  height: min(540px, 94dvh);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.story-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  padding: 14px 16px;
}

.sp-bar {
  display: block;
  height: 3px;
  width: 100%;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.35);
  overflow: hidden;
  position: relative;
}

.sp-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  animation: storybar 3s linear forwards;
}

@keyframes storybar {
  from {
    width: 0;
  }
  to {
    width: 100%;
  }
}

.story-slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 30% 26px 70px;
  background-size: cover;
  background-position: center;
}

.story-slide::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 30%, transparent 55%, rgba(0, 0, 0, 0.55));
}

.story-caption {
  position: relative;
  z-index: 2;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.35;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  max-width: 320px;
}

.story-head {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 26px 56px 12px 18px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent);
}

.story-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.story-head .story-name {
  color: #fff;
  font-weight: 700;
  font-size: 0.86rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.story-head .story-time {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.74rem;
  flex-shrink: 0;
}

.story-close {
  position: absolute;
  top: 18px;
  right: 14px;
  z-index: 8;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.16);
  transition: background-color 0.15s ease;
}

.story-close svg {
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

.story-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.story-tap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 4;
  cursor: pointer;
}

.story-prev {
  left: 0;
}

.story-next {
  right: 0;
}

/* ============================================================
   New chat popover
   ============================================================ */
.newchat-pop {
  position: fixed;
  z-index: 300;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(520px, calc(100dvh - 16px));
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
}

.newchat-pop[hidden] {
  display: none;
}

.ncp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
  transition: background-color 0.12s ease;
}

.ncp-item:hover {
  background: var(--surface-2);
}

.ncp-av {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.68rem;
}

.ncp-name {
  font-weight: 600;
  font-size: 0.88rem;
}

/* ============================================================
   Reaction popover
   ============================================================ */
.reaction-pop {
  position: fixed;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-pop);
}

.reaction-pop button {
  padding: 4px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.reaction-pop button:hover {
  transform: scale(1.25);
  background: var(--surface-2);
}

/* ---------- Message "more" popover (shared, JS-positioned) ---------- */
.msg-more-pop {
  position: fixed;
  z-index: 300;
  min-width: 170px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
}

.msg-more-pop button {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-2);
  text-align: left;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.msg-more-pop button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.msg-more-pop button.danger {
  color: var(--danger);
}

.msg-more-pop button.danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

/* ============================================================
   Light theme specific patches
   ============================================================ */
html[data-theme="light"] .chat::before {
  opacity: 0.5;
}

html[data-theme="light"] .msg-me .bubble {
  color: #fff;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  .sidebar {
    width: 320px;
  }
}

@media (max-width: 860px) {
  .app {
    height: 100dvh;
  }

  .chat-actions button:nth-of-type(3),
  .chat-actions button:nth-of-type(4) {
    display: none;
  }
}

@media (max-width: 720px) {
  .rail {
    display: none;
  }

  .sidebar {
    width: 100%;
    border-right: none;
  }

  .app.in-chat .sidebar {
    display: none;
  }

  .chat {
    display: none;
    width: 100%;
  }

  .app.in-chat .chat {
    display: flex;
  }

  .back-btn {
    display: inline-flex;
  }

  .chat-head {
    min-height: 54px;
  }

  .chat-scroll {
    padding: 10px 12px;
  }

  .msg-body {
    max-width: 84%;
  }
}

@media (max-width: 480px) {
  .story-frame {
    border-radius: 0;
    width: 100vw;
    height: 100dvh;
  }

  .reaction-pop {
    max-width: 92vw;
    flex-wrap: wrap;
  }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
/* ============================================================
   v2: message polish (tails, in-bubble time, action bar)
   ============================================================ */
.msg-in .bubble::before,
.msg-me .bubble::before {
  content: "";
  position: absolute;
  top: 2px;
  width: 11px;
  height: 11px;
  background: inherit;
}

.msg-in .bubble::before {
  left: -5px;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.msg-me .bubble::before {
  right: -5px;
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}

.bubble-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 3px;
  font-size: 0.64rem;
  opacity: 0.78;
  line-height: 1;
  white-space: nowrap;
}

.msg-me .bubble-foot {
  color: rgba(255, 255, 255, 0.92);
}

.msg-in .bubble-foot {
  color: var(--text-3);
}

.quote-ref {
  display: block;
  margin-bottom: 6px;
  padding: 5px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: rgba(127, 127, 127, 0.12);
  font-size: 0.8em;
  line-height: 1.4;
  max-width: 260px;
  color: inherit;
  overflow: hidden;
}

.quote-ref .quote-name {
  display: block;
  font-weight: 700;
  font-size: 0.9em;
  color: var(--accent-text, var(--accent));
  margin-bottom: 1px;
}

.msg-me .quote-ref .quote-name {
  color: rgba(255, 255, 255, 0.95);
}

.quote-ref .quote-txt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0.9;
}

.bubble-photo {
  padding: 0;
  overflow: hidden;
  width: 230px;
}

.photo-img {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.photo-cap {
  padding: 7px 11px;
  font-size: 0.74rem;
  color: inherit;
  opacity: 0.9;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.msg-near {
  margin-top: 1px;
}

/* ---------- Shared floating message action bar ----------
   #msg-bar is ONE body-level element, positioned by JS (openMsgBar) with
   fixed coordinates relative to the .chat-scroll rect. Visibility is the
   hidden attribute only — never display:none (that would also make its
   getBoundingClientRect() return a zero-size box). */
.msg-bar {
  position: fixed;
  z-index: 280; /* above every bubble (.chat > * is z-index 1), below pops */
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-pop);
}

.msg-bar button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: color 0.12s ease, background-color 0.12s ease;
}

.msg-bar button:hover {
  color: var(--text);
  background: var(--surface-2);
}

.msg-bar svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* voice playback */
.bubble-voice .play-ic {
  transition: background-color 0.15s ease, transform 0.15s ease;
  cursor: pointer;
}

.bubble-voice .play-ic:hover {
  transform: scale(1.08);
}

.bubble-voice .play-ic.is-playing svg {
  content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%235865f2'%3E%3Crect x='6.5' y='4' width='3.4' height='16' rx='1.6'/%3E%3Crect x='14.1' y='4' width='3.4' height='16' rx='1.6'/%3E%3C/svg%3E");
}

.waveform {
  position: relative;
  overflow: hidden;
}

.waveform .wf-progress {
  position: absolute;
  inset: 0;
  width: 0;
  background: var(--accent-soft);
  transition: width 0.1s linear;
  pointer-events: none;
}

.bubble-voice.playing .waveform i {
  animation: wfplay 0.9s ease-in-out infinite alternate;
}

@keyframes wfplay {
  from {
    transform: scaleY(1);
  }
  to {
    transform: scaleY(0.45);
  }
}

/* system messages */
.msg-sys {
  align-self: center;
  margin: 10px 0 4px;
  padding: 5px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* ============================================================
   v2: composer reply chip
   ============================================================ */
.composer-reply {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}

.cr-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.cr-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-text, var(--accent));
}

.cr-text {
  font-size: 0.8rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cr-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
}

.cr-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.cr-close svg {
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ============================================================
   v2: emoji picker + menu popovers
   ============================================================ */
.emoji-pop {
  position: fixed;
  z-index: 300;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
}

.emoji-pop button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.15rem;
  line-height: 1;
  transition: transform 0.1s ease, background-color 0.1s ease;
}

.emoji-pop button:hover {
  transform: scale(1.15);
  background: var(--surface-2);
}

.menu-pop {
  position: fixed;
  z-index: 300;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
}

.menu-pop[hidden] {
  display: none;
}

.menu-pop button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-2);
  text-align: left;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.menu-pop button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.menu-pop button.danger {
  color: var(--danger);
}

.menu-pop button.danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.menu-pop svg {
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}

/* ============================================================
   v2: call modal
   ============================================================ */
.call-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(6, 6, 12, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-modal[hidden] {
  display: none;
}

.call-card {
  width: min(340px, 92vw);
  padding: 40px 24px 28px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  text-align: center;
}

.call-avatar-wrap {
  position: relative;
  width: 108px;
  height: 108px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: callpulse 1.8s ease-out infinite;
}

.call-pulse-2 {
  animation-delay: 0.9s;
}

@keyframes callpulse {
  0% {
    transform: scale(0.8);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

.call-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.call-name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.call-status {
  font-size: 0.8rem;
  color: var(--text-3);
  margin-bottom: 6px;
}

.call-timer {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--text-2);
  margin-bottom: 6px;
}

.call-timer[hidden] {
  display: none;
}

.call-btns {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 24px;
}

.call-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.call-btn:hover {
  transform: scale(1.07);
}

.call-btn:active {
  transform: scale(0.94);
}

.call-btn svg {
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  fill: none;
}

.call-btn-danger {
  background: #ef4444;
}

.call-btn-accept {
  background: #22c55e;
}

.call-btn-ghost {
  background: var(--surface-3);
}

/* ============================================================
   v2: connecting splash
   ============================================================ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  transition: opacity 0.45s ease, visibility 0.45s ease, background-color 0.25s ease;
}

.splash.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-logo {
  animation: splashpop 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes splashpop {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.splash-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

/* ============================================================
   v3: live app (login, modals, forms, bits)
   ============================================================ */
[hidden] {
  display: none !important;
}

/* ---------- login ---------- */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 70% 55% at 72% 8%, var(--accent-soft), transparent 62%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 36px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 22px;
}

.login-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 6px;
}

.login-sub {
  color: var(--text-2);
  font-size: 0.92rem;
  margin: 0 0 22px;
}

.login-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 22px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--pill, 999px);
}

.login-tab {
  flex: 1;
  padding: 8px 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-3);
  border-radius: var(--pill, 999px);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.login-tab.is-active {
  color: var(--text);
  background: var(--surface-3);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lbl {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-2);
  margin-top: 6px;
}

.inp {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
}

.inp:focus {
  border-color: var(--accent);
}

.inp::placeholder {
  color: var(--text-3);
}

.form-err {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--danger);
  margin: 6px 0 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--pill, 999px);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(88, 101, 242, 0.35);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.25);
}

.btn-primary:disabled {
  opacity: 0.6;
  transform: none;
  cursor: default;
}

.btn-block {
  width: 100%;
}

/* Keep action-row buttons aligned: .btn-primary's base margin is for stacked forms. */
.modal-actions .btn-primary {
  margin-top: 0;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--pill, 999px);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}

.btn-ghost:active {
  transform: translateY(0) scale(0.97);
}

/* ---------- empty list ---------- */
.list-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 20px;
  text-align: center;
  color: var(--text-3);
}

.list-empty p {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-2);
}

.list-empty span {
  font-size: 0.82rem;
}

/* ---------- msg avatar hidden (grouping spacer) ---------- */
.msg-avatar-hidden {
  visibility: hidden;
}

/* ---------- typing dots wrap ---------- */
.tdot-wrap {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

/* ---------- modals ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 6, 12, 0.72);
}

.modal {
  width: min(440px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  padding: 26px 24px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 16px;
}

.modal-sub {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-2);
  margin: 16px 0 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.member-item:hover {
  background: var(--surface-2);
}

.member-item input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.story-inp {
  resize: none;
  min-height: 84px;
  line-height: 1.5;
}

.bg-swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.is-selected {
  border-color: var(--text);
  transform: scale(1.1);
}

/* ---------- story progress (single bar) ---------- */
/* Canonical .story-progress/.sp-bar live in the Story modal section above. */

/* ---------- me menu ---------- */
#me-menu {
  position: fixed;
  right: 12px;
  bottom: 12px;
}

.rail-me .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
}

/* ============================================================
   v4: polish — motion + visual refinement (2026-08-03)
   Every animation added here runs on transform/opacity (or a
   one-shot static state like focus glow); the global reduced-
   motion block above kills all of them.
   ============================================================ */

/* ---------- theme switch crossfade ----------
   Progressive enhancement: main.js wraps the data-theme swap in
   document.startViewTransition() when the API exists (fallback:
   plain swap). The pseudo-elements below only exist in browsers
   with View Transitions support, so the rule is a no-op elsewhere.
   Reduced-motion users skip the transition in JS. */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.32s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Key containers crossfade colors on theme swap when View
   Transitions is unavailable (body already transitions). */
.rail,
.sidebar,
.chat,
.chat-head,
.chat-note,
.chat-input,
.search,
.side-tabs,
.login-card,
.modal,
.call-card {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* ---------- message entry pop (class added by JS on live append only) ---------- */
@keyframes msg-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-pop {
  animation: msg-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- popover / menu entrances ----------
   Pops are shown by removing the hidden attribute (display:none ->
   block/flex), which restarts their CSS animation on each open. */
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.newchat-pop,
.reaction-pop,
.msg-more-pop,
.emoji-pop,
.menu-pop {
  animation: pop-in 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

/* transform-origin approximated toward each pop's anchor */
.newchat-pop { transform-origin: 18% 0; }
.reaction-pop { transform-origin: 50% 100%; }
.msg-more-pop { transform-origin: 80% 0; }
.emoji-pop { transform-origin: 50% 100%; }
#more-pop { transform-origin: 85% 0; }
#me-menu { transform-origin: 85% 100%; }

/* ---------- modal entrances (close is instant: hidden=true) ---------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-back { animation: fade-in 0.18s ease; }
.modal-back .modal { animation: modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
.call-modal { animation: fade-in 0.18s ease; }
.call-card { animation: modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
.story-modal { animation: fade-in 0.2s ease; }
.story-frame { animation: modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1); }

/* ---------- story slide + caption entrances ----------
   JS re-triggers these classes (remove -> reflow -> add) in
   showStorySlide so every slide animates, not just the first. */
@keyframes story-in {
  from {
    opacity: 0.2;
    transform: scale(1.03);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes story-caption {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.story-slide.story-in { animation: story-in 0.25s ease; }
.story-caption.caption-in { animation: story-caption 0.3s cubic-bezier(0.16, 1, 0.3, 1) 0.04s both; }

/* ---------- unread badge pulse (class only on live unread increment) ---------- */
@keyframes badge-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.unread-badge.pulse {
  animation: badge-pulse 0.45s cubic-bezier(0.16, 1, 0.3, 1) 2;
}

/* ---------- online status dot: very subtle opacity ring (infinite) ---------- */
.convo-avatar .status-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--online);
  opacity: 0;
  animation: dot-ring 2.6s ease-out infinite;
  pointer-events: none;
}

@keyframes dot-ring {
  0% { opacity: 0.45; }
  60%, 100% { opacity: 0; }
}

/* ---------- splash logo ring pulse (wrapper span added in index.html) ---------- */
.splash-ring {
  position: relative;
  display: inline-flex;
}

.splash-ring::before {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: splash-ring 2.6s ease-out infinite;
  will-change: transform, opacity;
}

@keyframes splash-ring {
  0% { transform: scale(0.85); opacity: 0.5; }
  70%, 100% { transform: scale(1.22); opacity: 0; }
}

/* ---------- login screen: card entrance + slow drifting blobs ---------- */
.login-screen {
  position: relative;
  overflow: hidden;
}

.login-screen::before,
.login-screen::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
}

.login-screen::before {
  width: 70vmin;
  height: 70vmin;
  left: -20vmin;
  top: -16vmin;
  background: radial-gradient(circle at 32% 30%, var(--accent-soft), transparent 62%);
  animation: blob-drift 26s ease-in-out infinite alternate;
}

.login-screen::after {
  width: 56vmin;
  height: 56vmin;
  right: -16vmin;
  bottom: -18vmin;
  background: radial-gradient(circle at 62% 40%, rgba(34, 197, 94, 0.1), transparent 60%);
  animation: blob-drift 34s ease-in-out infinite alternate-reverse;
}

@keyframes blob-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(6vmin, 4vmin, 0) scale(1.1); }
}

.login-card {
  position: relative;
  z-index: 1;
  animation: login-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes login-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* input focus: soft accent glow (static state, not animated) */
.inp {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.inp:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- themed thin scrollbars ---------- */
.chat-scroll,
.convo-list,
.member-list,
.newchat-pop {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

.chat-scroll::-webkit-scrollbar,
.convo-list::-webkit-scrollbar,
.member-list::-webkit-scrollbar,
.newchat-pop::-webkit-scrollbar {
  width: 8px;
}

.chat-scroll::-webkit-scrollbar-track,
.convo-list::-webkit-scrollbar-track,
.member-list::-webkit-scrollbar-track,
.newchat-pop::-webkit-scrollbar-track {
  background: transparent;
}

.chat-scroll::-webkit-scrollbar-thumb,
.convo-list::-webkit-scrollbar-thumb,
.member-list::-webkit-scrollbar-thumb,
.newchat-pop::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.chat-scroll::-webkit-scrollbar-thumb:hover,
.convo-list::-webkit-scrollbar-thumb:hover,
.member-list::-webkit-scrollbar-thumb:hover,
.newchat-pop::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ---------- empty list: CSS-drawn ripple ring motif (no images) ---------- */
.list-empty::before {
  content: "";
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: radial-gradient(circle at 50% 50%, var(--accent) 0 3px, transparent 4px);
}

.list-empty {
  gap: 8px;
}

/* ---------- day separators + system messages: subtle typography ---------- */
.day-sep,
.msg-sys {
  letter-spacing: 0.03em;
}

/* ---------- light theme: hairline on white bubbles against the cream bg ---------- */
html[data-theme="light"] .msg-in .bubble,
html[data-theme="light"] .typing {
  border: 1px solid rgba(9, 9, 11, 0.07);
}

/* ============================================================
   v5: profile + settings
   ============================================================ */
.modal-profile .profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 18px;
}

.profile-ring {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  margin-bottom: 12px;
  background: var(--surface-2);
}

.profile-ring.has-story {
  background: var(--ring-ig);
  cursor: pointer;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  background: var(--surface-2);
}

.profile-name {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
}

.profile-user {
  color: var(--text-2);
  font-size: 0.9rem;
  word-break: break-all;
}

.profile-status {
  font-size: 0.78rem;
  color: var(--online);
}

.profile-status.off {
  color: var(--text-3);
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 2px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-2);
}

.profile-row span:last-child {
  color: var(--text);
  font-weight: 600;
}

#prf-message {
  margin-top: 14px;
}

.field-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.field-row:hover {
  background: var(--surface-2);
}

.field-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  margin: 0;
}

#settings-signout {
  color: var(--danger, #f87171);
  border-color: color-mix(in srgb, var(--danger, #f87171) 40%, var(--border));
}

#err-settings {
  margin-top: 10px;
}

/* ============================================================
   v6: images, invites, story segments, reply, animation boost
   ============================================================ */
.img-bubble {
  max-width: 260px;
  border-radius: 12px;
  display: block;
  margin-bottom: 6px;
}

.invite-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invite-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.invite-chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--surface-2);
}

#story-progress {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  padding: 14px 16px;
}

.sp-seg {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.sp-fill {
  position: absolute;
  inset: 0;
  background: #fff;
  width: 0;
}

.sp-seg.done .sp-fill {
  width: 100%;
}

.sp-seg.active .sp-fill {
  animation: storybar 3s linear forwards;
}

.story-reply {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 12px;
  z-index: 9;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}

.story-reply input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  outline: none;
}

.story-reply input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.story-reply button {
  padding: 10px 16px;
  border-radius: 999px;
  background: #fff;
  color: #111;
  font-weight: 700;
}

/* animation boost (transform/opacity only; reduced-motion kill is global) */
@keyframes aurora {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-screen {
  background-size: 180% 180%;
  animation: aurora 14s ease-in-out infinite;
}

.unread-badge {
  /* static by default; the one-shot .pulse class (live increment) is defined
     in the badge-pulse section above */
}

.story-item.has-story .ring-box {
  animation: ringShimmer 2.4s ease-in-out infinite;
}

@keyframes ringShimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* ============================================================
   v7: polish + production (toasts, conn status, tokens)
   ============================================================ */
:root {
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-1: 160ms;
  --dur-2: 260ms;
  --dur-3: 420ms;
}

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: 92vw;
  max-width: 460px;
}

.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  animation: toast-in var(--dur-3) var(--ease-out) both;
}

.toast.err {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
}

.toast.ok {
  color: var(--online);
  border-color: rgba(35, 197, 90, 0.45);
}

.toast.leaving {
  animation: toast-out var(--dur-2) var(--ease-out) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
}

.convo-list.init .convo-row {
  animation: row-in var(--dur-3) var(--ease-out) both;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
}

/* ============================================================
   v8: alive-feel pass (ambient motion, transitions, feedback)
   ============================================================ */
/* slow-drifting chat backdrop glow */
.chat::after {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(42% 34% at 28% 22%, var(--glow-strong, rgba(88,101,242,0.10)), transparent 70%),
              radial-gradient(36% 30% at 74% 66%, var(--glow-soft, rgba(35,197,90,0.06)), transparent 70%);
  animation: chatdrift 26s ease-in-out infinite alternate;
}

@keyframes chatdrift {
  from { transform: translate3d(-2.5%, -2%, 0) scale(1); }
  to   { transform: translate3d(2.5%, 2.5%, 0) scale(1.12); }
}

/* online dot pulse ring */
.status-dot {
  box-shadow: 0 0 0 0 var(--online);
  animation: dotpulse 2.2s ease-out infinite;
}

@keyframes dotpulse {
  0%   { box-shadow: 0 0 0 0 rgba(35, 197, 90, 0.55); }
  70%  { box-shadow: 0 0 0 5px rgba(35, 197, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(35, 197, 90, 0); }
}

/* chat log entrance on conversation switch */
.chat-log.chat-enter { animation: chatenter 0.34s var(--ease-out, cubic-bezier(0.16,1,0.3,1)); }

@keyframes chatenter {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* skeleton loaders (WhatsApp-style) */
.skel { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
.skel-row { display: flex; gap: 10px; align-items: flex-end; }
.skel-av { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; }
.skel-bubble { height: 34px; border-radius: 14px; }
.skel-mine { margin-left: auto; }
.skel-line { border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: skelshimmer 1.4s infinite linear; }

@keyframes skelshimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* message stagger entrance on fresh render (non-live) */
.chat-log.stagger .msg { animation: msgpop 0.3s var(--ease-out, cubic-bezier(0.16,1,0.3,1)) backwards; }
.chat-log.stagger .msg:nth-child(1) { animation-delay: 0.02s; }
.chat-log.stagger .msg:nth-child(2) { animation-delay: 0.05s; }
.chat-log.stagger .msg:nth-child(3) { animation-delay: 0.08s; }
.chat-log.stagger .msg:nth-child(4) { animation-delay: 0.11s; }
.chat-log.stagger .msg:nth-child(5) { animation-delay: 0.14s; }
.chat-log.stagger .msg:nth-child(6) { animation-delay: 0.17s; }
.chat-log.stagger .msg:nth-child(7) { animation-delay: 0.2s; }
.chat-log.stagger .msg:nth-child(8) { animation-delay: 0.23s; }
.chat-log.stagger .msg:nth-child(9) { animation-delay: 0.26s; }
.chat-log.stagger .msg:nth-child(10) { animation-delay: 0.29s; }

@keyframes msgpop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* press feedback */
.btn:active, .ci-btn:active, .send-btn:active, .rail-item:active, .r-chip:active, .convo-row:active, .story-item:active, .side-tab:active, .login-tab:active {
  transform: scale(0.97);
}

/* ============================================================
   v9: unread + pin round (WhatsApp counters, unread divider,
   jump-to-latest pill, pinned convos, rail unread badges)
   ============================================================ */

/* ---------- "Unread messages" divider inside the chat ---------- */
.unread-sep {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--online);
  animation: sep-in var(--dur-3) var(--ease-out) both;
}

.unread-sep::before,
.unread-sep::after {
  content: "";
  height: 1px;
  width: 48px;
  background: color-mix(in srgb, var(--online) 45%, transparent);
}

@keyframes sep-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* ---------- jump-to-latest pill (bottom-center, above composer) ---------- */
.jump-pill {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: var(--shadow-pop);
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.jump-pill svg {
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}

.jump-pill .jump-label {
  font-weight: 600;
  opacity: 0.85;
}

.jump-pill:hover {
  background: var(--accent-hover);
}

.jump-pill:active {
  transform: translateX(-50%) scale(0.96);
}

.jump-pill.pill-in {
  animation: pill-in var(--dur-3) var(--ease-out) both;
}

@keyframes pill-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.94);
  }
}

/* ---------- pinned conversation indicator ---------- */
.pin-ic {
  width: 13px;
  height: 13px;
  color: var(--accent);
  flex-shrink: 0;
}

.pin-ic svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 1.8;
}

/* ---------- rail unread totals (Discord-style) ---------- */
.rail-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--online);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--pane);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* light theme: green counter contrast bump */
html[data-theme="light"] .unread-badge,
html[data-theme="light"] .rail-badge {
  background: var(--online);
}

/* ============================================================
   v10: composer alignment + photo attachments (chat & stories)
   ============================================================ */

/* Emoji + attach buttons: lift 3px so their icon centers match the
   taller 44px send button (38px buttons are bottom-anchored). */
#btn-emoji,
#btn-attach,
#btn-mic {
  margin-bottom: 3px;
}

/* ---------- story photo slides ---------- */
.story-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  user-select: none;
}

.story-slide .story-caption {
  z-index: 3;
}

/* soft scrim so captions stay readable over photos */
.story-slide .story-caption {
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7), 0 4px 18px rgba(0, 0, 0, 0.6);
}

/* ---------- story post modal: photo attach row ---------- */
.modal-hint {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-3);
}

.story-attach {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.story-attach-name {
  font-size: 0.78rem;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   v11: message pinning + inline edit
   ============================================================ */

/* ---------- pinned-messages chip in the chat head ---------- */
#btn-pins {
  position: relative;
}

#btn-pins .pins-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--pane);
  pointer-events: none;
}

/* ---------- pinned list popover ---------- */
.pins-pop {
  width: 300px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}

.pins-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
}

.pins-item:hover {
  background: var(--surface-2);
}

.pins-item-who {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
}

.pins-item-txt {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* ---------- pin badge on a pinned message bubble ---------- */
.pin-badge {
  width: 12px;
  height: 12px;
  color: var(--accent);
  flex-shrink: 0;
  margin: 2px 0 0 4px;
  vertical-align: middle;
}

.pin-badge svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 1.8;
}

/* ---------- jump-to-pinned highlight ---------- */
.msg.pin-jump .bubble {
  animation: pin-jump 1.2s var(--ease-out) 2;
}

@keyframes pin-jump {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(88, 101, 242, 0);
  }
  30% {
    box-shadow: 0 0 0 4px rgba(88, 101, 242, 0.55);
  }
}

/* ---------- edit mode: hide the "Replying to" prefix ---------- */
.composer-reply.editing .cr-reply-prefix {
  display: none;
}

/* ============================================================
   v12: theme scenes + accent palette + font size
   ============================================================ */
:root[data-accent="green"]   { --accent:#22c55e; --accent-hover:#1ea54e; --accent-soft:rgba(34,197,94,.14); --accent-ring:rgba(34,197,94,.45); }
:root[data-accent="pink"]    { --accent:#ec4899; --accent-hover:#be185d; --accent-soft:rgba(236,72,153,.14); --accent-ring:rgba(236,72,153,.45); }
:root[data-accent="cyan"]    { --accent:#06b6d4; --accent-hover:#0891b2; --accent-soft:rgba(6,182,212,.14); --accent-ring:rgba(6,182,212,.45); }
:root[data-accent="orange"]  { --accent:#f59e0b; --accent-hover:#d97706; --accent-soft:rgba(245,158,11,.16); --accent-ring:rgba(245,158,11,.5); }
:root[data-accent="violet"]  { --accent:#8b5cf6; --accent-hover:#7c3aed; --accent-soft:rgba(139,92,246,.16); --accent-ring:rgba(139,92,246,.5); }
:root[data-accent="red"]     { --accent:#ef4444; --accent-hover:#dc2626; --accent-soft:rgba(239,68,68,.15); --accent-ring:rgba(239,68,68,.5); }

html[data-theme="dark"][data-scene="aurora"] .chat { background: #0c0e1d; }
html[data-theme="dark"][data-scene="aurora"] :is(.chat::before, .chat::after) { background: radial-gradient(rgba(139,92,246,.16) 1px, transparent 1.4px); background-size: 26px 26px; }
html[data-theme="dark"][data-scene="aurora"] { --glow-strong: rgba(139,92,246,.16); --glow-soft: rgba(168,85,247,.08); --in-bubble:#1c2140; --out-bubble-from:#5b21b6; --out-bubble-to:#4c1d95; }
html[data-theme="dark"][data-scene="hacker"] { --accent:#22c55e; --accent-hover:#16a34a; --accent-soft:rgba(34,197,94,.14); --accent-ring:rgba(34,197,94,.5); --chat-bg:#0a0f0a; --glow-strong: rgba(34,197,94,.12); --glow-soft: rgba(34,197,94,.06); --out-bubble-from:#14532d; --out-bubble-to:#166534; --dot: rgba(34,197,94,.28); }
html[data-theme="dark"][data-scene="hacker"] .chat::before { background-image: repeating-linear-gradient(0deg, transparent, transparent 3px, var(--dot) 3px, var(--dot) 4px); background-size: 4px 4px; }
html[data-theme="light"][data-scene="paper"] { --chat-bg:#ece9df; --dot: rgba(120,100,60,.16); --in-bubble:#ffffff; --out-bubble-from:#2bbd6e; --out-bubble-to:#168a4a; }
html[data-theme="light"][data-scene="paper"] .chat::before { background-image: radial-gradient(var(--dot) 1.2px, transparent 1.5px); background-size: 18px 18px; }
html[data-theme="dark"][data-scene="paper"] { --chat-bg:#141319; --dot: rgba(255,255,255,.06); --in-bubble:#22212b; --out-bubble-from:#24ab5f; --out-bubble-to:#168a4a; }

html { font-size: var(--font-size, 15px); }

/* ---------- settings: accent swatches + font range ---------- */
.accent-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 0 4px;
}

.accent-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--swatch, var(--accent));
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.accent-swatch:hover { transform: scale(1.12); }
.accent-swatch.is-on { border-color: var(--text); box-shadow: 0 0 0 2px var(--pane); }

.range-inp {
  width: 100%;
  accent-color: var(--accent);
  margin: 2px 0 6px;
}

/* ---------- rich text (Discord-style formatting) ---------- */
.rich-code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
  background: color-mix(in srgb, var(--text) 12%, transparent);
  padding: 0 4px;
  border-radius: 6px;
}
pre.rich-code {
  display: block;
  margin: 6px 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  border-radius: 10px;
}
.rich-mention {
  color: var(--accent);
  font-weight: 700;
}

/* ---------- starred + status ---------- */
.star-badge {
  font-size: 0.8rem;
  color: var(--accent);
  margin: 2px 0 0 5px;
  vertical-align: middle;
  line-height: 1;
}
#btn-stars .star-btn-ic {
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
}
.status-row {
  display: flex;
  gap: 8px;
}
.status-row .inp { flex: 1; }

/* ---------- in-chat search + double-tap + hits ---------- */
.chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--pane);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.chat-search input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.85rem;
  outline: none;
}
.chat-search input:focus { border-color: var(--accent); }
.search-count {
  font-size: 0.72rem;
  color: var(--text-3);
  font-weight: 700;
  white-space: nowrap;
}
.search-close {
  color: var(--text-2);
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 50%;
}
.search-close:hover { background: var(--surface-2); }
.msg.search-hit .bubble {
  box-shadow: 0 0 0 3px var(--accent);
  animation: pin-jump 1.4s var(--ease-out) 2;
}
.like-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  font-size: 2rem;
  color: var(--accent);
  pointer-events: none;
  z-index: 3;
  animation: like-burst 0.85s var(--ease-out) forwards;
}
.msg { position: relative; }
@keyframes like-burst {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  30% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }
}

/* ---------- mention picker ---------- */
.mention-pop {
  max-height: 260px;
  overflow-y: auto;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
}
.mention-item.is-on { background: var(--accent-soft); }
.mention-user {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-3);
}

/* ---------- presence modes ---------- */
.status-dot.idle { background: var(--presence-idle, #f59e0b); }
.status-dot.dnd { background: var(--presence-dnd, #ef4444); }
.convo-avatar .status-dot.idle::after { border-color: var(--presence-idle, #f59e0b); }
.convo-avatar .status-dot.dnd::after { border-color: var(--presence-dnd, #ef4444); }
.chat-peer-status.idle { color: var(--presence-idle, #f59e0b); }
.chat-peer-status.dnd { color: var(--presence-dnd, #ef4444); }

/* ---------- mobile smoothness: isolate reflow (contain) ---------- */
.convo-row { contain: content; }
.msg { contain: content; }
.chat-scroll { scroll-behavior: auto; }

/* ---------- forward + wallpaper + story reactions ---------- */
.msg-fwd {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
.msg-fwd b { font-weight: 800; }
.fwd-pop, .wall-pop { max-height: 300px; overflow-y: auto; width: 230px; }
.fwd-title { font-size: 0.72rem; font-weight: 700; color: var(--text-3); padding: 4px 10px 6px; }
.wall-chip {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface-2); flex-shrink: 0;
}
.wall-chip.w-dots { background-image: radial-gradient(var(--accent) 1.2px, transparent 1.5px); background-size: 6px 6px; }
.wall-chip.w-grid { background-image: linear-gradient(var(--accent) 1px, transparent 1px), linear-gradient(90deg, var(--accent) 1px, transparent 1px); background-size: 7px 7px; }
.wall-chip.w-cross { background-image: repeating-linear-gradient(45deg, var(--accent) 0 1px, transparent 1px 6px), repeating-linear-gradient(-45deg, var(--accent) 0 1px, transparent 1px 6px); }
.wall-chip.w-zig { background-image: repeating-linear-gradient(0deg, var(--accent) 0 2px, transparent 2px 6px); }
.chat[data-wall="dots"] .chat::before { background-image: radial-gradient(var(--dot, rgba(255,255,255,.10)) 1.4px, transparent 1.8px); background-size: 14px 14px; }
.chat[data-wall="grid"] .chat::before { background-image: linear-gradient(var(--dot, rgba(255,255,255,.06)) 1px, transparent 1px), linear-gradient(90deg, var(--dot, rgba(255,255,255,.06)) 1px, transparent 1px); background-size: 24px 24px; }
.chat[data-wall="cross"] .chat::before { background-image: repeating-linear-gradient(45deg, var(--dot, rgba(255,255,255,.05)) 0 1px, transparent 1px 10px), repeating-linear-gradient(-45deg, var(--dot, rgba(255,255,255,.05)) 0 1px, transparent 1px 10px); }
.chat[data-wall="zig"] .chat::before { background-image: repeating-linear-gradient(0deg, var(--dot, rgba(255,255,255,.05)) 0 2px, transparent 2px 7px); }
.story-quick {
  position: absolute;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  gap: 10px;
}
.sq-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 1.2rem;
  backdrop-filter: blur(4px);
  transition: transform 0.15s ease;
}
.sq-btn:hover { transform: scale(1.15); }

/* ---------- global search + group info ---------- */
.search-global {
  color: var(--text-3);
  padding: 2px 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.search-global:hover { color: var(--text); background: var(--surface-2); }
.gsearch-pop { width: 300px; max-height: 380px; overflow: hidden; padding: 8px; }
.gsearch-pop input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.85rem;
  outline: none;
  margin-bottom: 6px;
}
.gsearch-pop input:focus { border-color: var(--accent); }
.gsearch-results { max-height: 320px; overflow-y: auto; }
.gsearch-results .ncp-name { display: flex; flex-direction: column; gap: 1px; }
.gs-conv { font-weight: 700; font-size: 0.8rem; }
.gs-body {
  color: var(--text-3);
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 210px;
}
.gi-list { max-height: 380px; overflow-y: auto; }
.gi-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
}
.gi-row:hover { background: var(--surface-2); }
.gi-row .convo-avatar { width: 40px; height: 40px; font-size: 0.7rem; }
.gi-meta { display: flex; flex-direction: column; min-width: 0; }
.gi-name { font-weight: 700; font-size: 0.88rem; }
.gi-status { color: var(--accent); font-size: 0.76rem; }
.gi-presence { color: var(--text-3); font-size: 0.74rem; }
.gi-count { font-size: 0.74rem; color: var(--text-3); font-weight: 700; padding: 4px 10px 8px; }
.danger-btn { color: var(--danger, #f87171); border-color: rgba(248,113,113,.4); }

/* ---------- story quote card + in-bubble timestamps ---------- */
.bubble {
  position: relative;
  padding-bottom: 18px;
}
.bubble-time {
  position: absolute;
  right: 8px;
  bottom: 5px;
  font-size: 0.6rem;
  line-height: 1;
  opacity: 0.72;
  color: var(--text-3);
  pointer-events: none;
  user-select: none;
}
.story-quote {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  min-width: 0;
}
.sq-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  flex-shrink: 0;
}
.sq-img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.sq-text {
  font-size: 0.74rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- voice notes + reactors + list typing ---------- */
#btn-mic.rec { color: #fff; background: var(--danger, #ef4444); animation: mic-pulse 1s ease-in-out infinite; }
@keyframes mic-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }
.voice-bubble { display: block; max-width: 220px; height: 36px; margin: 2px 0 4px; }
.reactors-pop { min-width: 220px; max-width: 300px; }
.reactors-row { padding: 6px 10px; font-size: 0.85rem; }
.convo-row.row-typing .convo-preview { color: var(--accent); font-style: italic; }

/* ---------- own presence dot on the rail avatar ---------- */
.rail-me { position: relative; }
.rail-me .status-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border: 2px solid var(--pane);
}

/* ---------- own status in the me menu ---------- */
.me-status {
  font-size: 0.76rem;
  color: var(--accent);
  padding: 4px 12px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- kill the blue tap-highlight flash on mobile ---------- */
* {
  -webkit-tap-highlight-color: transparent;
}

/* ---------- profile pictures ---------- */
.pfp-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  pointer-events: none;
}
.convo-avatar, .msg-avatar, .ncp-av, .ring-inner, .profile-avatar, .avatar, .story-avatar, .gi-row .convo-avatar {
  position: relative;
  overflow: hidden;
}
#pfp-preview { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); }

/* ---------- kill mobile pull-to-refresh / overscroll bounce ---------- */
html, body {
  overscroll-behavior-y: none;
}
.chat-scroll, .convo-list, .gsearch-results, .gi-list, .pins-pop, .emoji-pop {
  overscroll-behavior: contain;
}

/* ---------- v22: notification hint + send button disabled state ---------- */
.notif-hint {
  margin: 6px 0 0;
}
.notif-hint:empty {
  display: none;
}
.send-btn:disabled {
  opacity: 0.55;
  transform: scale(0.96);
  cursor: default;
  box-shadow: none;
}
