/* ==========================================================================
   Tokki Web — design system estilo Apple
   Paleta oficial (amarelo/preto) adaptativa a light/dark, fonte Quicksand,
   molas estilo SwiftUI via cubic-bezier.
   ========================================================================== */

@font-face {
  font-family: "Tokki Quicksand";
  src: url("fonts/quicksand-latin-variable.ttf") format("truetype");
  font-weight: 300 700;
  font-style: normal;
  font-display: block;
}

:root {
  --yellow: #eab308;
  --yellow-bright: #facc15;
  --ink: #121417;

  --bg: #fbfbfd;
  --card: #ffffff;
  --field: #f0f1f4;
  --text: #121417;
  --secondary: #5f6672;
  --separator: rgba(0, 0, 0, 0.08);
  --incoming: #ffffff;
  --outgoing: #fae07a;
  --on-outgoing: #121417;
  --green: #34c759;
  --blue: #3b82f6;
  --red: #ff3b30;
  --backdrop: rgba(0, 0, 0, 0.34);
  --wallpaper-dot: rgba(0, 0, 0, 0.035);
  --bar-blur: rgba(251, 251, 253, 0.88);

  --spring: cubic-bezier(0.32, 0.72, 0, 1);         /* sheet do iOS */
  --spring-bouncy: cubic-bezier(0.34, 1.4, 0.44, 1); /* pop com bounce */
  --radius-bubble: 14px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

.dark {
  --bg: #0a0c0e;
  --card: #16181c;
  --field: #20242b;
  --text: #f6f6f6;
  --secondary: #9aa1ab;
  --separator: rgba(255, 255, 255, 0.09);
  --incoming: #1d2127;
  --outgoing: #eab308;
  --on-outgoing: #121417;
  --backdrop: rgba(0, 0, 0, 0.55);
  --wallpaper-dot: rgba(255, 255, 255, 0.035);
  --bar-blur: rgba(10, 12, 14, 0.78);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Tokki Quicksand", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

input, textarea { user-select: text; }

.logo { display: block; flex-shrink: 0; }
.logo > img { display: block; width: 100%; height: 100%; }
.logo > .logo-dark { display: none; }
.dark .logo > .logo-light { display: none; }
.dark .logo > .logo-dark { display: block; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

input, textarea {
  font: inherit;
  color: var(--text);
  border: none;
  outline: none;
  background: none;
}

::placeholder { color: var(--secondary); opacity: 0.75; }

.hidden { display: none !important; }

/* ==========================================================================
   Splash
   ========================================================================== */

#splash {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(180deg, #1a1e24 0%, #0e1014 100%);
  transition: opacity 0.5s ease, visibility 0.5s;
}
#splash.gone { opacity: 0; visibility: hidden; }
#splash .trace-logo {
  width: 148px; height: 148px;
}
#splash .splash-wordmark {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-top: 8px; transform: translateY(-12px);
  animation: splash-wordmark-in 0.55s var(--spring) 0.85s backwards;
}
#splash .word {
  color: #fff; font-family: "Tokki Quicksand", sans-serif;
  font-size: 30px; font-weight: 700; letter-spacing: 0.367em;
  padding-left: 0.367em; line-height: 1;
}
#splash .splash-tagline {
  color: rgba(255, 255, 255, 0.45); font-family: "Tokki Quicksand", sans-serif;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.3em; padding-left: 0.3em; line-height: 1;
}
@keyframes splash-wordmark-in { from { transform: translateY(2px); opacity: 0; } }

/* ==========================================================================
   Auth
   ========================================================================== */

#auth {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px calc(16px) calc(24px + var(--sab));
  background: var(--bg);
  overflow-y: auto;
  transition: opacity 0.45s ease, visibility 0.45s;
}
#auth.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.auth-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
  animation: auth-in 0.7s var(--spring);
}
@keyframes auth-in { from { transform: translateY(26px) scale(0.97); opacity: 0; } }

