:root {
  --bg: #0e1621;
  --bg-secondary: #17212b;
  --bg-tertiary: #242f3d;
  --bg-hover: #2b5278;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --text: #f5f5f5;
  --text-secondary: #8b9aab;
  --text-link: #6ab3f3;
  --accent: #2aabee;
  --accent-hover: #229ed9;
  --online: #4dcd5e;
  --danger: #e53935;
  --border: rgba(255,255,255,0.06);
  --header-h: 56px;
  --composer-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-tertiary: #edeff2;
  --bg-hover: #e3f1fc;
  --bubble-out: #d9f0ff;
  --bubble-in: #f1f2f4;
  --text: #1c1c1e;
  --text-secondary: #707579;
  --text-link: #168acd;
  --accent: #2aabee;
  --accent-hover: #229ed9;
  --online: #35b654;
  --danger: #e53935;
  --border: rgba(0,0,0,0.08);
}
html { transition: background-color 0.2s ease; }
:root[data-theme="light"] .story-viewer-header .header-btn,
:root[data-theme="light"] .story-viewer-name,
:root[data-theme="light"] .story-viewer-time,
:root[data-theme="light"] .story-viewer-caption,
:root[data-theme="light"] .story-viewer-views { color: #fff; }

* { box-sizing: border-box; margin: 0; padding: 0; }
/* Generic hidden utility — several elements only had scoped combos before,
   which silently failed to hide things like the register name field or the
   empty-state placeholder. This is the fallback for all of them. */
.hidden { display: none !important; }
html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

/* ========== HEADER ========== */
.app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  padding-left: 8px;
  padding-right: 8px;
  gap: 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.header-btn {
  width: 42px;
  height: 42px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.header-btn:active { background: rgba(127,127,127,0.18); }
.header-btn.hidden { display: none; }
.header-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 4px;
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}
.header-sub {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  line-height: 1.2;
}
.header-sub.hidden { display: none; }
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--online);
  flex-shrink: 0;
}
.online-dot.off { background: var(--text-secondary); }

/* ========== VIEWS ========== */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.view.active { display: flex; animation: view-fade-in 0.2s ease; }
@keyframes view-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-item, .modal-item, .settings-row, .story-tile { transition: background-color 0.15s ease; }

/* ========== SEARCH ========== */
.search-bar {
  padding: 8px 12px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--text-secondary);
}
.search-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-input-wrap input::placeholder { color: var(--text-secondary); }

/* ========== CHAT LIST ========== */
.chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.chat-item:active { background: var(--bg-tertiary); }
.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.lg { width: 80px; height: 80px; font-size: 28px; }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.chat-item-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chat-item-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.badge.hidden { display: none; }
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: 40px 24px;
  text-align: center;
  gap: 12px;
}
.empty-state p { font-size: 15px; line-height: 1.45; }

/* FAB */
.fab {
  position: absolute;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(42,171,238,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}
.fab:active { background: var(--accent-hover); transform: scale(0.95); }
.fab.hidden { display: none; }
.fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #fff;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}
.chat-item.pickable { cursor: pointer; }
.chat-item.picked { background: var(--bg-tertiary); }
.pick-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-item.picked .pick-check { background: var(--accent); border-color: var(--accent); }

/* ========== CHAT VIEW ========== */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2317212b' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.msg-row {
  display: flex;
  max-width: 85%;
}
.msg-row.out { align-self: flex-end; }
.msg-row.in { align-self: flex-start; }
.bubble {
  padding: 8px 12px 6px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.35;
}
.msg-row.out .bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}
.msg-row.in .bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}
.bubble-text { white-space: pre-wrap; }
.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-secondary);
}
.bubble-file {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.bubble-file a { color: var(--text-link); text-decoration: none; }
.msg-date {
  align-self: center;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 10px;
  margin: 8px 0;
}

/* COMPOSER */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.composer-btn:active { background: rgba(127,127,127,0.18); }
.composer-input-wrap {
  flex: 1;
  background: var(--bg);
  border-radius: 20px;
  padding: 10px 14px;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
}
.composer-input-wrap textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.35;
  max-height: 100px;
}
.composer-input-wrap textarea::placeholder { color: var(--text-secondary); }
.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:not(:disabled):active { background: var(--accent-hover); }

/* ========== SETTINGS / PROFILE ========== */
.settings-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding-bottom: 24px;
}
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  background: var(--bg-secondary);
  gap: 10px;
}
.profile-name { font-size: 22px; font-weight: 600; }
.profile-username { color: var(--text-secondary); font-size: 15px; }
.profile-bio { color: var(--text-secondary); font-size: 14px; text-align: center; max-width: 280px; }
.settings-section {
  margin-top: 12px;
  background: var(--bg-secondary);
}
.settings-section-title {
  padding: 12px 16px 6px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--bg-tertiary); }
