/* ═══════════════════════════════════════════════════════════════════
   Nova Messenger – Dark Theme (Telegram-inspired)
   ═══════════════════════════════════════════════════════════════════ */

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

:root {
  --bg-base:       #0e1621;
  --bg-surface:    #17212b;
  --bg-elevated:   #1e2c3a;
  --bg-hover:      #242f3d;
  --bg-input:      #1c2733;
  --accent:        #2B5EE8;
  --accent-hover:  #3a6ef5;
  --accent-dim:    rgba(43,94,232,0.18);
  --green:         #4ddb6e;
  --red:           #e84040;
  --text-primary:  #e8edf2;
  --text-secondary:#7d8e9e;
  --text-muted:    #4a5a6b;
  --border:        rgba(255,255,255,0.06);
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --radius:        12px;
  --radius-msg:    18px;
  --font:          'Manrope', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
  --sidebar-w:     300px;
  --header-h:      60px;
  --input-h:       64px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── SCREENS ─────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; height: 100vh; }
.screen.active { display: flex; }

/* ── LOGIN ───────────────────────────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  background: radial-gradient(ellipse at 60% 40%, #1a2d4a 0%, var(--bg-base) 70%);
}

/* SSL Warning Banner */
.ssl-warning {
  background: var(--bg-elevated);
  border: 2px solid #ff9800;
  border-radius: var(--radius);
  padding: 16px;
  max-width: 500px;
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.2);
}

.ssl-warning-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.ssl-warning-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

.ssl-warning-text strong {
  color: #ff9800;
  font-size: 14px;
}

.ssl-warning-text code {
  background: var(--bg-base);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--green);
  display: inline-block;
  margin: 4px 0;
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 40px;
  width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  animation: fadeUp .4s ease both;
}

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

.login-logo { margin-bottom: 4px; }
.login-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}
.login-sub { color: var(--text-secondary); font-size: 13px; margin-top: -8px; }

.input-wrap { width: 100%; }
.text-input {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  padding: 12px 16px;
  outline: none;
  transition: border-color .2s;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--text-muted); }

.error-hint {
  color: var(--red);
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 20px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: border-color .2s, color .2s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── APP LAYOUT ──────────────────────────────────────────────────── */
#app-screen { display: none; }
#app-screen.active { display: flex; }

.app-layout {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: 220px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-search { padding: 10px 12px; }
.search-input {
  width: 100%;
  background: var(--bg-hover);
  border: none;
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  cursor: default;
}

.chat-list-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 4px 16px 8px;
}

.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.chats-list::-webkit-scrollbar { width: 4px; }
.chats-list::-webkit-scrollbar-track { background: transparent; }
.chats-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-dim); }

.chat-item .user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}

.chat-item .online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg-surface);
}

.chat-item .online-dot.offline {
  background: var(--text-muted);
}

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

.chat-item .user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item .user-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.chat-item .user-status.online {
  color: var(--green);
}

.chat-item .unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

/* No chat selected placeholder */
.no-chat-selected {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  gap: 12px;
}

.no-chat-icon {
  font-size: 64px;
  opacity: 0.5;
}

.no-chat-text {
  font-size: 16px;
}

/* Chat avatar in header */
.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex;
  }
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.user-row:hover { background: var(--bg-hover); }

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.online-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  position: absolute;
  bottom: 10px;
  left: 41px;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-status { font-size: 12px; color: var(--green); }

.call-icon-btn {
  width: 30px;
  height: 30px;
  background: var(--accent-dim);
  border: none;
  border-radius: 8px;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.user-row:hover .call-icon-btn,
.chat-item:hover .call-icon-btn { opacity: 1; }
.call-icon-btn:hover { background: var(--accent); color: #fff; }

/* ── CHAT AREA ───────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.015'%3E%3Cpath d='M0 38.59l2.83-2.83 1.41 1.41L1.41 40H0v-1.41zM0 1.4l2.83 2.83 1.41-1.41L1.41 0H0v1.41zM38.59 40l-2.83-2.83 1.41-1.41L40 38.59V40h-1.41zM40 1.41l-2.83 2.83-1.41-1.41L38.59 0H40v1.41zM20 18.6l2.83-2.83 1.41 1.41L21.41 20l2.83 2.83-1.41 1.41L20 21.41l-2.83 2.83-1.41-1.41L18.59 20l-2.83-2.83 1.41-1.41L20 18.59z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.chat-title { 
  font-size: 16px; 
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.chat-sub { 
  font-size: 12px; 
  color: var(--text-secondary); 
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Chat header actions - desktop */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 7px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── MESSAGES ────────────────────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  scroll-behavior: smooth;
}
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }

.messages-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 100%;
  justify-content: flex-end;
  padding: 0 12px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 2px 0;
  animation: msgIn .2s ease both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.own { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}
.msg-row.own .msg-avatar { display: none; }

.msg-bubble-wrap { max-width: 68%; display: flex; flex-direction: column; }
.msg-row.own .msg-bubble-wrap { align-items: flex-end; }

.msg-sender {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 3px;
  padding-left: 2px;
}

.msg-bubble {
  background: var(--bg-elevated);
  border-radius: var(--radius-msg) var(--radius-msg) var(--radius-msg) 4px;
  padding: 8px 12px 6px;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}
.msg-row.own .msg-bubble {
  background: #1b3a6b;
  border-radius: var(--radius-msg) var(--radius-msg) 4px var(--radius-msg);
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 2px;
}

/* System messages */
.sys-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 0;
}

/* ── TYPING BAR ───────────────────────────────────────────────────── */
.typing-bar {
  min-height: 22px;
  padding: 0 20px;
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  transition: opacity .2s;
}

/* ── INPUT AREA ──────────────────────────────────────────────────── */
.input-area {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px;
  position: relative;
}

.emoji-toggle {
  font-size: 22px;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.msg-input {
  flex: 1;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  padding: 10px 14px;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  word-break: break-word;
  transition: border-color .2s;
}
.msg-input:focus { border-color: var(--accent); }
.msg-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}
.msg-input::-webkit-scrollbar { width: 4px; }
.msg-input::-webkit-scrollbar-thumb { background: var(--bg-hover); }

.send-btn {
  width: 42px;
  height: 42px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }

/* ── EMOJI PICKER ────────────────────────────────────────────────── */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 320px;
  max-height: 300px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  padding: 8px;
  z-index: 100;
}
.emoji-picker.hidden { display: none; }
.emoji-picker::-webkit-scrollbar { width: 4px; }
.emoji-picker::-webkit-scrollbar-thumb { background: var(--bg-hover); }

.emoji-category-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 6px 4px 4px;
}
.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 4px;
}
.emoji-item {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, transform .1s;
  border: none;
  background: none;
}
.emoji-item:hover { background: var(--bg-hover); transform: scale(1.2); }

/* ── CALL OVERLAY ────────────────────────────────────────────────── */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(8px);
}
.call-overlay.hidden { display: none; }

.call-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 280px;
  box-shadow: var(--shadow);
  animation: fadeUp .3s ease;
}
.call-panel.hidden { display: none; }

.call-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  animation: pulse 1.5s ease infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(43,94,232,.5); }
  50%       { box-shadow: 0 0 0 14px rgba(43,94,232,0); }
}
.call-name { font-size: 20px; font-weight: 700; }
.call-status { font-size: 13px; color: var(--text-secondary); }

.call-actions { display: flex; gap: 24px; margin-top: 8px; }
.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, filter .15s;
}
.call-btn.green { background: var(--green); color: #fff; }
.call-btn.red   { background: var(--red);   color: #fff; }
.call-btn:hover { filter: brightness(1.15); transform: scale(1.06); }

/* ── ACTIVE CALL ─────────────────────────────────────────────────── */
.active-call {
  width: 100%;
  height: 100%;
  position: relative;
  background: #000;
}
.active-call.hidden { display: none; }

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}
.local-video {
  position: absolute;
  bottom: 120px;
  right: 20px;
  width: 140px;
  height: 100px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.2);
  background: #222;
}

