/* Rotas by Sator — chat público. Cores idênticas ao WhatsApp (CONTRATO.md). */

:root {
  --header-mobile-bg: #008069;
  --header-mobile-fg: #FFFFFF;
  --header-desktop-bg: #F0F2F5;
  --header-desktop-fg: #111B21;
  --wallpaper-bg: #EFEAE2;
  --balloon-in-bg: #FFFFFF;
  --balloon-out-bg: #D9FDD3;
  --text-main: #111B21;
  --text-secondary: #667781;
  --icon-color: #54656F;
  --tick-read: #53BDEB;
  --tick-sent: #667781;
  --accent: #00A884;
  --composer-bg: #F0F2F5;
  --composer-field-bg: #FFFFFF;
  --datestamp-bg: #FFFFFF;
  --datestamp-fg: #54656F;
  --notice-bg: #FFEECD;
  --notice-fg: #54656F;
  --link-color: #027EB5;
  --sidebar-bg: #FFFFFF;
  --sidebar-row-active: #F0F2F5;
  --sidebar-divider: #E9EDEF;
  --unread-badge: #25D366;
  --theme-color: #008069;
  --frame-outer-bg: #D1D7DB;
  --frame-band: #00A884;
  --balloon-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --overlay-scrim: rgba(11, 20, 26, 0.45);
  --wallpaper-filter: none;
  --wallpaper-opacity: 0.055;
  --danger: #F15C5C;
  --scrollbar: rgba(17, 27, 33, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --header-mobile-bg: #1F2C34;
    --header-mobile-fg: #E9EDEF;
    --header-desktop-bg: #202C33;
    --header-desktop-fg: #E9EDEF;
    --wallpaper-bg: #0B141A;
    --balloon-in-bg: #202C33;
    --balloon-out-bg: #005C4B;
    --text-main: #E9EDEF;
    --text-secondary: #8696A0;
    --icon-color: #AEBAC1;
    --tick-read: #53BDEB;
    --tick-sent: #8696A0;
    --accent: #00A884;
    --composer-bg: #202C33;
    --composer-field-bg: #2A3942;
    --datestamp-bg: #182229;
    --datestamp-fg: #8696A0;
    --notice-bg: #182229;
    --notice-fg: #FFD279;
    --link-color: #53BDEB;
    --sidebar-bg: #111B21;
    --sidebar-row-active: #2A3942;
    --sidebar-divider: #222D34;
    --unread-badge: #00A884;
    --theme-color: #1F2C34;
    --frame-outer-bg: #0C1317;
    --frame-band: #00A884;
    --overlay-scrim: rgba(0, 0, 0, 0.6);
    --wallpaper-filter: invert(1);
    --wallpaper-opacity: 0.05;
    --scrollbar: rgba(233, 237, 239, 0.2);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background: var(--wallpaper-bg);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
a { color: var(--link-color); }

.viewport {
  min-height: 100dvh;
  min-height: var(--app-vh, 100dvh);
  background: var(--wallpaper-bg);
}

.app-frame { height: 100dvh; height: var(--app-vh, 100dvh); }

.app {
  height: 100dvh;
  height: var(--app-vh, 100dvh);
  display: flex;
  background: var(--wallpaper-bg);
  overflow: hidden;
}

/* ---------- Ícones genéricos ---------- */
.icon-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--icon-color);
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
}
.icon-btn:active { background: rgba(134, 150, 160, 0.18); }
.icon-btn:disabled { opacity: .38; cursor: default; }
.icon-btn:disabled:active { background: none; }

.avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #128C7E;
  user-select: none;
}
.avatar--me {
  background: #DFE5E7;
  color: #667781;
}
@media (prefers-color-scheme: dark) {
  .avatar--me { background: #2A3942; color: #AEBAC1; }
}

/* ================= SIDEBAR (desktop, WhatsApp Web) ================= */
.sidebar {
  display: none;
  flex-direction: column;
  width: 32%;
  min-width: 320px;
  max-width: 420px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-divider);
}
.sidebar__top {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--header-desktop-bg);
  flex: none;
}
.sidebar__brand {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--header-desktop-fg);
  opacity: .8;
}
.sidebar__top-icons { display: flex; }
.sidebar__search { padding: 8px 12px; flex: none; }
.sidebar__search-box {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--composer-bg);
  border-radius: 8px;
  padding: 0 12px;
  height: 34px;
  color: var(--icon-color);
}
.sidebar__search-box input {
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
  width: 100%;
  color: var(--text-main);
}
.sidebar__search-box input::placeholder { color: var(--text-secondary); }
.sidebar__list { flex: 1; overflow-y: auto; }
.chat-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: none;
  border: none;
  text-align: left;
  border-bottom: 1px solid var(--sidebar-divider);
}
.chat-row--active, .chat-row:active { background: var(--sidebar-row-active); }
.chat-row__body { flex: 1; min-width: 0; }
.chat-row__top { display: flex; justify-content: space-between; gap: 8px; }
.chat-row__name {
  font-size: 15px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-row__time { font-size: 12px; color: var(--text-secondary); flex: none; }
.chat-row__bottom { display: flex; align-items: center; gap: 4px; margin-top: 3px; }
.chat-row__preview {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-row__tick { color: var(--tick-sent); flex: none; }
.chat-row__tick.is-read { color: var(--tick-read); }
.chat-row__badge {
  flex: none;
  background: var(--unread-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 19px;
  height: 19px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ================= CHAT ================= */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  height: var(--app-vh, 100dvh);
  position: relative;
  background: var(--wallpaper-bg);
}

.chat__header {
  flex: none;
  height: calc(56px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 4px;
  padding-right: 8px;
  background: var(--header-mobile-bg);
  color: var(--header-mobile-fg);
}
.chat__header .avatar { margin-left: 4px; margin-right: 6px; }
.chat__back { color: var(--header-mobile-fg); }
.chat__title { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.chat__name {
  font-size: 16.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--header-mobile-fg);
}
.chat__status {
  font-size: 12.5px;
  color: var(--header-mobile-fg);
  opacity: .82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 15px;
}
.chat__actions { display: flex; }
.chat__actions .icon-btn { color: var(--header-mobile-fg); }

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .chat__header { background: var(--header-desktop-bg); color: var(--header-desktop-fg); height: 60px; padding-top: 0; }
  .chat__name, .chat__status { color: var(--header-desktop-fg); }
  .chat__status { opacity: .65; }
  .chat__actions .icon-btn, .chat__back { color: var(--icon-color); }
  .chat__back { display: none; }
}

/* ---------- Menu ⋮ ---------- */
.menu {
  position: absolute;
  top: calc(52px + env(safe-area-inset-top));
  right: 8px;
  z-index: 30;
  background: var(--balloon-in-bg);
  color: var(--text-main);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(11,20,26,.28), 0 0 0 1px rgba(11,20,26,.06);
  min-width: 230px;
  overflow: hidden;
  padding: 8px 0;
}
@media (min-width: 900px) { .menu { top: 56px; } }
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 11px 18px;
  font-size: 14.5px;
  color: var(--text-main);
}
.menu button:active { background: var(--sidebar-row-active); }

/* ---------- Aviso amarelo ---------- */
.notice {
  flex: none;
  background: var(--notice-bg);
  color: var(--notice-fg);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  padding: 8px 22px;
}

/* ---------- Fio da conversa ---------- */
.thread {
  flex: 1;
  position: relative;
  min-height: 0;
}
.thread__wallpaper {
  position: absolute;
  inset: 0;
  background-image: url("papel-de-parede.svg");
  background-size: 240px 240px;
  background-repeat: repeat;
  opacity: var(--wallpaper-opacity);
  filter: var(--wallpaper-filter);
  pointer-events: none;
}
.thread__scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}
.thread__scroll::-webkit-scrollbar { width: 6px; }
.thread__scroll::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
.thread__messages {
  min-height: 100%;
  padding: 12px 6% 14px;
  display: flex;
  flex-direction: column;
}
@media (min-width: 900px) { .thread__messages { padding-left: 8%; padding-right: 8%; } }

.datestamp { display: flex; justify-content: center; margin: 10px 0 14px; }
.datestamp span {
  background: var(--datestamp-bg);
  color: var(--datestamp-fg);
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 7.5px;
  box-shadow: var(--balloon-shadow);
}

.row { display: flex; margin-bottom: 2px; }
.row--in { justify-content: flex-start; }
.row--out { justify-content: flex-end; }
.row--tight { margin-top: -1px; }

.bubble {
  position: relative;
  max-width: 78%;
  padding: 6px 8px 8px 9px;
  border-radius: 7.5px;
  box-shadow: var(--balloon-shadow);
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
@media (min-width: 900px) {
  .bubble { max-width: 65%; font-size: 14.2px; }
}
.bubble--in { background: var(--balloon-in-bg); border-top-left-radius: 2px; color: var(--balloon-in-bg); }
.bubble--out { background: var(--balloon-out-bg); border-top-right-radius: 2px; color: var(--balloon-out-bg); }
.bubble--in .bubble__text, .bubble--out .bubble__text { color: var(--text-main); }
/* A hora do balão é SEMPRE o texto secundário (#667781 / #8696A0), como no WhatsApp (verificação de 28/09). */
.bubble--in .bubble__time, .bubble--out .bubble__time { color: var(--text-secondary); }
.row--tight .bubble--in { border-top-left-radius: 7.5px; }
.row--tight .bubble--out { border-top-right-radius: 7.5px; }

.bubble__tail { position: absolute; top: 0; width: 8px; height: 13px; }
.bubble__tail--in { left: -8px; }
.bubble__tail--out { right: -8px; transform: scaleX(-1); }

.bubble__text { color: var(--text-main); white-space: pre-wrap; }
.bubble__text b, .bubble__text strong { font-weight: 700; }
.bubble__text i, .bubble__text em { font-style: italic; }
.bubble__text s { text-decoration: line-through; }
.bubble__text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(11,20,26,.06);
  padding: .05em .3em;
  border-radius: 4px;
  font-size: .92em;
}
@media (prefers-color-scheme: dark) { .bubble__text code { background: rgba(233,237,239,.08); } }
.bubble__text a { text-decoration: underline; word-break: break-all; }

.bubble__meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 4px 0 -2px 6px;
  transform: translateY(3px);
}
.bubble__time { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.bubble__tick { color: var(--tick-sent); }
.bubble__tick.is-read { color: var(--tick-read); }
.bubble__tick--fail { color: var(--danger); }

.bubble--media .bubble__card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(11,20,26,.04);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 4px;
}
@media (prefers-color-scheme: dark) { .bubble--media .bubble__card { background: rgba(233,237,239,.06); } }
.bubble--media img { max-width: 100%; border-radius: 6px; margin-bottom: 4px; }

