/* ============================================================
   SignalLine — design tokens
   Palette: near-black charcoal-blue base, amber signal accent,
   cyan secondary status. Inspired by fiber-optic instrument
   panels: signal bars, ping readouts, connection states.
   ============================================================ */

:root {
  --bg: #0b0f14;
  --panel: #111823;
  --panel-raised: #151e2b;
  --border: #1e2a38;
  --border-soft: #182230;
  --text: #e7eef5;
  --text-muted: #7c93a8;
  --text-dim: #4b5d70;

  --amber: #ffb454;
  --amber-dim: #8a6431;
  --cyan: #5fd4d0;
  --cyan-dim: #2f6f6c;
  --red: #ff6b6b;
  --green: #4ade80;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --shadow-panel: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* Only the chat page needs the whole page locked (so only its internal
   panels scroll, keeping the composer pinned) — login/admin pages rely on
   normal page scrolling and must NOT have this applied. */
body.chat-page-body {
  overflow: hidden;
}

body {
  background-image:
    radial-gradient(circle at 15% 10%, rgba(255, 180, 84, 0.06), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(95, 212, 208, 0.06), transparent 40%);
}

a { color: inherit; }

::selection { background: var(--amber); color: #101010; }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

button, input {
  font-family: inherit;
  color: inherit;
}

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

/* ---------- Signal mark (shared logo element) ---------- */
.signal-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
}
.signal-mark span {
  width: 4px;
  border-radius: 2px;
  background: var(--amber);
  display: block;
}
.signal-mark span:nth-child(1) { height: 6px;  background: var(--cyan); }
.signal-mark span:nth-child(2) { height: 11px; background: var(--cyan); }
.signal-mark span:nth-child(3) { height: 16px; }
.signal-mark span:nth-child(4) { height: 20px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}
.brand .dot { color: var(--amber); }

/* ============================================================
   AUTH PAGE
   ============================================================ */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--panel-raised), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  padding: 36px 32px 28px;
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), var(--cyan), transparent);
  opacity: 0.8;
}

.auth-header {
  margin-bottom: 28px;
}

.auth-header .brand { margin-bottom: 10px; }

.auth-header h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0 0 6px;
  font-weight: 600;
}

.auth-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 0.92rem;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(255, 180, 84, 0.12);
  outline: none;
}

.field input::placeholder { color: var(--text-dim); }

.btn-primary {
  width: 100%;
  background: var(--amber);
  color: #14100a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
  margin-top: 6px;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-toggle {
  margin-top: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-toggle button {
  background: none;
  border: none;
  color: var(--cyan);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.error-banner {
  display: none;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.82rem;
  margin-bottom: 16px;
}
.error-banner.visible { display: block; }

.auth-footnote {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
}

/* ============================================================
   CHAT PAGE
   ============================================================ */
.chat-shell {
  height: 100vh;
  height: 100dvh; /* accounts for mobile browser chrome (address bar) */
  height: calc(var(--app-height, 100vh)); /* JS fallback for older WebViews */
  display: flex;
  flex-direction: column;
  position: relative; /* anchors the info-drawer */
}

/* ---- Compact header (avatar + title/subtitle + actions), like a WhatsApp chat header ---- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
  position: relative; /* anchors the more-menu popover */
}

.header-info-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  min-width: 0;
  flex: 1;
  text-align: left;
}
.header-info-btn:hover { background: rgba(255, 255, 255, 0.04); }

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  flex-shrink: 0;
  padding-bottom: 8px;
}
.header-avatar span { width: 3px; }

.header-avatar.is-user-avatar {
  align-items: center;
  padding-bottom: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: #101010;
  background-size: cover;
  background-position: center;
}

.header-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.header-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.98rem;
}

.header-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 4px;
  transition: background 0.2s ease;
}
.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}
.status-dot.offline { background: var(--red); }

.header-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
}
.header-icon-btn:hover { color: var(--cyan); background: rgba(95, 212, 208, 0.08); }

/* ---- overflow "more" menu (admin panel / sign out) ---- */
.more-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 12px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  flex-direction: column;
  padding: 6px;
  min-width: 170px;
  z-index: 40;
}

.more-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.86rem;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  width: 100%;
}
.more-menu-item:hover { background: var(--panel); }
#logoutBtn.more-menu-item:hover { color: var(--red); }

