/* === BlackEnvelope — Telegram-Style Dark Theme === */

:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-hover: #202b36;
  --panel-active: #2b5278;
  --chat-bg: #0e1621;
  --line: #1e2c3a;
  --text: #f5f5f5;
  --muted: #6c7883;
  --primary: #2b5278;
  --accent: #4ea4f6;
  --msg-out: #2b5278;
  --msg-in: #182533;
  --success: #4fae4e;
  --danger: #e55353;
  --alt: #3a4a5b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
}

body {
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", "Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
}
body.auth-active {
  overflow: auto;
  height: auto;
}

input, textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: opacity var(--transition);
  white-space: nowrap;
}
button:hover { opacity: 0.85; }
button:disabled { opacity: 0.4; cursor: default; }
button.alt { background: var(--alt); }
button.success { background: var(--success); }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; padding: 6px 8px; }
button.ghost.danger { background: transparent; color: var(--danger); }
button.ghost:hover { background: var(--panel-hover); }

.hidden { display: none !important; }

/* === AUTH PAGE === */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 40px 36px 32px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 8px;
}
.auth-logo h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.auth-logo .tagline {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin: 24px 0 20px;
  border-bottom: 2px solid var(--line);
}
.auth-tab {
  flex: 1;
  background: none;
  color: var(--muted);
  padding: 10px 0;
  border-radius: 0;
  font-weight: 500;
  position: relative;
  transition: color var(--transition);
}
.auth-tab.active {
  color: var(--accent);
}
.auth-tab.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form input {
  background: var(--bg);
}
.auth-form button.primary-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.auth-divider span {
  padding: 0 10px;
}
.google-auth-btn {
  display: flex;
  justify-content: center;
}
.auth-billing-notice {
  border: 1px solid rgba(255, 188, 66, 0.45);
  background: rgba(255, 188, 66, 0.12);
  color: #ffd98c;
  font-size: 12px;
  line-height: 1.45;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.auth-hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.auth-links {
  display: flex;
  justify-content: flex-end;
  margin-top: -4px;
}
.auth-links a,
.auth-back-link {
  color: var(--accent);
  font-size: 12px;
  text-decoration: none;
}
.auth-links a:hover,
.auth-back-link:hover {
  text-decoration: underline;
}
.auth-form-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.auth-back-link {
  text-align: center;
}
.payment-verify-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.payment-verify-card {
  text-align: center;
  padding: 40px 32px;
}
.payment-verify-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 18px;
}
.payment-verify-spinner.done {
  animation: none;
  border-color: #4caf50;
  border-top-color: #4caf50;
}
@keyframes spin { to { transform: rotate(360deg); } }
.payment-verify-msg {
  color: var(--fg);
  font-size: 15px;
  line-height: 1.5;
}

/* === IN-APP CONFIRM / PASSPHRASE MODALS === */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.confirm-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 20px 16px;
  max-width: 360px;
  width: 100%;
}
.confirm-msg {
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 20px;
  white-space: pre-line;
}
.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
}
.confirm-btn.ok {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.confirm-btn.ok.danger {
  background: var(--danger);
  border-color: var(--danger);
}
.confirm-btn.cancel {
  opacity: 0.8;
}
.passphrase-card {
  max-width: 400px;
}
.passphrase-input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  box-sizing: border-box;
}
.passphrase-input:focus {
  outline: none;
  border-color: var(--accent);
}
.passphrase-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 16px;
  margin-bottom: 8px;
}

/* === APP LAYOUT === */
.app-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
}

/* === SIDEBAR === */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: -webkit-fill-available;
  position: relative;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.hamburger-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 20px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--panel-hover); }

.search-bar {
  flex: 1;
  position: relative;
}
.search-bar input {
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 13px;
  background: var(--bg);
}

.notification-badge {
  position: relative;
  flex-shrink: 0;
}
.notification-badge .badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background var(--transition);
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-family: inherit;
}
.conversation-item:hover { background: var(--panel-hover); }
.conversation-item.active { background: var(--panel-active); }

.conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conversation-name {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conversation-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conversation-time {
  color: var(--muted);
  font-size: 12px;
}
.conversation-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.fab {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform var(--transition), box-shadow var(--transition);
  z-index: 5;
  padding: 0;
}
.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

/* === AVATARS === */
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar.sm {
  width: 36px;
  height: 36px;
  font-size: 14px;
}
.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 22px;
}

/* === CHAT PANEL === */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--chat-bg);
  position: relative;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  gap: 12px;
  text-align: center;
  padding: 20px;
}
.chat-empty .empty-icon {
  font-size: 48px;
  opacity: 0.3;
}
.chat-empty .empty-text {
  font-size: 16px;
  max-width: 300px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 56px;
}
.back-btn {
  display: none;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 20px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-header-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-status {
  color: var(--muted);
  font-size: 12px;
}
.chat-header-actions {
  display: flex;
  gap: 4px;
}
.header-action-btn {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 16px;
  transition: background var(--transition), color var(--transition);
}
.header-action-btn:hover {
  background: var(--panel-hover);
  color: var(--text);
}

/* === GROUP TOPICS BAR === */
.topics-bar {
  display: flex;
  gap: 4px;
  padding: 6px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex-shrink: 0;
}
.topic-chip {
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.topic-chip:hover { border-color: var(--accent); color: var(--text); }
.topic-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* === MESSAGES === */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.date-divider {
  display: flex;
  justify-content: center;
  margin: 12px 0;
}
.date-divider span {
  background: rgba(0,0,0,0.35);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 12px;
}

.bubble-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 4px;
  max-width: 70%;
}
.bubble-group.out { align-self: flex-end; align-items: flex-end; }
.bubble-group.in { align-self: flex-start; align-items: flex-start; }

.bubble-sender {
  font-size: 12px;
  font-weight: 600;
  padding: 0 12px;
  margin-bottom: 2px;
  cursor: pointer;
}
.bubble-sender:hover { text-decoration: underline; }
.mention { cursor: pointer; }
.mention:hover { text-decoration: underline; }

.bubble {
  padding: 7px 12px 6px;
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  position: relative;
  max-width: 100%;
}
.bubble.in {
  background: var(--msg-in);
  border-bottom-left-radius: 4px;
}
.bubble.out {
  background: var(--msg-out);
  border-bottom-right-radius: 4px;
}
.bubble.in.first { border-top-left-radius: var(--radius-lg); }
.bubble.out.first { border-top-right-radius: var(--radius-lg); }
.bubble.in.last { border-bottom-left-radius: var(--radius-lg); }
.bubble.out.last { border-bottom-right-radius: var(--radius-lg); }

.bubble-text {
  font-size: 14px;
}
.bubble-media {
  margin-bottom: 6px;
}
.bubble-media-image {
  width: 100%;
  max-width: 320px;
  border-radius: 10px;
  display: block;
}
.bubble-media-video {
  width: 100%;
  max-width: 320px;
  border-radius: 10px;
  display: block;
  background: #000;
}
.bubble-media-audio {
  width: 100%;
  max-width: 320px;
}
.bubble-media-link {
  display: inline-block;
  margin-top: 6px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  text-decoration: none;
}
.bubble-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.bubble-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.bubble-action-btn {
  background: transparent;
  border: 0;
  padding: 2px 6px;
  border-radius: 10px;
  color: rgba(255,255,255,0.55);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity var(--transition), background var(--transition);
}
.bubble-action-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.10);
}
.bubble-action-btn.danger {
  color: var(--danger);
  background: rgba(255,255,255,0.10);
}
.bubble:hover .bubble-action-btn {
  opacity: 1;
}
.bubble-time {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
}
.bubble-topic {
  font-size: 11px;
  color: var(--accent);
  opacity: 0.7;
}