.auth-card .logo { width: 76px; height: 76px; align-self: center; }
.auth-card .auth-heading { display: grid; gap: 4px; }
.auth-card h1 {
  font-family: "Tokki Quicksand", sans-serif;
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em; text-align: center;
}
.auth-card .tagline { color: var(--secondary); font-size: 14px; font-weight: 500; text-align: center; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; position: relative;
  background: var(--field); border-radius: 999px; padding: 2.5px; margin-top: 8px;
}
.segmented .thumb {
  position: absolute; top: 2.5px; bottom: 2.5px; left: 2.5px; width: calc(50% - 2.5px);
  background: var(--card); border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.35s var(--spring);
}
.segmented[data-mode="register"] .thumb { transform: translateX(100%); }
.segmented button {
  position: relative; z-index: 1; padding: 8px 0; font-size: 13.5px; font-weight: 600;
  color: var(--secondary); border-radius: 999px; transition: color 0.25s;
}
.segmented button.active { color: var(--text); }

.form-group {
  background: var(--card); border-radius: 14px; overflow: hidden;
  border: 1px solid var(--separator);
}
.form-group .row { display: flex; align-items: center; padding: 0 16px; }
.form-group .row + .row { border-top: 0.5px solid var(--separator); }
.form-group input { flex: 1; padding: 13px 0; font-size: 16px; }

#auth-name-row {
  overflow: hidden;
  max-height: 0; opacity: 0;
  transition: max-height 0.4s var(--spring), opacity 0.3s;
  border-top-width: 0 !important;
}
.auth-card.register #auth-name-row { max-height: 52px; opacity: 1; border-top-width: 0.5px !important; }

.btn-primary {
  background: linear-gradient(180deg, var(--yellow-bright), var(--yellow)); color: var(--ink);
  font-size: 16px; font-weight: 550;
  height: 40px; min-height: 40px; padding: 0 24px; border-radius: 999px;
  box-shadow: 0 3px 10px rgba(234, 179, 8, 0.16), inset 0 1px rgba(255, 255, 255, 0.28);
  transition: transform 0.2s var(--spring-bouncy), opacity 0.2s, box-shadow 0.2s;
}
.btn-primary:hover { box-shadow: 0 4px 12px rgba(234, 179, 8, 0.22), inset 0 1px rgba(255, 255, 255, 0.34); }
.btn-primary:active { transform: scale(0.975); box-shadow: 0 2px 8px rgba(234, 179, 8, 0.18); }
.btn-primary:disabled { opacity: 0.45; }

.auth-error {
  color: #b45309; background: rgba(234, 179, 8, 0.14);
  font-size: 13px; font-weight: 500;
  padding: 10px 14px; border-radius: 12px;
  animation: shake 0.4s ease;
}
.dark .auth-error { color: var(--yellow-bright); }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}

/* ==========================================================================
   Layout principal (duas colunas no desktop, empilhado no mobile)
   ========================================================================== */

#app {
  position: fixed; inset: 0;
  display: flex;
  width: 100%; max-width: 100%;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.45s ease;
}
#app.gone { opacity: 0; visibility: hidden; pointer-events: none; }

#sidebar {
  width: 372px; min-width: 300px; max-width: 420px;
  display: flex; flex-direction: column;
  border-right: 0.5px solid var(--separator);
  background: var(--bg);
  z-index: 2;
}

#chat-pane {
  flex: 1;
  display: flex; flex-direction: column;
  position: relative;
  background: var(--bg);
  min-width: 0;
  overflow: hidden;
}

/* Papel de parede sutil do chat */
#chat-pane::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(var(--wallpaper-dot) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}

/* Mobile: navegação empilhada estilo UINavigationController */
@media (max-width: 799px) {
  #sidebar { width: 100%; min-width: 0; max-width: none; overflow: hidden; border-right: none; }
  #chat-pane {
    position: fixed; inset: 0; z-index: 5;
    transform: translateX(100%);
    transition: transform 0.42s var(--spring);
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.18);
    visibility: hidden;
    touch-action: pan-y;
    will-change: transform;
  }
  body.chat-open #chat-pane { transform: translateX(0); visibility: visible; }
  body.chat-open #sidebar {
    transform: translateX(-88px);
    transition: transform 0.42s var(--spring);
    pointer-events: none;
  }
  #sidebar { transition: transform 0.42s var(--spring); }
  body.chat-open.chat-swipe-dragging #chat-pane {
    transform: translateX(var(--chat-swipe-x, 0px));
    transition: none;
  }
  body.chat-open.chat-swipe-dragging #sidebar {
    transform: translateX(var(--sidebar-swipe-x, -88px));
    transition: none;
  }
  body.chat-open.chat-swipe-completing #chat-pane {
    transform: translateX(100%);
    transition: transform 0.28s var(--spring);
  }
  body.chat-open.chat-swipe-completing #sidebar {
    transform: translateX(0);
    transition: transform 0.28s var(--spring);
  }
}
@media (min-width: 800px) {
  #back-btn { display: none; }
}

