/* ─────────────────────────────────────────────────────────────────────────────
   NEXUS — Secure Messaging | Global Stylesheet
   Futuristic · Black · Neon Green/Cyan accent
───────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:           #000000;
  --bg-1:         #080808;
  --bg-2:         #0e0e0e;
  --bg-3:         #141414;
  --bg-4:         #1a1a1a;
  --border:       rgba(255,255,255,0.06);
  --border-glow:  rgba(0,255,180,0.18);
  --accent:       #00ffb4;
  --accent-2:     #00b4ff;
  --accent-dim:   rgba(0,255,180,0.12);
  --accent-dim2:  rgba(0,255,180,0.06);
  --text-1:       #f0f0f0;
  --text-2:       #888;
  --text-3:       #444;
  --danger:       #ff4466;
  --radius:       12px;
  --radius-lg:    18px;
  --font:         'Space Grotesk', system-ui, sans-serif;
  --mono:         'JetBrains Mono', 'Courier New', monospace;
  --sidebar-w:    280px;
  --shadow:       0 4px 32px rgba(0,0,0,0.8);
  --glow:         0 0 20px rgba(0,255,180,0.15);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: var(--font); }
input:focus, textarea:focus, button:focus { outline: none; }

/* Global hidden utility */
.hidden { display: none !important; }

/* ── CANVAS BG ── */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.35;
}

/* ── SCREEN LAYER ── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  transition: opacity 0.4s ease;
}
.screen.screen-hidden  { opacity: 0; pointer-events: none; }
.screen.active  { opacity: 1; pointer-events: all; }

/* ══════════════════════════════════════════════════════════════
   AUTH SCREEN
══════════════════════════════════════════════════════════════ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-container {
  width: 420px;
  max-width: calc(100vw - 32px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px 32px;
  position: relative;
  box-shadow: var(--shadow), 0 0 60px rgba(0,255,180,0.04);
  animation: slideUp 0.5s cubic-bezier(0.22,1,0.36,1) both;
}

.auth-container::before {
  content: '';
  position: absolute;
  top: -1px; left: 50%; transform: translateX(-50%);
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 50%;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Logo */
.logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.logo-icon { width: 40px; height: 40px; animation: rotateSlow 20s linear infinite; }
@keyframes rotateSlow { to { transform: rotate(360deg); } }
.logo-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-tagline {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.5px;
  margin-bottom: 28px;
  font-family: var(--mono);
}

/* Tabs */
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  gap: 0;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  font-size: 12px;
  letter-spacing: 2px;
  font-weight: 600;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  transition: all 0.25s;
  text-transform: uppercase;
}
.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.auth-tab:hover:not(.active) { color: var(--text-2); }

/* Form */
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-form.hidden { display: none; }

.field-group { display: flex; flex-direction: column; gap: 7px; }
.field-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
}
.field-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.field-wrap:focus-within {
  border-color: var(--border-glow);
  box-shadow: 0 0 0 3px rgba(0,255,180,0.06);
}
.field-wrap.compact { margin: 0; }
.field-icon {
  padding: 0 12px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  align-items: center;
}
.field-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-1);
  font-size: 14px;
  padding: 12px 14px 12px 0;
  font-family: var(--mono);
}
.field-input::placeholder { color: var(--text-3); }

/* Errors */
.form-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 18px;
  font-family: var(--mono);
  letter-spacing: 0.3px;
}

/* Primary button */
.btn-primary {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  background: linear-gradient(135deg, rgba(0,255,180,0.12), rgba(0,180,255,0.08));
  border: 1px solid var(--border-glow);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,255,180,0.08), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}
.btn-primary:hover::before { opacity: 1; }
.btn-primary:hover {
  box-shadow: 0 0 24px rgba(0,255,180,0.15);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

/* Note */
.auth-note {
  margin-top: 22px;
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-family: var(--mono);
}

/* ══════════════════════════════════════════════════════════════
   APP SCREEN
══════════════════════════════════════════════════════════════ */
#app-screen {
  display: flex;
  height: 100%;
  background: var(--bg);
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 5;
}