/* === LIKE BUTTON & AVATAR STACK === */
.avatar.xs {
  width: 20px;
  height: 20px;
  font-size: 9px;
  border: 1.5px solid var(--panel);
}
.like-btn {
  color: rgba(255,255,255,0.55) !important;
  font-size: 12px;
}
.like-btn.liked {
  color: var(--accent) !important;
  opacity: 1;
}
.like-avatar-stack {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: 0 2px;
  vertical-align: middle;
}
.like-avatar-stack .avatar {
  position: relative;
}
.like-more-count {
  font-size: 10px;
  color: var(--muted);
  margin-left: 2px;
}
.likes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.likes-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.likes-list-username {
  flex: 1;
  font-weight: 500;
}
.primary-btn.sm {
  padding: 4px 10px;
  font-size: 12px;
  width: auto;
}

/* === VIEW TOGGLE BAR === */
.view-toggle-bar {
  display: flex;
  gap: 4px;
  padding: 4px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex-shrink: 0;
}
.view-toggle-bar.hidden { display: none; }
.view-toggle-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.view-toggle-btn.active {
  background: var(--primary);
  color: var(--text);
  border-color: var(--primary);
}
.view-toggle-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--text);
}

.no-messages {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--muted);
  font-size: 14px;
}

.load-older-hint {
  align-self: center;
  margin: 2px 0 10px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}

/* === COMPOSE BAR === */
.compose-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.compose-bar .composer-wrap {
  flex: 1;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  min-height: 40px;
  max-height: 120px;
  position: relative;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 400;
}
.compose-bar .composer-wrap:focus-within {
  border-color: var(--accent);
}
.compose-bar textarea {
  width: 100%;
  resize: none;
  border-radius: 20px;
  padding: 10px 16px;
  min-height: 40px;
  max-height: 120px;
  background: transparent;
  border: 0;
  color: var(--text);
  caret-color: var(--text);
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  font-weight: inherit;
}
.compose-bar textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}
.composer-overlay {
  position: absolute;
  inset: 0;
  padding: 10px 16px;
  pointer-events: none;
  overflow: hidden;
}
.composer-overlay-inner {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  font-weight: inherit;
  color: transparent; /* only show colored spans */
}
.composer-overlay-inner .mention {
  font-weight: inherit;
}
.mention-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 10px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 14px 40px rgba(0,0,0,0.35);
}
.mention-suggestions .suggestion-item {
  padding: 10px 12px;
}
.mention-suggestion-username {
  font-weight: 800;
}
.attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--alt);
  color: #fff;
  border: 0;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: opacity var(--transition);
}
.attach-btn:hover { opacity: 0.85; }
.attach-btn:disabled { opacity: 0.3; }
.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: opacity var(--transition);
}
.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.3; }
.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.attachment-preview #attachmentName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-preview button {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 18px;
}

/* === SETTINGS PANEL === */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}
.settings-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  background: var(--panel);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.settings-panel.open { transform: translateX(0); }

.settings-profile {
  padding: 24px 20px;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.settings-profile .profile-name {
  font-size: 16px;
  font-weight: 600;
}
.settings-profile .profile-detail {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
}

.settings-menu {
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}
.settings-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: none;
  border: 0;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background var(--transition);
}
.settings-item:hover { background: var(--panel-hover); }
.settings-item .settings-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  color: var(--muted);
}
.settings-item.danger {
  /* Prevent red-on-red: these buttons also match button.danger (background red). */
  background: transparent;
  color: var(--danger);
}
.settings-item.danger:hover { background: rgba(229, 83, 83, 0.12); }
.settings-item.danger .settings-icon { color: var(--danger); }

