@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink: #17151f;
  --panel: #211f2b;
  --panel-raised: #2a2836;
  --hairline: #322f3d;
  --text: #f2eef9;
  --muted: #9a91b0;
  --accent: #7c6cf6;
  --accent-soft: rgba(124, 108, 246, 0.18);
  --accent-glow: rgba(124, 108, 246, 0.45);
  --good: #4fd1a5;
  --good-glow: rgba(79, 209, 165, 0.45);
  --bad: #f23f43;
  --bubble-mine: linear-gradient(135deg, #7c6cf6, #6659e0);
  --bubble-theirs: #2a2836;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;
}

html[data-theme="light"] {
  --ink: #f5f2fb;
  --panel: #ffffff;
  --panel-raised: #f1edf9;
  --hairline: #e3ddf0;
  --text: #201e2b;
  --muted: #6c6480;
  --accent: #6d5ef5;
  --accent-soft: rgba(109, 94, 245, 0.12);
  --accent-glow: rgba(109, 94, 245, 0.3);
  --good: #1fa980;
  --good-glow: rgba(31, 169, 128, 0.3);
  --bad: #e0393f;
  --bubble-mine: linear-gradient(135deg, #6d5ef5, #5c4de0);
  --bubble-theirs: #f1edf9;
}

html, body { transition: background 0.15s ease; }

* { box-sizing: border-box; }

/* Themed scrollbars (Chrome/Edge/Safari + Firefox) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--hairline);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #3a3f4c;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-soft);
}

/* ---------- Wordmark ---------- */

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}

.wordmark .dot {
  color: var(--accent);
  font-size: 0.9em;
}

.logo-mark {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.12em;
  margin-right: 0.28em;
}

/* ---------- Sidebar tabs ---------- */

.tab-row {
  display: flex;
  border-bottom: 1px solid var(--hairline);
  padding: 0 10px;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 12px 4px;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.badge {
  background: var(--bad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#notifications-btn .badge {
  position: absolute;
  top: 2px;
  right: 2px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }

/* ---------- Friends / requests / notifications rows ---------- */

.people-list {
  overflow-y: auto;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin: 0 8px 2px;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

.list-row:hover { background: var(--panel-raised); }

.list-row .meta { min-width: 0; flex: 1; }
.list-row .username { font-weight: 600; font-size: 14px; }
.list-row .sub-line { font-size: 12px; color: var(--muted); }

.row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.pill-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.pill-btn:active:not(:disabled) { transform: scale(0.94); }

.pill-btn.accept { background: var(--accent); color: #fff; }
.pill-btn.accept:hover { filter: brightness(1.08); }

.pill-btn.decline { background: var(--panel-raised); color: var(--muted); border: 1px solid var(--hairline); }
.pill-btn.decline:hover { color: var(--bad); border-color: var(--bad); }

/* Friend request accepted: a quick, satisfying pop-and-fade before the
   row is removed from the list. */
.row-accepted {
  animation: row-accept-pop 0.4s ease-out forwards;
  pointer-events: none;
}

@keyframes row-accept-pop {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.03); opacity: 1; background: var(--accent-soft); }
  100% { transform: scale(1); opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .pill-btn:active:not(:disabled) { transform: none; }
  .row-accepted { animation: none; opacity: 0.4; }
}

.notification-row {
  padding: 12px 18px;
  border-bottom: 1px solid var(--hairline);
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.notification-row.unread { background: var(--accent-soft); }

.notification-row .n-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Settings modal ---------- */

.modal-lg { max-width: 440px; }

.cropper-stage {
  width: 280px;
  height: 280px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: var(--panel-raised);
  cursor: grab;
  touch-action: none;
}

.cropper-stage:active { cursor: grabbing; }

.cropper-zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 16px;
}

.cropper-zoom-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.elastic-slider input[type="range"]:active {
  transform: scaleY(1.6);
}

.elastic-slider.bounce-min input[type="range"] { animation: elastic-bounce-left 0.35s ease-out; }
.elastic-slider.bounce-max input[type="range"] { animation: elastic-bounce-right 0.35s ease-out; }

@keyframes elastic-bounce-left {
  0% { transform: translateX(0); }
  35% { transform: translateX(-6px); }
  100% { transform: translateX(0); }
}

@keyframes elastic-bounce-right {
  0% { transform: translateX(0); }
  35% { transform: translateX(6px); }
  100% { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .cropper-zoom-row input[type="range"] { transition: none; }
  .elastic-slider input[type="range"]:active { transform: none; }
  .elastic-slider.bounce-min input[type="range"],
  .elastic-slider.bounce-max input[type="range"] { animation: none; }
}

.settings-tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-raised);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 22px;
}

.settings-tab, .info-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
}

.settings-tab.active, .info-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Per-conversation wallpaper swatches ---------- */

.wallpaper-swatch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.wallpaper-swatch {
  width: 100%;
  aspect-ratio: 1.3;
  border-radius: var(--radius-md);
  border: 2px solid var(--hairline);
  background-color: var(--panel-raised);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.wallpaper-swatch:hover { transform: scale(1.04); }

.wallpaper-swatch.selected {
  border-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .wallpaper-swatch:hover { transform: none; }
}

.settings-heading {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  transition: background 0.15s ease;
  cursor: pointer;
}

.switch-track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(18px);
  background: var(--accent);
}

/* ---------- Auth page ---------- */

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  position: relative;
  overflow: hidden;
  background: var(--ink);
}

