/* ============================================================
   MESSENGER v2 — Tema Branco e Azul (Firebase)
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-50: #eff6ff;
  --bg-app: #f0f2f5;
  --bg-white: #ffffff;
  --bg-chat: #e8f0fe;
  --bubble-self: #2563eb;
  --bubble-self-text: #ffffff;
  --bubble-other: #ffffff;
  --bubble-other-text: #1f2937;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.15);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 20px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100vh; height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-white);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

@media (min-width: 481px) {
  body { display: flex; justify-content: center; align-items: center; background: var(--bg-app); }
  #app { height: 100vh; height: 100dvh; border-radius: 0; }
}

.screen { display: none; flex-direction: column; height: 100%; width: 100%; }
.screen.active { display: flex; }

/* ---- TELA DE BOAS-VINDAS ---- */
#welcome-screen {
  justify-content: center; align-items: center;
  background: linear-gradient(160deg, #2563eb 0%, #1d4ed8 50%, #1e40af 100%);
}
.welcome-container { text-align: center; padding: 40px 32px; width: 100%; max-width: 360px; }
.welcome-icon {
  width: 72px; height: 72px; background: rgba(255,255,255,0.2);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px; color: #fff;
}
.welcome-icon svg { width: 36px; height: 36px; }
.welcome-title { font-size: 2rem; font-weight: 700; color: #fff; margin-bottom: 8px; }
.welcome-subtitle { font-size: 0.95rem; color: rgba(255,255,255,0.85); margin-bottom: 32px; }
.welcome-form { display: flex; flex-direction: column; gap: 12px; }
.welcome-form .input-field {
  background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.25);
  color: #fff; text-align: center; font-size: 1.1rem; padding: 14px 16px;
}
.welcome-form .input-field::placeholder { color: rgba(255,255,255,0.5); }
.welcome-form .input-field:focus { border-color: #fff; background: rgba(255,255,255,0.2); }

.btn-primary {
  background: #fff; color: var(--primary); border: none; padding: 14px 24px;
  border-radius: var(--radius-md); font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(0,0,0,0.2); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- HEADER ---- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--primary); color: #fff;
  flex-shrink: 0; z-index: 10;
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; }
.header-right { gap: 4px; }
.header-app-name { font-size: 1.2rem; font-weight: 700; }
.header-btn {
  background: none; border: none; color: #fff; cursor: pointer; padding: 6px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.header-btn:hover { background: rgba(255,255,255,0.15); }
.header-btn:active { background: rgba(255,255,255,0.25); }
.danger-btn:hover { background: rgba(239,68,68,0.3) !important; }

/* ---- LISTA DE CONVERSAS ---- */
.conversations-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px; border-bottom: 1px solid var(--border);
}
.section-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }

.btn-icon {
  background: var(--primary); color: #fff; border: none; width: 36px; height: 36px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition);
}
.btn-icon:hover { background: var(--primary-dark); transform: scale(1.05); }
.btn-icon:active { transform: scale(0.95); }

.conversations-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.conversation-item {
  display: flex; align-items: center; padding: 12px 16px; gap: 14px;
  cursor: pointer; transition: background var(--transition);
  border-bottom: 1px solid var(--border-light);
}
.conversation-item:hover { background: var(--primary-50); }
.conversation-item:active { background: var(--primary-light); }
.conversation-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 600; flex-shrink: 0;
}
.conversation-info { flex: 1; min-width: 0; }
.conversation-name { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.conversation-preview { font-size: 0.85rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.conversation-time { font-size: 0.75rem; color: var(--text-muted); }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }

/* ---- EMPTY STATE ---- */
.empty-state {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--text-muted); gap: 8px; padding: 40px 20px;
}
.empty-state svg { opacity: 0.4; margin-bottom: 8px; }
.empty-state p { font-size: 0.95rem; }
.empty-state-hint { font-size: 0.85rem !important; opacity: 0.7; }