.system-note {
  align-self: center;
  background: var(--datestamp-bg);
  color: var(--datestamp-fg);
  font-size: 12.5px;
  padding: 7px 14px;
  border-radius: 7.5px;
  margin: 6px 0 12px;
  text-align: center;
  max-width: 85%;
  box-shadow: var(--balloon-shadow);
}
.system-note--erro { color: var(--danger); }

.bubble--resend { cursor: pointer; }

/* ---------- Botão descer ---------- */
.scroll-down {
  position: absolute;
  right: 16px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--balloon-in-bg);
  color: var(--icon-color);
  border: none;
  box-shadow: 0 1px 4px rgba(11,20,26,.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.scroll-down__badge {
  position: absolute;
  top: -6px;
  right: -4px;
  background: var(--unread-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(11,20,26,.82);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  max-width: 86%;
  text-align: center;
  z-index: 20;
}

/* ---------- Barra de digitação ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--composer-bg);
}
.composer__field-wrap {
  flex: 1;
  background: var(--composer-field-bg);
  border-radius: 21px;
  padding: 0 6px 0 14px;
  display: flex;
  align-items: center;
  min-height: 42px;
  max-height: 130px;
}
.composer__field {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  resize: none;
  font-size: 16px;
  line-height: 1.4;
  padding: 10px 0;
  max-height: 118px;
  color: var(--text-main);
}
@media (min-width: 900px) { .composer__field { font-size: 15px; } }
.composer__field::placeholder { color: var(--text-secondary); }
.composer__send {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.composer__send svg { margin: 0 auto; }
.composer__send .icon-send { margin-left: 2px; }
.composer__attach { display: none; }
@media (min-width: 900px) { .composer__attach { display: flex; } }

/* ---------- Overlay: nome / sobre / pausada ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.sheet {
  background: var(--balloon-in-bg);
  color: var(--text-main);
  border-radius: 10px;
  padding: 26px 24px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.sheet--center { text-align: center; }
.sheet--center svg { margin: 0 auto 10px; color: var(--icon-color); }
.sheet h2 { margin: 0 0 8px; font-size: 19px; }
.sheet p { margin: 0 0 18px; font-size: 14px; color: var(--text-secondary); line-height: 1.45; }
.sheet__input {
  width: 100%;
  border: none;
  border-bottom: 2px solid var(--accent);
  outline: none;
  font-size: 16px;
  padding: 8px 2px;
  margin-bottom: 22px;
  background: none;
  color: var(--text-main);
}
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 12px;
  font-size: 14.5px;
  font-weight: 600;
}
.btn-ghost {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 12px;
  font-size: 14px;
  margin-top: 4px;
}

.overlay--pausada { background: var(--wallpaper-bg); }
.overlay--pausada .sheet { box-shadow: none; max-width: 320px; }

.banner-offline {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-size: 13px;
  padding: 7px 10px;
  z-index: 60;
}

[hidden] { display: none !important; }

/* ================= Moldura desktop grande (WhatsApp Web ≥1440) ================= */
@media (min-width: 1440px) {
  .viewport {
    background: var(--frame-outer-bg);
    display: flex;
    flex-direction: column;
  }
  .viewport::before {
    content: "";
    display: block;
    height: 127px;
    background: var(--frame-band);
    flex: none;
  }
  .app-frame {
    position: relative;
    flex: 1;
    max-width: 1600px;
    width: calc(100% - 38px);
    margin: -108px auto 19px;
    height: calc(100dvh - 19px - 19px);
    height: calc(var(--app-vh, 100dvh) - 19px - 19px);
    box-shadow: 0 10px 46px rgba(0,0,0,.35);
    border-radius: 3px;
    overflow: hidden;
  }
  .app { position: absolute; inset: 0; height: auto; }
  .chat, .sidebar { height: 100%; }
}

@media (max-width: 899px) {
  .sidebar { display: none; }
}