/* ==========================================================================
   Sidebar — lista de conversas
   ========================================================================== */

.sidebar-header {
  padding: calc(10px + var(--sat)) 16px 6px;
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-header .top {
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-header .brand { display: flex; align-items: center; gap: 9px; }
.sidebar-header .brand .logo { width: 30px; height: 30px; }
.sidebar-header h1 { font-size: 28px; font-weight: 650; letter-spacing: -0.03em; }
.sidebar-header .actions { display: flex; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--yellow);
  transition: transform 0.2s var(--spring-bouncy), background 0.2s;
}
.icon-btn:hover { background: var(--field); }
.icon-btn:active { transform: scale(0.88); }
.icon-btn svg { width: 20px; height: 20px; }

.search-wrap {
  display: flex; align-items: center; gap: 7px;
  background: var(--field); border-radius: 999px; padding: 8px 13px;
}
.search-wrap svg { width: 15px; height: 15px; color: var(--secondary); flex-shrink: 0; }
.search-wrap input { flex: 1; font-size: 15px; }

.filters { display: flex; gap: 7px; padding: 2px 0 8px; }
.filter-chip {
  padding: 5.5px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--secondary);
  background: var(--field);
  transition: all 0.3s var(--spring);
}
.filter-chip.active {
  background: var(--yellow); color: var(--ink);
  transform: scale(1.04);
}
.filter-chip .count {
  display: inline-block; min-width: 17px; padding: 0 4px; margin-left: 4px;
  background: var(--ink); color: var(--yellow);
  border-radius: 999px; font-size: 11px; text-align: center;
}
.filter-chip:not(.active) .count { background: var(--yellow); color: var(--ink); }

#conv-list {
  flex: 1;
  min-width: 0; max-width: 100%;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  padding: 0 8px calc(12px + var(--sab));
}

.conv-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 9px 10px; border-radius: 14px;
  text-align: left;
  transition: background 0.18s, transform 0.18s var(--spring-bouncy);
}
.conv-row.is-entering { animation: row-in 0.45s var(--spring) backwards; }
.conv-row:hover { background: var(--card); }
.conv-row:active { transform: scale(0.985); }
.conv-row.selected { background: var(--yellow); }
.conv-row.selected .name, .conv-row.selected .preview, .conv-row.selected .time { color: var(--ink); }
.conv-row.selected .preview { opacity: 0.72; }
@keyframes row-in { from { opacity: 0; transform: translateY(10px); } }

.avatar {
  position: relative; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2d3540, #121821);
  color: var(--yellow); font-weight: 600;
  overflow: visible;
}
.avatar .img-clip {
  position: absolute; inset: 0; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar .initials { position: relative; z-index: 0; }
.avatar.size-48 { width: 48px; height: 48px; font-size: 16px; }
.avatar.size-36 { width: 36px; height: 36px; font-size: 13px; }
.avatar.size-28 { width: 28px; height: 28px; font-size: 10.5px; }
.avatar.size-96 { width: 96px; height: 96px; font-size: 34px; }
.avatar .logo { width: 55%; height: 55%; }

.online-dot {
  position: absolute; right: -1px; bottom: -1px; z-index: 2;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--green);
  border: 2.5px solid var(--bg);
}

.conv-row .middle { flex: 1; min-width: 0; }
.conv-row .line1 { display: flex; align-items: baseline; gap: 6px; }
.conv-row .name {
  font-size: 15.5px; font-weight: 550; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-row .time { margin-left: auto; font-size: 12px; color: var(--secondary); flex-shrink: 0; }
.conv-row .time.unread { color: var(--yellow); font-weight: 600; }
.conv-row .line2 { display: flex; align-items: center; gap: 8px; margin-top: 1px; }
.conv-row .preview {
  flex: 1; font-size: 13.5px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-row .preview.typing { color: var(--yellow); font-weight: 600; }

.unread-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--yellow); color: var(--ink);
  border-radius: 999px; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  animation: badge-pop 0.4s var(--spring-bouncy);
}
@keyframes badge-pop { from { transform: scale(0); } }