/* ---- Member drawer (slides in from the right) ---- */
.info-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 45;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}
.info-drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.info-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 46;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  box-shadow: var(--shadow-panel);
}
.info-drawer.open {
  transform: translateX(0);
}

.info-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border-soft);
}
.info-drawer-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0;
  font-weight: 600;
}

.drawer-close-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}
.drawer-close-btn:hover { border-color: var(--red); color: var(--red); }

.info-drawer-section {
  padding: 14px 18px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.info-drawer-section h4 {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 500;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 0.86rem;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: #101010;
  flex-shrink: 0;
}

.avatar.avatar-img {
  display: block;
  object-fit: cover;
  background: var(--panel-raised);
}

.avatar-edit-btn {
  position: relative;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 8px;
}

.avatar-edit-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  color: #06222a;
  display: grid;
  place-items: center;
  border: 2px solid var(--panel);
}

.avatar-edit-btn:hover .avatar-edit-badge {
  background: var(--amber);
}

.user-row .dot-online {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  margin-left: auto;
  flex-shrink: 0;
}
.user-row .dot-online.offline {
  background: var(--text-dim);
}

.user-row-clickable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding-left: 8px;
  padding-right: 8px;
  margin: 0 -8px;
  transition: background 0.12s ease;
}
.user-row-clickable:hover {
  background: var(--panel-raised);
}
.user-row-clickable.active-dm {
  background: rgba(255, 180, 84, 0.1);
}

.member-list-empty {
  color: var(--text-dim);
  font-size: 0.82rem;
  padding: 8px 0;
}

.drawer-room-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 12px;
  margin-bottom: 16px;
  cursor: pointer;
  text-align: left;
}
.drawer-room-link:hover {
  border-color: var(--cyan-dim);
  background: rgba(95, 212, 208, 0.06);
}

.drawer-room-icon {
  width: 26px;
  height: 18px;
  border-radius: 6px;
  background: var(--panel);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding-bottom: 3px;
  flex-shrink: 0;
}
.drawer-room-icon span { width: 2px; }

.info-drawer-footer {
  padding: 14px 18px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
}

.me-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  min-width: 0;
  color: var(--text-muted);
}

.me-tag span:not(.avatar) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Main chat column ---- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; /* flex item — without this it can grow past its track */
  flex: 1;
  background: var(--bg);
}

