:root {
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --panel: #ffffff;
  --chat-bg: #dfe7ee;
  --pattern: rgba(58, 123, 213, 0.06);
  --text: #0f1419;
  --muted: #707579;
  --line: #e6e8eb;
  --hover: #f2f3f5;
  --active: #3a7bd5;
  --active-text: #ffffff;
  --accent: #3a7bd5;
  --accent-2: #2f69bd;
  --in: #ffffff;
  --out: #e3f2d4;
  --out-meta: #4fae4e;
  --danger: #e53935;
  --ok: #2e9d58;
  --shadow: 0 1px 2px rgba(16, 35, 47, 0.15);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1621;
    --bg-2: #17212b;
    --panel: #17212b;
    --chat-bg: #0e1621;
    --pattern: rgba(120, 170, 255, 0.04);
    --text: #f5f5f5;
    --muted: #8a99a8;
    --line: #0b1219;
    --hover: #202b36;
    --active: #2b5278;
    --accent: #5aa0f2;
    --accent-2: #4a8fe0;
    --in: #182533;
    --out: #2b5278;
    --out-meta: #7fc6ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1621;
  --bg-2: #17212b;
  --panel: #17212b;
  --chat-bg: #0e1621;
  --pattern: rgba(120, 170, 255, 0.04);
  --text: #f5f5f5;
  --muted: #8a99a8;
  --line: #0b1219;
  --hover: #202b36;
  --active: #2b5278;
  --accent: #5aa0f2;
  --accent-2: #4a8fe0;
  --in: #182533;
  --out: #2b5278;
  --out-meta: #7fc6ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- botoes ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; width: 100%;
  background: var(--bg-2); transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: inline-grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- entrada ---------- */
.auth {
  height: 100%; overflow: auto; display: grid; place-items: center; padding: 24px 16px;
  background: var(--bg-2);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel); border-radius: 20px;
  padding: 32px 28px; box-shadow: 0 8px 40px rgba(0, 0, 0, .08);
}
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { margin: 10px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); }
.tabs { display: flex; background: var(--bg-2); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: grid; gap: 14px; }
.auth-form label, .field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-form input, .field input, .field textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 11px 13px; font-size: 15px; font-weight: 400; color: var(--text); outline: none;
}
.field textarea { resize: vertical; min-height: 70px; }
.auth-form input:focus, .field input:focus, .field textarea:focus, .at-input:focus-within { border-color: var(--accent); }
.at-input { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); }
.at-input span { padding-left: 13px; color: var(--muted); font-weight: 600; font-size: 15px; }
.auth-form .at-input input, .field .at-input input { border: 0; padding-left: 2px; }
.hint { font-weight: 400; font-size: 12.5px; color: var(--muted); min-height: 1em; }
.hint.ok { color: var(--ok); }
.hint.bad { color: var(--danger); }
.form-error { margin: 0; color: var(--danger); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }
.lead { margin: 0; color: var(--muted); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100%; height: 100dvh; }
.sidebar { position: relative; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-width: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--bg-2); border-radius: 22px; padding: 0 14px; height: 42px; border: 1.5px solid transparent; }
.search:focus-within { border-color: var(--accent); background: var(--bg); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; height: 100%; }
.conn { text-align: center; font-size: 13px; color: var(--muted); padding: 4px; }
.list { flex: 1; overflow-y: auto; padding: 4px 8px 90px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 10px 6px; }
.empty-note { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 14px; }