.settings-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}
.settings-note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* === Profile Modal === */
.profile-modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 0 12px;
  text-align: center;
}
.profile-modal-header .avatar.lg {
  width: 72px;
  height: 72px;
  font-size: 28px;
}
.profile-modal-username {
  font-size: 18px;
  font-weight: 700;
}
.profile-modal-displayname {
  font-size: 14px;
  color: var(--muted);
  margin-top: -2px;
}
.profile-modal-status {
  font-size: 13px;
  color: var(--accent);
}
.profile-modal-bio {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}
.profile-modal-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.profile-modal-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.profile-modal-meta-row a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.profile-modal-meta-row a:hover { text-decoration: underline; }
.profile-modal-actions {
  display: flex;
  gap: 8px;
}
.profile-modal-actions button { flex: 1; }
.profile-key-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.profile-key-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.profile-key-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  border-radius: var(--radius-sm);
  width: 100%;
  text-align: left;
  border: none;
  cursor: pointer;
}
.profile-key-btn:hover { opacity: 0.85; background: var(--panel-hover); }
.profile-key-btn.danger { color: var(--danger); background: transparent; }
.key-backup-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 0;
}
.key-backup-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.key-backup-dot.backed-up { background: var(--success); }
.key-backup-dot.not-backed-up { background: var(--danger); }
.profile-loading {
  text-align: center;
  color: var(--muted);
  padding: 20px;
}

/* === Docs Modal === */
.docs {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}
.docs .muted { color: var(--muted); }
.docs-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.docs-section h4 {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.docs-section ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.docs-section li { color: var(--text); }
.docs code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  white-space: nowrap;
}
.docs-callout {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--muted);
}
.docs-callout strong { color: var(--text); }
.docs-callout.danger {
  border-color: rgba(229, 83, 83, 0.35);
  background: rgba(229, 83, 83, 0.08);
  color: rgba(245, 245, 245, 0.85);
}
.docs-subsection {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.docs-section h5 {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin: 0;
}
.docs-section ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.docs-section ol li { color: var(--text); }
.docs-note {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}
.docs-img-wrap {
  text-align: center;
  margin: 8px 0;
}
.docs-img {
  max-width: 260px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.auth-help-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 0 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.auth-help-link:hover { opacity: 0.8; }

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-section label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.member-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.member-item:last-child { border-bottom: 0; }
.member-name {
  flex: 1;
  font-size: 13px;
}
.member-role {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}

.invite-suggestions {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg);
}
.suggestion-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition);
}
.suggestion-item:last-child { border-bottom: 0; }
.suggestion-item:hover, .suggestion-item.active {
  background: var(--panel-hover);
}

/* === SEARCH RESULTS IN SIDEBAR === */
.search-results {
  flex: 1;
  overflow-y: auto;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background var(--transition);
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-family: inherit;
}
.search-result-item:hover { background: var(--panel-hover); }
.search-result-info {
  flex: 1;
  min-width: 0;
}
.search-result-name {
  font-size: 14px;
  font-weight: 500;
}
.search-result-status {
  font-size: 12px;
  color: var(--muted);
}

/* === TOAST === */
.push-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: #1e3a5f;
  color: var(--fg);
  font-size: 13px;
  z-index: 200;
  flex-shrink: 0;
}
.push-banner span { flex: 1; }
.push-banner-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.push-banner-dismiss {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: toastIn 0.25s ease;
  pointer-events: all;
  max-width: 340px;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}

/* === FAB MENU === */
.fab-menu {
  position: absolute;
  bottom: 82px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 6;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}
.fab-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}
.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition);
  white-space: nowrap;
}
.fab-menu-item:hover { background: var(--panel-hover); }
.fab-menu-icon { font-size: 16px; width: 20px; text-align: center; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* === MOBILE === */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    position: relative;
    height: 100dvh;
  }
  .sidebar {
    width: 100%;
    max-width: 100vw;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
  }
  .chat-panel {
    position: fixed;
    inset: 0;
    z-index: 50;
    width: 100%;
    max-width: 100vw;
    height: 100dvh;
    min-height: -webkit-fill-available;
    background: var(--chat-bg);
    display: none;
    overflow-x: hidden;
  }
  .chat-panel.mobile-visible {
    display: flex;
    flex-direction: column;
  }

  .compose-bar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .attachment-preview {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .messages-area {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .hidden-mobile { display: none !important; }
  .back-btn { display: flex !important; }
  .bubble-group { max-width: 85%; }

  .auth-card {
    padding: 30px 24px 24px;
  }

  .modal-overlay {
    padding: 12px;
  }
  .modal {
    max-height: 90vh;
  }

  .settings-panel {
    width: 85%;
  }

  .fab {
    bottom: 16px;
    right: 16px;
  }
}

/* === Settings Page Enhancements === */

.settings-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 12px 20px 4px;
}

