/* ── Modals ────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75); z-index: 1000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--gray-900); border: 3px solid var(--white);
  width: 100%; max-width: 440px; max-height: 80vh;
  overflow-y: auto; box-shadow: var(--shadow-modal);
  animation: modal-enter 300ms ease;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--white); color: var(--black);
}
.modal-head h3 {
  font-family: var(--font-display); font-size: 1.1rem; font-weight: 900;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.modal-head button {
  background: none; border: none; color: var(--black);
  font-size: 1.4rem; cursor: pointer; padding: 4px; line-height: 1;
}
.modal-head button:hover { color: var(--accent); }

.modal-search {
  display: block; width: calc(100% - 48px); margin: 16px 24px;
  padding: 12px 14px; background: var(--gray-800);
  border: 2px solid var(--gray-600); color: var(--white);
  font-family: var(--font-mono); font-size: 0.75rem;
  letter-spacing: 0.05em; outline: none;
}
.modal-search::placeholder { color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.1em; }
.modal-search:focus { border-color: var(--accent); }

.modal-form {
  padding: 20px 24px; display: flex; flex-direction: column; gap: 14px;
}
.modal-form input, .modal-form textarea {
  width: 100%; padding: 12px 14px;
  background: var(--gray-800); border: 2px solid var(--gray-600);
  color: var(--white); font-family: var(--font-body); font-size: 0.85rem;
  outline: none; resize: none; transition: border-color var(--transition-fast);
}
.modal-form input::placeholder, .modal-form textarea::placeholder { color: var(--gray-500); }
.modal-form input:focus, .modal-form textarea:focus { border-color: var(--accent); }

.user-list { max-height: 280px; overflow-y: auto; }
.user-list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; cursor: pointer;
  border-bottom: 1px solid var(--gray-800);
  transition: background var(--transition-fast);
}
.user-list-item:hover { background: var(--gray-800); }
.user-list-item .avatar { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.user-list-item span { font-size: 0.85rem; font-weight: 500; }
.user-list-item input[type="checkbox"] { margin-left: auto; accent-color: var(--accent); }
.friend-add-btn {
  margin-left: auto;
  padding: 5px 14px; background: var(--accent); border: none;
  color: var(--white); font-family: var(--font-mono);
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  cursor: pointer; transition: all var(--transition-fast);
}
.friend-add-btn:hover { background: var(--accent-dim); }

.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.sel-tag {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: var(--accent-bg);
  border: 1px solid var(--accent);
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600;
  color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em;
}
.sel-tag button {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 0.85rem; padding: 0; line-height: 1;
}

.primary-btn {
  padding: 16px 24px; background: var(--accent); border: none;
  color: var(--white); font-family: var(--font-mono);
  font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  cursor: pointer; transition: all var(--transition-fast);
}
.primary-btn:hover { background: var(--accent-dim); }

/* ── Image Viewer ──────────────────────────────── */
.image-viewer { cursor: zoom-out; background: rgba(0, 0, 0, 0.92); }
.image-viewer img { max-width: 90vw; max-height: 90vh; object-fit: contain; border: 3px solid var(--white); }

/* ── Emoji Picker (reaction - small) ──────────── */
.emoji-picker {
  display: none; position: fixed;
  background: var(--gray-800); border: 2px solid var(--white);
  padding: 6px; gap: 2px; z-index: 1001; box-shadow: var(--shadow-hard);
}
.emoji-picker.open { display: flex; }
.emoji-picker button {
  background: none; border: none; font-size: 1.2rem;
  padding: 6px 8px; cursor: pointer; line-height: 1;
  transition: background var(--transition-fast);
}
.emoji-picker button:hover { background: var(--gray-700); }

