:root {
  --navy: #0f172a;
  --navy-light: #1e293b;
  --navy-lighter: #26324a;
  --slate: #94a3b8;
  --emerald: #10b981;
  --emerald-dark: #0ea571;
  --border: #2b3750;
  --text: #e8edf5;
  --bad: #e24c4c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; } /* evita a pagina inteira rolar - so as listas internas rolam */
body {
  font-family: 'Inter', -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--navy);
  color: var(--text);
}
.hidden { display: none !important; }

/* ---- shared auth-style views (login / pairing) ---- */
.center-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% -10%, #152036 0%, var(--navy) 55%);
  padding: 16px;
}
.card {
  background: var(--navy-light);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 32px 32px;
  text-align: center;
}
.logo { display: block; margin: 0 auto 20px; max-width: 170px; height: auto; }
.logo-sm { height: 22px; width: auto; }
h1 { font-size: 1.1rem; font-weight: 600; margin: 0 0 2px; }
.subtitle { color: var(--slate); font-size: 0.85rem; margin: 0 0 20px; }
.hint { color: var(--slate); font-size: 0.8rem; line-height: 1.5; margin-top: 14px; text-align: left; }
.hint.muted { text-align: center; font-style: italic; }

label { display: block; text-align: left; font-size: 0.8rem; color: var(--slate); margin-bottom: 6px; font-weight: 500; }
input[type=text], input[type=password] {
  width: 100%; padding: 11px 13px; margin-bottom: 16px;
  background: #0f1626; border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 0.92rem; font-family: inherit; outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--emerald); }
button {
  width: 100%; padding: 12px; border: none; border-radius: 9px;
  background: var(--emerald); color: #04140d; font-weight: 600; font-size: 0.92rem;
  cursor: pointer; transition: background .15s; font-family: inherit;
}
button:hover { background: var(--emerald-dark); }
.error {
  background: rgba(226,76,76,0.12); border: 1px solid rgba(226,76,76,0.4);
  color: #f3a0a0; font-size: 0.82rem; padding: 9px 12px; border-radius: 8px;
  margin-bottom: 16px; text-align: center;
}
.pair-code {
  font-size: 2rem; letter-spacing: 6px; font-weight: 700; color: var(--emerald);
  background: #0f1626; border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin: 10px 0;
}

/* ---- inbox layout ---- */
#view-inbox { display: flex; height: 100vh; height: 100dvh; } /* dvh: barra do navegador no celular nao empurra o layout */
.sidebar {
  width: 300px; min-width: 240px; background: var(--navy-light);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.icon-btn {
  width: auto; padding: 6px 10px; background: transparent; border: 1px solid var(--border);
  color: var(--slate); border-radius: 8px; font-size: 1rem;
}
.icon-btn:hover { color: var(--text); border-color: var(--emerald); background: transparent; }
.sidebar-top-actions { display: flex; gap: 8px; position: relative; }
.search-box { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.search-box input {
  margin-bottom: 0; background: #0f1626; border-radius: 999px; font-size: 0.85rem; padding: 9px 14px;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab-btn {
  flex: 1; background: transparent; border: none; color: var(--slate);
  padding: 10px; font-size: 0.82rem; font-weight: 500; border-bottom: 2px solid transparent;
  cursor: pointer; border-radius: 0;
}
.tab-btn:hover { background: var(--navy-lighter); color: var(--text); }
.tab-btn.active { color: var(--emerald); border-bottom-color: var(--emerald); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; align-items: center; gap: 10px; position: relative;
}
.chat-item:hover { background: var(--navy-lighter); }
.chat-item-menu-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; padding: 0; border: none; border-radius: 50%;
  background: transparent; color: var(--slate); font-size: 0.95rem; opacity: 0; transition: opacity .12s;
}
.chat-item-menu-btn:hover { background: var(--navy); color: var(--text); }
@media (hover: hover) and (pointer: fine) {
  .chat-item:hover .chat-item-menu-btn { opacity: 1; }
}
@media (hover: none) {
  .chat-item-menu-btn { opacity: 0.55; } /* no touch, sempre visivel (sem hover pra revelar) */
}
.chat-item.active { background: var(--navy-lighter); border-left: 3px solid var(--emerald); }
.chat-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--navy-lighter);
  border: 1px solid var(--border); color: var(--emerald); font-weight: 700; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-item .name { font-weight: 600; font-size: 0.9rem; display:flex; justify-content:space-between; align-items:center; gap: 8px; }
.chat-item .name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display:flex; align-items:center; gap:5px; }
.chat-item .preview { color: var(--slate); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge {
  background: var(--emerald); color: #04140d; font-size: 0.7rem; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; flex-shrink: 0;
}
.mute-icon { font-size: 0.75rem; opacity: 0.6; }

.thread {
  flex: 1; display: flex; flex-direction: column;
  background-color: var(--navy);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(16,185,129,0.045) 0%, transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(16,185,129,0.04) 0%, transparent 40%);
}
.thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--slate); font-size: 0.9rem; }
.thread-empty-inner { text-align: center; }
.thread-empty-logo { width: 64px; opacity: 0.25; margin-bottom: 14px; }
.thread-active { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.thread-header {
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--navy-light);
  display: flex; align-items: center; gap: 12px;
}
.back-btn { display: none; }
.thread-header-name { font-weight: 600; font-size: 0.95rem; flex: 1; }
.thread-header-actions { display: flex; gap: 6px; position: relative; }
.thread-header-actions .icon-btn.active-toggle { color: var(--emerald); border-color: var(--emerald); }