.sidebar-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text-2);
}
.user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: auto;
  box-shadow: 0 0 6px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

/* New Chat */
.new-chat-wrap {
  padding: 16px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.new-chat-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 10px;
}
.new-chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.new-chat-form .field-wrap {
  flex: 1;
  background: var(--bg-2);
}
.new-chat-form .field-input {
  padding: 9px 12px 9px 0;
  font-size: 13px;
}

.btn-new-chat {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--accent-dim);
  border: 1px solid var(--border-glow);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.btn-new-chat:hover {
  background: rgba(0,255,180,0.2);
  box-shadow: 0 0 12px rgba(0,255,180,0.2);
}

/* Conv list */
.conv-list-label {
  padding: 14px 18px 6px;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-3);
  font-weight: 600;
}
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

.conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.18s;
  position: relative;
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--bg-3); }
.conv-item.active {
  background: var(--accent-dim2);
  border-color: var(--border-glow);
}
.conv-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0,255,180,0.3), rgba(0,180,255,0.3));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  font-family: var(--mono);
}
.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-last {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-meta { text-align: right; flex-shrink: 0; }
.conv-time {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
}
.conv-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-size: 9px;
  font-weight: 700;
  margin-top: 4px;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.enc-badge {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.5px;
}
.btn-logout {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ── CHAT PANEL ── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  position: relative;
}

/* Welcome */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  text-align: center;
  animation: fadeIn 0.4s ease;
}
.welcome-icon { animation: floatIcon 4s ease-in-out infinite; }
@keyframes floatIcon {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
.chat-welcome h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-2);
  margin-top: 8px;
}
.chat-welcome p { font-size: 13px; color: var(--text-3); max-width: 340px; line-height: 1.6; }
.welcome-features {
  display: flex;
  gap: 24px;
  margin-top: 12px;
}
.feat {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
}
.feat svg { color: var(--accent); opacity: 0.6; }

/* Chat View */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  animation: fadeIn 0.3s ease;
}
.chat-view.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Chat Header */
.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(8,8,8,0.8);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
}
.chat-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-glow), transparent);
  opacity: 0.5;
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0,255,180,0.3), rgba(0,180,255,0.3));
  border: 1.5px solid var(--border-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
  flex-shrink: 0;
}
.chat-recipient {
  font-size: 15px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text-1);
}
.chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}
.status-pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 5px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
.enc-indicator {
  font-size: 10px;
  color: var(--accent);
  font-family: var(--mono);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border-glow);
  border-radius: 6px;
  background: var(--accent-dim2);
  letter-spacing: 0.5px;
}

/* Messages */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
  display: flex;
  flex-direction: column;
}
.messages-wrap::-webkit-scrollbar { width: 4px; }
.messages-wrap::-webkit-scrollbar-track { background: transparent; }
.messages-wrap::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }
.messages { display: flex; flex-direction: column; gap: 6px; }

/* Date separator */
.date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 10px;
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
  letter-spacing: 1px;
}
.date-sep::before, .date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Message bubble */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  animation: msgIn 0.25s cubic-bezier(0.22,1,0.36,1);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg.sent { align-self: flex-end; align-items: flex-end; }
.msg.recv { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 11px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}
.msg.sent .msg-bubble {
  background: linear-gradient(135deg, rgba(0,255,180,0.14), rgba(0,180,255,0.08));
  border: 1px solid rgba(0,255,180,0.2);
  border-bottom-right-radius: 4px;
  color: var(--text-1);
}
.msg.recv .msg-bubble {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-1);
}
.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 0;
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
}
.msg-enc-icon {
  color: var(--accent);
  opacity: 0.5;
}