/* ── Full Emoji Picker (chat input) ───────────── */
.full-emoji-picker {
  display: none; position: fixed;
  bottom: 80px; right: 20px;
  width: 340px; max-height: 360px;
  background: var(--gray-800); border: 2px solid var(--white);
  box-shadow: var(--shadow-modal); z-index: 1001;
  flex-direction: column;
}
.full-emoji-picker.open { display: flex; }
.emoji-picker-header {
  padding: 10px; border-bottom: 1px solid var(--gray-700);
}
.emoji-picker-header input {
  width: 100%; padding: 8px 10px;
  background: var(--gray-700); border: 1px solid var(--gray-600);
  color: var(--white); font-family: var(--font-mono); font-size: 0.75rem;
  outline: none;
}
.emoji-picker-header input:focus { border-color: var(--accent); }
.emoji-picker-header input::placeholder { color: var(--gray-500); }
.emoji-cats {
  display: flex; gap: 2px; margin-top: 6px; flex-wrap: wrap;
}
.emoji-cats button {
  background: none; border: none; padding: 4px 6px;
  font-size: 0.9rem; cursor: pointer; color: var(--gray-400);
  transition: all var(--transition-fast); border-radius: 0;
}
.emoji-cats button:hover, .emoji-cats button.active { background: var(--gray-700); color: var(--white); }
.emoji-grid {
  padding: 8px; overflow-y: auto; flex: 1;
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 2px; max-height: 260px;
}
.emoji-grid button {
  background: none; border: none; padding: 6px;
  font-size: 1.2rem; cursor: pointer; line-height: 1;
  transition: background var(--transition-fast);
  display: flex; align-items: center; justify-content: center;
}
.emoji-grid button:hover { background: var(--gray-700); }

/* ── Mention Autocomplete ──────────────────────── */
.mention-dropdown {
  display: none; position: fixed;
  background: var(--gray-800); border: 2px solid var(--white);
  box-shadow: var(--shadow-hard); z-index: 1001;
  max-height: 200px; overflow-y: auto; min-width: 200px;
}
.mention-dropdown.open { display: block; }
.mention-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--gray-700);
  font-size: 0.85rem; font-weight: 500;
  transition: background var(--transition-fast);
}
.mention-option:hover, .mention-option.selected { background: var(--accent); color: var(--white); }

/* ── Context Menu ──────────────────────────────── */
.context-menu {
  display: none; position: fixed;
  background: var(--gray-800); border: 2px solid var(--white);
  z-index: 1002; box-shadow: var(--shadow-hard); min-width: 140px;
}
.context-menu.open { display: block; }
.context-menu button {
  display: block; width: 100%; padding: 12px 16px;
  background: none; border: none; border-bottom: 1px solid var(--gray-700);
  color: var(--white); font-family: var(--font-mono);
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.15em;
  text-align: left; cursor: pointer; transition: all var(--transition-fast);
}
.context-menu button:last-child { border-bottom: none; }
.context-menu button:hover { background: var(--accent); color: var(--white); }

/* ── Bottom Nav (mobile) ───────────────────────── */
.bottom-nav {
  display: none; grid-column: 1 / -1; grid-row: 4;
  background: var(--gray-900); border-top: 3px solid var(--white);
  /* WeChat-style slide-down when sub-sections are open */
  transition:
    transform 0.32s cubic-bezier(0.32, 0.72, 0.4, 1),
    max-height 0.32s cubic-bezier(0.32, 0.72, 0.4, 1),
    border-top-width 0.32s cubic-bezier(0.32, 0.72, 0.4, 1);
  transform: translateY(0);
  max-height: 90px;
  overflow: hidden;
  will-change: transform, max-height;
}
.bottom-nav.nav-hidden {
  transform: translateY(100%);
  max-height: 0;
  border-top-width: 0;
  pointer-events: none;
}
.app.has-server-rail .bottom-nav { grid-column: 2 / -1; }
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 8px 0;
  background: none; border: none; border-right: 1px solid var(--gray-700);
  color: var(--gray-500); font-family: var(--font-mono);
  font-size: 0.55rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  cursor: pointer; transition: all var(--transition-fast);
}
.bottom-nav-item:last-child { border-right: none; }
.bottom-nav-item:hover, .bottom-nav-item.active { color: var(--white); background: var(--gray-800); }
.bottom-nav-item.active { color: var(--accent); border-top: 2px solid var(--accent); }