.messages {
  flex: 1;
  min-height: 0; /* the key fix — lets this child actually respect the flex container's space instead of growing to fit all messages */
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  gap: 10px;
  padding: 3px 0;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.msg-row.self {
  justify-content: flex-end;
}

.msg-row .avatar { margin-top: 2px; flex-shrink: 0; }

.msg-body {
  position: relative;
  min-width: 0;
  max-width: 74%;
  background: var(--panel-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 7px 12px 9px;
}

.msg-row.self .msg-body {
  background: rgba(255, 180, 84, 0.1);
  border-color: var(--amber-dim);
}

@media (max-width: 640px) {
  .msg-body { max-width: 84%; }
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.msg-row.self .msg-meta {
  justify-content: flex-end;
}

.msg-username {
  font-weight: 600;
  font-size: 0.86rem;
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
}

.msg-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.system-line {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 6px 0;
  letter-spacing: 0.02em;
}
.system-line .join { color: var(--green); }
.system-line .leave { color: var(--red); }

.typing-indicator {
  height: 20px;
  padding: 0 24px 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  font-style: italic;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 24px 18px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  max-height: 140px;
  min-height: 44px;
  line-height: 1.4;
  transition: border-color 0.15s ease;
}
.composer textarea:focus {
  border-color: var(--cyan);
  outline: none;
  box-shadow: 0 0 0 3px rgba(95, 212, 208, 0.12);
}
.composer textarea::placeholder { color: var(--text-dim); }

.send-btn {
  background: var(--amber);
  border: none;
  color: #14100a;
  border-radius: var(--radius-md);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 40px;
}
.empty-state .signal-mark { margin-bottom: 14px; justify-content: center; width: 100%; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row, .system-line { animation: fadeIn 0.18s ease; }

@media (prefers-reduced-motion: reduce) {
  .msg-row, .system-line { animation: none; }
  * { transition: none !important; }
}

/* ============================================================
   MOBILE-FRIENDLINESS
   ============================================================ */

/* Prevent iOS Safari from auto-zooming into inputs (needs >=16px) */
.field input,
.composer textarea,
.admin-form input {
  font-size: 16px;
}
@media (min-width: 640px) {
  .field input,
  .composer textarea,
  .admin-form input {
    font-size: 0.92rem;
  }
}

/* Respect notches / home-indicator areas */
.composer {
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
.auth-shell {
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.admin-content {
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Bigger, thumb-friendly tap targets on small screens */
@media (max-width: 640px) {
  .btn-primary,
  .send-btn,
  .action-btn,
  .header-icon-btn,
  .more-menu-item {
    min-height: 44px;
  }
  .auth-card {
    padding: 28px 22px 22px;
  }
  .chat-header,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }
  .messages {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ============================================================
   ADMIN PANEL
   ============================================================ */
.admin-shell {
  min-height: 100vh;
  background: var(--bg);
}

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-back {
  text-decoration: none;
}

.admin-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  border-radius: 999px;
  padding: 3px 9px;
}

.back-to-chat {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.back-to-chat:hover { color: var(--cyan); }

.admin-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.banner {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.85rem;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--red);
}
.banner-ok {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: var(--green);
}

.admin-card {
  background: linear-gradient(180deg, var(--panel-raised), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 20px 22px;
}

.admin-card h2 {
  font-family: var(--font-display);
  font-size: 1.02rem;
  margin: 0 0 6px;
  font-weight: 600;
}

.admin-sub {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 0 0 16px;
  line-height: 1.5;
}

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.user-count-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  color: var(--text-muted);
  margin: 4px 0 16px;
  cursor: pointer;
}
.checkbox-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--amber);
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.toggle-label {
  font-size: 0.9rem;
  font-weight: 500;
}
.toggle-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 3px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s ease;
}
.slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch input:checked + .slider {
  background: var(--amber-dim);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: var(--amber);
}

/* User cards */
.user-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.user-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--bg);
}

.user-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-card-info {
  min-width: 0;
  flex: 1;
}

.user-card-name {
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.you-tag {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}

.user-card-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.user-card-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-dim);
}

.user-card-badges {
  margin-top: 10px;
}

.role-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  border-radius: 999px;
  padding: 2px 8px;
}

.user-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.action-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}
.action-btn-danger:hover {
  border-color: var(--red);
  color: var(--red);
}

@media (max-width: 480px) {
  .user-card-actions {
    width: 100%;
  }
  .action-btn {
    flex: 1 1 calc(50% - 4px);
    text-align: center;
  }
}

/* ============================================================
   COMPOSER: emoji / attach / voice / media messages
   ============================================================ */

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  width: 40px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover {
  color: var(--cyan);
  background: rgba(95, 212, 208, 0.08);
}

.composer-wrap {
  position: relative;
}

/* ---- Emoji picker ---- */
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 24px;
  width: 300px;
  max-width: calc(100vw - 48px);
  height: 320px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  flex-direction: column;
  overflow: hidden;
  z-index: 30;
}

.emoji-picker-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-soft);
  padding: 6px 6px 0;
  gap: 2px;
  overflow-x: auto;
}

.emoji-tab {
  background: none;
  border: none;
  font-size: 1.1rem;
  padding: 6px 9px;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  opacity: 0.5;
  transition: opacity 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}
.emoji-tab.active {
  opacity: 1;
  background: var(--panel);
}

.emoji-search {
  margin: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 0.82rem;
  color: var(--text);
}
.emoji-search:focus {
  outline: none;
  border-color: var(--cyan);
}

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 4px 8px 10px;
}

.emoji-item {
  background: none;
  border: none;
  font-size: 1.35rem;
  padding: 6px 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease, transform 0.08s ease;
}
.emoji-item:hover {
  background: rgba(255, 180, 84, 0.12);
  transform: scale(1.15);
}

/* ---- Attach menu ---- */
.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 66px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  flex-direction: column;
  padding: 6px;
  gap: 2px;
  z-index: 30;
  min-width: 180px;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.88rem;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.attach-menu-item:hover {
  background: var(--panel);
}

.attach-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ---- Staged attachment preview above composer ---- */
.attach-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--panel);
  border-top: 1px solid var(--border-soft);
}

.attach-preview-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.attach-preview img#attachPreviewImg {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.attach-preview audio#attachPreviewAudio {
  height: 36px;
  max-width: 240px;
}

.attach-preview-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.attach-preview-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
}
.attach-preview-cancel:hover { border-color: var(--red); color: var(--red); }