.settings-avatar-wrap {
  position: relative;
  display: inline-block;
}

.change-avatar-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--panel);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.settings-toggle-status,
.settings-detail-right {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.settings-chevron {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  transition: transform var(--transition);
}
.settings-chevron.open {
  transform: rotate(180deg);
}

.settings-collapsible {
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.settings-item.sub-item {
  padding-left: 40px;
  font-size: 13px;
}

.settings-profile .profile-detail {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.avatar.has-image {
  background-size: cover;
  background-position: center;
  color: transparent;
}

/* === Storage Modal Styles === */

.storage-bar {
  width: 100%;
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 12px;
}

.storage-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  background: var(--accent);
}
.storage-bar-fill.warn {
  background: #e5ca77;
}
.storage-bar-fill.critical {
  background: var(--danger);
}

.storage-summary {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.storage-breakdown {
  list-style: none;
  padding: 0;
}

.storage-breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.storage-breakdown-item .storage-name {
  color: var(--text);
}

.storage-breakdown-item .storage-size {
  color: var(--muted);
  font-size: 12px;
}

/* === Edit Profile Modal === */

.profile-edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.profile-edit-form label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

.profile-edit-form input {
  margin-bottom: 4px;
}

/* === NOTIFICATION DROPDOWN === */
.notification-badge {
  position: relative;
}
.notification-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 320px;
  max-height: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notification-dropdown.hidden { display: none; }

.notification-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.notification-mark-read {
  font-size: 12px;
  color: var(--accent);
  padding: 2px 6px;
}

.notification-dropdown-list {
  overflow-y: auto;
  flex: 1;
}

.notification-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--line);
}
.notification-row:hover { background: var(--panel-hover); }
.notification-row.unread { background: rgba(43, 82, 120, 0.15); }

.notification-row-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
  margin-top: 1px;
}

.notification-row-body {
  flex: 1;
  min-width: 0;
}
.notification-row-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.35;
}
.notification-row-text strong {
  font-weight: 600;
}
.notification-row-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.notification-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Message highlight animation for jump-to */
@keyframes highlightFlash {
  0% { background: rgba(229, 202, 119, 0.3); }
  100% { background: transparent; }
}
.message-highlight {
  animation: highlightFlash 2s ease-out;
}

@media (max-width: 768px) {
  .notification-dropdown {
    width: calc(100vw - 24px);
    right: -40px;
  }
}

/* === VOICE RECORDING === */
.mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--alt);
  border: none;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  color: var(--text);
  transition: opacity var(--transition), background var(--transition);
}
.mic-btn:hover { opacity: 0.85; }
.mic-btn.recording { background: var(--danger); }
.mic-btn:disabled { opacity: 0.3; pointer-events: none; }

.voice-recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.voice-recording-bar.hidden { display: none; }

.voice-recording-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: voicePulse 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes voicePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.voice-timer {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  min-width: 36px;
}

.voice-cancel-btn {
  color: var(--muted);
  font-size: 18px;
}
.voice-send-btn {
  flex-shrink: 0;
}

.bubble-media-audio.voice-message {
  height: 48px;
  border-radius: 24px;
  background: var(--bg);
  max-width: 260px;
}

/* === SKELETON LOADING === */
.conversation-list.is-loading .conversation-item {
  pointer-events: none;
  position: relative;
  overflow: hidden;
}
.conversation-list.is-loading .conversation-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--panel) 25%,
    var(--panel-hover) 50%,
    var(--panel) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