/* ── Mobile ────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { height: 52px; }
  .nav-logo { padding: 0 16px; padding-right: 30px; }
  .nav-logo span { font-size: 1.4rem; }
  .nav-logo em { font-size: 0.6rem; margin-left: 4px; }
  .nav-links { display: none; }
  .nav-user { display: none; }
  .nav-search.open { width: 140px; }
  .search-results { right: 48px; width: 260px; top: 52px; }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }
  .app.has-server-rail { grid-template-columns: 1fr; }
  .app.has-server-rail.server-view { grid-template-columns: 1fr; }
  .app.has-server-rail.server-view.server-members-open { grid-template-columns: 1fr; }
  .app.members-open { grid-template-columns: 1fr; }
  .app.full-width .app-section {
    max-width: none; border-left: none;
  }

  /* Mobile: server rail is a horizontal bar at top when no chat is open */
  .server-rail {
    flex-direction: row;
    grid-row: auto;
    border-right: none;
    border-bottom: 2px solid var(--gray-700);
    padding: 6px 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .server-rail-divider { width: 2px; height: 32px; margin: 0 4px; }
  .server-rail-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .server-rail-btn, .server-icon { width: 40px; height: 40px; font-size: 0.9rem; }

  .channel-sidebar {
    border-right: none;
    grid-row: auto;
  }
  .app.has-server-rail.server-view .server-rail { display: flex; }
  .app.has-server-rail.server-view .channel-sidebar { display: flex; }
  .app.has-server-rail.server-view .app-section { display: none; }
  .app.has-server-rail.server-view .bottom-nav { display: none; }
  .app.has-server-rail.server-view.chat-view .server-rail { display: none; }
  .app.has-server-rail.server-view.chat-view .channel-sidebar { display: none; }
  .app.has-server-rail.server-view.chat-view .chat { display: flex; }

  .server-members-panel {
    position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    z-index: 500;
  }
  .friends-items { grid-template-columns: 1fr; }
  .stories-feed { grid-template-columns: 1fr; }
  .settings-body { max-width: none; }

  .app-section { display: flex; border-right: none; }
  .chat { display: none; }
  .app.chat-view .app-section { display: none; }
  .app.chat-view .chat { display: flex; }
  .app.chat-view .bottom-nav { display: none; }
  .back-btn { display: block; }

  .members-panel {
    position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    z-index: 500; display: none;
  }
  .app.members-open .members-panel { display: flex; }

  .conv-delete { display: block; }

  .full-emoji-picker { left: 10px; right: 10px; width: auto; bottom: 70px; }
}

@media (max-width: 480px) {
  .auth-card { width: 100%; }
  .modal { max-width: 100%; }
  .chat-header { padding: 0 14px; }
  .chat-input { padding: 10px 14px; }
  .messages { padding: 8px 2px; }
}

