:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel2: #1c2733;
  --line: #101921;
  --txt: #ffffff;
  --muted: #708499;
  --accent: #5288c1;
  --accent2: #64b5ef;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --danger: #e5484d;
  --ok: #4dcd5e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin-top: 10px; text-align: center; }
.ic { width: 24px; height: 24px; display: block; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- LOGIN ---------- */
.auth {
  align-items: center; justify-content: center; padding: 24px; overflow: hidden;
  background: radial-gradient(140% 90% at 50% -20%, #2f6fb0 0%, #1b2b3d 42%, #0e1621 100%);
}
.auth-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.auth-bg .b {
  position: absolute; border-radius: 50%; opacity: .16;
  background: linear-gradient(135deg, #7cc4f5, #3f72af);
  animation: float 9s ease-in-out infinite;
}
.auth-bg .b1 { width: 130px; height: 130px; left: -34px; top: 10%; }
.auth-bg .b2 { width: 72px; height: 72px; right: 9%; top: 7%; opacity: .12; animation-delay: 1.4s; }
.auth-bg .b3 { width: 170px; height: 170px; right: -46px; bottom: 8%; opacity: .1; animation-delay: .8s; }
.auth-bg .b4 { width: 92px; height: 92px; left: 8%; bottom: 16%; opacity: .09; animation-delay: 2.1s; }
@keyframes float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-24px) } }
.auth-card {
  position: relative; width: 100%; max-width: 380px;
  background: rgba(23,33,43,.74);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 24px; padding: 28px 22px 22px;
  backdrop-filter: blur(16px);
  box-shadow: 0 26px 70px rgba(0,0,0,.5);
  animation: rise .5s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.brand { text-align: center; margin-bottom: 22px; }
.logo {
  width: 106px; height: 106px; margin: 0 auto 14px; border-radius: 30px;
  background: linear-gradient(135deg, rgba(124,196,245,.22), rgba(63,114,175,.22));
  border: 1px solid rgba(255,255,255,.10);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 16px 40px rgba(63,114,175,.45);
}
.logo svg { width: 82px; height: 82px; filter: drop-shadow(0 8px 14px rgba(0,0,0,.35)); }
.brand h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: .4px; }
.brand-tag { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: var(--muted); }
.brand-tag .ic { width: 14px; height: 14px; color: var(--accent2); }
#authForm { display: flex; flex-direction: column; gap: 11px; }
.field {
  display: flex; align-items: center; gap: 10px;
  background: rgba(12,20,28,.7);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 14px; padding: 0 14px;
}
.field .ic { color: var(--muted); width: 20px; height: 20px; flex: 0 0 auto; }
.field input {
  flex: 1; border: none; background: none; color: var(--txt);
  padding: 15px 0; font-size: 16px; outline: none;
}
.field:focus-within { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(100,181,239,.15); }
.primary {
  margin-top: 4px; padding: 15px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, #64b5ef, #5288c1);
  color: #fff; font-size: 16px; font-weight: 600; letter-spacing: .2px;
  box-shadow: 0 10px 24px rgba(82,136,193,.35);
}
.primary:active { transform: translateY(1px); }
.link { align-self: center; margin-top: 16px; background: none; border: none; color: var(--accent2); font-size: 14px; }
.avatar-picker {
  width: 92px; height: 92px; margin: 2px auto 6px; border-radius: 50%;
  background: rgba(12,20,28,.7); border: 2px dashed rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  cursor: pointer; text-align: center; color: var(--muted); font-size: 10px; line-height: 1.25;
}
.avatar-picker.filled { border-style: solid; border-color: var(--accent2); }
.avatar-picker img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-picker .ic { width: 22px; height: 22px; margin: 0 auto 2px; }

