/* ============================================================
 * Chat Familiar — Estilos 100% locales (Mobile-First)
 * Sin CDNs ni fuentes externas para máxima velocidad y uso offline.
 * ============================================================ */

:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --surface-3: #283548;
  --border: #2a364b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --danger: #ef4444;
  --warn: #f59e0b;
  --info: #38bdf8;

  --bubble-me: #065f46;
  --bubble-other: #1e293b;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* Banners */
.banner {
  padding: 9px 14px;
  font-size: 13px;
  text-align: center;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.banner-danger {
  background: rgba(239, 68, 68, 0.22);
  color: #fecaca;
  border-bottom: 1px solid rgba(239, 68, 68, 0.45);
}
.banner-warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fde68a;
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
}
.banner-info {
  background: rgba(56, 189, 248, 0.14);
  color: #bae6fd;
  border-bottom: 1px solid rgba(56, 189, 248, 0.3);
  text-align: left;
  justify-content: space-between;
}
.banner-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 16px;
  padding: 4px 6px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Avatares */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}
.avatar-gina { background: linear-gradient(135deg, #ec4899, #db2777); }
.avatar-betto { background: linear-gradient(135deg, #10b981, #059669); }
.avatar-paulo { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.avatar-familia { background: linear-gradient(135deg, #f59e0b, #d97706); font-size: 20px; }

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

/* ============================================================
 * PANTALLA DE ACCESO (Mobile-First)
 * ============================================================ */
.auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 62%);
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.auth-logo {
  text-align: center;
  margin-bottom: 20px;
}
.logo-circle {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  margin: 0 auto 10px;
  background: linear-gradient(135deg, #10b981, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
}
.auth-logo h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.auth-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-section {
  margin-bottom: 18px;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.profile-card {
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px 6px;
  min-height: 92px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.profile-card.selected {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.15);
  transform: translateY(-2px);
}
.profile-name {
  font-weight: 600;
  font-size: 14px;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input {
  width: 100%;
  padding: 14px 48px 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px; /* Evita zoom automático en iOS Safari */
  outline: none;
}
.password-wrap input:focus {
  border-color: var(--primary);
}
.icon-btn-inline {
  position: absolute;
  right: 6px;
  min-width: 40px;
  min-height: 40px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.85;
}
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 13px;
}

/* Botones (áreas táctiles >= 44px para móvil) */
.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  min-height: 46px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:active {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
}
.btn-full {
  width: 100%;
  margin-top: 14px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.icon-btn:active,
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.push-active {
  background: rgba(16, 185, 129, 0.18);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.45);
}

/* ============================================================
 * CHAT PRINCIPAL (Mobile-First: pantalla completa + transición)
 * ============================================================ */
.chat-screen {
  height: 100%;
  width: 100%;
  position: relative;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  transition: transform 0.22s ease;
}

.chat-screen.mobile-in-chat .sidebar {
  transform: translateX(-100%);
  pointer-events: none;
}

.sidebar-header {
  padding: calc(10px + var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.me-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.me-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.me-info strong {
  font-size: 16px;
}
.status-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.rooms-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
}

.room-item {
  width: 100%;
  min-height: 66px;
  background: transparent;
  border: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 4px;
}
.room-item:active,
.room-item:hover {
  background: var(--surface-2);
}
.room-item.active {
  background: rgba(16, 185, 129, 0.16);
}

.room-item-body {
  flex: 1;
  min-width: 0;
}
.room-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}
.room-item-name {
  font-weight: 600;
  font-size: 15.5px;
}
.room-item-time {
  font-size: 11.5px;
  color: var(--text-muted);
}
.room-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.room-item-preview {
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unread-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  text-align: center;
}
.btn-link-danger {
  background: none;
  border: none;
  color: #fca5a5;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
}

/* Conversación activa */
.chat-main {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-header {
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.room-header-info h2 {
  font-size: 16px;
  font-weight: 700;
}
.e2e-pill {
  font-size: 11px;
  font-weight: 600;
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 3px 7px;
  border-radius: 999px;
}

/* Mensajes */
.messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 290px;
  padding: 20px;
}
.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}
.empty-state p {
  font-size: 13.5px;
}

.date-divider {
  align-self: center;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 4px 12px;
  border-radius: 999px;
  margin: 8px 0 4px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}
.msg-row.me {
  align-self: flex-end;
  align-items: flex-end;
}
.msg-row.other {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  padding: 9px 12px 7px;
  border-radius: 16px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  min-width: 90px;
}
.msg-row.me .msg-bubble {
  background: var(--bubble-me);
  border-bottom-right-radius: 4px;
}
.msg-row.other .msg-bubble {
  background: var(--bubble-other);
  border-bottom-left-radius: 4px;
}

.msg-sender {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 3px;
}
.sender-gina { color: #f472b6; }
.sender-betto { color: #34d399; }
.sender-paulo { color: #818cf8; }

.msg-text {
  font-size: 15px;
  white-space: pre-wrap;
}

.msg-photo {
  display: block;
  max-width: 250px;
  max-height: 320px;
  width: 100%;
  border-radius: 10px;
  object-fit: cover;
  cursor: pointer;
  margin-bottom: 4px;
}
.msg-caption {
  font-size: 14px;
  margin-top: 4px;
  white-space: pre-wrap;
}

.msg-audio-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 215px;
}
.msg-audio-wrap audio {
  width: 225px;
  max-width: 100%;
  height: 38px;
}
.msg-audio-label {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.8);
}

.msg-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  text-decoration: none;
  color: var(--text);
  min-width: 210px;
  max-width: 270px;
}
.msg-file-card:hover {
  background: rgba(0, 0, 0, 0.34);
}
.msg-file-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.msg-file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.msg-file-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-file-size {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.7);
}
.msg-file-dl {
  font-size: 18px;
  flex-shrink: 0;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 4px;
}

/* Composer táctil */
.composer-bar,
.recording-bar {
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.composer-bar textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* Evita zoom en iOS */
  outline: none;
  line-height: 1.35;
}
.composer-bar textarea:focus {
  border-color: var(--primary);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-mic {
  background: #0ea5e9;
}

/* Grabación */
.recording-bar {
  align-items: center;
  justify-content: space-between;
  padding-left: 10px;
  padding-right: 10px;
}
.rec-cancel {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.16);
}
.rec-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* Modales */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 16px;
}

.camera-viewport {
  background: #000;
  position: relative;
  aspect-ratio: 4 / 3;
  max-height: 58dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.camera-viewport video,
.camera-viewport img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.camera-fallback {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.camera-controls {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.shutter-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--primary);
  cursor: pointer;
}
.shutter-btn:active {
  transform: scale(0.92);
}

.preview-controls {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preview-controls input {
  width: 100%;
  padding: 12px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.preview-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Lightbox */
.lightbox-wrap {
  width: 100%;
  max-width: 900px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.lightbox-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.lightbox-btns {
  display: flex;
  gap: 6px;
}
#lightbox-img {
  max-width: 100%;
  max-height: 76dvh;
  border-radius: 10px;
  object-fit: contain;
}
.lightbox-caption {
  font-size: 14px;
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 200;
}

.mobile-only {
  display: inline-flex;
}

/* ============================================================
 * DESKTOP / TABLET (>= 769px)
 * ============================================================ */
@media (min-width: 769px) {
  .mobile-only {
    display: none !important;
  }
  .sidebar {
    position: static;
    width: 320px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    transform: none !important;
    pointer-events: auto !important;
  }
  .chat-main {
    flex: 1;
  }
  .msg-row {
    max-width: 72%;
  }
  .composer-bar textarea {
    font-size: 15px;
  }
}