#wave-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  position: relative;
  z-index: 1;
}

/* ---------- Glow border (cursor-following spotlight edge) ---------- */

.glow-border {
  position: relative;
}

.glow-border .edge-light {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: radial-gradient(220px circle at var(--mx, 50%) var(--my, 50%), var(--accent-glow), transparent 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 2;
}

.glow-border:hover .edge-light,
.glow-border:focus-within .edge-light {
  opacity: 1;
}

.glow-border-inner {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .glow-border .edge-light { transition: none; }
}

.auth-card header {
  margin-bottom: 24px;
}

.auth-card .tagline {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 0;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-raised);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 22px;
}

.tabs button {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}

.tabs button.active {
  background: var(--accent);
  color: #fff;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #565b66;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 15px;
  padding: 6px 8px;
  color: var(--muted);
  opacity: 0.6;
  border-radius: var(--radius-sm);
}

.password-toggle:hover { opacity: 1; }
.password-toggle.showing { opacity: 1; color: var(--accent); }

/* Avatar picker on the register form */

.avatar-picker {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--muted);
}

.avatar-preview .avatar {
  width: 100%;
  height: 100%;
  font-size: 20px;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-picker .btn-secondary {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 0;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-secondary {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.btn-secondary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary:hover { border-color: var(--accent); }

.form-error {
  background: rgba(245, 101, 101, 0.12);
  border: 1px solid rgba(245, 101, 101, 0.35);
  color: #ff9b9b;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.form-error.visible { display: block; }

.form-error.success {
  background: rgba(35, 165, 90, 0.12);
  border-color: rgba(35, 165, 90, 0.35);
  color: #6fdb9b;
}

/* ---------- App shell ---------- */

.app-shell {
  height: 100%;
  display: flex;
  position: relative;
}

.app-shell.sidebar-collapsed .sidebar {
  display: none;
}

#sidebar-reopen-btn {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 45;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
}

.app-shell.sidebar-collapsed #sidebar-reopen-btn {
  display: block;
}

@media (max-width: 760px) {
  .sidebar.hide-on-mobile { display: none; }
  .chat-pane.hide-on-mobile { display: none; }
  #sidebar-toggle-btn,
  #sidebar-reopen-btn {
    display: none;
  }
  .app-shell.sidebar-collapsed .chat-header {
    padding-left: 22px;
  }
}

.sidebar {
  background: var(--ink);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 300px;
  flex-shrink: 0;
}

@media (max-width: 760px) {
  .sidebar {
    width: 100%;
  }
}

.sidebar-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.me-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
}