.seal { flex-shrink: 0; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 60px 24px; text-align: center; color: var(--secondary);
}
.empty-state .logo { width: 54px; height: 54px; opacity: 0.5; }
.empty-state .title { font-size: 17px; font-weight: 600; color: var(--text); }
.empty-state .sub { font-size: 13.5px; }

/* ==========================================================================
   Chat
   ========================================================================== */

.chat-header {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--sat)) 12px 8px;
  background: var(--bar-blur);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
#back-btn {
  display: flex; align-items: center; gap: 2px;
  color: var(--yellow); font-size: 16px; font-weight: 600;
  padding: 6px 6px 6px 0; margin-left: -4px;
  transition: opacity 0.2s;
}
#back-btn:active { opacity: 0.5; }
#back-btn svg { width: 12px; height: 20px; }
@media (max-width: 799px) { #back-btn { display: flex; } }

.chat-title-btn {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  transition: transform 0.2s var(--spring-bouncy);
}
.chat-title-btn:active { transform: scale(0.97); }
.chat-title-btn .name-line {
  display: flex; align-items: center; gap: 5px;
  font-size: 16.5px; font-weight: 550; letter-spacing: -0.01em;
  max-width: 100%;
}
.chat-title-btn .name-line span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-title-btn .status { font-size: 11.5px; color: var(--secondary); height: 15px; }
.chat-title-btn .status.online { color: var(--green); font-weight: 600; }
.chat-title-btn .status.typing { color: var(--yellow); font-weight: 600; }

#chat-avatar-btn { transition: transform 0.2s var(--spring-bouncy); }
#chat-avatar-btn:active { transform: scale(0.9); }

#messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  width: 100%; min-width: 0;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  padding: 12px 14px 8px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
  scroll-behavior: auto;
}

.chat-placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--secondary); position: relative;
}
.chat-placeholder .logo { width: 76px; height: 76px; opacity: 0.35; }
.chat-placeholder .t { font-size: 17px; font-weight: 600; color: var(--text); opacity: 0.7; }

.load-older {
  align-self: center;
  font-size: 12px; font-weight: 600; color: var(--secondary);
  background: var(--card); border-radius: 999px;
  padding: 6px 14px; margin: 4px 0 8px;
  border: 0.5px solid var(--separator);
  transition: transform 0.2s var(--spring-bouncy);
}
.load-older:active { transform: scale(0.94); }

.date-chip {
  align-self: center;
  font-size: 11.5px; font-weight: 600; color: var(--secondary);
  background: var(--card); border: 0.5px solid var(--separator);
  padding: 4.5px 12px; border-radius: 999px; margin: 8px 0 4px;
}

/* --- Linha de mensagem --- */

.msg-row {
  display: flex; align-items: flex-end; gap: 7px;
  max-width: 100%;
  isolation: isolate;
}
.msg-row.is-entering { animation: msg-in 0.38s var(--spring) backwards; }
@keyframes msg-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } }
.msg-row.mine { flex-direction: row-reverse; }
.msg-row .stack {
  display: flex; flex-direction: column; gap: 3px;
  max-width: min(76%, 460px);
  align-items: flex-start;
  position: relative; z-index: 1;
}
.msg-row.mine .stack { align-items: flex-end; }

/* Avatar da mensagem em grupo acima da máscara usada na cauda do balão. */
.msg-row > [data-profile] { position: relative; z-index: 3; flex-shrink: 0; }

.msg-row .avatar { margin-bottom: 3px; cursor: pointer; }

.author {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; color: var(--secondary);
  padding-left: 14px; cursor: pointer;
}

/* --- Bolha com rabinho (estilo iMessage) --- */

.bubble {
  position: relative;
  padding: 7px 12px;
  border-radius: var(--radius-bubble);
  background: var(--incoming);
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.06);
  cursor: default;
  transition: transform 0.25s var(--spring-bouncy), filter 0.25s;
  word-wrap: break-word; overflow-wrap: break-word;
  min-width: 0;
}
.mine .bubble { background: var(--outgoing); color: var(--on-outgoing); }
.msg-row:not(.mine) .bubble { padding-left: 16px; }
.msg-row.mine .bubble { padding-right: 16px; }

