/* ====== reset basico ====== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body {
  background: #0b141a;
  color: #e9edef;
  font-size: 15px;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; background: none; border: none; outline: none; }

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

/* ====== auth ====== */
#auth-screen { justify-content: center; align-items: center; padding: 24px; }
.auth-box {
  width: 100%; max-width: 380px;
  background: #111b21;
  border: 1px solid #1f2c34;
  border-radius: 12px;
  padding: 24px;
}
.logo { text-align: center; margin-bottom: 20px; }
.logo h1 { margin-top: 8px; color: #00a884; font-size: 24px; }
.logo .tagline { font-size: 12px; color: #8696a0; margin-top: 4px; }
.tabs { display: flex; gap: 4px; background: #0b141a; border-radius: 8px; padding: 4px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; border-radius: 6px;
  color: #8696a0; font-weight: 500; transition: all .15s;
}
.tab.active { background: #1f2c34; color: #e9edef; }

.auth-form { display: none; flex-direction: column; gap: 10px; }
.auth-form.active { display: flex; }
.auth-form input {
  background: #2a3942; padding: 12px 14px; border-radius: 8px;
  color: #e9edef;
}
.auth-form input::placeholder { color: #8696a0; }
.auth-form button[type="submit"] {
  background: #00a884; color: #fff; padding: 12px; border-radius: 8px;
  font-weight: 600; margin-top: 6px; transition: background .15s;
}
.auth-form button[type="submit"]:hover { background: #008f72; }
.auth-form button[type="submit"]:disabled { background: #5a6e77; cursor: not-allowed; }
.hint { font-size: 12px; color: #8696a0; margin-top: 6px; line-height: 1.4; }
.error { color: #f15c6d; font-size: 13px; margin-top: 4px; min-height: 16px; }

/* ====== topbar ====== */
.topbar {
  height: 56px; flex-shrink: 0;
  background: #202c33;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid #0b141a;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(56px + env(safe-area-inset-top, 0));
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.topbar-title strong { font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #8696a0; }
.status-dot.online { background: #00a884; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #aebac1; transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: #374248; }
.icon-btn.danger { color: #f15c6d; }
.icon-btn.send { background: #00a884; color: #fff; }
.icon-btn.send:hover { background: #008f72; }

.chat-topbar { gap: 12px; }
.chat-contact { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.chat-contact strong { font-size: 16px; font-weight: 600; }
.chat-contact-status { font-size: 12px; color: #8696a0; }
.chat-contact-status.online { color: #00a884; }

/* ====== contacts list ====== */
.contacts-list { flex: 1; overflow-y: auto; }
.contact-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #1f2c34;
  cursor: pointer; transition: background .15s;
}
.contact-item:hover { background: #182229; }
.contact-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #00a884; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 18px; flex-shrink: 0;
}
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 500; }
.contact-status { font-size: 12px; color: #8696a0; }
.contact-status.online { color: #00a884; }
.unread-badge {
  background: #00a884; color: #fff;
  font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; flex-shrink: 0;
}
.contact-signal {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #ffd279; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.contact-signal:hover { background: #374248; }
.contact-signal:active { transform: scale(1.2); }
.contact-item.signal-flash {
  animation: signal-flash 0.5s ease-in-out 6;
}
@keyframes signal-flash {
  0%, 100% { background: transparent; }
  50% { background: #2a3942; }
}
.contact-remove {
  color: #8696a0; padding: 8px; opacity: 0;
  transition: opacity .15s;
}
.contact-item:hover .contact-remove { opacity: 1; }

.empty-state {
  padding: 40px 24px; text-align: center;
  color: #8696a0; line-height: 1.6;
}
.empty-state strong { color: #00a884; }

/* ====== chat ====== */
.ephemeral-warning {
  background: #182229; color: #ffd279;
  padding: 8px 16px; font-size: 12px;
  display: flex; align-items: center; gap: 6px;
  justify-content: center; text-align: center;
  border-bottom: 1px solid #1f2c34;
}
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
  background-color: #0b141a;
  background-image:
    radial-gradient(#182229 1px, transparent 1px),
    radial-gradient(#182229 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: 0 0, 20px 20px;
}
.message {
  max-width: 75%;
  padding: 7px 10px 8px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  animation: msg-in .15s ease-out;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.message.mine {
  align-self: flex-end;
  background: #005c4b;
  border-bottom-right-radius: 2px;
}
.message.theirs {
  align-self: flex-start;
  background: #202c33;
  border-bottom-left-radius: 2px;
}
.message-time {
  font-size: 10px; color: #8696a0;
  margin-top: 2px; text-align: right;
}
.message img { max-width: 100%; border-radius: 4px; display: block; }
.message audio { width: 220px; max-width: 100%; }

.typing-indicator {
  padding: 6px 16px; font-size: 12px; color: #00a884;
  font-style: italic;
}
.typing-indicator.hidden { display: none; }

.chat-input {
  flex-shrink: 0;
  background: #202c33;
  padding: 8px;
  display: flex; align-items: flex-end; gap: 6px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
}
.chat-input textarea {
  flex: 1; background: #2a3942;
  padding: 10px 14px;
  border-radius: 20px;
  resize: none; max-height: 120px;
  line-height: 1.4;
}
.chat-input textarea::placeholder { color: #8696a0; }
.chat-input .icon-btn { flex-shrink: 0; }

/* ====== modal ====== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal.active { display: flex; }
.modal-content {
  background: #202c33; border-radius: 12px;
  padding: 20px; width: 100%; max-width: 360px;
}
.modal-content h3 { margin-bottom: 8px; }
.modal-content input {
  background: #2a3942; padding: 10px 14px;
  border-radius: 8px; width: 100%;
  margin-top: 12px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px;
}
.modal-actions button {
  padding: 8px 16px; border-radius: 6px;
  background: #00a884; color: #fff; font-weight: 500;
}
.modal-actions .btn-secondary {
  background: transparent; color: #aebac1;
}

/* ====== toast ====== */
.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #202c33;
  color: #e9edef;
  padding: 10px 20px; border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 200;
  transition: transform .25s, opacity .25s;
  opacity: 0;
  pointer-events: none;
  font-size: 14px;
  white-space: nowrap;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ====== mobile-first responsivo ====== */
@media (min-width: 768px) {
  .screen { max-width: 480px; margin: 0 auto; border-left: 1px solid #1f2c34; border-right: 1px solid #1f2c34; }
}

/* rec indicator */
.rec-indicator {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #f15c6d; color: #fff;
  padding: 10px 20px; border-radius: 20px;
  display: none; align-items: center; gap: 8px;
  z-index: 50;
  animation: pulse 1s infinite;
}
.rec-indicator.active { display: flex; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .7; } }