.me-row:hover { background: var(--panel-raised); }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-raised);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  color: var(--muted);
  font-size: 15px;
}

.avatar-lg { width: 72px; height: 72px; font-size: 26px; }

.me-row .name { font-weight: 600; font-size: 14px; }
.me-row .sub { font-size: 12px; color: var(--muted); }

.search-box {
  padding: 12px 18px;
}

.search-box input {
  width: 100%;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 10px 18px 4px;
}

.conversation-list, .people-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0 8px;
}

.convo-item, .person-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--text);
  position: relative;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

.convo-item:hover, .person-item:hover { background: var(--panel-raised); }
.convo-item.active { background: var(--accent); color: #fff; }
.convo-item.active .preview { color: rgba(255, 255, 255, 0.75); }

.convo-item .meta { min-width: 0; flex: 1; }
.convo-item .username { font-weight: 600; font-size: 14px; }
.convo-item .preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #565b66;
  position: absolute;
  right: -1px;
  bottom: -1px;
  border: 2px solid var(--panel);
}

.status-dot.online { background: var(--good); animation: dot-breathe 2.4s ease-in-out infinite; }
.status-dot.away { background: #e8b23d; }
.status-dot.busy { background: var(--bad); }

@keyframes dot-breathe {
  0%, 100% { box-shadow: 0 0 0 0 var(--good-glow); }
  50% { box-shadow: 0 0 0 4px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot.online, .status-dot-lg.online { animation: none; }
}

.avatar-with-status {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
}

.status-dot-lg {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #565b66;
  position: absolute;
  right: -1px;
  bottom: -1px;
  border: 2px solid var(--panel);
}

.status-dot-lg.online { background: var(--good); animation: dot-breathe-lg 2.4s ease-in-out infinite; }
.status-dot-lg.away { background: #e8b23d; }
.status-dot-lg.busy { background: var(--bad); }

@keyframes dot-breathe-lg {
  0%, 100% { box-shadow: 0 0 0 0 var(--good-glow); }
  50% { box-shadow: 0 0 0 5px transparent; }
}

.status-select {
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text);
  font-size: 12px;
  border-radius: var(--radius-sm);
  padding: 5px 6px;
  max-width: 90px;
}

.status-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.empty-note {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Chat pane ---------- */

.chat-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  height: 100%;
  background: var(--panel);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--hairline);
  transition: padding-left 0.18s ease;
}

.app-shell.sidebar-collapsed .chat-header {
  padding-left: 60px;
}

.chat-header .back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 0 4px 0 0;
}

@media (max-width: 760px) {
  .chat-header .back-btn { display: block; }
}

.chat-header .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .presence { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row {
  display: flex;
  animation: bubble-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.highlight-flash .bubble {
  animation: highlight-flash-anim 1.4s ease-out;
}

@keyframes highlight-flash-anim {
  0%, 15% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble-row { animation: none; }
}

.bubble-row.mine { justify-content: flex-end; }

.bubble-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(440px, 68vw);
}

.bubble-row.mine .bubble-group { align-items: flex-end; }
.bubble-row.theirs .bubble-group { align-items: flex-start; }

.bubble {
  min-width: 0;
  max-width: 100%;
  width: fit-content;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.bubble-row.mine .bubble {
  background: var(--bubble-mine);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble-row.theirs .bubble {
  background: var(--bubble-theirs);
  border-bottom-left-radius: 4px;
}

.bubble-time {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--muted);
  margin-top: 3px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.msg-ticks {
  display: inline-flex;
  align-items: center;
}

.seen-label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--muted);
  text-align: right;
  padding-right: 4px;
  margin-top: -4px;
  margin-bottom: 2px;
}

.group-sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
  padding-left: 2px;
}