/* Cauda contínua: a peça colorida é recortada pela cor do chat, sem ponta. */
.bubble::before, .bubble::after {
  content: none;
  position: absolute; bottom: -1px; height: 20px; pointer-events: none;
}
.msg-row.last-of-group .bubble::before,
.msg-row.last-of-group .bubble::after { content: ""; }
.bubble::before { z-index: 0; width: 20px; }
.bubble::after { z-index: 1; width: 26px; background: var(--bg); }
.bubble > * { position: relative; z-index: 2; }

.msg-row.last-of-group.mine .bubble::before {
  right: -7px; background: var(--outgoing); border-bottom-left-radius: 15px;
}
.msg-row.last-of-group.mine .bubble::after {
  right: -26px; border-bottom-left-radius: 10px;
}
.msg-row.last-of-group:not(.mine) .bubble::before {
  left: -7px; background: var(--incoming); border-bottom-right-radius: 15px;
}
.msg-row.last-of-group:not(.mine) .bubble::after {
  left: -26px; border-bottom-right-radius: 10px;
}

.bubble .reply-quote {
  display: flex; gap: 7px; align-items: stretch;
  background: rgba(0, 0, 0, 0.055);
  border-radius: 10px; padding: 6px 9px; margin: 2px 0 6px;
  font-size: 12px; max-width: 300px;
  cursor: pointer;
}
.dark .bubble .reply-quote { background: rgba(255, 255, 255, 0.07); }
.mine .bubble .reply-quote { background: rgba(0, 0, 0, 0.09); }
.bubble .reply-quote .bar { width: 3px; border-radius: 3px; background: var(--yellow); flex-shrink: 0; }
.mine .bubble .reply-quote .bar { background: var(--ink); }
.bubble .reply-quote .q-author { font-weight: 600; display: block; }
.bubble .reply-quote .q-text {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; opacity: 0.8;
}

.bubble .body { display: inline; font-size: 14.5px; white-space: pre-wrap; user-select: none; }
.bubble .body.deleted { font-style: italic; opacity: 0.6; font-size: 13.5px; }

.bubble .img-wrap {
  margin: 2px -7px 4px; border-radius: 12px; overflow: hidden;
  max-width: 280px; cursor: pointer;
  background: var(--field);
}
.bubble .img-wrap img {
  display: block; width: 100%; max-height: 340px; object-fit: cover;
  -webkit-user-drag: none;
  transition: transform 0.3s var(--spring);
}
.bubble .img-wrap:active img { transform: scale(0.98); }

.bubble .meta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; line-height: 1; color: var(--secondary);
  margin: 0 0 0 8px; vertical-align: baseline;
}
/* Quando não há texto (foto apenas), o metadata é filho direto do balão e
   deve ocupar o canto inferior direito, sem herdar o fluxo inline do texto. */
.bubble > .meta { display: flex; width: fit-content; margin: 5px 0 0 auto; }
.mine .bubble .meta { color: rgba(18, 20, 23, 0.55); }
.bubble .meta .edited { font-style: italic; }
.bubble .meta svg { width: 11px; height: 11px; }

.reactions {
  display: flex; gap: 3px; padding: 0 6px;
  margin-top: -1px;
}
.reaction-pill {
  font-size: 11px; font-weight: 600;
  background: var(--card); border: 0.5px solid var(--separator);
  border-radius: 999px; padding: 2.5px 7px;
  animation: badge-pop 0.35s var(--spring-bouncy);
  cursor: pointer;
}
.reaction-pill.own { border-color: var(--yellow); background: rgba(234, 179, 8, 0.14); }

.typing-row { display: flex; align-items: flex-end; gap: 7px; }
.typing-bubble {
  background: var(--incoming); border-radius: var(--radius-bubble);
  padding: 12px 15px; display: flex; gap: 4px;
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.06);
  animation: msg-in 0.3s var(--spring);
}
.typing-bubble i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--secondary);
  animation: typing-dot 1.2s infinite;
}
.typing-bubble i:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-dot { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* --- Composer --- */

.composer-wrap {
  position: relative; z-index: 3;
  padding: 8px 12px calc(10px + var(--sab));
  background: var(--bar-blur);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex; flex-direction: column; gap: 8px;
}

.composer-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 0.5px solid var(--separator);
  border-radius: 13px; padding: 8px 12px;
  animation: banner-in 0.35s var(--spring);
}
@keyframes banner-in { from { opacity: 0; transform: translateY(10px); } }
.composer-banner .bar { width: 3px; height: 32px; border-radius: 3px; background: var(--yellow); }
.composer-banner .b-title { font-size: 11.5px; font-weight: 600; color: var(--yellow); }
.composer-banner .b-text {
  font-size: 13px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw;
}
.composer-banner .close {
  margin-left: auto; width: 26px; height: 26px; min-width: 26px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: var(--secondary);
  line-height: 1;
}
.composer-banner .close svg { width: 12px; height: 12px; display: block; }
.composer-banner .close:hover { background: var(--field); }