.settings-row-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.settings-row-label { flex: 1; font-size: 16px; }
.settings-row-value { color: var(--text-secondary); font-size: 14px; }
.settings-toggle {
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--bg-tertiary);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.settings-toggle.on { background: var(--accent); }
.settings-toggle::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.settings-toggle.on::after { transform: translateX(18px); }
.logout-btn {
  margin: 20px 16px;
  width: calc(100% - 32px);
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: rgba(229,57,53,0.15);
  color: var(--danger);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}
.logout-btn:active { background: rgba(229,57,53,0.25); }

/* ========== AUTH OVERLAY ========== */
#auth-screen {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}
#auth-screen.hidden { display: none; }
.auth-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: linear-gradient(135deg, #2aabee, #229ed9);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: 0 8px 24px rgba(42,171,238,0.35);
}
.auth-logo svg { width: 52px; height: 52px; color: #fff; }
.auth-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-secondary); text-align: center; margin-bottom: 12px; max-width: 280px; line-height: 1.4; }
.auth-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-wizard { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-step { display: none; flex-direction: column; gap: 12px; position: relative; padding-top: 4px; }
.auth-step.active { display: flex; animation: auth-step-in 0.22s cubic-bezier(0.2,0.8,0.2,1); }
@keyframes auth-step-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: translateX(0); } }
.auth-back {
  position: absolute;
  top: -2px;
  left: -2px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
}
.auth-back:active { background: var(--bg-tertiary); }
.auth-step-title { font-size: 15px; font-weight: 600; text-align: center; color: var(--text-secondary); margin-bottom: 2px; }
.auth-input.shake { animation: auth-shake 0.35s; border-color: var(--danger); }
@keyframes auth-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.auth-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.auth-btn:active { background: var(--accent-hover); }
.auth-btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.auth-switch {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  margin-top: 4px;
}
.auth-switch a { color: var(--accent); text-decoration: none; cursor: pointer; }
.auth-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ========== MODALS ========== */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; animation: overlay-fade-in 0.18s ease; }
@keyframes overlay-fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.open .modal-sheet { animation: sheet-slide-up 0.22s cubic-bezier(0.2,0.8,0.2,1); }
@keyframes sheet-slide-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal-sheet {
  background: var(--bg-secondary);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80%;
  overflow-y: auto;
  padding: 12px 0 calc(16px + var(--safe-bottom));
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: rgba(127,127,127,0.35);
  border-radius: 2px;
  margin: 0 auto 12px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  padding: 0 20px 12px;
}
.modal-list { list-style: none; }
.modal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
}
.modal-item:active { background: var(--bg-tertiary); }
.modal-item .avatar { width: 44px; height: 44px; font-size: 16px; }

/* ---- generic prompt/confirm dialog (center card, replaces prompt()/confirm()/alert()) ---- */
#dialog-modal { align-items: center; padding: 20px; }
.modal-card {
  background: var(--bg-secondary);
  border-radius: 16px;
  width: 100%;
  max-width: 340px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: modal-card-in 0.18s cubic-bezier(0.2,0.8,0.2,1);
}
@keyframes modal-card-in {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.modal-card-message { font-size: 14.5px; color: var(--text-secondary); line-height: 1.4; margin-bottom: 4px; white-space: pre-line; }
.modal-card-message:empty { display: none; }
.modal-card-input {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
}
.modal-card-input:focus { outline: none; border-color: var(--accent); }
.modal-card-input.hidden { display: none; }
.modal-card-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}
.modal-card-error.hidden { display: none; }
.modal-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-card-btn {
  padding: 9px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.modal-card-btn:active { background: var(--accent-hover); }
.modal-card-btn.secondary { background: transparent; color: var(--text-secondary); }
.modal-card-btn.secondary:active { background: var(--bg-tertiary); }
.modal-card-btn.danger { background: var(--danger); }


/* ========== BOTTOM NAV (Telegram-like) ========== */
.bottom-nav {
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  z-index: 15;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 0 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 24px; height: 24px; }

/* ========== NEW CHAT PANEL ========== */
#view-newchat .user-list {
  flex: 1;
  overflow-y: auto;
}

/* lightbox */
#lightbox {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
}
#lightbox.open { display: flex; }
#lightbox img {
  max-width: 95%;
  max-height: 90%;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* typing */