/* System / info messages */
.msg-system {
  align-self: center;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
  padding: 6px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  letter-spacing: 0.3px;
  margin: 8px 0;
}

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(8,8,8,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 21;
  flex-shrink: 0;
}
.mobile-topbar::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-glow), transparent);
  opacity: 0.4;
}
.btn-hamburger, .btn-back {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-hamburger:active, .btn-back:active {
  background: var(--bg-4);
  color: var(--accent);
  border-color: var(--border-glow);
}
.mobile-logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.mobile-chat-title {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text-1);
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 19;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

/* Input Bar */
.input-bar {
  padding: 14px 20px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: rgba(8,8,8,0.8);
  backdrop-filter: blur(10px);
}
.input-wrap {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.input-wrap:focus-within {
  border-color: var(--border-glow);
  box-shadow: 0 0 0 3px rgba(0,255,180,0.06);
}
.msg-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-1);
  font-size: 14px;
  padding: 12px 16px;
  resize: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: none;
}
.msg-input::-webkit-scrollbar { display: none; }
.msg-input::placeholder { color: var(--text-3); }

.btn-send {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, rgba(0,255,180,0.2), rgba(0,180,255,0.12));
  border: 1px solid var(--border-glow);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.btn-send:hover {
  background: linear-gradient(135deg, rgba(0,255,180,0.3), rgba(0,180,255,0.2));
  box-shadow: 0 0 20px rgba(0,255,180,0.2);
  transform: translateY(-1px);
}
.btn-send:active { transform: translateY(0); }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-3);
  border: 1px solid var(--border-glow);
  color: var(--text-1);
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 13px;
  font-family: var(--mono);
  letter-spacing: 0.3px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 16px rgba(0,255,180,0.08);
  z-index: 100;
  transition: transform 0.35s cubic-bezier(0.22,1,0.36,1), opacity 0.35s;
  opacity: 0;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── SCROLLBAR GLOBAL ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
══════════════════════════════════════════════════════════════ */
@media (max-width: 700px) {

  /* Show mobile top bar */
  .mobile-topbar { display: flex; }

  /* Sidebar becomes a slide-over drawer */
  :root { --sidebar-w: min(320px, calc(100vw - 48px)); }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.22,1,0.36,1), box-shadow 0.3s;
    box-shadow: none;
    /* Respect iOS notch */
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,0.8), 0 0 60px rgba(0,255,180,0.04);
  }

  /* Chat panel takes full width */
  .chat-panel {
    width: 100%;
    flex: 1;
  }

  /* Hide desktop chat header on mobile (we use mobile-topbar instead) */
  .chat-header { display: none; }

  /* Slightly more touch-friendly conv items */
  .conv-item { padding: 12px 12px; min-height: 60px; }
  .conv-avatar { width: 40px; height: 40px; font-size: 15px; }

  /* Auth card padding tweak */
  .auth-container { padding: 32px 22px 26px; }
  .logo-text { font-size: 20px; letter-spacing: 5px; }

  /* Slightly larger message bubbles on phone */
  .msg { max-width: 85%; }
  .msg-bubble { font-size: 15px; padding: 12px 16px; }

  /* Input bar safe area */
  .input-bar {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  .msg-input { font-size: 16px; /* prevent iOS zoom on focus */ padding: 10px 14px; }
  .btn-send { width: 44px; height: 44px; }

  /* Welcome screen compacting */
  .chat-welcome { padding: 24px 20px; }
  .welcome-features { flex-direction: column; gap: 10px; align-items: center; }
  .chat-welcome h2 { font-size: 17px; }

  /* Messages padding */
  .messages-wrap { padding: 16px 12px 8px; }

  /* Toast stays above home bar */
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* Very small phones */
@media (max-width: 380px) {
  :root { --sidebar-w: calc(100vw - 32px); }
  .auth-container { padding: 28px 18px 22px; }
  .field-input { font-size: 15px; }
}