.composer { display: flex; align-items: flex-end; gap: 8px; }

#attach-btn {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--field); color: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s var(--spring-bouncy), background 0.2s;
}
#attach-btn:active { transform: scale(0.86); }
#attach-btn svg { width: 17px; height: 17px; }
#attach-btn.uploading { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.input-capsule {
  flex: 1; display: flex; align-items: flex-end; gap: 4px;
  background: var(--card); border: 0.5px solid var(--separator);
  border-radius: 999px; padding: 3px 3px 3px 13px;
  min-height: 36px;
}
#composer-input {
  flex: 1; resize: none; max-height: 110px;
  font-size: 15px; line-height: 1.35;
  padding: 6px 0;
}
#send-btn {
  width: 29px; height: 29px; border-radius: 50%; flex-shrink: 0;
  background: var(--field); color: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.25s var(--spring-bouncy);
  transform: scale(0.9);
}
#send-btn.enabled {
  background: var(--yellow); color: var(--ink); transform: scale(1);
}
#send-btn:active { transform: scale(0.85); }
#send-btn svg { width: 14px; height: 14px; }

/* ==========================================================================
   Sheets (modal estilo iOS)
   ========================================================================== */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: var(--backdrop);
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  transform: translateY(105%);
  transition: transform 0.45s var(--spring);
  max-height: calc(100% - 40px - var(--sat));
  display: flex; flex-direction: column;
  padding-bottom: var(--sab);
  box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}
.sheet.open { transform: translateY(0); pointer-events: auto; }

@media (min-width: 800px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: 440px; max-height: min(640px, calc(100% - 80px));
    border-radius: 18px;
    transform: translate(-50%, -46%) scale(0.94);
    opacity: 0;
    transition: transform 0.4s var(--spring), opacity 0.3s;
  }
  .sheet.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.sheet .grabber {
  width: 38px; height: 5px; border-radius: 3px;
  background: var(--separator); margin: 8px auto 2px;
  flex-shrink: 0;
}
@media (min-width: 800px) { .sheet .grabber { visibility: hidden; height: 2px; } }

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 10px; flex-shrink: 0;
}
.sheet-header .title { font-size: 17px; font-weight: 550; }
.sheet-header .spacer { width: 30px; }
.sheet-close {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--field); color: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s var(--spring-bouncy);
}
.sheet-close:active { transform: scale(0.86); }
.sheet-close svg { width: 13px; height: 13px; }

.sheet-body { overflow-y: auto; padding: 4px 16px 20px; }

.group-label {
  font-size: 12.5px; font-weight: 600; color: var(--secondary);
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 14px 14px 6px;
}
.group-footer { font-size: 12.5px; color: var(--secondary); padding: 7px 14px 0; }

.igroup {
  background: var(--card); border-radius: 14px;
  border: 0.5px solid var(--separator);
  overflow: hidden;
}
.igroup .irow {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 15px; min-height: 46px;
  width: 100%; text-align: left; font-size: 15.5px;
}
.igroup .irow + .irow { border-top: 0.5px solid var(--separator); }
.igroup .irow .lbl { color: var(--text); font-weight: 500; }
.igroup .irow .val { margin-left: auto; color: var(--secondary); user-select: text; }
.igroup .irow input { flex: 1; font-size: 15.5px; }
.igroup button.irow { cursor: pointer; transition: background 0.15s; }
.igroup button.irow:active { background: var(--field); }
.igroup .irow.destructive .lbl { color: var(--red); font-weight: 600; text-align: center; width: 100%; }

/* Switch estilo iOS */
.switch {
  position: relative; width: 50px; height: 30px; flex-shrink: 0; margin-left: auto;
  background: var(--field); border-radius: 999px;
  transition: background 0.3s;
}
.switch.on { background: var(--green); }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s var(--spring);
}
.switch.on::after { transform: translateX(20px); }

