/* ================================================
   MAKTUB — Estilo Telegram v4
   Fuente: Inter (Google Fonts)
   Tema: Oscuro profesional
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── VARIABLES ──────────────────────────────── */
:root {
  --bg-primary:     #0d1117;
  --bg-secondary:   #161b22;
  --bg-tertiary:    #1c2333;
  --bg-hover:       #21262d;
  --bg-msg-out:     #2b5278;
  --bg-msg-in:      #182533;
  --bg-deleted:     #161b22;

  --accent:         #3390ec;
  --accent-hover:   #2176d2;
  --accent-light:   rgba(51,144,236,0.15);
  --danger:         #ef4444;
  --danger-hover:   #dc2626;
  --success:        #22c55e;
  --warning:        #f59e0b;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary:  #484f58;
  --text-link:      #58a6ff;
  --text-msg-out:   #d4e8ff;
  --text-msg-in:    #d4eeff;

  --border:         #30363d;
  --shadow:         0 8px 32px rgba(0,0,0,0.5);
  --shadow-sm:      0 2px 8px rgba(0,0,0,0.3);

  --radius:         12px;
  --radius-sm:      8px;
  --radius-bubble:  18px;

  --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Consolas', 'Monaco', monospace;
  --transition: 0.15s ease;
  --sidebar-width: 300px;
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Solo el chat necesita overflow hidden (para evitar scroll del body) */
body.is-chat-page {
  overflow: hidden;
  height: 100dvh;
}

/* ─── SCROLLBAR ──────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ─── UTILIDADES ─────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.flex-1 { flex: 1; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ─── BOTONES ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(51,144,236,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 12px; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: rgba(239,68,68,0.12); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon svg { width: 20px; height: 20px; }

/* ─── INPUTS ─────────────────────────────────── */
.input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--transition);
  letter-spacing: -0.01em;
  /* Evitar zoom en iOS al enfocar un input */
  font-size: max(16px, 0.9rem);
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-tertiary); }

/* ─── SPINNER ─────────────────────────────────── */
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── LOADING SCREEN ─────────────────────────── */
.loading-screen {
  position: fixed; inset: 0;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

/* ─── LAYOUT PRINCIPAL ───────────────────────── */
.chat-layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  min-height: 60px;
}
.sidebar-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
  letter-spacing: -0.02em;
}
.sidebar-actions { display: flex; gap: 4px; }