.bubble-row.mine .bubble-time { text-align: right; }

/* ---------- Call log (centered system message) ---------- */

.call-log-row {
  display: flex;
  justify-content: center;
  margin: 4px 0;
}

.call-log-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
}

.call-log-pill.missed { color: var(--bad); border-color: rgba(245, 101, 101, 0.35); }
.call-log-icon { font-size: 13px; }
.call-log-time { opacity: 0.7; font-family: var(--font-mono); }

/* ---------- Message hover actions ---------- */

.bubble-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.bubble-row.mine .bubble-wrap { align-self: flex-end; align-items: flex-end; }
.bubble-row.theirs .bubble-wrap { align-items: flex-start; }

.msg-menu-btn {
  background: none;
  border: none;
  color: var(--muted);
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.bubble-row:hover .msg-menu-btn { opacity: 1; }
.msg-menu-btn:hover { background: var(--panel-raised); color: var(--text); }
.msg-menu-btn svg { width: 13px; height: 13px; }

.message-menu {
  display: none;
  position: fixed;
  flex-direction: column;
  gap: 1px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 60;
  min-width: 150px;
  padding: 4px;
}

.message-menu.visible { display: flex; }

.message-menu button {
  text-align: left;
  padding: 8px 10px;
  background: none;
  border: none;
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-menu button:hover { background: var(--panel); }

.msg-action-btn:hover { color: var(--text); border-color: var(--accent); }

.reply-quote {
  border-left: 2px solid rgba(255,255,255,0.4);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  opacity: 0.85;
  border-radius: 4px;
  background: rgba(0,0,0,0.12);
  max-width: 100%;
  white-space: normal;
}

.bubble-row.theirs .reply-quote { border-left-color: var(--accent); }

.reply-quote .rq-name { font-weight: 700; }

.reply-quote > div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.forwarded-tag {
  font-size: 11px;
  opacity: 0.7;
  font-style: italic;
  margin-bottom: 3px;
}

.edited-tag {
  font-size: 10px;
  opacity: 0.7;
  margin-left: 6px;
}

.edit-input {
  width: 100%;
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: inherit;
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  resize: vertical;
}

.edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.edit-actions button {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
}

.edit-actions .save { background: #fff; color: var(--accent); }
.edit-actions .cancel { background: rgba(255,255,255,0.15); color: inherit; }

/* ---------- Voice message bubble ---------- */

.voice-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.voice-bubble audio {
  height: 32px;
  max-width: 220px;
}

/* ---------- Reply preview / schedule popover / recording bar ---------- */

.reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
}

.reply-preview-bar {
  width: 3px;
  align-self: stretch;
  background: var(--accent);
  border-radius: 2px;
}

.reply-preview-body { flex: 1; min-width: 0; }
.reply-preview-label { font-size: 11px; color: var(--accent); font-weight: 700; }
.reply-preview-text {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-tray {
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
}

.tray-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px 0;
}

.tray-tab {
  background: none;
  border: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 6px 16px;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
}

.tray-tab:hover { color: var(--text); }
.tray-tab.active { background: var(--panel); color: var(--text); }

.emoji-picker {
  padding: 10px 14px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}

.emoji-picker button {
  background: none;
  border: none;
  font-size: 20px;
  padding: 6px;
  border-radius: 6px;
}

.emoji-picker button:hover { background: var(--panel); }

.gif-picker {
  padding: 10px 14px;
  max-height: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gif-search-input {
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  overflow-y: auto;
  max-height: 200px;
}

.gif-results img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.1s ease;
  background: var(--panel);
}

.gif-results img:hover { transform: scale(1.03); }

.gif-results .empty-note { grid-column: 1 / -1; }

.sticker-picker {
  padding: 10px 14px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.sticker-picker button {
  background: none;
  border: none;
  font-size: 30px;
  padding: 6px;
  border-radius: 8px;
}

.sticker-picker button:hover { background: var(--panel); }

.link-picker {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-picker-hint {
  font-size: 12px;
  color: var(--muted);
}

.composer {
  position: relative;
}

.mention-autocomplete {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 8px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  padding: 6px;
}

.mention-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.mention-option:hover,
.mention-option.highlighted {
  background: var(--accent-soft);
}

.mention-option .avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.mention-option .username {
  font-size: 13.5px;
  font-weight: 600;
}

.mention {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  padding: 1px 4px;
  border-radius: 4px;
}

.bubble-row.mine .mention {
  color: #fff;
  background: rgba(255, 255, 255, 0.25);
}

.image-only-bubble {
  background: none !important;
  padding: 0 !important;
}

.image-bubble {
  max-width: 280px;
  width: fit-content;
}

.image-bubble a {
  display: block;
  max-width: 100%;
}

.image-bubble img,
.image-bubble video {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.sticker-bubble {
  font-size: 64px;
  line-height: 1;
  background: none !important;
  padding: 4px !important;
}

.bubble-row.mine .sticker-bubble,
.bubble-row.theirs .sticker-bubble {
  background: none;
}

.schedule-popover {
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
  padding: 14px 18px;
}

.schedule-popover input[type="datetime-local"] {
  color-scheme: dark;
}

.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
}

.recording-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  animation: pulse-dot 1.1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.recording-hint { color: var(--muted); font-size: 13px; flex: 1; }
.recording-bar .btn-primary, .recording-bar .btn-secondary { padding: 7px 14px; width: auto; }

.composer-icon {
  font-size: 17px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
  color: var(--muted);
}

.composer-icon svg {
  width: 21px;
  height: 21px;
  display: block;
}

.composer-icon:hover { color: var(--text); background: var(--panel-raised); }

@media (max-width: 480px) {
  .composer-icon {
    width: 28px;
    height: 28px;
  }
  .composer-icon svg {
    width: 17px;
    height: 17px;
  }
  .composer-pill-icons {
    gap: 0;
  }
  #schedule-btn {
    display: none;
  }
}

.composer-icon.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Calls ---------- */

.call-btns { display: flex; gap: 2px; flex-shrink: 0; }

.call-modal { text-align: center; }

.call-status-name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
}

.call-status-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

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

.call-action {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  font-size: 20px;
  display: grid;
  place-items: center;
  color: #fff;
}

.call-action svg {
  width: 22px;
  height: 22px;
}

.call-action.accept { background: var(--good); }
.call-action.decline { background: var(--bad); }
.call-action.mute, .call-action.camera { background: var(--panel-raised); color: var(--text); border: 1px solid var(--hairline); }
.call-action.mute.off, .call-action.camera.off { background: var(--bad); color: #fff; }
.call-action.video-upgrade { background: var(--accent); color: #fff; }

.call-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 20%, rgba(109, 94, 245, 0.12), transparent 55%),
    #05060a;
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: call-overlay-in 0.25s ease-out;
}

@keyframes call-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.call-overlay-header {
  text-align: center;
  padding: 28px 20px 10px;
}

.call-video-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#remote-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-lg);
  background: #0c0e14;
}

#remote-video.sr-audio-only {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#local-video {
  position: absolute;
  bottom: 18px;
  right: 18px;
  width: 140px;
  border-radius: var(--radius-md);
  border: 2px solid var(--hairline);
  background: #0c0e14;
}