/* Perfil */
.profile-head {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 12px 0 18px;
}
.profile-head .p-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 22px; font-weight: 650; letter-spacing: -0.02em;
}
.profile-head .p-status { font-size: 13px; color: var(--secondary); }
.profile-head .p-status.online { color: var(--green); font-weight: 600; }

.avatar-edit { position: relative; cursor: pointer; }
.avatar-edit .cam {
  position: absolute; right: -2px; bottom: -2px; z-index: 3;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--yellow); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}
.avatar-edit .cam svg { width: 12px; height: 12px; }

/* ==========================================================================
   Menu de contexto (mensagem)
   ========================================================================== */

#ctx-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.12);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
#ctx-backdrop.open { opacity: 1; pointer-events: auto; }

#ctx-menu {
  position: fixed; z-index: 61;
  display: flex; flex-direction: column; gap: 8px;
  opacity: 0; pointer-events: none;
  transform: scale(0.6);
  transform-origin: var(--ctx-origin, center bottom);
  transition: transform 0.35s var(--spring-bouncy), opacity 0.2s;
  width: 232px;
}
#ctx-menu.open { opacity: 1; pointer-events: auto; transform: scale(1); }

.emoji-bar {
  display: flex; gap: 2px; justify-content: space-between;
  background: var(--card); border-radius: 999px; padding: 6px 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
}
.emoji-bar button {
  font-size: 22px; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s var(--spring-bouncy), background 0.2s;
}
.emoji-bar button:hover { transform: scale(1.25); }
.emoji-bar button:active { transform: scale(0.9); }
.emoji-bar button.own { background: rgba(234, 179, 8, 0.2); }

.ctx-list {
  background: var(--card); border-radius: 14px; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
}
.ctx-list button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 11.5px 15px; font-size: 15.5px;
  transition: background 0.12s;
}
.ctx-list button:hover { background: var(--field); }
.ctx-list button + button { border-top: 0.5px solid var(--separator); }
.ctx-list button.destructive { color: var(--red); }
.ctx-list button svg { width: 17px; height: 17px; opacity: 0.6; }

/* ==========================================================================
   Action sheet (apagar)
   ========================================================================== */

.action-sheet {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--sab)); z-index: 70;
  display: flex; flex-direction: column; gap: 9px;
  transform: translateY(120%);
  transition: transform 0.4s var(--spring);
}
.action-sheet.open { transform: translateY(0); }
@media (min-width: 800px) {
  .action-sheet { left: 50%; right: auto; bottom: 40px; width: 340px; margin-left: -170px; }
}
.action-sheet .as-group {
  background: var(--bar-blur);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  border-radius: 14px; overflow: hidden;
}
.action-sheet .as-title {
  padding: 12px 16px 10px; text-align: center;
  font-size: 13px; color: var(--secondary);
  border-bottom: 0.5px solid var(--separator);
}
.action-sheet button {
  display: block; width: 100%; padding: 15px; text-align: center;
  font-size: 17px; color: var(--blue);
  transition: background 0.12s;
}
.action-sheet button:active { background: var(--field); }
.action-sheet button + button { border-top: 0.5px solid var(--separator); }
.action-sheet button.destructive { color: var(--red); }
.action-sheet button.bold { font-weight: 600; }

/* ==========================================================================
   Visualizador de imagem
   ========================================================================== */

#lightbox {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, 0.92);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
#lightbox.open { opacity: 1; pointer-events: auto; }
#lightbox img {
  max-width: 94vw; max-height: 92vh; border-radius: 6px;
  transform: scale(0.92);
  transition: transform 0.35s var(--spring);
}
#lightbox.open img { transform: scale(1); }

/* ==========================================================================
   Toast
   ========================================================================== */

#toast {
  position: fixed; top: calc(14px + var(--sat)); left: 50%; z-index: 90;
  transform: translate(-50%, -80px);
  background: var(--card); color: var(--text);
  font-size: 13.5px; font-weight: 600;
  padding: 11px 20px; border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  border: 0.5px solid var(--separator);
  transition: transform 0.45s var(--spring);
  max-width: 88vw; text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

/* Barra de conexão */
#conn-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4;
  background: var(--yellow); color: var(--ink);
  font-size: 12px; font-weight: 600; text-align: center;
  padding: 4px;
  transform: translateY(-100%);
  transition: transform 0.35s var(--spring);
}
body.disconnected #conn-banner { transform: translateY(0); }

