:root {
  --green: #075E54;
  --green-light: #128C7E;
  --accent: #25D366;
  --bg: #ECE5DD;
  --mine: #DCF8C6;
  --theirs: #FFFFFF;
  --text: #222;
  --muted: #667781;
  --danger: #d9534f;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); height: 100%; }
body { display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--green-light); text-decoration: none; }

/* ---------- avatar ---------- */
.avatar { display:inline-flex; align-items:center; justify-content:center; width:28px; height:28px; border-radius:50%; color:#fff; font-weight:bold; font-size:.85rem; }
.chat-avatar { width:46px; height:46px; border-radius:50%; color:#fff; font-weight:bold; font-size:1.2rem; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.chat-avatar-sm { width:34px; height:34px; border-radius:50%; color:#fff; font-weight:bold; font-size:.9rem; display:flex; align-items:center; justify-content:center; flex-shrink:0; margin-right:8px; }
.chat-cover-img { object-fit: cover; background: #ccc; }
.cover-upload-btn { display:block; text-align:center; background: var(--green); color:#fff; border-radius:8px; padding:8px; font-size:.9rem; cursor:pointer; margin-top: 0; }

/* ---------- topo ---------- */
.topbar { background: var(--green); color: #fff; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; font-weight: bold; position: sticky; top: 0; z-index: 10; gap:8px; }
.topbar .me { font-weight:normal; font-size:.85rem; opacity:.9; display:flex; align-items:center; gap:6px; }

/* ---------- container ---------- */
.container { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 600px; margin: 0 auto; padding: 0 0 70px; min-height: 0; }
h1 { font-size: 1.3rem; padding: 16px; margin: 0; color: var(--green); }

/* ---------- flash ---------- */
.flash { padding: 0 16px; }
.flash-msg { background: #fff3cd; border: 1px solid #ffe69c; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: .9rem; }

/* ---------- nav inferior ---------- */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid #ddd; display: flex; justify-content: space-around; padding: 8px 0; max-width: 600px; margin: 0 auto; z-index: 20; }
.bottom-nav a { font-size: 1.4rem; padding: 4px 14px; }

/* ---------- formulários ---------- */
.auth-box { padding: 0 16px; display: flex; flex-direction: column; }
.auth-box h1 { padding: 16px 0; }
label { font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=tel], input[type=password] { border: 1px solid #ccc; border-radius: 8px; padding: 12px; font-size: 1rem; width: 100%; }
button { margin-top: 16px; background: var(--green); color: #fff; border: none; border-radius: 8px; padding: 12px; font-size: 1rem; cursor: pointer; }
button:active { background: var(--green-light); }
.btn-secondary { background: #888; margin-top: 0; }
.btn-danger { background: var(--danger); }
.hint, .empty { padding: 0 16px; color: var(--muted); font-size: .85rem; }
.empty { text-align: center; }

/* ---------- lista conversas ---------- */
.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-list li { background: #fff; border-bottom: 1px solid #eee; display: flex; align-items: center; }
.chat-list li.pinned { background: #f0faf5; }
.chat-row { display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; flex: 1; color: var(--text); min-width: 0; }
.chat-info { flex: 1; min-width: 0; }
.chat-title-row { display: flex; justify-content: space-between; align-items: center; }
.chat-title { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex:1; }
.chat-preview { color: var(--muted); font-size: .9rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: .7rem; background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 6px; font-weight: normal; }
.unread-badge { background: var(--accent); color: #fff; border-radius: 50%; min-width: 20px; height: 20px; font-size: .75rem; font-weight: bold; display: flex; align-items: center; justify-content: center; padding: 0 4px; flex-shrink:0; }
.pin-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 10px 12px; margin-top: 0; color: var(--muted); }
.blocked-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; }
.block-form { padding: 0 16px 8px; }

/* ---------- cabeçalho conversa ---------- */
.chat-header { background: var(--green); color: #fff; display: flex; align-items: center; padding: 10px 12px; position: sticky; top: 49px; z-index: 9; gap:6px; }
.chat-header .back { color: #fff; font-size: 1.3rem; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.typing-indicator { font-size: .75rem; color: #b2dfdb; min-height: 14px; }
.chat-menu summary { list-style: none; cursor: pointer; font-size: 1.4rem; padding: 0 6px; }
.chat-menu summary::-webkit-details-marker { display: none; }
.chat-menu { position: relative; }
.menu-content { position: absolute; right: 0; top: 30px; background: #fff; color: var(--text); border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,.2); padding: 10px; width: 240px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.menu-content a { padding: 6px 4px; display:block; }
.menu-content form { padding: 0; }
.menu-content button { margin-top: 0; font-size: .9rem; padding: 8px; width:100%; }
.menu-section { border-top: 1px solid #eee; padding-top: 8px; }
.menu-label { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.menu-hint, .menu-info { font-size: .75rem; color: var(--muted); }
.nickname-form { display: flex; gap: 6px; }
.nickname-form input { flex: 1; padding: 6px 8px; font-size: .9rem; }
.nickname-form button { margin-top: 0; padding: 6px 10px; width: auto; font-size: .85rem; }

/* ---------- scroll infinito ---------- */
.load-older { text-align: center; padding: 8px; }
.load-older button { background: var(--green-light); font-size: .85rem; padding: 6px 16px; margin: 0; border-radius: 20px; }
.hidden { display: none !important; }

/* ---------- mensagens ---------- */
.messages { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.msg { max-width: 82%; border-radius: var(--radius); font-size: .95rem; position: relative; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.mine { background: var(--mine); align-self: flex-end; border-bottom-right-radius: 2px; }
.msg.theirs { background: var(--theirs); align-self: flex-start; border-bottom-left-radius: 2px; }
.msg.deleted { background: #f5f5f5; color: var(--muted); font-style: italic; padding: 6px 10px; font-size: .88rem; align-self: center; max-width: 90%; }
.msg-sender { font-size: .78rem; font-weight: bold; padding: 6px 10px 0; }
.msg-text { padding: 6px 10px; white-space: pre-wrap; word-break: break-word; }
.msg-footer { display: flex; align-items: center; justify-content: flex-end; padding: 2px 6px 4px; gap: 4px; }
.msg-time { font-size: .68rem; color: var(--muted); }
.msg-react-btn, .msg-reply-btn, .msg-del-btn { background: none; border: none; cursor: pointer; font-size: .85rem; padding: 0 2px; margin: 0; color: var(--muted); line-height: 1; }

/* ---------- reply quote ---------- */
.reply-quote { border-left: 3px solid var(--green-light); background: rgba(0,0,0,.05); border-radius: 4px; padding: 4px 8px; margin: 6px 10px 0; cursor: pointer; }
.reply-quote-sender { font-size: .75rem; color: var(--green-light); font-weight: bold; display: block; }
.reply-quote-text { font-size: .82rem; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- reply bar ---------- */
.reply-bar { display: flex; align-items: center; background: #e8f5e9; border-top: 2px solid var(--accent); padding: 6px 12px; gap: 8px; position: fixed; bottom: 110px; left: 0; right: 0; max-width: 600px; margin: 0 auto; z-index: 15; }
.reply-preview { flex: 1; min-width: 0; }
.reply-preview span { display: block; }
#reply-sender { font-size: .78rem; color: var(--green-light); font-weight: bold; }
#reply-text { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar button { background: none; border: none; font-size: 1.1rem; color: var(--muted); cursor: pointer; margin: 0; padding: 0; }

/* ---------- media ---------- */
.media-tap-wrap { cursor: pointer; padding: 6px 10px 2px; }
.media-tap-label { color: var(--green-light); font-size: .88rem; font-weight: bold; padding: 4px 0; }
.media-timer { font-weight: normal; font-size: .8rem; }
.msg-media { max-width: 100%; border-radius: 6px; display: block; }
.msg-thumb { max-width: 100%; border-radius: 6px; display: block; filter: blur(4px); transition: filter .2s; }
.msg-thumb.revealed { filter: none; }
.msg-audio { width: 100%; padding: 6px 10px; }
.msg-unavailable { color: var(--muted); font-style: italic; font-size: .85rem; padding: 6px 10px; }

/* ---------- reações ---------- */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 8px 4px; }
.reaction-pill { background: rgba(0,0,0,.07); border-radius: 12px; padding: 2px 8px; font-size: .85rem; cursor: pointer; border: none; margin: 0; }
.reaction-panel { position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%); background: #fff; border-radius: 30px; box-shadow: 0 2px 16px rgba(0,0,0,.2); padding: 6px 12px; z-index: 40; }
.reaction-options { display: flex; gap: 8px; }
.reaction-options button { font-size: 1.4rem; background: none; border: none; cursor: pointer; margin: 0; padding: 4px; }

/* ---------- barra de envio ---------- */
.send-bar { position: fixed; bottom: 56px; left: 0; right: 0; max-width: 600px; margin: 0 auto; background: #f0f0f0; display: flex; align-items: center; gap: 6px; padding: 8px; border-top: 1px solid #ddd; z-index: 15; }
.send-bar input[type=text] { flex: 1; border-radius: 20px; padding: 10px 14px; }
.send-bar button, .attach-btn, .voice-btn { background: var(--accent); color: #fff; border: none; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; cursor: pointer; margin: 0; flex-shrink: 0; }
.attach-btn { background: #ccc; color: var(--text); }
.voice-btn { background: #ccc; color: var(--text); }
.voice-btn.recording { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ---------- modal de confirmação ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; max-width: 280px; width: 90%; }
.modal-box p { margin: 0 0 16px; font-size: 1rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions button { margin: 0; padding: 8px 18px; font-size: .95rem; }

/* ---------- invite ---------- */
.invite-input { margin: 0 16px 16px; width: calc(100% - 32px); border: 1px solid #ccc; border-radius: 8px; padding: 12px; }
.btn { display: block; margin: 0 16px; background: var(--green); color: #fff; text-align: center; border-radius: 8px; padding: 12px; }
.btn-outline { background: #fff; color: var(--green); border: 2px solid var(--green); margin-top: 10px; }
.invite-banner { margin: 0 16px 8px; background: #e7f3ff; border: 1px solid #b6dcff; border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.invite-landing { display: flex; flex-direction: column; gap: 8px; }
.invite-landing .btn, .invite-landing .btn-outline { margin-top: 8px; }

/* ---------- botão outline e divisor ---------- */
.button-outline { margin-top: 16px; background: #fff; color: var(--green); border: 2px solid var(--green); border-radius: 8px; padding: 10px; font-size: 1rem; cursor: pointer; width: 100%; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: .85rem; margin: 16px; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid #ddd; }
.divider span { padding: 0 10px; }

/* ---------- ajuste altura chat ---------- */
body:has(.chat-header) .container { height: 100vh; padding-bottom: 130px; }
