:root {
  --bg: #ffffff;
  --surface: #f6f8f8;
  --line: #e3e7e8;
  --text: #1c2124;
  --muted: #5d676c;
  --accent: #0b7c6d;
  --accent-ink: #ffffff;
  --accent-soft: #dcf2ee;
  --mine-bg: #0b7c6d;
  --mine-ink: #ffffff;
  --theirs-bg: #eef1f2;
  --theirs-ink: #1c2124;
  --danger: #b3261e;
  --online: #1e8e3e;
  --badge: #d93025;
  --focus: #0b7c6d55;
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f2224;
    --surface: #272b2e;
    --line: #353a3d;
    --text: #e8ecee;
    --muted: #9aa5ab;
    --accent: #4fd1bd;
    --accent-ink: #062a25;
    --accent-soft: #1d3d38;
    --mine-bg: #1f6f63;
    --mine-ink: #f1fffc;
    --theirs-bg: #30363a;
    --theirs-ink: #e8ecee;
    --danger: #f2b8b5;
    --online: #6dd58c;
    --badge: #f28b82;
    --focus: #4fd1bd55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Google Sans Text", Roboto, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

[hidden] { display: none !important; }

h1 { font-size: 18px; font-weight: 500; margin: 12px 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
strong { font-weight: 500; }

button { font: inherit; color: inherit; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.center {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px;
  gap: 8px;
}
.view.center p { margin: 0 0 8px; max-width: 280px; }

.hero-logo { width: 56px; height: 56px; }

.btn {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 9px 20px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }

.link-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 6px 8px; border-radius: 8px; font-size: 13px;
}
.link-btn:hover { background: var(--surface); color: var(--text); }

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 50%; background: none; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.error { color: var(--danger); font-size: 13px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  background: #fef7e0; color: #5c4400;
  font-size: 12px; text-align: center; padding: 6px 12px;
}
@media (prefers-color-scheme: dark) { .banner { background: #4a3d10; color: #fde293; } }

/* Login */
.gsi { min-height: 44px; display: grid; place-items: center; margin-top: 8px; }
.dev-login {
  display: grid; gap: 8px; width: 100%; max-width: 260px; margin-top: 16px;
  padding: 14px; border: 1px dashed var(--line); border-radius: 12px;
}
.dev-tag { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 !important; }
.dev-login input {
  font: inherit; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}

/* Barra superior */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 10px 14px; border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.bar-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.bar-title > div { display: flex; flex-direction: column; line-height: 1.25; }
.lock {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}

/* Lista de pessoas */
.people { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.person {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px; border: 0; border-radius: 14px; background: none;
  text-align: left; cursor: pointer;
}
.person:hover { background: var(--surface); }
.person .info { flex: 1; min-width: 0; }
.person .row { display: flex; align-items: baseline; gap: 8px; }
.person .name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .time { font-size: 11px; color: var(--muted); flex: none; }
.person .preview {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px;
}
.person .preview span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person.unread .name, .person.unread .preview span:first-child { color: var(--text); font-weight: 500; }
.person .preview .is-typing { color: var(--accent); font-style: italic; }
.person.offline .avatar { opacity: .55; }

.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--badge); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center; flex: none;
}
@media (prefers-color-scheme: dark) { .badge { color: #3c0d0a; } }
.badge.mini {
  position: absolute; top: 2px; right: 0;
  min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px;
}

/* Avatares */
.avatar {
  --hue: 170;
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: hsl(var(--hue) 45% 88%); color: hsl(var(--hue) 55% 26%);
  font-weight: 500; font-size: 15px; text-transform: uppercase;
}
@media (prefers-color-scheme: dark) {
  .avatar { background: hsl(var(--hue) 30% 30%); color: hsl(var(--hue) 60% 88%); }
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.xs { width: 26px; height: 26px; font-size: 11px; }
.avatar .dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--bg);
}

/* Estado vazio */
.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 6px;
}
.empty p { margin: 0; max-width: 270px; font-size: 13px; }
.empty-art { display: flex; margin-bottom: 10px; }
.empty-art span {
  width: 38px; height: 38px; border-radius: 50%;
  border: 2px dashed var(--line); background: var(--surface); margin-left: -10px;
}
.empty-art span:first-child { margin-left: 0; background: var(--accent-soft); border: 2px solid var(--accent); position: relative; z-index: 1; }

/* Rodapé com a própria conta */
.me-bar {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line); padding: 8px 8px 8px 14px;
}
.me { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Conversa */
.peer { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.peer .info { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.peer .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer .status { font-size: 12px; color: var(--muted); }
.peer .status.online { color: var(--online); }

.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 2px;
}
.intro {
  align-self: center; text-align: center; max-width: 260px;
  font-size: 12px; color: var(--muted); background: var(--surface);
  border-radius: 12px; padding: 8px 12px; margin: 4px 0 14px;
}

.msg { display: flex; flex-direction: column; max-width: 84%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg.gap { margin-top: 10px; }

.bubble {
  padding: 8px 12px; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.mine .bubble { background: var(--mine-bg); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs-bg); color: var(--theirs-ink); border-bottom-left-radius: 6px; }
.mine.cont .bubble { border-top-right-radius: 6px; }
.theirs.cont .bubble { border-top-left-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.meta { font-size: 11px; color: var(--muted); margin: 3px 6px 0; }
.meta.seen { color: var(--accent); }
.meta button {
  border: 0; background: none; padding: 0; color: var(--danger);
  text-decoration: underline; cursor: pointer; font-size: 11px;
}

.typing {
  display: flex; gap: 4px; align-self: flex-start;
  margin: 0 12px 6px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--theirs-bg);
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  margin: 6px 10px 10px; padding: 4px 4px 4px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: none; color: var(--text);
  font: inherit; padding: 8px 0; max-height: 120px; min-height: 36px;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.send-btn:disabled { background: none; color: var(--muted); cursor: default; }

.counter { margin: -4px 22px 8px; font-size: 11px; color: var(--muted); text-align: right; }
.counter.over { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .spinner, .typing span { animation: none; }
}

/* Canal da equipe */
.avatar.team { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) { .avatar.team { background: var(--accent-soft); color: var(--accent); } }
.team-row { border-bottom: 1px solid var(--line); margin-bottom: 4px; padding-bottom: 4px; }
.sender { font-size: 11px; font-weight: 500; color: var(--muted); margin: 0 10px 2px; }

/* Respostas rápidas */
.quick {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 10px 0;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