.typing-indicator {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 0 16px 4px;
  min-height: 18px;
}
.edit-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  color: var(--accent);
}
.edit-banner.hidden { display: none; }
.edit-banner-icon { flex-shrink: 0; display: flex; }
.edit-banner-text { flex: 1; font-size: 13.5px; font-weight: 500; }
.edit-banner-cancel {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  padding: 4px;
}
.msg-sender-name {
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--accent);
}
.bubble-edited {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.8;
}
.read-ticks { display: inline-flex; margin-left: 2px; vertical-align: middle; }
.read-ticks.read svg { color: #4fc3f7; }

/* scrollbar thin */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(127,127,127,0.25); border-radius: 2px; }

@media (min-width: 720px) {
  #app { max-width: 480px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* SigmaChat 4.0 additions */
.voice-btn.recording {
  color: #ff5c68;
  background: rgba(255,92,104,.14);
  animation: pulse-record 1.15s infinite;
}
@keyframes pulse-record {
  50% { transform: scale(1.08); }
}
.voice-message { display:flex; align-items:center; gap:8px; min-width:220px; }
.voice-message audio { width:190px; height:38px; }
.nav-item.hidden { display:none; }

.admin-scroll { flex:1; overflow-y:auto; -webkit-overflow-scrolling:touch; padding-bottom:calc(24px + var(--safe-bottom)); }
.admin-hero { display:flex; align-items:center; gap:14px; padding:20px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border); }
.admin-badge { width:48px; height:48px; border-radius:14px; display:grid; place-items:center; background:var(--bg-tertiary); font-size:25px; }
.admin-title { font-size:19px; font-weight:700; }
.admin-sub { color:var(--text-secondary); margin-top:3px; font-size:13px; }
.admin-stats { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; padding:12px; }
.admin-stat { background:var(--bg-secondary); border:1px solid var(--border); border-radius:12px; padding:10px; display:flex; gap:8px; align-items:center; min-width:0; }
.admin-stat-icon { font-size:19px; }
.admin-stat b { display:block; font-size:16px; }
.admin-stat span { display:block; color:var(--text-secondary); font-size:11px; white-space:nowrap; }
.admin-section { margin:0 12px; background:var(--bg-secondary); border-radius:12px; overflow:hidden; }
.admin-section-head { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px; border-bottom:1px solid var(--border); font-weight:600; }
.admin-search { width:150px; border:0; outline:0; background:var(--bg); color:var(--text); border-radius:10px; padding:8px 10px; }
.admin-user { display:flex; align-items:center; gap:10px; padding:10px 12px; border-bottom:1px solid var(--border); }
.admin-user:last-child { border-bottom:0; }
.admin-user-main { flex:1; min-width:0; }
.admin-user-main b,.admin-user-main span { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.admin-user-main span { color:var(--text-secondary); font-size:12px; margin-top:2px; }
.admin-actions { display:flex; gap:5px; }
.admin-action { border:0; border-radius:8px; padding:7px 9px; font-size:12px; cursor:pointer; color:#fff; }
.admin-action.info { background: #6b7785; }
.admin-action.ban { background:rgba(229,57,53,.9); }
.admin-action.unban { background:rgba(77,205,94,.8); }
.nav-admin-icon { font-size:17px; line-height:1; }

@media (min-width: 800px) {
  #app { max-width: 1100px; box-shadow:0 0 0 1px var(--border),0 12px 50px rgba(0,0,0,.25); }
  .view { max-width:760px; width:100%; margin:0 auto; }
  .app-header { max-width:1100px; margin:0 auto; width:100%; }
  .bottom-nav { max-width:760px; margin:0 auto; width:100%; }
  .chat-list { padding:0 6px; }
  .chat-item { border-radius:10px; border-bottom:0; margin:1px 0; }
  .messages { padding-left:24px; padding-right:24px; }
  .composer { padding-left:18px; padding-right:18px; }
  .settings-scroll,.admin-scroll { width:100%; }
}
@media (max-width: 380px) {
  .chat-item { padding-left:10px; padding-right:10px; gap:9px; }
  .avatar { width:48px; height:48px; }
  .composer { gap:3px; padding-left:5px; padding-right:5px; }
  .composer-btn,.send-btn { width:38px; height:38px; }
  .voice-message { min-width:190px; }
  .voice-message audio { width:160px; }
  .admin-stats { grid-template-columns:repeat(2,1fr); }
}
@supports (padding: max(0px)) {
  .app-header { padding-left:max(8px, env(safe-area-inset-left)); padding-right:max(8px, env(safe-area-inset-right)); }
  .composer { padding-left:max(10px, env(safe-area-inset-left)); padding-right:max(10px, env(safe-area-inset-right)); }
}

/* ========== STORIES BAR (on Chats screen) ========== */
.stories-bar {
  display: flex;
  gap: 4px;
  padding: 10px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 110px;
  opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
}
.stories-bar.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-color: transparent;
  overflow: hidden;
}
.stories-bar.empty { display: none; }
.stories-bar::-webkit-scrollbar { display: none; }
.story-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 68px;
  flex-shrink: 0;
  cursor: pointer;
  text-align: center;
}
.story-ring {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 2.5px;
  background: linear-gradient(135deg, #2aabee, #a695e7 45%, #ee7aae 90%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}
.story-ring.viewed { background: var(--bg-tertiary); }
.story-ring.no-story { background: transparent; }
.story-ring .avatar {
  width: 100%;
  height: 100%;
  border: 2.5px solid var(--bg-secondary);
  font-size: 16px;
}
.story-ring .story-plus {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.story-tile-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  max-width: 66px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.story-tile.mine .story-tile-label { color: var(--text); }

/* ========== STORIES GRID (full screen) ========== */
.stories-grid-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 14px 6px;
  padding: 16px 12px calc(20px + var(--safe-bottom));
}
.stories-grid .story-tile { width: 100%; }
.stories-grid .story-ring { width: 68px; height: 68px; margin: 0 auto; }

/* ========== STORY VIEWER ========== */
#story-viewer {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 90;
  display: none;
  flex-direction: column;
}
#story-viewer.open { display: flex; }
.story-progress {
  display: flex;
  gap: 4px;
  padding: calc(8px + var(--safe-top)) 10px 0;
  flex-shrink: 0;
}
.story-progress-seg {
  flex: 1;
  height: 2.5px;
  border-radius: 2px;
  background: rgba(255,255,255,0.3);
  overflow: hidden;
}
.story-progress-seg-fill {
  height: 100%;
  width: 0%;
  background: #fff;
}
.story-progress-seg.done .story-progress-seg-fill { width: 100%; transition: none; }
.story-progress-seg.active .story-progress-seg-fill { transition: width linear; }
.story-viewer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  flex-shrink: 0;
  color: #fff;
}
.story-viewer-header .avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.story-viewer-meta { flex: 1; min-width: 0; }
.story-viewer-name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-viewer-time { font-size: 12px; color: rgba(255,255,255,0.65); }
.story-viewer-header .header-btn { color: #fff; }
.story-viewer-media {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
  padding-bottom: 48px; /* visually centers the media a bit higher, away from the caption/views strip */
}
.story-viewer-media img, .story-viewer-media video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.story-viewer-caption {
  color: #fff;
  text-align: center;
  padding: 10px 20px calc(18px + var(--safe-bottom));
  font-size: 14.5px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  flex-shrink: 0;
}
.story-viewer-caption.hidden { display: none; }
.story-viewer-views {
  color: rgba(255,255,255,0.75);
  text-align: center;
  font-size: 12.5px;
  padding-bottom: 6px;
  flex-shrink: 0;
}
.story-viewer-views.hidden { display: none; }
.story-viewer-views.clickable { cursor: pointer; }
.story-nav-zone {
  position: absolute;
  top: 60px;
  bottom: 60px;
  width: 33%;
  cursor: pointer;
  z-index: 1;
}
.story-nav-zone.left { left: 0; }
.story-nav-zone.right { right: 0; }
#story-mute-slash { display: none; }
.header-btn.muted #story-mute-slash { display: block; }
.header-btn.muted #story-mute-waves { opacity: 0.35; }

/* ========== AVATAR EDIT (settings) ========== */
.avatar-edit-wrap { position: relative; display: inline-flex; cursor: pointer; }
.avatar-edit-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== PROFILE VIEW (other users) ========== */
.profile-online-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text-secondary);
}
.profile-msg-btn { max-width: 260px; margin-top: 6px; }

/* clickable header for opening a peer's profile */
.header-center.clickable { cursor: pointer; }

/* ========== VIDEO MESSAGES ========== */
.bubble-video {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.bubble-video video {
  max-width: 240px;
  max-height: 320px;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}
.bubble-video::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 4px -22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center/20px no-repeat;
  pointer-events: none;
}

/* lightbox video support */
#lightbox video { max-width: 95%; max-height: 90%; border-radius: 4px; display: none; }

/* ========== MODAL DANGER ITEM ========== */
.modal-item.danger { color: var(--danger); }
.modal-item.danger .settings-row-icon { color: var(--danger); }
.modal-item span { font-size: 15.5px; }
.member-role-tag { color: var(--accent); font-weight: 500; }
.member-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  font-size: 14px;
  flex-shrink: 0;
  margin-left: 6px;
}
.member-action-btn.danger { color: var(--danger); }
.member-action-btn:active { background: var(--border); }

/* long-press feedback on own bubbles */
.msg-row.out .bubble { cursor: pointer; }
.msg-row.in .bubble { cursor: pointer; }

/* ========== TOAST ========== */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  background: rgba(30,30,30,0.95);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 80%;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
