:root {
  --bg: #0d0f12;
  --surface: #161920;
  --surface-2: #1d212b;
  --border: #262b36;
  --primary: #ff3b5c;
  --primary-hover: #e02e4d;
  --text: #f0f2f5;
  --muted: #8b949e;
  --warn-bg: rgba(255, 184, 77, 0.12);
  --warn-border: rgba(255, 184, 77, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; }
body { background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
.container { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.center { text-align: center; padding: 20px 0; }
.muted { color: var(--muted); }
.block { display: block; width: 100%; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

/* ---------- Cabecera ---------- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; padding: 12px 0;
}
.nav-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.logo { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; }
.logo span { color: var(--primary); }
#nav { display: flex; align-items: center; gap: 10px; }
.nav-icon { position: relative; font-size: 1.25rem; padding: 4px 6px; line-height: 1; }
.nav-user { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.nav-user span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

main { padding: 20px 0 48px; }
.view { display: flex; flex-direction: column; gap: 16px; }
.view.hidden { display: none; }

/* ---------- Componentes base ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
h2 { font-size: 1.2rem; }

input, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 12px; border-radius: 8px; margin-bottom: 12px; font-size: 1rem; resize: none;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
input[type='file'] { padding: 8px; font-size: 0.9rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }

button, .btn {
  display: inline-block; background: var(--primary); color: #fff; border: none; padding: 10px 18px;
  border-radius: 8px; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: background 0.15s; text-align: center;
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--muted); }
button.secondary:hover { color: var(--text); border-color: var(--text); }
button.small { padding: 6px 12px; font-size: 0.85rem; }
.icon-btn { background: none; color: var(--muted); padding: 6px 8px; border-radius: 8px; font-size: 1rem; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.error-msg { color: #ff6b6b; font-size: 0.9rem; min-height: 1.2em; }
.toggle-text { margin-top: 12px; font-size: 0.9rem; color: var(--muted); }
.toggle-text a { color: var(--primary); font-weight: 600; }

.badge {
  background: var(--primary); color: #fff; font-size: 0.7rem; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-icon .badge { position: absolute; top: -4px; right: -6px; }

.banner { padding: 10px 12px; border-radius: 8px; font-size: 0.88rem; margin: 0 0 12px; border: 1px solid var(--border); background: var(--surface-2); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.banner button { margin-left: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); font-size: 0.92rem; box-shadow: 0 6px 24px rgba(0,0,0,.45);
}

/* ---------- Avatares ---------- */
.avatar { border-radius: 50%; object-fit: cover; background: var(--border); flex-shrink: 0; display: inline-block; }
.avatar-sm { width: 36px; height: 36px; }
.avatar-lg { width: 84px; height: 84px; border: 2px solid var(--primary); }
.avatar.ph { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); }
.avatar-sm.ph { font-size: 0.95rem; }
.avatar-lg.ph { font-size: 2rem; border: 2px solid var(--primary); }

/* ---------- Composer ---------- */
.composer-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.composer-tools { display: flex; align-items: center; gap: 12px; }
.file-upload-btn { color: var(--primary); font-size: 0.9rem; font-weight: 600; cursor: pointer; margin: 0; }
#char-count { color: var(--muted); font-size: 0.85rem; }
#media-preview { margin-bottom: 12px; }
#media-preview img, #media-preview video { max-height: 180px; max-width: 100%; border-radius: 8px; display: block; margin-bottom: 8px; }

/* ---------- Publicaciones ---------- */
.post { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.post-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 0.9rem; }
.post-author { display: flex; align-items: center; gap: 10px; min-width: 0; }
.post-user-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.post-user-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-user-info small { color: var(--muted); font-size: 0.8rem; }
.post-header time { color: var(--muted); font-size: 0.75rem; margin-left: auto; white-space: nowrap; }
.post-content { margin-bottom: 12px; white-space: pre-wrap; word-break: break-word; }
.post-media { display: block; width: 100%; max-height: 460px; object-fit: cover; border-radius: 8px; margin-bottom: 12px; background: #000; }
.like-btn { background: rgba(255, 59, 92, 0.1); color: var(--primary); padding: 6px 12px; font-size: 0.85rem; }
.like-btn:hover { background: rgba(255, 59, 92, 0.2); }
.like-btn.liked { background: rgba(255, 59, 92, 0.22); }

/* ---------- Perfil ---------- */
.profile-header { display: flex; align-items: flex-start; gap: 20px; }
.profile-info { min-width: 0; }
.profile-info h2 { font-size: 1.3rem; word-break: break-word; }
.profile-info .username { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
.profile-info .bio { font-size: 0.95rem; margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.profile-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.85rem; margin-top: 10px; }
.profile-stats b { color: var(--text); }
.profile-actions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; }
.profile-tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab-btn { background: none; color: var(--muted); padding: 10px 20px; border-radius: 0; border-bottom: 2px solid transparent; }
.tab-btn:hover { background: none; color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72); display: flex; justify-content: center; align-items: center; z-index: 100; padding: 16px; }
.modal-content { width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; }
.modal-content h3 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* ---------- Mensajes ---------- */
#inbox { display: flex; flex-direction: column; gap: 16px; }
.e2ee-note { color: var(--muted); font-size: 0.85rem; margin: 6px 0 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { margin: 0; }
.inline-form button { white-space: nowrap; }

.chat-item { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; padding: 12px 14px; }
.chat-item:hover { border-color: var(--primary); }
.chat-item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.chat-item-main span { font-size: 0.88rem; }
.chat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.75rem; color: var(--muted); }

.chat-card { display: flex; flex-direction: column; height: calc(100dvh - 130px); min-height: 380px; padding: 12px; }
.chat-head { display: flex; align-items: center; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.chat-title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title:hover { color: var(--primary); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; overscroll-behavior: contain; }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 14px; word-break: break-word; }
.bubble .txt { white-space: pre-wrap; }
.bubble time { display: block; font-size: 0.68rem; opacity: 0.7; margin-top: 2px; text-align: right; }
.bubble.in { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.chat-form textarea { margin: 0; max-height: 140px; }

.safety-number { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.25rem; letter-spacing: 1px; text-align: center; padding: 16px 8px; margin: 12px 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; word-spacing: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .nav-user span:last-child { display: none; }
  .profile-header { flex-direction: column; align-items: center; text-align: center; }
  .profile-stats, .profile-actions { justify-content: center; }
  .inline-form { flex-direction: column; }
  .bubble { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Evita desbordamientos horizontales en teléfonos */
body, html {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Hace que las cajas de chat, perfiles y publicaciones se adapten al ancho del celular */
.container, .post, .profile-card, .chat-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 10px;
  box-sizing: border-box;
}

/* Modales y menús flotantes responsivos */
@media (max-width: 768px) {
  /* Hace que las ventanas flotantes ocupen casi toda la pantalla en móviles */
  .modal, .edit-profile-modal {
    width: 95% !important;
    max-height: 90vh;
    left: 50% !important;
    transform: translateX(-50%);
    padding: 15px;
  }
  
  /* Ajusta la barra de navegación superior para que no se amontone */
  header, .navbar {
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }
}