.chat-list { flex: 1; overflow-y: auto; padding: 8px 0; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: rgba(51,144,236,0.12); }
.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}
.chat-item-status {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.chat-item-status.online { color: var(--success); }

/* Acciones en el item del sidebar (llamadas) */
.chat-item-actions {
  display: flex; gap: 4px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.chat-item:hover .chat-item-actions { opacity: 1; pointer-events: auto; }
.call-btn-sm {
  width: 28px; height: 28px;
  border-radius: 50%; background: transparent;
  color: var(--text-secondary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.call-btn-sm:hover { background: var(--accent); color: #fff; }
.call-btn-sm svg { width: 14px; height: 14px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
.my-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ─── AVATAR ─────────────────────────────────── */
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  letter-spacing: 0;
}
.avatar-sm { width: 36px; height: 36px; font-size: 0.875rem; }
.online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: var(--success);
  border: 2px solid var(--bg-secondary);
  border-radius: 50%;
}

/* ─── CHAT MAIN ──────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
  position: relative;
}

/* ─── HEADER ─────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
  flex-shrink: 0;
}
.chat-header .online-dot { border-color: var(--bg-secondary); }

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.chat-header-status { font-size: 0.75rem; color: var(--text-secondary); }
.chat-header-status.online { color: var(--success); }

/* Botones de llamada en header */
.call-btn {
  width: 36px; height: 36px;
  border-radius: 50%; border: none;
  background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.call-btn:hover { background: var(--accent); color: #fff; }
.call-btn svg { width: 19px; height: 19px; }

/* ─── MENSAJES ───────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 14px;
  color: var(--text-tertiary);
  padding: 40px;
}
.empty-state svg { opacity: 0.35; width: 52px; height: 52px; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); }
.empty-state p { font-size: 0.875rem; text-align: center; }

/* Separador de fecha */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0 8px;
  gap: 12px;
}
.date-separator span {
  background: rgba(30,40,60,0.85);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.01em;
}

/* Wrapper mensaje */
.message-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  padding: 1px 0;
}
.message-wrapper.outgoing { flex-direction: row-reverse; }
.message-wrapper.same-sender .avatar { visibility: hidden; }
.message-wrapper.same-sender.outgoing .avatar { visibility: hidden; }

/* Bubble */
.message-bubble {
  max-width: min(72%, 520px);
  padding: 9px 13px;
  border-radius: var(--radius-bubble);
  position: relative;
  word-break: break-word;
  transition: background var(--transition);
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}
.message-bubble:hover { filter: brightness(1.06); }

/* Ajuste de bordes según posición */
.incoming .message-bubble {
  background: var(--bg-msg-in);
  color: var(--text-msg-in);
  border-bottom-left-radius: 5px;
}
.outgoing .message-bubble {
  background: var(--bg-msg-out);
  color: var(--text-msg-out);
  border-bottom-right-radius: 5px;
}
.incoming.same-sender .message-bubble { border-top-left-radius: 5px; }
.outgoing.same-sender .message-bubble { border-top-right-radius: 5px; }

/* Nombre del remitente (en grupos) */
.message-sender-name {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 3px;
  opacity: 0.9;
}

/* Texto del mensaje */
.message-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: inherit;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}

/* Footer del mensaje (hora + ticks) */
.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  opacity: 0.7;
}
.message-time {
  font-size: 0.68rem;
  font-weight: 400;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.message-ticks { display: flex; align-items: center; }
.message-ticks svg { width: 16px; height: 16px; }
.ticks-read { color: #5ab4ff; opacity: 1; }

/* Indicador editado */
.edited-label {
  font-size: 0.65rem;
  opacity: 0.7;
  font-style: italic;
  margin-right: 4px;
}

/* Mensaje eliminado */
.message-deleted-text {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Reply quote */
.reply-quote {
  background: rgba(255,255,255,0.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--transition);
}
.reply-quote:hover { background: rgba(255,255,255,0.12); }
.reply-quote-sender { font-size: 0.72rem; font-weight: 600; color: var(--accent); }
.reply-quote-text { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Reacciones */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.reaction-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  transition: background var(--transition);
  color: var(--text-secondary);
}
.reaction-btn:hover, .reaction-btn.mine { background: rgba(51,144,236,0.2); border-color: rgba(51,144,236,0.4); }

/* Menú contextual de mensaje */
.message-context-menu {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  min-width: 160px;
  overflow: hidden;
  animation: fadeInScale 0.1s ease;
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.context-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  font-size: 0.875rem; font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Auto-destruct overlay */
.auto-destruct-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: var(--radius-bubble);
  gap: 8px; cursor: pointer;
}
.auto-destruct-overlay svg { color: #ef4444; }
.auto-destruct-timer {
  position: absolute; bottom: 8px; right: 8px;
  background: rgba(239,68,68,0.9);
  color: #fff; font-size: 0.75rem; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
}

/* Imágenes / Videos */
.message-image {
  max-width: 100%; max-height: 320px;
  border-radius: 10px; cursor: pointer;
  display: block; object-fit: cover;
}
.message-video { max-width: 100%; max-height: 320px; border-radius: 10px; }

/* Audio */
.audio-player { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.audio-play-btn {
  width: 38px; height: 38px;
  background: rgba(51,144,236,0.2);
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); flex-shrink: 0;
  transition: background var(--transition);
}
.audio-play-btn:hover { background: rgba(51,144,236,0.35); }
.audio-play-btn svg { width: 18px; height: 18px; }
.audio-progress-wrapper { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.audio-waveform-bar { height: 3px; background: rgba(255,255,255,0.15); border-radius: 3px; cursor: pointer; }
.audio-waveform-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.1s; }
.audio-duration { font-size: 0.72rem; color: var(--text-secondary); }

/* PDF */
.pdf-message {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: rgba(255,255,255,0.06);
  border-radius: 10px; cursor: pointer;
  transition: background var(--transition); min-width: 200px;
}
.pdf-message:hover { background: rgba(255,255,255,0.1); }
.pdf-icon { color: var(--danger); flex-shrink: 0; }
.pdf-info { flex: 1; min-width: 0; }
.pdf-name { font-size: 0.875rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-size { font-size: 0.72rem; color: var(--text-secondary); margin-top: 2px; }

/* ─── TYPING ─────────────────────────────────── */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.typing-indicator.show { display: flex; }
.typing-dots { display: flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typingDot 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── INPUT ÁREA ─────────────────────────────── */
.chat-input-area {
  padding: 10px 14px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 4px 8px 4px 4px;
  transition: border-color var(--transition);
  min-height: 44px;
}
.message-input-wrapper:focus-within { border-color: var(--accent); }

#messageInput {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  padding: 6px 8px;
  letter-spacing: -0.01em;
}
#messageInput::placeholder { color: var(--text-tertiary); }

.attach-btn {
  width: 36px; height: 36px;
  border-radius: 50%; border: none;
  background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition); flex-shrink: 0;
}
.attach-btn:hover { color: var(--accent); background: var(--accent-light); }
.attach-btn svg { width: 20px; height: 20px; }

.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%; border: none;
  background: var(--accent); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 12px rgba(51,144,236,0.4);
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.06); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--bg-tertiary); color: var(--text-tertiary); box-shadow: none; cursor: not-allowed; }
.send-btn svg { width: 20px; height: 20px; }

/* ─── MODALES ────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); z-index: 500;
  align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px; max-width: 360px; width: 90%;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: 10px; letter-spacing: -0.02em; }
.modal p { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 22px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ─── TOAST ──────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%); z-index: 600;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: #2a3242;
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem; font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── LIGHTBOX ───────────────────────────────── */
.lightbox {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.92); z-index: 400;
  align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.lightbox.open { display: flex; }
.lightbox-close {
  position: absolute; top: 20px; right: 20px;
  background: rgba(255,255,255,0.1); border: none;
  color: #fff; font-size: 1.2rem;
  width: 40px; height: 40px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }
.lightbox-content { max-width: 90vw; max-height: 90vh; }
.lightbox-content img, .lightbox-content video { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px; }

/* ─── GALERÍA ────────────────────────────────── */
.gallery-tab {
  flex: 1; padding: 12px 8px;
  background: none; border: none;
  color: var(--text-secondary); cursor: pointer;
  font-family: var(--font); font-size: 0.8rem; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  letter-spacing: -0.01em;
}
.gallery-tab:hover { color: var(--text-primary); }
.gallery-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; }
.gallery-item {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  cursor: pointer; position: relative; background: var(--bg-tertiary);
}
.gallery-item img, .gallery-item video { width: 100%; height: 100%; object-fit: cover; }
.gallery-item .check-overlay {
  position: absolute; inset: 0;
  background: rgba(51,144,236,0.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
}
.gallery-item.selected .check-overlay { opacity: 1; }

/* ─── UPLOAD PREVIEW ─────────────────────────── */
.upload-preview {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.upload-preview.show { display: flex; }
.preview-thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.preview-info { flex: 1; min-width: 0; }
.preview-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-size { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.upload-progress { height: 3px; background: rgba(255,255,255,0.1); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.upload-progress-bar { height: 100%; background: var(--accent); border-radius: 3px; width: 0; transition: width 0.3s; }

/* ─── TOGGLE SWITCH ──────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-tertiary);
  border-radius: 24px; cursor: pointer;
  transition: background var(--transition);
  border: 1.5px solid var(--border);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; top: 1px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); background: #fff; }

/* ─── EMOJI PICKER ───────────────────────────── */
.emoji-categories {
  display: flex;
  overflow-x: auto;
  padding: 8px 10px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.emoji-categories::-webkit-scrollbar { display: none; }
.emoji-cat-btn {
  flex-shrink: 0; background: none; border: none;
  font-size: 1.1rem; cursor: pointer;
  padding: 5px 8px; border-radius: 8px;
  transition: background var(--transition);
}
.emoji-cat-btn:hover, .emoji-cat-btn.active { background: var(--bg-hover); }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px; padding: 10px;
  max-height: 200px; overflow-y: auto;
}
.emoji-btn {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; padding: 5px; border-radius: 6px;
  transition: background var(--transition); line-height: 1;
}
.emoji-btn:hover { background: var(--bg-hover); }

/* ─── LOGIN ──────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg-primary);
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}
.login-logo {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 32px;
}
.login-logo-icon {
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: 0 4px 16px rgba(51,144,236,0.3);
}
.login-logo-icon svg { width: 28px; height: 28px; color: #fff; }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.03em; }
.login-logo span { font-size: 0.8rem; color: var(--text-secondary); }

.form-group { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.01em; text-transform: uppercase; }

.password-wrapper { position: relative; }
.password-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 4px;
  display: flex; align-items: center; transition: color var(--transition);
}
.password-toggle:hover { color: var(--text-primary); }
.password-wrapper .input { padding-right: 42px; }

.btn-login { width: 100%; margin-top: 8px; padding: 13px; font-size: 0.95rem; font-weight: 600; }

.login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  color: #fca5a5;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}
.login-error.show { display: block; }

.login-footer {
  display: flex; align-items: flex-start; gap: 10px;
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.lock-icon { color: var(--text-tertiary); flex-shrink: 0; padding-top: 1px; }
.lock-icon svg { width: 14px; height: 14px; }
.login-footer p { font-size: 0.75rem; color: var(--text-tertiary); line-height: 1.5; }

/* ─── LLAMADAS ───────────────────────────────── */

/* Llamada entrante */
.call-incoming-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); z-index: 700;
  align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.call-incoming-modal.show { display: flex; }
.call-incoming-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
  max-width: 300px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: slideUp 0.25s ease;
}
.call-incoming-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: #fff;
  margin: 0 auto 16px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(51,144,236,0.4); }
  50% { box-shadow: 0 0 0 16px rgba(51,144,236,0); }
}
.call-incoming-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.02em; }
.call-incoming-type { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 28px; }
.call-incoming-actions { display: flex; justify-content: center; gap: 32px; }
.call-action-btn {
  width: 62px; height: 62px;
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; transition: transform var(--transition), box-shadow var(--transition);
}
.call-action-btn:hover { transform: scale(1.08); }
.call-action-btn span { font-size: 0.65rem; color: var(--text-secondary); }
.call-accept { background: var(--success); box-shadow: 0 4px 16px rgba(34,197,94,0.4); }
.call-reject { background: var(--danger); box-shadow: 0 4px 16px rgba(239,68,68,0.4); }
.call-action-btn svg { width: 24px; height: 24px; color: #fff; }

/* Llamada activa */
.call-active-overlay {
  display: none; position: fixed; inset: 0;
  background: #0d1117; z-index: 600;
  flex-direction: column; align-items: center; justify-content: center;
}
.call-active-overlay.show { display: flex; }

/* Videollamada: streams */
.call-video-container {
  position: absolute; inset: 0;
  background: #000;
}
.call-remote-video {
  width: 100%; height: 100%;
  object-fit: cover;
}
.call-local-video {
  position: absolute; bottom: 120px; right: 20px;
  width: 120px; height: 160px;
  border-radius: 12px; overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
  background: #111;
}
.call-local-video video { width: 100%; height: 100%; object-fit: cover; }

/* Llamada de voz: info */
.call-info {
  text-align: center; z-index: 1; padding: 40px 20px;
}
.call-big-avatar {
  width: 100px; height: 100px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; font-weight: 700; color: #fff;
  margin: 0 auto 20px;
}
.call-peer-name { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.03em; }
.call-status { font-size: 0.9rem; color: var(--text-secondary); }
.call-duration { font-size: 1rem; font-weight: 500; color: var(--text-primary); margin-top: 4px; }

/* Controles de llamada */
.call-controls {
  position: absolute; bottom: 48px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 20px; z-index: 2;
}
.call-ctrl-btn {
  width: 58px; height: 58px;
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; transition: all var(--transition);
}
.call-ctrl-btn:hover { transform: scale(1.08); }
.call-ctrl-btn svg { width: 22px; height: 22px; color: #fff; }
.call-ctrl-btn span { font-size: 0.62rem; color: rgba(255,255,255,0.7); }
.call-ctrl-mute { background: rgba(255,255,255,0.15); }
.call-ctrl-mute.active { background: var(--danger); }
.call-ctrl-cam { background: rgba(255,255,255,0.15); }
.call-ctrl-cam.active { background: var(--danger); }
.call-ctrl-speaker { background: rgba(255,255,255,0.15); }
.call-ctrl-end { background: var(--danger); box-shadow: 0 4px 16px rgba(239,68,68,0.4); width: 66px; height: 66px; }

/* ─── EDICIÓN DE MENSAJE ─────────────────────── */
.message-edit-input {
  background: rgba(255,255,255,0.08);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 6px 10px;
  color: inherit;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  width: 100%;
  outline: none;
  min-height: 36px;
  max-height: 200px;
  overflow-y: auto;
  letter-spacing: -0.01em;
}
.edit-actions {
  display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end;
}
.edit-save-btn, .edit-cancel-btn {
  padding: 4px 12px; border-radius: 6px;
  font-size: 0.78rem; font-weight: 500;
  border: none; cursor: pointer; font-family: var(--font);
  transition: all var(--transition);
}
.edit-save-btn { background: var(--accent); color: #fff; }
.edit-save-btn:hover { background: var(--accent-hover); }
.edit-cancel-btn { background: var(--bg-tertiary); color: var(--text-secondary); }
.edit-cancel-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── BADGE ADMIN ────────────────────────────── */
.admin-badge {
  font-size: 0.65rem; font-weight: 600;
  background: rgba(51,144,236,0.2);
  color: var(--accent);
  padding: 1px 6px; border-radius: 4px;
  vertical-align: middle; margin-left: 4px;
}

/* ─── PROFILE PAGE ───────────────────────────── */
.profile-page {
  min-height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
}

.profile-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 0 40px;
}

/* Cabecera de perfil fija en móvil */
.profile-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.profile-topbar h1 {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  letter-spacing: -0.02em;
}

.profile-back {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
  flex-shrink: 0;
}
.profile-back:hover { background: var(--bg-hover); }
.profile-back svg { width: 22px; height: 22px; }

/* Banner de perfil */
.profile-banner {
  background: linear-gradient(135deg, rgba(51,144,236,0.2), rgba(51,144,236,0.05));
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar-big {
  width: 88px; height: 88px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; font-weight: 700; color: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
  position: relative;
}

.profile-display-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.profile-user-handle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Sección de ajustes */
.profile-section-header {
  padding: 18px 16px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.profile-card {
  margin: 0 12px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.profile-card-inner {
  padding: 18px 18px 20px;
}

.profile-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.profile-card h3 svg {
  color: var(--accent);
}

.profile-success {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  color: #86efac;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: none;
  margin-bottom: 12px;
  animation: slideUp 0.2s ease;
}
.profile-success.show { display: block; }
.profile-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: none;
  margin-bottom: 12px;
  animation: slideUp 0.2s ease;
}
.profile-error.show { display: block; }

.profile-action-row {
  margin: 0 12px 32px;
}

/* ─── RESPONSIVE ─────────────────────────────── */

/* ── Tabletas ── */
@media (max-width: 900px) {
  :root { --sidebar-width: 260px; }
}

/* ── Móvil ── */
@media (max-width: 700px) {
  :root { --sidebar-width: 100vw; }

  /* ── Chat layout en móvil: chat visible por defecto, sidebar oculto ── */
  .chat-layout {
    position: relative;
    overflow: hidden;
  }

  /* Sidebar oculto a la izquierda por defecto en móvil */
  .sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 100%;
    z-index: 20;
    transform: translateX(-100%);
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }
  /* Sidebar visible (cuando el usuario pulsa "usuarios") */
  .sidebar.visible-mobile {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Chat visible por defecto en móvil */
  .chat-main {
    position: absolute;
    inset: 0;
    width: 100%;
    transform: translateX(0);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }
  /* Chat oculto cuando el sidebar está abierto */
  .chat-main.hidden-mobile {
    transform: translateX(100%);
  }

  /* Mostrar botón "Usuarios" en header del chat en móvil */
  #backBtn { display: flex !important; }

  /* Mostrar botón "Volver al chat" en header del sidebar en móvil */
  #sidebarBackBtn { display: flex !important; }

  /* Ocultar botones de llamada en la lista de usuarios en móvil (evita interceptar toques) */
  .chat-item-actions { display: none !important; }

  /* Bubbles más anchos */
  .message-bubble { max-width: 88%; }

  /* Header más compacto */
  .chat-header { padding: 8px 12px; min-height: 56px; }
  .chat-header .btn-icon { width: 40px; height: 40px; }
  .chat-header-name { font-size: 0.9rem; }

  /* Input area: evitar que el teclado lo tape */
  .chat-input-area {
    padding: 8px 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /* Botones de acción más grandes (44px mínimo táctil) */
  .attach-btn { width: 42px; height: 42px; }
  .send-btn { width: 46px; height: 46px; }
  .btn-icon { width: 40px; height: 40px; }

  /* Sidebar footer en móvil */
  .sidebar-header { padding: 16px; min-height: 64px; }
  .chat-item { padding: 12px 16px; min-height: 70px; }
  .avatar { width: 46px; height: 46px; }
  .avatar-sm { width: 40px; height: 40px; font-size: 1rem; }
  .online-dot { width: 11px; height: 11px; }

  /* Sidebar footer con safe area */
  .sidebar-footer {
    padding: 14px 16px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  /* Galería: más columnas pequeñas */
  .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }

  /* Llamadas en móvil */
  .call-local-video { width: 90px; height: 120px; bottom: 120px; right: 12px; }
  .call-controls { bottom: max(40px, env(safe-area-inset-bottom, 40px)); gap: 14px; }
  .call-ctrl-btn { width: 52px; height: 52px; }
  .call-ctrl-end { width: 60px; height: 60px; }

  /* Modal de llamada entrante */
  .call-incoming-card { padding: 28px 20px; }

  /* Emoji picker posición */
  #emojiPicker { bottom: 0; left: 0; right: 0; max-width: 100%; border-radius: 16px 16px 0 0; }

  /* Menú contextual más grande */
  .context-menu-item { padding: 14px 18px; font-size: 0.95rem; }
  .context-menu-item svg { width: 18px; height: 18px; }

  /* Modal centrado */
  .modal { margin: 16px; max-width: calc(100% - 32px); }

  /* Toast abajo con safe area */
  .toast-container {
    bottom: max(80px, calc(env(safe-area-inset-bottom) + 70px));
  }

  /* Login */
  .login-card { padding: 28px 20px; border-radius: 20px; }

  /* Date separator más compacto */
  .date-separator span { font-size: 0.7rem; padding: 3px 12px; }
}

/* ── Móvil muy pequeño ── */
@media (max-width: 380px) {
  .chat-header-name { font-size: 0.85rem; }
  .message-bubble { max-width: 92%; }
  .call-ctrl-btn { width: 46px; height: 46px; }
  .call-ctrl-end { width: 54px; height: 54px; }
}

/* ── iOS safe areas ── */
@supports (padding-top: env(safe-area-inset-top)) {
  .sidebar-header,
  .chat-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }
  .chat-input-area {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .call-controls {
    bottom: max(40px, env(safe-area-inset-bottom));
  }
}

@keyframes bounceIn {
  0%   { transform: scale(0.7); opacity: 0; }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.notification-badge {
  position: absolute; top: -2px; right: -2px;
  width: 16px; height: 16px;
  background: var(--danger); border-radius: 50%;
  font-size: 0.6rem; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  animation: bounceIn 0.3s ease;
}