/* ---- Recording bar ---- */
.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--panel);
  border-top: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text);
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.1s infinite ease-in-out;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.recording-hint {
  color: var(--text-dim);
  flex: 1;
}

.recording-cancel,
.recording-stop {
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  cursor: pointer;
}
.recording-stop {
  color: var(--amber);
  border-color: var(--amber-dim);
}
.recording-cancel:hover { border-color: var(--red); color: var(--red); }
.recording-stop:hover { background: rgba(255, 180, 84, 0.1); }

/* ---- Media inside messages ---- */
.msg-image-wrap {
  display: inline-block;
  margin-bottom: 4px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 280px;
}
.msg-image {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  cursor: zoom-in;
}

.msg-audio-wrap {
  margin-bottom: 4px;
}
.msg-audio-wrap audio {
  height: 40px;
  max-width: 280px;
}

@media (max-width: 640px) {
  .emoji-picker { left: 8px; width: calc(100vw - 32px); }
  .attach-menu { left: 8px; }
  .msg-image-wrap, .msg-audio-wrap audio { max-width: 220px; }
}

/* ============================================================
   REPLY & DELETE
   ============================================================ */

/* ---- Reply preview above composer ---- */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 24px;
  background: var(--panel);
  border-top: 1px solid var(--border-soft);
}

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

.reply-preview-body {
  min-width: 0;
  flex: 1;
}

.reply-preview-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cyan);
}

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

/* ---- Per-message three-dot menu (Reply / Delete / Select) ---- */
.msg-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.msg-more-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0.7;
  transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.msg-more-btn:hover {
  opacity: 1;
  color: var(--cyan);
  background: rgba(95, 212, 208, 0.12);
}

.msg-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  flex-direction: column;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  padding: 6px;
  min-width: 140px;
  z-index: 20;
}
.msg-row.self .msg-menu {
  right: auto;
  left: 0;
}
.msg-menu.open {
  display: flex;
}

.msg-menu-item {
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.84rem;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.msg-menu-item:hover {
  background: var(--panel);
}
.msg-menu-item.danger:hover {
  color: var(--red);
}

/* ---- Quoted reply block inside a message ---- */
.msg-reply-quote {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
  padding: 5px 10px;
  border-left: 3px solid var(--cyan-dim);
  background: rgba(95, 212, 208, 0.06);
  border-radius: 4px;
  cursor: pointer;
  max-width: 320px;
}

.msg-reply-quote:hover {
  background: rgba(95, 212, 208, 0.1);
}

.msg-reply-quote-body {
  min-width: 0;
}

.msg-reply-quote-name {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--cyan);
}

.msg-reply-quote-text {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-row.highlight .msg-body {
  animation: replyHighlight 1.4s ease;
}
@keyframes replyHighlight {
  0% { background: rgba(255, 180, 84, 0.18); }
  100% { background: transparent; }
}

/* ---- Deleted message placeholder ---- */
.msg-deleted {
  font-size: 0.86rem;
  font-style: italic;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.msg-purge-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}
.msg-purge-btn:hover {
  color: var(--red);
  background: rgba(255, 107, 107, 0.1);
}

/* ============================================================
   MULTI-SELECT (long-press)
   ============================================================ */

.selection-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel-raised);
  flex-shrink: 0;
}

.selection-count {
  font-size: 0.88rem;
  font-weight: 600;
  flex: 1;
}

.selection-actions {
  display: flex;
  gap: 8px;
}

.selection-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.selection-action-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.selection-action-btn.danger:hover { border-color: var(--red); color: var(--red); }

@media (max-width: 480px) {
  .selection-action-btn span,
  .selection-action-btn { font-size: 0.76rem; padding: 7px 9px; }
}

/* Small checkmark badge that appears on every bubble once selection mode
   is active — filled in when that message is selected. */
.select-check {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--panel);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: transparent;
  flex-shrink: 0;
  z-index: 2;
  transition: background 0.12s ease, border-color 0.12s ease;
}

body.selection-mode .select-check { display: flex; }
body.selection-mode .msg-menu-wrap { display: none !important; }

.msg-row.selected .select-check {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #06222a;
}

.msg-row.selected .msg-body {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

body.selection-mode .msg-row {
  cursor: pointer;
}

body.selection-mode .msg-row,
body.selection-mode .msg-row * {
  -webkit-touch-callout: none;
}