/* ---- CHAT ---- */
.chat-header .header-left { flex: 1; min-width: 0; }
.chat-contact-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-contact-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.25);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; font-weight: 600; flex-shrink: 0;
}
.chat-contact-name { font-size: 0.95rem; font-weight: 600; display: block; line-height: 1.3; }
.chat-contact-status { font-size: 0.75rem; opacity: 0.8; display: block; line-height: 1.2; }

.messages-container {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column;
  gap: 4px; background: var(--bg-chat); overscroll-behavior: contain;
}

/* ---- BALÕES ---- */
.message { max-width: 80%; display: flex; flex-direction: column; animation: msg-in 0.2s ease; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message-self { align-self: flex-end; align-items: flex-end; }
.message-other { align-self: flex-start; align-items: flex-start; }
.message-bubble {
  padding: 10px 14px; border-radius: var(--radius-lg); font-size: 0.92rem;
  line-height: 1.45; word-break: break-word; box-shadow: var(--shadow-sm);
}
.message-self .message-bubble { background: var(--bubble-self); color: var(--bubble-self-text); border-bottom-right-radius: 4px; }
.message-other .message-bubble { background: var(--bubble-other); color: var(--bubble-other-text); border-bottom-left-radius: 4px; }
.message-time { font-size: 0.65rem; margin-top: 2px; padding: 0 4px; opacity: 0.7; }
.message-self .message-time { color: rgba(255,255,255,0.7); }
.message-other .message-time { color: var(--text-muted); }
.message-sender-name {
  font-size: 0.7rem; font-weight: 600; color: var(--primary); margin-bottom: 2px; padding: 0 4px;
}
.message-date-separator {
  text-align: center; margin: 12px 0; font-size: 0.75rem; color: var(--text-muted);
  background: rgba(255,255,255,0.7); align-self: center; padding: 4px 14px;
  border-radius: 12px; font-weight: 500;
}

/* ---- INPUT ---- */
.message-input-area {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: var(--bg-white); border-top: 1px solid var(--border); flex-shrink: 0;
}
.message-input {
  flex: 1; border-radius: 24px !important; padding: 12px 18px !important;
  font-size: 0.92rem !important; background: var(--bg-app) !important;
  border: 2px solid transparent !important;
}
.message-input:focus { border-color: var(--primary) !important; background: var(--bg-white) !important; }
.btn-send {
  width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff;
  border: none; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition); flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--primary-dark); transform: scale(1.05); }
.btn-send:active:not(:disabled) { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.input-field {
  width: 100%; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-md); font-size: 0.95rem; outline: none;
  transition: border-color var(--transition); font-family: inherit;
  color: var(--text-primary); background: var(--bg-white);
}
.input-field:focus { border-color: var(--primary); }
.input-field::placeholder { color: var(--text-muted); }

/* ---- MODAL ---- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 100; justify-content: center; align-items: center; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal { background: var(--bg-white); border-radius: var(--radius-xl); width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-header .header-btn { color: var(--text-secondary); }
.modal-header .header-btn:hover { background: var(--border-light); }
.modal-body { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.modal-label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.modal-body .btn-primary { margin-top: 4px; background: var(--primary); color: #fff; }
.modal-body .btn-primary:disabled { background: #93c5fd; }
.modal-body .btn-danger {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  padding: 12px 24px; border-radius: var(--radius-md); font-size: 0.9rem;
  font-weight: 500; cursor: pointer; transition: all var(--transition); margin-top: 8px;
}
.modal-body .btn-danger:hover { background: #fef2f2; }

.profile-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 600; margin: 0 auto 8px; }

/* ---- TOAST ---- */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1f2937; color: #fff; padding: 10px 24px; border-radius: var(--radius-md);
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow-md);
  opacity: 0; transition: all 0.3s ease; pointer-events: none; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ---- RESPONSIVE ---- */
@media (min-width: 481px) {
  #app { height: 90vh; max-height: 800px; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
}
@media (min-width: 768px) {
  #app { max-width: 420px; height: 85vh; max-height: 750px; border-radius: var(--radius-xl); }
}
@media all and (display-mode: standalone) {
  #app { max-width: 100%; height: 100vh; height: 100dvh; border-radius: 0; box-shadow: none; }
  body { background: var(--bg-white); }
}