/* ---------- TOPBAR / LISTA ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--safe-top)) 12px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar .title { flex: 1; font-size: 19px; font-weight: 600; }
.icon-btn {
  background: none; border: none; color: var(--muted); padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,.06); }
.list { flex: 1; overflow-y: auto; padding: 6px 0 calc(70px + var(--safe-bottom)); }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.row:active { background: var(--panel2); }
.avatar {
  width: 50px; height: 50px; border-radius: 50%; flex: 0 0 auto; position: relative;
  background: linear-gradient(135deg, #64b5ef, #5288c1);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 17px; color: #fff; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar .dot { position: absolute; right: 0; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--ok); border: 2px solid var(--panel); }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 600; display: flex; align-items: baseline; gap: 6px; }
.row .name small { color: var(--muted); font-weight: 400; font-size: 11px; }
.row .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; border-radius: 12px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 46px 24px; font-size: 14px; }
.empty .ic { width: 46px; height: 46px; margin: 0 auto 12px; opacity: .4; }
.bottomnav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tab { flex: 1; background: none; border: none; color: var(--muted); padding: 9px; display: flex; flex-direction: column; gap: 3px; align-items: center; font-size: 11px; }
.tab.active { color: var(--accent2); }

/* ---------- CHAT ---------- */
.chat {
  background: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,.022) 1px, transparent 1px);
  background-size: 22px 22px;
}
.chat-top { padding-left: 4px; }
.chat-top .peer { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.peer-txt { display: flex; flex-direction: column; min-width: 0; }
.peer-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-sub { font-size: 12px; color: var(--muted); height: 14px; }
.messages { flex: 1; overflow-y: auto; padding: 12px 10px 18px; display: flex; flex-direction: column; }
.daysep { align-self: center; margin: 12px 0 6px; font-size: 12px; color: #cdd8e6; background: rgba(0,0,0,.30); padding: 3px 12px; border-radius: 12px; }

.bubble {
  position: relative; max-width: 82%; margin-top: 3px;
  padding: 7px 11px 5px; border-radius: 15px; font-size: 15px; line-height: 1.38;
  word-wrap: break-word; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.14);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 6px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 6px; }
.bubble.first { margin-top: 10px; }
.bubble.group.in { border-bottom-left-radius: 15px; }
.bubble.group.out { border-bottom-right-radius: 15px; }
.bubble .btext p { margin: 0; }
.bmeta { display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-top: 2px; min-height: 12px; }
.btime { font-size: 10.5px; color: rgba(255,255,255,.55); }
.bubble.in .btime { color: var(--muted); }
.bmeta .ic { width: 13px; height: 13px; color: rgba(255,255,255,.65); }
.bubble .sender { font-size: 11px; font-weight: 700; letter-spacing: .2px; margin-bottom: 2px; }
.bubble.in .sender { color: var(--accent2); }
.bubble.out .sender { color: #cfe9ff; }
.bubble.undecryptable { font-style: italic; opacity: .65; }

/* midia */
.bubble.media { padding: 4px 4px 5px; width: fit-content; max-width: 82%; }
.bubble.media .cap { padding: 5px 7px 1px; }
.bubble .media-body { display: block; border-radius: 12px; overflow: hidden; }
.bubble img.media-img { display: block; max-width: 300px; max-height: 340px; width: auto; height: auto; }
.media-placeholder {
  width: 230px; height: 150px; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; background: rgba(0,0,0,.22); color: #cfd9e6; font-size: 12px;
}
.media-placeholder.audio { width: 250px; height: 54px; flex-direction: row; }
.media-file { display: flex; align-items: center; gap: 10px; padding: 8px; width: 250px; }
.media-file .fi { width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.media-file .fmeta { flex: 1; min-width: 0; }
.media-file .fname { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-file .fsize { font-size: 11px; opacity: .7; }
.media-file .fdl { color: inherit; opacity: .85; }
.bubble audio { display: block; width: 250px; height: 40px; }
.bubble video.media-video { display: block; max-width: 300px; max-height: 360px; border-radius: 12px; background: #000; }

.composer-wrap { background: var(--panel); border-top: 1px solid var(--line); }
.composer { display: flex; gap: 4px; align-items: center; padding: 8px 8px calc(8px + var(--safe-bottom)); }
.composer input { flex: 1; border: none; background: var(--panel2); color: var(--txt); padding: 12px 14px; border-radius: 20px; font-size: 16px; outline: none; }
.round-send { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--accent2); color: #fff; display: flex; align-items: center; justify-content: center; }
.round-send:active { background: var(--accent); }

/* ---------- SHEET (anexos) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
.sheet {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom));
  background: var(--panel); border-radius: 18px; padding: 8px; z-index: 31;
  display: flex; flex-direction: column; gap: 2px; animation: rise .2s ease;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.sheet button {
  display: flex; align-items: center; gap: 14px; background: none; border: none;
  color: var(--txt); font-size: 16px; padding: 15px 14px; border-radius: 12px; text-align: left;
}
.sheet button:active { background: var(--panel2); }
.sheet .ic { color: var(--accent2); }
.sheet button.danger { color: var(--danger); }
.sheet button.danger .ic { color: var(--danger); }
.sheet-note { font-size: 12px; color: var(--muted); padding: 2px 14px 10px; }
.sheet-title { font-size: 13px; color: var(--muted); padding: 12px 14px 6px; }
.forward-list { max-height: 46vh; overflow-y: auto; }
.forward-list .row { padding: 10px 14px; }

/* barra de resposta */
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 8px 0; padding: 7px 10px;
  background: var(--panel2); border-left: 3px solid var(--accent2); border-radius: 10px;
}
.rb-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rb-label { color: var(--accent2); font-size: 12px; font-weight: 600; }
.bmeta .edited { font-size: 10px; color: var(--muted); margin-right: 6px; font-style: italic; }
.bubble.out .bmeta .edited { color: rgba(255,255,255,.6); }
#replyName { color: var(--accent2); font-size: 12px; font-weight: 600; }
#replyPreview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* citacao dentro do balao */
.quote {
  border-left: 3px solid var(--accent2); background: rgba(0,0,0,.20);
  padding: 4px 8px; margin-bottom: 5px; border-radius: 6px; max-width: 100%;
}
.bubble.out .quote { border-left-color: #bfe0ff; }
.quote .qn { color: var(--accent2); font-size: 12px; font-weight: 600; }
.bubble.out .quote .qn { color: #bfe0ff; }
.quote .qp { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- GRAVACAO ---------- */
.record { background: #05080f; align-items: center; justify-content: center; }
.record #recordPreview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #05080f; }
.rec-audio { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rec-wave { display: flex; align-items: flex-end; gap: 5px; height: 46px; }
.rec-wave span { width: 6px; background: var(--accent2); border-radius: 3px; animation: wav .9s ease-in-out infinite; }
.rec-wave span:nth-child(2){ animation-delay:.15s } .rec-wave span:nth-child(3){ animation-delay:.3s }
.rec-wave span:nth-child(4){ animation-delay:.45s } .rec-wave span:nth-child(5){ animation-delay:.6s }
@keyframes wav { 0%,100% { height: 12px } 50% { height: 44px } }
.rec-time { font-size: 26px; font-weight: 700; }
.rec-actions { position: absolute; bottom: calc(40px + var(--safe-bottom)); left: 0; right: 0; display: flex; justify-content: center; gap: 60px; z-index: 2; }
.round { width: 62px; height: 62px; border-radius: 50%; border: none; background: rgba(255,255,255,.16); color: #fff; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px); }
.round.send { background: var(--accent2); } .round.hang { background: var(--danger); } .round.accept { background: var(--ok); }
.round.active { background: rgba(255,255,255,.42); }

/* ---------- CHAMADA ---------- */
.call { background: #05080f; }
.call #remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.call #localVideo { position: absolute; top: calc(14px + var(--safe-top)); right: 14px; width: 30%; max-width: 150px; border-radius: 14px; object-fit: cover; border: 1px solid var(--line); transform: scaleX(-1); z-index: 2; }
.call-info { position: absolute; top: calc(20px + var(--safe-top)); left: 0; right: 0; text-align: center; font-size: 15px; color: #cbd6ee; z-index: 2; }
.call-actions { position: absolute; bottom: calc(28px + var(--safe-bottom)); left: 0; right: 0; display: flex; justify-content: center; gap: 22px; z-index: 2; }
.incoming { align-items: center; justify-content: center; background: rgba(5,8,15,.96); }
.incoming-box { text-align: center; padding: 24px; }
.incoming-name { font-size: 22px; font-weight: 700; margin: 14px 0 4px; }
.pulse { width: 96px; height: 96px; border-radius: 50%; margin: 0 auto; background: linear-gradient(135deg, #64b5ef, #5288c1); display: flex; align-items: center; justify-content: center; animation: pulse 1.6s ease-in-out infinite; }
.pulse .ic { width: 40px; height: 40px; color: #fff; }
@keyframes pulse { 0%,100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(100,181,239,.5); } 50% { transform: scale(1.06); box-shadow: 0 0 0 18px rgba(100,181,239,0); } }
.incoming-actions { display: flex; justify-content: center; gap: 40px; margin-top: 26px; }

/* ---------- VIEWER / TOAST ---------- */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 60; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 96%; max-height: 92%; border-radius: 10px; }
.viewer-close { position: absolute; top: calc(16px + var(--safe-top)); right: 16px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.14); border: none; color: #fff; display: flex; align-items: center; justify-content: center; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); background: #000; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 70; max-width: 90%; text-align: center; }

/* ---------- status das mensagens (ticks) ---------- */
.bmeta .ic.tick { width: 15px; height: 15px; color: rgba(255,255,255,.6); }
.bmeta .ic.tick.read { color: #4fc3f7; }

/* ---------- FAB (novo post) ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, #64b5ef, #3f72af); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(63,114,175,.5); z-index: 20;
}
.fab .ic { width: 26px; height: 26px; }

/* ---------- Posts ---------- */
.post-card { margin: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.post-head .info { flex: 1; min-width: 0; }
.post-head .name { font-weight: 600; font-size: 15px; }
.post-head .time { font-size: 11px; color: var(--muted); }
.post-body { padding: 0 12px 12px; }
.post-text { white-space: pre-wrap; word-wrap: break-word; font-size: 15px; line-height: 1.4; }
.post-media { display: block; width: 100%; max-height: 420px; object-fit: cover; background: #000; }
.post-del { color: var(--muted); background: none; border: none; padding: 6px; }
.post-exp { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; }
.post-exp .ic { width: 12px; height: 12px; }
.post-textarea {
  width: calc(100% - 28px); margin: 0 14px; min-height: 90px; resize: none;
  background: var(--panel2); color: var(--txt); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font-size: 15px; font-family: inherit; outline: none;
}
.post-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px 14px; }
.post-pick { display: inline-flex; align-items: center; gap: 8px; color: var(--accent2); font-size: 14px; padding: 10px 12px; border-radius: 12px; background: var(--panel2); }
.post-pick .ic { width: 20px; height: 20px; }
.post-pub { margin-left: auto; padding: 12px 22px; }

/* ---------- Alerta estilo Dynamic Island ---------- */
.banner {
  position: fixed; top: calc(10px + var(--safe-top)); left: 50%;
  transform: translateX(-50%) translateY(-130%);
  width: min(92%, 420px);
  background: rgba(8,10,14,.94); backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.09); border-radius: 22px;
  padding: 10px 14px; display: flex; align-items: center; gap: 12px;
  z-index: 80; box-shadow: 0 16px 44px rgba(0,0,0,.55);
  opacity: 0; transition: transform .45s cubic-bezier(.2,.9,.25,1), opacity .35s;
}
.banner.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.banner-badge { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, #64b5ef, #3f72af); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.banner-badge .ic { width: 20px; height: 20px; color: #fff; }
.banner-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#bannerName { font-weight: 600; font-size: 14px; }
#bannerMsg { font-size: 13px; color: #c9d3e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