.call-hud {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
.call-hud-name { font-size: 18px; font-weight: 700; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.call-timer    { font-size: 14px; color: rgba(255,255,255,.7); font-family: var(--font-mono); margin-top: 4px; }

.call-controls {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(12px);
  border-radius: 50px;
  padding: 12px 20px;
}
.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .1s;
}
.ctrl-btn.active { background: rgba(255,255,255,.15); color: #fff; }
.ctrl-btn.muted  { background: rgba(255,255,255,.06); color: rgba(255,255,255,.4); }
.ctrl-btn.red    { background: var(--red); color: #fff; }
.ctrl-btn:hover  { transform: scale(1.07); }

/* ── MODAL ───────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-card {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  min-width: 280px;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow);
  animation: fadeUp .25s ease;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.modal-users { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow-y: auto; margin-bottom: 8px; }
.modal-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.modal-user-row:hover { background: var(--bg-hover); }

/* ── RESPONSIVE ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Don't collapse the sidebar to icons-only.
     It hides user names on very small screens (320–360px), which is not acceptable. */
  .emoji-picker { width: 260px; }
}

/* ── PERMISSION MODAL ────────────────────────────────────────────── */
.permission-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.permission-modal.active {
  display: flex;
}

.permission-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.permission-dialog {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow);
  animation: fadeUp .3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.permission-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.permission-dialog h2 {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: var(--text-primary);
}

.permission-dialog p {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

.permission-steps {
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 16px;
  width: 100%;
  margin: 8px 0;
}

.permission-steps h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.permission-steps ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.permission-steps li {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.permission-steps li strong {
  color: var(--accent);
  font-weight: 600;
}

.permission-buttons {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

.permission-btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}

.permission-btn.primary {
  background: var(--accent);
  color: #fff;
}

.permission-btn.primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.permission-btn.primary:active {
  transform: translateY(0);
}

.permission-btn.primary:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.permission-btn.secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.permission-btn.secondary:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.permission-status {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  width: 100%;
  text-align: center;
  min-height: 20px;
  transition: all .2s;
}

.permission-status.waiting {
  background: var(--accent-dim);
  color: var(--accent);
}

.permission-status.success {
  background: rgba(77, 219, 110, 0.15);
  color: var(--green);
}

.permission-status.error {
  background: rgba(232, 64, 64, 0.15);
  color: var(--red);
}

.browser-hint {
  background: var(--bg-base);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  margin-top: 8px;
}

.browser-hint strong {
  color: var(--accent);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE APP LAYOUT - Android Style
   ═══════════════════════════════════════════════════════════════════ */

/* Mobile-first: Default to full-screen app layout */
@media (max-width: 768px) {
  /* Reset to mobile app dimensions */
  html, body {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow: hidden;
    position: fixed;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* App layout - full screen */
  .app-layout {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    position: relative;
  }

  /* Sidebar - full width chat list */
  .sidebar {
    width: 100%;
    max-width: 100%;
    border-right: none;
    display: flex;
    flex-direction: column;
  }

  .sidebar-header {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    min-height: 56px;
  }

  .sidebar-logo {
    font-size: 22px;
    font-weight: 700;
  }

  .sidebar-search {
    padding: 8px 12px;
    background: var(--bg-surface);
  }

  .search-input {
    padding: 10px 14px;
    font-size: 15px;
  }

  .chats-list {
    padding: 4px 0;
  }

  .chat-item {
    padding: 12px 16px;
    margin: 2px 0;
    min-height: 68px;
  }

  .chat-item .user-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    font-size: 18px;
  }

  .chat-item .user-info {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 100px);
    overflow: hidden;
  }

  .chat-item .user-name {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .chat-item .user-status {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Chat area - full screen when active */
  .chat-area {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    display: none;
    background: var(--bg-base);
  }

  .chat-area.active {
    display: flex;
    flex-direction: column;
  }

  /* Hide sidebar when chat is active on mobile */
  .app-layout.chat-open .sidebar { display: none; }
  .app-layout.chat-open .chat-area { display: flex; }

  /* Chat header - mobile optimizations */
  .chat-header {
    padding: 8px 12px;
    background: var(--bg-surface);
    min-height: 56px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
  }

  .chat-header-info {
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .chat-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 16px;
  }

  .chat-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
  }

  .chat-sub {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
  }

  /* Header actions - make sure call button is visible */
  .chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* No hover on touch devices: keep call buttons visible */
  .call-icon-btn {
    opacity: 1;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 12px;
  }

  #video-call-btn {
    display: none !important; /* Controlled by JS */
  }

  #video-call-btn[style*="inline-flex"] {
    display: inline-flex !important;
    color: var(--green); /* Green color when online */
  }

  #video-call-btn:active {
    background: var(--accent-dim);
    transform: scale(0.95);
  }

  /* Back button - always visible on mobile */
  .mobile-only {
    display: inline-flex !important;
  }

  #back-to-chats-btn {
    margin-right: 0;
    color: var(--text-primary);
    background: var(--bg-hover);
    border-radius: 10px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 10px;
    flex-shrink: 0;
    display: inline-flex !important;
  }

  #back-to-chats-btn:hover {
    background: var(--bg-elevated);
  }

  #back-to-chats-btn:active {
    background: var(--bg-elevated);
    transform: scale(0.95);
  }

  #back-to-chats-btn svg {
    width: 22px;
    height: 22px;
  }

  /* Very small screens - additional optimizations */
  @media (max-width: 360px) {
    .chat-item {
      padding: 10px 12px;
    }

    .chat-item .user-avatar {
      width: 42px;
      height: 42px;
      min-width: 42px;
      font-size: 16px;
    }

    .chat-item .user-name {
      font-size: 14px;
    }

    .chat-item .user-status {
      font-size: 12px;
    }

    .chat-title {
      font-size: 14px;
    }

    .chat-sub {
      font-size: 11px;
    }

    .chat-avatar {
      width: 36px;
      height: 36px;
      min-width: 36px;
      font-size: 14px;
    }

    .icon-btn {
      width: 40px;
      height: 40px;
      min-width: 40px;
      padding: 8px;
    }

    #back-to-chats-btn {
      width: 40px;
      height: 40px;
      min-width: 40px;
      padding: 8px;
    }

    #back-to-chats-btn svg {
      width: 20px;
      height: 20px;
    }
  }

  /* Messages area */
  .messages-container {
    flex: 1;
    padding: 8px;
  }

  .msg-row {
    padding: 2px 4px;
  }

  .msg-bubble {
    padding: 10px 14px;
    font-size: 15px;
    max-width: 85%;
  }

  .msg-avatar {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }

  /* Input area - fixed at bottom */
  .input-area {
    padding: 8px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    min-height: 56px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .msg-input {
    padding: 10px 14px;
    font-size: 15px;
    max-height: 120px;
  }

  .send-btn {
    width: 44px;
    height: 44px;
  }

  .emoji-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  /* Typing indicator */
  .typing-bar {
    padding: 6px 16px;
    font-size: 13px;
    background: var(--bg-surface);
  }

  /* Emoji picker */
  .emoji-picker {
    bottom: 70px;
    left: 8px;
    right: 8px;
    max-height: 250px;
  }

  .emoji-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  /* Call UI adjustments */
  .call-panel {
    width: 90%;
    max-width: 320px;
  }

  .call-avatar {
    width: 80px;
    height: 80px;
    font-size: 32px;
  }

  .call-name {
    font-size: 20px;
  }

  .call-actions {
    gap: 24px;
  }

  .call-btn {
    width: 56px;
    height: 56px;
  }

  /* Active call */
  .remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .local-video {
    width: 100px;
    height: 140px;
    right: 12px;
    bottom: 120px;
  }

  .call-controls {
    bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    gap: 20px;
  }

  .ctrl-btn {
    width: 50px;
    height: 50px;
  }

  /* Modal adjustments */
  .modal-card {
    width: 90%;
    max-width: 320px;
    max-height: 80vh;
  }

  .modal-user-row {
    padding: 12px;
  }
}

/* Desktop adjustments */
@media (min-width: 769px) {
  .mobile-only {
    display: none !important;
  }

  .chat-area {
    display: flex !important;
  }

  /* Ensure call button is visible on desktop */
  .chat-header-actions {
    display: flex !important;
  }

  #video-call-btn {
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  #video-call-btn[style*="inline-flex"] {
    display: inline-flex !important;
    color: var(--green);
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .sidebar-header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .call-controls {
    bottom: max(40px, env(safe-area-inset-bottom));
  }
}

/* Prevent pull-to-refresh on mobile */
body {
  overscroll-behavior-y: contain;
}

/* Smooth scrolling */
.messages-container {
  -webkit-overflow-scrolling: touch;
}

/* Active states for touch */
.chat-item:active {
  background: var(--bg-hover);
}

.icon-btn:active,
.send-btn:active,
.call-btn:active,
.ctrl-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

/* Status bar styling for mobile browsers */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}
