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

:root {
  --primary: #075E54;
  --primary-light: #128C7E;
  --accent: #25D366;
  --bg: #ECE5DD;
  --bubble-out: #DCF8C6;
  --bubble-in: #FFFFFF;
  --text: #111;
  --text-sec: #667781;
  --danger: #d33;
}

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

/* ========== TELAS ========== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ========== LOGIN ========== */
#screen-auth {
  background: linear-gradient(135deg, #075E54 0%, #128C7E 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-box {
  background: #fff;
  padding: 32px 24px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
}
.logo { font-size: 56px; margin-bottom: 8px; }
.auth-box h1 { font-size: 28px; color: var(--primary); margin-bottom: 4px; }
.subtitle { color: var(--text-sec); margin-bottom: 24px; font-size: 14px; }

.auth-box input,
.new-body input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid #ddd;
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
}
.auth-box input:focus,
.new-body input:focus { border-color: var(--primary); }
.auth-box input.hidden { display: none; }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--primary-light); }

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.msg-error {
  color: var(--danger);
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
}

/* ========== HEADER ========== */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
  z-index: 10;
}
.app-header h2 { font-size: 18px; font-weight: 600; flex: 1; }

.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 22px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 50%;
  line-height: 1;
}
.icon-btn:active { background: rgba(255,255,255,0.18); }

.chat-title { flex: 1; min-width: 0; }
.chat-title h3 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle-small { font-size: 12px; opacity: 0.85; }

/* ========== LISTA DE CHATS ========== */
.list { flex: 1; overflow-y: auto; background: #fff; }
.chat-item {
  display: flex;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  align-items: center;
  gap: 12px;
}
.chat-item:active { background: #f5f5f5; }
.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--primary-light);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-info { flex: 1; min-width: 0; }
.chat-info h4 {
  font-size: 15.5px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-info p {
  font-size: 13px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-sec);
  font-size: 14px;
  line-height: 1.6;
}

/* ========== MENSAGENS ========== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
}
.message {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.message.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}
.message.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}
.message .sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-light);
  margin-bottom: 2px;
}
.message .text { white-space: pre-wrap; }
.message .meta {
  font-size: 11px;
  color: var(--text-sec);
  text-align: right;
  margin-top: 3px;
}

/* ========== INPUT DE MENSAGEM ========== */
.msg-form {
  display: flex;
  padding: 8px;
  background: #fff;
  gap: 8px;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.msg-form input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 24px;
  background: #f0f0f0;
  font-size: 15px;
  outline: none;
}
.send-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:active { background: var(--primary-light); }

/* ========== NOVO CHAT ========== */
.new-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #fff;
}
.new-body h3 {
  margin-bottom: 12px;
  font-size: 16px;
  color: var(--primary);
}
.new-body hr {
  border: none;
  border-top: 1px solid #eee;
  margin: 24px 0;
}




/* ============ NOVOS ============ */
.my-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background-color: #128C7E; background-size: cover; background-position: center;
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.offline-badge {
  background: #d33; color: #fff; padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; margin-right: 4px;
}
.offline-badge.hidden { display: none; }

.attach-btn { font-size: 20px; padding: 8px; }