.call-avatar-fallback {
  display: none;
}

.call-avatar-fallback.visible {
  display: grid;
  place-items: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--panel-raised);
  font-family: var(--font-display);
  font-size: 44px;
  color: var(--muted);
  position: relative;
}

.call-avatar-fallback.visible .avatar {
  width: 100%;
  height: 100%;
  font-size: 44px;
}

.call-avatar-fallback.visible::before,
.call-avatar-fallback.visible::after {
  content: '';
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0;
  animation: call-pulse-ring 2.2s ease-out infinite;
}

.call-avatar-fallback.visible::after {
  animation-delay: 1.1s;
}

@keyframes call-pulse-ring {
  0% { transform: scale(0.85); opacity: 0.55; }
  100% { transform: scale(1.35); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .call-avatar-fallback.visible::before,
  .call-avatar-fallback.visible::after {
    animation: none;
    opacity: 0;
  }
}

.call-device-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 22px;
}

.call-device-row .status-select {
  max-width: 160px;
  font-size: 11px;
}

.call-controls {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 22px;
}

.typing-indicator {
  font-size: 12px;
  padding: 0 22px 6px;
  height: 16px;
  font-family: var(--font-mono);
  background: linear-gradient(90deg, var(--accent), var(--good), var(--accent));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: typing-pulse 2.2s ease-in-out infinite;
}