.row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px;
  width: 100%; border: 0; background: transparent; text-align: left;
}
.row:hover { background: var(--hover); }
.row.active { background: var(--active); color: var(--active-text); }
.row.active .row-sub, .row.active .row-time, .row.active .ticks { color: rgba(255, 255, 255, .85); }
.row-body { flex: 1; min-width: 0; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 6px; }
.row-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: 12px; color: var(--muted); flex: none; }
.row-sub { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub .who { color: var(--text); }
.row.active .row-sub .who { color: #fff; }
.row-sub.typing { color: var(--accent); }
.row.active .row-sub.typing { color: #fff; }
.badge { flex: none; min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 7px; }
.row.active .badge { background: #fff; color: var(--active); }

.avatar {
  position: relative; flex: none; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .02em;
  user-select: none;
}
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.xs { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.avatar.online::after {
  content: ""; position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%;
  background: #4fce5d; border: 2.5px solid var(--panel);
}
.avatar svg { width: 55%; height: 55%; }

.fab {
  position: absolute; right: 20px; bottom: 20px; width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.fab:hover { background: var(--accent-2); }

/* ---------- conversa ---------- */
.chat {
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 20% 20%, var(--pattern) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, var(--pattern) 0 3px, transparent 4px);
  background-size: 60px 60px, 90px 90px;
}
.empty-chat { flex: 1; display: grid; place-items: center; padding: 16px; }
.bubble-hint { background: rgba(0, 0, 0, .25); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; text-align: center; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-height: 58px;
}
.chat-head .who { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; display: flex; align-items: center; gap: 12px; padding: 0; }
.chat-head .who-text { min-width: 0; }
.chat-head .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .status.on { color: var(--accent); }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 12px 0 8px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.messages-inner { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 14px; display: flex; flex-direction: column; gap: 2px; }
.load-more { align-self: center; margin: 4px 0 10px; }
.day { align-self: center; position: sticky; top: 4px; z-index: 1; background: rgba(0, 0, 0, .22); color: #fff; font-size: 13px; font-weight: 600; padding: 3px 11px; border-radius: 13px; margin: 10px 0 6px; }
.sys { align-self: center; background: rgba(0, 0, 0, .22); color: #fff; font-size: 13px; padding: 4px 12px; border-radius: 13px; margin: 6px 0; text-align: center; max-width: 85%; }

.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.msg.out { justify-content: flex-end; }
.msg .avatar { visibility: hidden; }
.msg.tail .avatar { visibility: visible; }
.bubble {
  position: relative; max-width: min(520px, 82%); background: var(--in); border-radius: var(--radius);
  padding: 6px 10px 6px; box-shadow: var(--shadow); overflow-wrap: anywhere; word-break: break-word;
}
.msg.out .bubble { background: var(--out); }
.msg.tail.in .bubble { border-bottom-left-radius: 4px; }
.msg.tail.out .bubble { border-bottom-right-radius: 4px; }
.msg.selected .bubble { outline: 2px solid var(--accent); }
.sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text a { color: var(--accent); }
.msg.out .text a { color: inherit; text-decoration: underline; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -4px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; user-select: none; }
.msg.out .meta { color: var(--out-meta); }
.ticks svg { width: 17px; height: 17px; stroke-width: 2.2; }
.ticks.pending svg { width: 13px; height: 13px; }
.deleted { font-style: italic; color: var(--muted); }
.reply-quote {
  display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--accent); background: rgba(58, 123, 213, .1);
  border-radius: 6px; padding: 4px 8px; margin: 2px 0 5px; font-size: 13.5px; overflow: hidden;
}
.reply-quote b { display: block; color: var(--accent); font-size: 13px; }
.reply-quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); opacity: .85; }
.photo { display: block; margin: -2px -6px 4px; border-radius: 10px; overflow: hidden; background: rgba(0, 0, 0, .08); cursor: zoom-in; max-width: calc(100% + 12px); }
.photo img { display: block; width: 100%; max-width: 420px; max-height: 420px; object-fit: cover; }
.msg.flash .bubble { animation: flash 1.2s ease; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }

.composer-wrap { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 760px; margin: 0 auto; }
.composer-bar {
  display: none; align-items: center; gap: 10px; background: var(--panel); border-radius: 14px 14px 0 0;
  padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line);
}
.composer-bar.show { display: flex; }
.composer-bar .bar-text { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; font-size: 13.5px; }
.composer-bar .bar-text b { display: block; color: var(--accent); }
.composer-bar .bar-text span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer {
  display: flex; align-items: flex-end; gap: 4px; background: var(--panel); border-radius: 22px;
  padding: 4px; box-shadow: var(--shadow);
}
.composer-bar.show + .composer { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer textarea {
  flex: 1; border: 0; background: transparent; resize: none; outline: none; max-height: 180px;
  padding: 10px 6px; line-height: 1.35; min-width: 0;
}
.send-btn { color: var(--accent); }
.send-btn:hover { color: var(--accent-2); }

.jump {
  position: absolute; right: 18px; bottom: 84px; width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--panel); color: var(--muted); box-shadow: 0 2px 8px rgba(0, 0, 0, .2); display: grid; place-items: center;
}
.jump .badge { position: absolute; top: -6px; right: -4px; }

/* ---------- emoji ---------- */
.composer-inner { position: relative; }
#emoji-btn.on { color: var(--accent); }
.emoji-panel {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 30; width: 352px; height: 340px;
  background: var(--panel); border-radius: 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, .28);
  display: flex; flex-direction: column; overflow: hidden; animation: fade .12s;
}
.emoji-grid { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 8px; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); align-content: start; }
.emoji-title { grid-column: 1 / -1; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 6px 4px 4px; }
.emoji-grid .empty-note { grid-column: 1 / -1; }
.emoji {
  border: 0; background: transparent; border-radius: 10px; aspect-ratio: 1; font-size: clamp(20px, 6.5vw, 25px); line-height: 1; min-width: 0;
  display: grid; place-items: center; padding: 0;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.emoji:hover { background: var(--hover); transform: scale(1.12); }
.emoji-tabs { display: flex; justify-content: space-around; border-top: 1px solid var(--line); padding: 4px; }
.emoji-tabs button { flex: 1; min-width: 0; max-width: 42px; border: 0; background: transparent; font-size: 19px; height: 34px; border-radius: 9px; opacity: .55; padding: 0; }
.emoji-tabs button:hover { background: var(--hover); opacity: .85; }
.emoji-tabs button.on { opacity: 1; background: var(--hover); }
.text.jumbo { font-size: 46px; line-height: 1.15; }
.msg .bubble:has(.text.jumbo):not(:has(.reply-quote)) { background: transparent; box-shadow: none; padding: 0 2px; }

/* ---------- gravacao ---------- */
.mic-btn { color: var(--muted); touch-action: none; }
.mic-btn:hover { color: var(--accent); }
.composer.recording > :not(.rec-bar) { display: none !important; }
.rec-bar { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 44px; padding-left: 4px; }
.rec-cancel { color: var(--danger); }
.rec-dot {
  --lvl: 0; width: 12px; height: 12px; border-radius: 50%; background: #e53935; flex: none;
  box-shadow: 0 0 0 calc(var(--lvl) * 9px) rgba(229, 57, 53, .25); transition: box-shadow .1s;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .45; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; }
.rec-hint { flex: 1; color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-send { background: var(--accent); color: #fff !important; }
.rec-send:hover { background: var(--accent-2); }

/* ---------- player de voz ---------- */
.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 300px; padding: 2px 0 0; }
.voice-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.msg.out .voice-btn { background: var(--out-meta); }
.voice-btn svg { width: 22px; height: 22px; }
.voice-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.voice-wave i { flex: 1; min-width: 2px; max-width: 3px; border-radius: 2px; background: currentColor; opacity: .35; }
.voice-wave i.played { opacity: 1; color: var(--accent); }
.msg.out .voice-wave i.played { color: var(--out-meta); }
.voice-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg.out .voice-time { color: var(--out-meta); }

/* ---------- camadas ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel);
  border-radius: 18px; padding: 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); display: grid; gap: 14px;
}
.modal h2 { margin: 0; font-size: 19px; }
.modal .actions { display: grid; gap: 8px; }
.profile-head { text-align: center; display: grid; justify-items: center; gap: 6px; }
.profile-head .pname { font-size: 20px; font-weight: 700; }
.profile-head .pstatus { color: var(--muted); font-size: 14px; }
.info-list { display: grid; gap: 2px; }
.info { display: flex; gap: 14px; align-items: flex-start; padding: 8px 6px; border-radius: 10px; }
.info svg { color: var(--muted); flex: none; margin-top: 2px; }
.info .v { font-size: 15px; overflow-wrap: anywhere; }
.info .k { font-size: 13px; color: var(--muted); }
.picker { max-height: 280px; overflow: auto; display: grid; gap: 2px; }
.check { margin-left: auto; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; }
.row.picked .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.row .check svg { width: 14px; height: 14px; stroke-width: 3; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg-2); border-radius: 16px; padding: 4px 10px; font-size: 13px; }

.menu {
  position: fixed; z-index: 60; min-width: 190px; background: var(--panel); border-radius: 12px; padding: 6px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, .25); animation: fade .1s;
}
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; text-align: left; font-size: 14.5px; }
.menu button:hover { background: var(--hover); }
.menu button svg { width: 20px; height: 20px; color: var(--muted); }
.menu button.danger { color: var(--danger); }
.menu button.danger svg { color: var(--danger); }

.drawer { position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .4); animation: fade .15s; }
.drawer-panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: min(320px, 85vw); background: var(--panel);
  display: flex; flex-direction: column; animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(-100%); } }
.drawer-top { padding: 22px 20px 16px; background: var(--bg-2); display: grid; gap: 10px; }
.drawer-top .n { font-weight: 700; font-size: 16px; }
.drawer-top .u { color: var(--muted); font-size: 14px; }
.drawer-panel nav { padding: 8px; display: grid; }
.drawer-panel nav button { display: flex; gap: 16px; align-items: center; border: 0; background: transparent; padding: 12px; border-radius: 10px; text-align: left; }
.drawer-panel nav button:hover { background: var(--hover); }
.drawer-panel nav svg { color: var(--muted); }
.drawer-foot { margin-top: auto; padding: 14px 20px; color: var(--muted); font-size: 12.5px; }

.viewer { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .9); display: grid; place-items: center; cursor: zoom-out; }
.viewer img { max-width: 96vw; max-height: 92vh; object-fit: contain; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 80; background: rgba(20, 24, 28, .92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 4px 20px rgba(0, 0, 0, .3);
}

/* ---------- celular ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .22s ease; }
  .app.in-chat .chat { transform: none; }
  .back-btn { display: inline-grid; }
  .bubble { max-width: 86%; }
  .jump { bottom: 80px; }
  .auth-card { padding: 26px 18px; }
  .emoji-panel { width: auto; left: 0; height: 300px; }
  .emoji-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .voice { min-width: 190px; }
}