.pending-attachment {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #fff3cd; border-top: 1px solid #ffeeba;
  font-size: 13px; color: #856404; gap: 8px;
}
.pending-attachment.hidden { display: none; }
.pending-attachment span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-attachment .icon-btn { color: #856404; font-size: 16px; }

.message.pending { opacity: 0.7; }
.message.pending .meta::after { content: ''; }

.attachment { margin-bottom: 6px; }
.attachment img, .attachment video {
  width: 240px;
  height: 240px;
  object-fit: contain;
  background: #00000010;
  border-radius: 8px;
  display: block;
  cursor: pointer;
}
.attachment audio { width: 100%; max-width: 240px; }
.attachment.file a {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.06); padding: 8px 12px; border-radius: 8px;
  text-decoration: none; color: inherit; font-size: 13px;
}
.attachment .size { font-size: 11px; color: #666; }

/* Avatar picker (auth + profile) */
.avatar-picker { margin-bottom: 16px; display: flex; justify-content: center; }
.avatar-picker.hidden { display: none; }
.avatar-preview {
  width: 90px; height: 90px; border-radius: 50%;
  background-color: #e0e0e0; background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #666; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 2px dashed #bbb; transition: border-color 0.2s;
}
.avatar-preview:hover { border-color: var(--primary); }
.avatar-preview.large { width: 120px; height: 120px; font-size: 15px; }
.avatar-preview.has-image { border-style: solid; border-color: var(--primary); color: transparent; }

.profile-avatar-wrap { display: flex; justify-content: center; margin-bottom: 24px; }

.new-body input:disabled, .new-body input[disabled] { background: #f0f0f0; color: #999; }

/* ============ REPLY BAR ============ */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #e8f5e9;
  border-top: 1px solid #c8e6c9;
  gap: 8px;
}
.reply-bar.hidden { display: none; }
.reply-bar-content { flex: 1; min-width: 0; border-left: 3px solid var(--primary); padding-left: 8px; }
.reply-bar-name { font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.reply-bar-text { font-size: 13px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { color: #555; }

/* ============ BOLHA COM RESPOSTA ============ */
.message .reply-inner {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--primary-light);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 12px;
  cursor: pointer;
}
.message .reply-inner .reply-name { font-weight: 600; color: var(--primary-light); margin-bottom: 1px; }
.message .reply-inner .reply-text { color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ BOTÃO 3 PONTINHOS ============ */
.message { position: relative; }
.message .msg-dots {
  position: absolute;
  top: 2px;
  right: -28px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message:hover .msg-dots,
.message.show-dots .msg-dots { opacity: 1; }

/* ============ SWIPE PARA RESPONDER ============ */
.message.dragging { transition: none !important; opacity: 0.7; }

/* ============ MENU CONTEXTO ============ */
.msg-menu-backdrop {
  position: fixed; inset: 0; z-index: 998;
  background: rgba(0,0,0,0.15);
}
.msg-menu-backdrop.hidden { display: none; }
.msg-menu {
  position: fixed;
  z-index: 999;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  padding: 6px;
  min-width: 160px;
}
.msg-menu.hidden { display: none; }
.msg-menu-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: transparent;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
  color: #222;
}
.msg-menu-btn:hover { background: #f0f0f0; }
.msg-menu-btn.danger { color: #d33; }

/* ============ IMAGE VIEWER ============ */
.image-viewer {
  position: fixed; inset: 0; z-index: 1000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.image-viewer.hidden { display: none; }
.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  will-change: transform;
}
.image-viewer-close {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 2;
}

/* ============ REPLY BAR ============ */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #e8f5e9;
  border-top: 1px solid #c8e6c9;
  gap: 8px;
}
.reply-bar.hidden { display: none; }
.reply-bar-content { flex: 1; min-width: 0; border-left: 3px solid var(--primary); padding-left: 8px; }
.reply-bar-name { font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.reply-bar-text { font-size: 13px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { color: #555; }

/* ============ BOLHA COM RESPOSTA ============ */
.message .reply-inner {
  background: rgba(0,0,0,0.06);
  border-left: 3px solid var(--primary-light);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 12px;
  cursor: pointer;
}
.message .reply-inner .reply-name { font-weight: 600; color: var(--primary-light); margin-bottom: 1px; }
.message .reply-inner .reply-text { color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ BOTÃO 3 PONTINHOS ============ */
.message { position: relative; }
.message .msg-dots {
  position: absolute;
  top: 2px;
  right: -28px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message:hover .msg-dots,
.message.show-dots .msg-dots { opacity: 1; }

/* ============ SWIPE PARA RESPONDER ============ */
.message.dragging { transition: none !important; opacity: 0.7; }

/* ============ MENU CONTEXTO ============ */
.msg-menu-backdrop {
  position: fixed; inset: 0; z-index: 998;
  background: rgba(0,0,0,0.15);
}
.msg-menu-backdrop.hidden { display: none; }
.msg-menu {
  position: fixed;
  z-index: 999;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  padding: 6px;
  min-width: 160px;
}
.msg-menu.hidden { display: none; }
.msg-menu-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: transparent;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
  color: #222;
}
.msg-menu-btn:hover { background: #f0f0f0; }
.msg-menu-btn.danger { color: #d33; }

/* ============ IMAGE VIEWER ============ */
.image-viewer {
  position: fixed; inset: 0; z-index: 1000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.image-viewer.hidden { display: none; }
.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  will-change: transform;
}
.image-viewer-close {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 2;
}

/* ============ FIX: overflow horizontal após swipe ============ */
.messages {
  overflow-x: hidden !important;
}
.message {
  max-width: 78%;
}



/* (removido) */

/* Indicador visual durante o swipe (ícone ↩ à esquerda) */
.message.dragging::before {
  content: '↩';
  position: absolute;
  left: -34px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  color: var(--primary);
  opacity: 0.8;
}



/* ============ 3 PONTINHOS LIMPOS ============ */
.message {
  position: relative;
}

.message .msg-dots {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #888;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}

/* Mensagem MINHA (out, à direita) → botão do lado ESQUERDO, fora da bolha */
.message.out .msg-dots {
  right: 100%;
  margin-right: 4px;
}

/* Mensagem DO OUTRO (in, à esquerda) → botão do lado DIREITO, fora da bolha */
.message.in .msg-dots {
  left: 100%;
  margin-left: 4px;
}

.message .msg-dots:active {
  opacity: 1;
  color: var(--primary);
}