.thread-messages {
  flex: 1; overflow-y: auto; padding: 18px 6% ; display: flex; flex-direction: column; gap: 2px;
}
.msg {
  position: relative;
  max-width: 65%; padding: 7px 9px 8px 10px; margin: 3px 0; font-size: 0.9rem; line-height: 1.35;
  word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
.msg.in {
  align-self: flex-start; background: var(--navy-light); color: var(--text);
  border-radius: 2px 10px 10px 10px;
}
.msg.out {
  align-self: flex-end; background: var(--emerald); color: #04140d;
  border-radius: 10px 2px 10px 10px;
}
.msg .meta {
  display: flex; align-items: center; gap: 3px; text-align: right; font-size: 0.66rem; opacity: 0.65;
  float: right; margin-left: 8px; margin-top: 4px;
}
.msg .ticks {
  font-size: 0.68rem; line-height: 1; letter-spacing: -2px; margin-left: 1px;
  color: rgba(4,20,13,0.55); /* cinza-escuro sobre o verde do balao proprio */
}
.msg.in .ticks { color: var(--slate); } /* nao deveria aparecer em msg recebida, mas por garantia */
.msg .ticks.read { color: #53bdeb; opacity: 1; }
.msg .edited-tag { font-style: italic; opacity: 0.8; margin-right: 2px; }
.msg::after { content: ""; clear: both; display: table; }
.msg img.media {
  max-width: 260px; max-height: 320px; width: auto; height: auto; object-fit: cover;
  border-radius: 8px; display: block; margin-bottom: 4px; cursor: pointer;
}
.msg video.media { max-width: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
/* player de audio proprio (nao usa o <audio controls> nativo - sem botao de baixar, visual WhatsApp) */
.voice-player { display: flex; align-items: center; gap: 8px; width: 210px; margin-bottom: 4px; padding: 2px 0; }
.vp-play {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; padding: 0; border: none;
  background: rgba(0,0,0,0.18); color: inherit; font-size: 0.85rem; display: flex; align-items: center; justify-content: center;
}
.msg.out .vp-play { background: rgba(0,0,0,0.15); }
.vp-bar {
  flex: 1; height: 3px; background: rgba(255,255,255,0.25); border-radius: 2px; cursor: pointer; position: relative;
}
.msg.out .vp-bar { background: rgba(0,0,0,0.2); }
.vp-progress { height: 100%; background: currentColor; border-radius: 2px; width: 0%; }
.vp-time { font-size: 0.7rem; opacity: 0.75; flex-shrink: 0; min-width: 30px; text-align: right; }

/* barra de hover (reacoes rapidas + "⌄") - flutua ACIMA do balao, longe do horario.
   sempre no DOM; so aparece (opacity) em telas com mouse de verdade, pra nao atrapalhar o toque. */
.msg-hover-bar {
  position: absolute; top: -38px; right: 4px; display: flex; align-items: center; gap: 1px;
  background: var(--navy-lighter); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px; box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 3;
}
.msg.in .msg-hover-bar { right: auto; left: 4px; }
@media (hover: hover) and (pointer: fine) {
  .msg:hover .msg-hover-bar { opacity: 1; pointer-events: auto; }
}
.msg-hover-bar button {
  width: 26px; height: 26px; padding: 0; border: none; border-radius: 50%;
  background: transparent; font-size: 0.95rem; display: flex; align-items: center; justify-content: center;
}
.msg-hover-bar button:hover { background: var(--navy); }
.msg-hover-bar .hover-chevron { font-size: 0.75rem; color: var(--slate); margin-left: 2px; }

.pinned-badge { font-size: 0.7rem; margin-right: 3px; opacity: 0.8; }

/* visualizador de imagem em tela cheia */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 4px; }

/* anel colorido no avatar indicando status nao visto, igual ao WhatsApp */
.status-ring { box-shadow: 0 0 0 2px var(--navy-light), 0 0 0 4px var(--emerald); }
.status-ring.viewed { box-shadow: 0 0 0 2px var(--navy-light), 0 0 0 4px var(--border); }

/* ---- visualizador de status (estilo stories) ---- */
.status-viewer {
  position: fixed; inset: 0; background: #000; z-index: 60;
  display: flex; flex-direction: column;
}
.sv-progress { display: flex; gap: 4px; padding: 10px 10px 0; }
.sv-seg { flex: 1; height: 3px; background: rgba(255,255,255,0.3); border-radius: 2px; overflow: hidden; }
.sv-seg-fill { height: 100%; width: 0%; background: #fff; }
.sv-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #fff; }
.sv-header-body { flex: 1; display: flex; flex-direction: column; }
.sv-header-body .sv-time { font-size: 0.72rem; opacity: 0.7; }
.sv-header .icon-btn { color: #fff; border-color: rgba(255,255,255,0.3); }
.sv-content {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative;
  padding: 10px; overflow: hidden; /* min-height:0 evita midia alta empurrar o rodape (reagir/responder) pra fora da tela */
}
.sv-content img, .sv-content video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.sv-text-status {
  color: #fff; font-size: 1.4rem; text-align: center; padding: 30px; line-height: 1.5;
  max-width: 500px;
}
.voice-player.sv-audio { width: 280px; background: rgba(255,255,255,0.1); padding: 14px 18px; border-radius: 14px; color: #fff; }
.sv-tap-zone { position: absolute; top: 60px; bottom: 70px; width: 30%; z-index: 1; }
.sv-tap-left { left: 0; }
.sv-tap-right { right: 0; }
.sv-footer { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.sv-footer input {
  flex: 1; margin-bottom: 0; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25);
  color: #fff; border-radius: 999px;
}
.sv-footer input::placeholder { color: rgba(255,255,255,0.6); }
.sv-footer button { width: auto; background: transparent; color: #fff; font-size: 1.3rem; padding: 6px 10px; }
.sv-footer button:hover { background: rgba(255,255,255,0.12); }
.msg .doc-link {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  background: rgba(0,0,0,0.15); margin-bottom: 4px; text-decoration: none; color: inherit; font-size: 0.85rem;
}
.msg.sticker-msg { background: transparent; box-shadow: none; padding: 0; }
.msg.sticker-msg img.media { width: 130px; border-radius: 0; margin-bottom: 0; }

/* icone que aparece arrastando a mensagem pra direita (responder, estilo WhatsApp) */
.swipe-reply-icon {
  position: absolute; left: 4px; width: 26px; display: flex; align-items: center; justify-content: center;
  color: var(--emerald); font-size: 1.2rem; opacity: 0; pointer-events: none; z-index: 1;
}

.quoted-ref {
  display: block; margin-bottom: 5px; padding: 5px 8px; border-left: 3px solid var(--emerald);
  background: rgba(0,0,0,0.15); border-radius: 6px; font-size: 0.78rem; opacity: 0.85;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg.out .quoted-ref { background: rgba(0,0,0,0.1); border-left-color: #04140d; }

.msg-reactions {
  display: flex; gap: 3px; margin-top: -4px; margin-bottom: 4px; flex-wrap: wrap;
}
.msg-reactions .chip {
  background: var(--navy-lighter); border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.72rem; padding: 1px 6px;
}
.msg-reactions .chip.mine { border-color: var(--emerald); }

/* ---- menus suspensos genericos ---- */
.dropdown-menu {
  position: absolute; background: var(--navy-lighter); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); z-index: 20; overflow: hidden;
  min-width: 190px;
}
.dropdown-menu button {
  width: 100%; text-align: left; background: transparent; border: none; border-radius: 0;
  padding: 11px 14px; font-size: 0.85rem; font-weight: 500; color: var(--text);
}
.dropdown-menu button:hover { background: var(--navy); }
#chat-menu { top: 44px; right: 0; }

.msg-menu { position: fixed; min-width: 210px; }
.quick-reactions {
  display: flex; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.quick-reactions button {
  width: auto; padding: 4px; font-size: 1.3rem; background: transparent; border-radius: 6px;
}
.quick-reactions button:hover { background: var(--navy); }

/* ---- respondendo (preview acima da caixa de texto) ---- */
.reply-preview {
  margin: 0 16px; background: var(--navy-lighter); border-radius: 8px;
  padding: 8px 10px; display: flex; align-items: stretch; gap: 8px; font-size: 0.82rem;
}
.reply-preview-bar { width: 3px; background: var(--emerald); border-radius: 2px; flex-shrink: 0; }
.reply-preview-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.reply-preview-label { color: var(--emerald); font-size: 0.72rem; font-weight: 600; }
#reply-preview-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--slate); }
.reply-preview button { width: auto; background: transparent; color: var(--slate); padding: 2px 6px; align-self: center; }

.send-form {
  display: flex; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border);
  background: var(--navy-light); align-items: flex-end;
}
/* pilula unica com emoji + texto + anexo dentro, igual ao padrao do WhatsApp */
.send-pill {
  flex: 1; display: flex; align-items: flex-end; gap: 2px;
  background: #0f1626; border-radius: 22px; padding: 4px 6px 4px 10px; min-width: 0;
}
.send-pill .icon-btn { flex-shrink: 0; border: none; font-size: 1.25rem; padding: 7px; background: transparent; }
#send-input {
  flex: 1; min-width: 0; margin-bottom: 0; background: transparent; border: none;
  padding: 8px 6px; font-size: 0.92rem; font-family: inherit; color: var(--text);
  resize: none; outline: none; line-height: 1.3;
  max-height: 120px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word; /* nunca rola na horizontal - sempre quebra linha */
}
.send-btn {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}

.attach-preview {
  margin: 0 16px; background: var(--navy-lighter); border: 1px solid var(--emerald); border-radius: 8px;
  padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem;
}
.attach-preview button { width: auto; background: transparent; color: var(--slate); padding: 2px 6px; }

.emoji-picker {
  position: absolute; bottom: 64px; left: 16px; width: 280px; max-height: 220px; overflow-y: auto;
  background: var(--navy-lighter); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; z-index: 5;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.emoji-picker button {
  background: transparent; border: none; font-size: 1.2rem; padding: 4px; border-radius: 6px; width: auto;
}
.emoji-picker button:hover { background: var(--navy); }

/* ---- settings modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { width: 100%; max-width: 380px; padding: 28px 26px; }
.modal h2 { font-size: 1.05rem; margin: 0 0 18px; }
.settings-row {
  display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.settings-label { color: var(--slate); }
.danger-btn {
  width: 100%; margin-top: 20px; padding: 11px; border: 1px solid var(--bad); background: transparent;
  color: var(--bad); border-radius: 9px; font-weight: 600; cursor: pointer;
}
.danger-btn:hover { background: rgba(226,76,76,0.1); }
.ghost-btn {
  width: 100%; margin-top: 10px; padding: 11px; border: 1px solid var(--border); background: transparent;
  color: var(--slate); border-radius: 9px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { color: var(--text); background: transparent; }

/* ---- lista de conversas/contatos dentro de modais (encaminhar, compor status) ---- */
.forward-chat-list {
  max-height: 260px; overflow-y: auto; margin: 4px 0 14px;
  border: 1px solid var(--border); border-radius: 9px;
}
.forward-chat-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 0.85rem; font-weight: 400;
  margin: 0; text-align: left;
}
.forward-chat-row:last-child { border-bottom: none; }
.forward-chat-row:hover { background: var(--navy-lighter); }
.forward-chat-row input[type=checkbox] { width: auto; margin: 0; accent-color: var(--emerald); flex-shrink: 0; }
.forward-chat-row .chat-avatar { width: 28px; height: 28px; font-size: 0.75rem; }

/* ---- compor status ---- */
.composer-card { max-width: 420px; max-height: 85vh; overflow-y: auto; text-align: left; }
.composer-type-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.ct-tab {
  flex: 1; background: var(--navy-lighter); border: 1px solid var(--border); color: var(--slate);
  padding: 8px; border-radius: 8px; font-size: 0.82rem; font-weight: 500;
}
.ct-tab.active { background: var(--emerald); color: #04140d; border-color: var(--emerald); }
.sc-panel textarea {
  width: 100%; background: #0f1626; border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-family: inherit; font-size: 0.9rem; padding: 10px; resize: vertical; margin-bottom: 10px;
}
.sc-colors { display: flex; gap: 8px; margin-bottom: 14px; }
.sc-color-swatch {
  width: 28px; height: 28px; border-radius: 50%; padding: 0; border: 2px solid transparent;
}
.sc-color-swatch.selected { border-color: #fff; }
.sc-file-name { font-size: 0.8rem; color: var(--slate); margin: 6px 0; }
.sc-subheading { font-size: 0.85rem; margin: 6px 0 8px; color: var(--text); }
.sc-audience { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; font-size: 0.85rem; }
.sc-audience label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.sc-audience input[type=radio] { width: auto; margin: 0; accent-color: var(--emerald); }
#sc-post { margin-top: 6px; }

@media (max-width: 720px) {
  #view-inbox { position: relative; overflow: hidden; }
  .sidebar { width: 100%; position: absolute; inset: 0; z-index: 2; transition: transform .2s ease; }
  .sidebar.chat-open { transform: translateX(-100%); pointer-events: none; }
  .thread { width: 100%; }
  .back-btn { display: inline-flex; align-items: center; justify-content: center; }
}