/* iOS amplia automaticamente a viewport ao focar campos menores que 16 px. */
@media (max-width: 799px) {
  input, textarea { font-size: 16px !important; }
}

/* Escala compacta exclusiva do app instalado na tela inicial. */
@media (max-width: 799px) {
  .pwa body { font-size: 14px; }
  .pwa #splash { gap: 14px; }
  .pwa #splash .trace-logo { width: 118px; height: 118px; }
  .pwa #splash .splash-wordmark { gap: 8px; margin-top: 6px; }
  .pwa #splash .word { font-size: 25px; }
  .pwa #splash .splash-tagline { font-size: 8px; }
  .pwa #auth { padding: 18px 16px calc(18px + var(--sab)); }
  .pwa .auth-card { max-width: 340px; gap: 11px; }
  .pwa .auth-card .logo { width: 66px; height: 66px; }
  .pwa .auth-card h1 { font-size: 24px; }
  .pwa .auth-card .tagline { font-size: 13px; }
  .pwa .btn-primary { height: 38px; min-height: 38px; padding-block: 0; font-size: 15px; }
  .pwa .sidebar-header { padding: calc(7px + var(--sat)) 13px 4px; gap: 8px; }
  .pwa .sidebar-header .brand { gap: 7px; }
  .pwa .sidebar-header .brand .logo { width: 27px; height: 27px; }
  .pwa .sidebar-header h1 { font-size: 25px; }
  .pwa .sidebar-header .actions { gap: 4px; }
  .pwa .icon-btn { width: 32px; height: 32px; }
  .pwa .icon-btn svg { width: 18px; height: 18px; }
  .pwa .search-wrap { padding: 7px 11px; }
  .pwa .filters { gap: 6px; padding-bottom: 6px; }
  .pwa .filter-chip { padding: 5px 11px; font-size: 12.5px; }
  .pwa #conv-list { padding-inline: 6px; }
  .pwa .conv-row { gap: 10px; padding: 7px 8px; border-radius: 13px; }
  .pwa .avatar.size-48 { width: 43px; height: 43px; font-size: 14px; }
  .pwa .conv-row .name { font-size: 14.5px; }
  .pwa .conv-row .preview { font-size: 12.75px; }
  .pwa .conv-row .time { font-size: 11px; }
  .pwa .unread-badge { min-width: 19px; height: 19px; font-size: 11px; }
  .pwa .chat-header { gap: 8px; padding: calc(6px + var(--sat)) 10px 6px; }
  .pwa .chat-title-btn .name-line { font-size: 15.5px; }
  .pwa .chat-title-btn .status { font-size: 10.75px; height: 14px; }
  .pwa #chat-avatar-btn .avatar.size-36 { width: 32px; height: 32px; }
  .pwa #messages { padding: 10px 10px 6px; gap: 3px; }
  .pwa .msg-row { gap: 6px; }
  .pwa .msg-row .stack { max-width: min(80%, 430px); }
  .pwa .bubble { padding: 7px 12px 5px; min-width: 0; }
  .pwa .bubble .body { font-size: 14px; }
  .pwa .bubble .body.deleted { font-size: 12.75px; }
  .pwa .bubble .reply-quote { font-size: 11.5px; }
  .pwa .composer-wrap { padding: 6px 9px calc(7px + var(--sab)); gap: 6px; }
  .pwa #attach-btn { width: 32px; height: 32px; }
  .pwa .input-capsule { min-height: 35px; }
  .pwa #send-btn { width: 28px; height: 28px; }
  .pwa .sheet-header { padding: 6px 14px 8px; }
  .pwa .sheet-header .title { font-size: 16px; }
  .pwa .sheet-body { padding-inline: 13px; }
  .pwa .igroup .irow { min-height: 43px; padding: 10px 13px; font-size: 15px; }
  .pwa .profile-head .p-name { font-size: 20px; }
  .pwa .avatar.size-96 { width: 86px; height: 86px; font-size: 30px; }
  .pwa .action-sheet button { padding: 13px; font-size: 16px; }
  .pwa .emoji-bar button { font-size: 20px; width: 35px; height: 35px; }
}

/* Scrollbars discretos no desktop */
@media (min-width: 800px) {
  ::-webkit-scrollbar { width: 8px; }
  ::-webkit-scrollbar-thumb { background: var(--separator); border-radius: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
}