/* ── PWA Install Banner ──────────────────────────────── */
#pwa-install-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 99999;
  background: var(--gray-800, #1a1a1a); border-top: 2px solid var(--accent, #ff3d00);
  padding: 12px 16px; animation: pwa-slide-up .3s ease;
}
@keyframes pwa-slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.pwa-install-content {
  display: flex; align-items: center; gap: 12px; max-width: 600px; margin: 0 auto;
}
.pwa-install-icon { width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; }
.pwa-install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.pwa-install-text strong { color: var(--white, #fff); font-size: 15px; }
.pwa-install-text span { color: var(--gray-400, #999); font-size: 13px; }
#pwa-install-btn {
  background: var(--accent, #ff3d00); color: #fff; border: none; padding: 8px 20px;
  border-radius: 6px; font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
}
#pwa-install-btn:hover { opacity: .85; }
#pwa-install-dismiss {
  background: none; border: none; color: var(--gray-500, #666); font-size: 22px;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}
#pwa-install-dismiss:hover { color: var(--white, #fff); }

/* Universal NOID loader — square outline with a smooth orange "snake" segment */
.noid-loader { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.noid-loader .nl-track { stroke: var(--gray-700); }
.noid-loader .nl-snake {
  stroke: var(--accent);
  stroke-dasharray: 22 78;
  stroke-dashoffset: 0;
  animation: noid-snake 1.2s linear infinite;
}
@keyframes noid-snake { to { stroke-dashoffset: -100; } }
/* Standalone loader inside the message stream (no bubble wrap, same height as a 1-line bubble so it aligns with avatar) */
.msg-decrypting {
  display: flex; align-items: center;
  min-height: 42px; padding: 0 4px;
}
.msg-wrap.own .msg-decrypting { justify-content: flex-end; }
/* ── Voice/audio pill height reservation (CSS only — no audio/voice JS change) ──
   A voice memo first detects as audio (~42px loader/pill) then upgrades to the
   taller .msg-voice-wrap (~56px). Reserve the taller height on BOTH the decrypt
   placeholder AND the cached pills so the audio→voice upgrade never grows the
   message above the read line. box-sizing:border-box makes min-height the TOTAL
   height regardless of the global box model. */
.msg-decrypting[data-file-type="audio"],
.msg-decrypting[data-file-type="voice"] { min-height: 56px; }
.msg-audio-wrap,
.msg-voice-wrap { min-height: 56px; box-sizing: border-box; }
/* Generic centered loader for any list/section that's still loading */
.list-loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; height: 100%; width: 100%; padding: 20px;
  /* span full width inside grid parents (Friends, etc.) so the loader
     lands at the visual center, not in column 1 of a tracks-layout */
  grid-column: 1 / -1;
}
/* Decrypt failure message (shown instead of an endless loader when decrypt fails) */
.msg-decrypt-failed {
  display: flex; align-items: center;
  min-height: 42px;
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--danger);
  padding: 0 14px; border: 1px dashed var(--danger);
  background: rgba(211, 47, 47, 0.06);
}


.apps-grid-empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 240px;
}
.apps-coming-soon {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  font-weight: 800; letter-spacing: 0.02em;
  color: var(--text, #f5f5f0); opacity: 0.55;
  text-transform: uppercase;
}


/* ── In-app sandboxed document viewer (.html/.md/.txt) ─────────────────── */
.doc-viewer-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.doc-viewer-overlay[hidden] { display: none; }
.doc-viewer-sheet { width: 100%; max-width: 560px; height: 88vh; max-height: 88vh; margin: 0 auto;
  background: var(--gray-900); border: 3px solid var(--white);
  display: flex; flex-direction: column; overflow: hidden; }
.doc-viewer-bar { display: flex; align-items: center; gap: 10px; height: 52px; flex-shrink: 0;
  padding: 0 12px; border-bottom: 3px solid var(--white); background: var(--gray-900); }
.doc-viewer-badge { font-family: var(--font-mono); font-size: 0.58rem; letter-spacing: 0.08em;
  color: var(--accent); border: 1px solid var(--accent); padding: 2px 6px; white-space: nowrap; }
.doc-viewer-title { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 0.72rem;
  color: var(--gray-300); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-viewer-dl, .doc-viewer-close { background: none; border: none; color: var(--white);
  font-size: 1rem; cursor: pointer; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.doc-viewer-dl:hover, .doc-viewer-close:hover { color: var(--accent); }
.doc-viewer-frame { flex: 1; width: 100%; border: none; background: var(--gray-900); }
@media (max-width: 600px) { .doc-viewer-sheet { height: 100vh; max-height: 100vh; max-width: 100%; border: none; } }

/* ── NoidSharePicker — the shared send-to-chats sheet (2026-06-12) ──
   One picker for every share surface (Bible quotes, Notes snapshots, …).
   Flat design law: sharp corners, 2px borders, accent orange only. */
.nsp-overlay { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.nsp-sheet { width: 100%; max-height: 78vh; display: flex; flex-direction: column; background: var(--gray-900); border-top: 2px solid var(--white); }
.nsp-head { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; text-transform: uppercase; color: var(--white); padding: 14px 16px 10px; }
.nsp-preview { margin: 0 16px 10px; border: 1px solid var(--gray-700); border-left: 3px solid var(--accent); background: var(--gray-800); padding: 10px 12px; max-height: 120px; overflow: hidden; }
.nsp-hint { font-family: var(--font-mono); font-size: 0.55rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gray-500); padding: 0 16px 10px; }
.nsp-search { padding: 0 16px 10px; }
.nsp-search input { width: 100%; height: 36px; background: var(--gray-800); border: 2px solid var(--gray-700); color: var(--gray-300); outline: none; padding: 0 10px; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em; }
.nsp-search input::placeholder { color: var(--gray-500); letter-spacing: 0.08em; }
.nsp-list { flex: 1; min-height: 120px; overflow-y: auto; border-top: 1px solid var(--gray-700); }
.nsp-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--gray-800); padding: 11px 16px; cursor: pointer; color: inherit; }
.nsp-row:active { background: var(--gray-800); }
.nsp-av { width: 34px; height: 34px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border: 2px solid var(--gray-500); background: var(--gray-800); color: var(--white); font-family: var(--font-display); font-weight: 700; font-size: 0.85rem; }
.nsp-av.grp { border-color: var(--gray-400); }
.nsp-name { flex: 1; min-width: 0; font-family: var(--font-display); font-weight: 600; font-size: 0.8rem; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nsp-type { font-family: var(--font-mono); font-size: 0.45rem; font-weight: 700; letter-spacing: 0.1em; color: var(--gray-500); }
.nsp-check { width: 18px; height: 18px; flex-shrink: 0; border: 2px solid var(--gray-600); }
.nsp-row.on .nsp-check { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--gray-900); }
.nsp-row.on .nsp-name { color: var(--accent); }
.nsp-empty { font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gray-500); text-align: center; padding: 34px 16px; }
.nsp-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 2px solid var(--gray-700); }
.nsp-e2ee { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 0.55rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gray-400); }
.nsp-send { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; background: var(--accent); color: #fff; border: none; padding: 11px 18px; cursor: pointer; }
.nsp-send:disabled { background: var(--gray-700); color: var(--gray-500); cursor: default; }
.nsp-comment { padding: 0 16px 10px; }
.nsp-comment textarea { width: 100%; background: var(--gray-800); border: 2px solid var(--gray-700); color: var(--white); outline: none; padding: 8px 10px; font-family: var(--font-body); font-size: 0.8rem; resize: none; }
.nsp-comment textarea::placeholder { color: var(--gray-500); font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; }
.nsp-comment textarea:focus { border-color: var(--gray-500); }

/* ── NoidShare grouped destination sheet (ix-share-router 2026-06-12) ── */
.nsh-group { border-top: 1px solid var(--gray-800); }
.nsh-group:first-child { border-top: none; }
.nsh-group-head { font-family: var(--font-mono); font-size: 0.5rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gray-500); padding: 11px 16px 5px; background: var(--gray-900); position: sticky; top: 0; }
.nsp-av.ic { font-size: 1rem; }
.nsh-plus { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; color: var(--accent); line-height: 1; }
.nsh-emoji { font-size: 1.05rem; }
.nsp-e2ee.warn { color: var(--accent); }

.context-menu button:active { background: var(--accent); color: var(--white); }