.typing-indicator:empty { animation: none; }

@keyframes typing-pulse {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

@media (prefers-reduced-motion: reduce) {
  .typing-indicator { animation: none; background: none; -webkit-text-fill-color: var(--muted); color: var(--muted); }
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  padding: 2px 4px;
}

.text-link-btn:hover {
  text-decoration: underline;
}

.list-row-delete {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.list-row-wrap:hover .list-row-delete,
.list-row-delete:focus-visible {
  opacity: 1;
}

.list-row-delete:hover {
  background: rgba(231, 76, 60, 0.15);
  color: var(--bad, #e74c3c);
}

@media (max-width: 760px) {
  .list-row-delete {
    opacity: 1;
  }
}

.composer {
  border-top: 1px solid var(--hairline);
  padding: 14px 18px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.composer-attach {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
}

.composer-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 4px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 6px 8px 6px 16px;
}

.composer-pill textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 4px;
  font-size: 14px;
  line-height: 1.4;
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer-pill textarea:focus {
  outline: none;
}

.composer-pill-icons {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: filter 0.15s ease;
}

.send-btn:hover { filter: brightness(1.08); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

.chat-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

#strands-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

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

.chat-empty .wordmark { opacity: 0.5; margin-bottom: 10px; }

/* ---------- Scanner (sweeping light on hover) ---------- */

.scanner-hover {
  position: relative;
  overflow: hidden;
}

.scanner-hover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, var(--accent-glow) 50%, transparent 60%);
  background-size: 250% 250%;
  background-position: 120% 0;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.scanner-hover:hover::after {
  opacity: 1;
  animation: scanner-sweep 1.1s ease-in-out;
}

@keyframes scanner-sweep {
  0% { background-position: 120% 0; }
  100% { background-position: -20% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .scanner-hover:hover::after { animation: none; opacity: 0; }
}

/* ---------- Halftone reveal (dot pattern on hover) ---------- */

.halftone-hover {
  position: relative;
  overflow: hidden;
}

.halftone-hover::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--accent) 1.1px, transparent 1.1px);
  background-size: 7px 7px;
  mix-blend-mode: overlay;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.halftone-hover:hover::after {
  opacity: 0.55;
}

@media (prefers-reduced-motion: reduce) {
  .halftone-hover::after { transition: none; }
}

/* ---------- Profile modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop.visible { display: flex; }

/* The cropper opens on top of an already-open modal (profile settings,
   group info) — it needs to win regardless of DOM order, since
   .modal-backdrop elements otherwise stack purely by DOM position. */
#cropper-modal { z-index: 60; }

.modal {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.55);
  animation: modal-in 0.16s ease-out;
}

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

@media (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0 0 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn-secondary { flex: 1; }
.modal-actions .btn-primary { flex: 1; }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.icon-btn:hover { color: var(--text); background: var(--panel-raised); }
