:root {
  --brand: #6d28d9;
  --brand-d: #5b21b6;
  --brand-soft: #f3eefe;
  --bg: #ffffff;
  --bg2: #f7f6fb;
  --line: #ebe8f3;
  --text: #1f1b2e;
  --muted: #7a7590;
  --mine: #6d28d9;
  --mine-text: #ffffff;
  --theirs: #f1eff7;
  --on: #22c55e;
  --away: #f59e0b;
  --off: #c4c0d2;
  --danger: #dc2626;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #2a2145;
    --bg: #14111f;
    --bg2: #1b1730;
    --line: #2a2540;
    --text: #ece9f7;
    --muted: #9a94b3;
    --theirs: #25203a;
    --off: #4a4563;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app { height: 100vh; height: 100dvh; height: var(--appH, 100dvh); display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; background: var(--bg); position: relative; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.boot { flex: 1; display: grid; place-items: center; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { justify-content: center; padding: calc(24px + var(--sat)) 28px calc(24px + var(--sab)); text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 18px; box-shadow: 0 8px 24px rgba(109, 40, 217, .25); }
.login h1 { margin: 0 0 6px; font-weight: 500; font-size: 22px; letter-spacing: -.01em; }
.login p.sub { margin: 0 0 26px; color: var(--muted); font-size: 15px; font-weight: 300; }
.login form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); outline: none; font-size: 16px; }
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field input.code { text-align: center; letter-spacing: .45em; font-size: 24px; font-weight: 500; padding-left: calc(14px + .45em); }
.btn { padding: 13px 16px; border-radius: 12px; font-weight: 500; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-d); }
.btn.primary:disabled { opacity: .55; }
.btn.ghost { color: var(--brand); }
.btn.danger { color: var(--danger); }
.err { color: var(--danger); font-size: 14px; min-height: 20px; text-align: center; margin: 2px 0 0; }
.login .links { display: flex; justify-content: space-between; margin-top: 4px; font-size: 14px; }
.login .links button { color: var(--brand); padding: 6px 2px; }
.login .links button:disabled { color: var(--muted); }

/* ---------- barras ---------- */
.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--sat)) 14px 10px; border-bottom: 1px solid var(--line); background: var(--bg); min-height: 56px; }
.bar .grow { flex: 1; min-width: 0; }
.bar h2 { margin: 0; font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .small { font-size: 12.5px; color: var(--muted); display: block; line-height: 1.2; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .small.typing { color: var(--brand); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:active { background: var(--bg2); }
.icon-btn svg { width: 22px; height: 22px; }
.me-btn { padding: 0; }

/* ---------- avisos ---------- */
.banner { padding: 9px 14px; font-size: 13.5px; background: var(--brand-soft); color: var(--text); display: flex; gap: 10px; align-items: center; }
.banner.warn { background: #fef3c7; color: #78350f; }
@media (prefers-color-scheme: dark) { .banner.warn { background: #3b2f0b; color: #fde68a; } }
.banner span { flex: 1; }
.banner button { color: var(--brand); font-weight: 500; padding: 4px 6px; }

/* ---------- lista ---------- */
.seg { display: flex; gap: 6px; padding: 10px 14px 6px; }
.seg button { padding: 7px 14px; border-radius: 999px; font-size: 14px; background: var(--bg2); color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sab); }
.ghead { display: flex; align-items: center; gap: 8px; padding: 12px 16px 6px; font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); width: 100%; text-align: left; }
.ghead .chev { transition: transform .15s; display: inline-block; }
.ghead .chev.closed { transform: rotate(-90deg); }
.ghead .grow { flex: 1; font-weight: 500; }
.ghead .cnt { font-size: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; width: 100%; text-align: left; }
.row:active { background: var(--bg2); }
.row .meta { flex: 1; min-width: 0; }
.row .nm { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .st { font-size: 13px; color: var(--muted); font-weight: 300; }
.row .st.typing { color: var(--brand); }
.av { position: relative; width: 42px; height: 42px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 500; font-size: 15px; flex: none; }
.av.sm { width: 36px; height: 36px; font-size: 13px; }
.dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--off); border: 2px solid var(--bg); }
.dot.on { background: var(--on); }
.dot.away { background: var(--away); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--brand); color: #fff; font-size: 12.5px; font-weight: 500; display: grid; place-items: center; flex: none; }
.empty { padding: 48px 28px; text-align: center; color: var(--muted); font-weight: 300; }

/* ---------- conversa ---------- */
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg2); padding: 3px 12px; border-radius: 999px; margin: 10px 0 6px; }
.bub { max-width: 82%; padding: 8px 12px 6px; border-radius: 18px; background: var(--theirs); align-self: flex-start; border-bottom-left-radius: 6px; word-wrap: break-word; overflow-wrap: anywhere; }
.bub.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.bub .t { white-space: pre-wrap; font-weight: 400; }
.bub .h { font-size: 11px; opacity: .7; text-align: right; margin-top: 2px; }
.bub.pending { opacity: .6; }
.more { align-self: center; color: var(--brand); font-size: 14px; padding: 6px 12px; }
.typingline { padding: 2px 16px 4px; font-size: 13px; color: var(--brand); min-height: 20px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--sab)); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg2); border-radius: 20px; padding: 10px 14px; max-height: 130px; outline: none; line-height: 1.35; font-size: 16px; }
.composer textarea:focus { border-color: var(--brand); }
.send { width: 42px; height: 42px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .5; }
.send svg { width: 20px; height: 20px; }

/* ---------- menu (folha de baixo) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(15, 10, 30, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 720px; background: var(--bg); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--sab)); }
.sheet .who { display: flex; align-items: center; gap: 12px; padding: 4px 4px 14px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.sheet .who b { font-weight: 500; display: block; }
.sheet .who span { font-size: 13px; color: var(--muted); }
.sheet .item { display: block; width: 100%; text-align: left; padding: 14px 6px; font-size: 16px; }
.sheet .item.danger { color: var(--danger); }
.sheet .item small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; font-weight: 300; }
.sheet input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); outline: none; margin: 8px 0; }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--sab)); transform: translateX(-50%); background: #1f1b2e; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86%; z-index: 30; text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
