/* Preventive — chat estilo WhatsApp (tokens da design §7). Sem marca nem papel de parede do WhatsApp. */
:root {
  --header: #008069;
  --chat-bg: #EFEAE2;
  --out: #D9FDD3;
  --in: #FFFFFF;
  --text: #111B21;
  --muted: #667781;
  --read: #53BDEB;
  --bar: #F0F2F5;
  --send: #00A884;
  --sys-bg: #FFEECD;
  --sys-text: #54656F;
  --danger: #D93025;
  --radius: 7.5px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #D1D7DB;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hide-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- casca ---------- */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--chat-bg);
  overflow: hidden;
}
@media (min-width: 520px) {
  .app { box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 6px 24px rgba(11, 20, 26, .18); }
}

/* ---------- cabeçalho ---------- */
.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--sat)) calc(6px + var(--sar)) 8px calc(12px + var(--sal));
  background: var(--header);
  color: #fff;
  min-height: calc(56px + var(--sat));
  z-index: 5;
}
.avatar {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #DFE5E7;
  color: var(--header);
  display: grid; place-items: center;
  font-weight: 600; font-size: 19px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.title { flex: 1; min-width: 0; line-height: 1.2; }
.name { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; opacity: .85; min-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.typing { font-style: italic; opacity: 1; }

.menu-wrap { position: relative; flex: none; }
.menu {
  position: absolute; right: 4px; top: 46px;
  min-width: 190px;
  background: #fff; color: var(--text);
  border-radius: 8px;
  box-shadow: 0 2px 14px rgba(11, 20, 26, .28);
  padding: 6px 0;
  z-index: 20;
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 18px; font-size: 16px; }
.menu button:active, .menu button:hover { background: #F0F2F5; }

/* ---------- botões ---------- */
.icon-btn {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  padding: 0;
}
.icon-btn.light { color: #fff; }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn:active { background: rgba(11, 20, 26, .08); }
.icon-btn svg, .round svg { display: block; }
.round {
  flex: none;
  width: 46px; height: 46px;
  border: 0; border-radius: 50%;
  background: var(--send); color: #fff;
  display: grid; place-items: center;
  padding: 0;
}
.round:disabled { opacity: .55; }
:focus-visible { outline: 2px solid var(--read); outline-offset: 2px; }

/* ---------- faixa RF-8 ---------- */
.banner {
  flex: none;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 4px 6px 14px;
  background: var(--sys-bg);
  color: var(--sys-text);
  font-size: 13px; line-height: 1.3;
  z-index: 4;
}
.banner span { flex: 1; }

/* ---------- área do chat ---------- */
.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* padrão de pontos próprio (duas grades deslocadas) */
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(rgba(11, 20, 26, .075) 1.2px, transparent 1.6px),
    radial-gradient(rgba(11, 20, 26, .05) 1px, transparent 1.4px);
  background-size: 26px 26px, 26px 26px;
  background-position: 0 0, 13px 13px;
}
.chat-inner { padding: 8px calc(10px + var(--sar)) 10px calc(10px + var(--sal)); display: flex; flex-direction: column; min-height: 100%; justify-content: flex-end; }
.older {
  align-self: center; margin: 4px 0 10px;
  background: rgba(255, 255, 255, .92); color: var(--header);
  border: 0; border-radius: 16px; padding: 7px 16px; font-size: 13.5px; font-weight: 500;
  box-shadow: 0 1px 1px rgba(11, 20, 26, .13);
}
.older:disabled { opacity: .6; }

.day { display: flex; justify-content: center; margin: 10px 0 6px; }
.day span {
  background: rgba(255, 255, 255, .92); color: var(--sys-text);
  font-size: 12.5px; padding: 5px 12px; border-radius: 8px;
  box-shadow: 0 1px 1px rgba(11, 20, 26, .13);
}

.empty { align-self: center; text-align: center; color: var(--sys-text); font-size: 13.5px; background: rgba(255, 255, 255, .85); padding: 8px 14px; border-radius: 8px; margin: 16px 0; max-width: 85%; }

.row { display: flex; flex-direction: column; margin-top: 2px; max-width: 100%; }
.row.out { align-items: flex-end; }
.row.in { align-items: flex-start; }
.row.first { margin-top: 8px; }

.bubble {
  position: relative;
  max-width: 82%;
  padding: 6px 8px 6px 9px;
  border-radius: var(--radius);
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  font-size: 15.5px; line-height: 1.32;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.out .bubble { background: var(--out); }
.in .bubble { background: var(--in); }
.bubble.tail::before {
  content: ""; position: absolute; top: 0; width: 9px; height: 13px; background: inherit;
}
.out .bubble.tail { border-top-right-radius: 0; }
.out .bubble.tail::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.in .bubble.tail { border-top-left-radius: 0; }
.in .bubble.tail::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }

.txt { white-space: pre-wrap; }
.meta {
  float: right; position: relative; top: 5px;
  margin: 3px 0 -6px 10px;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted); line-height: 1; white-space: nowrap;
}
.meta .tick { display: inline-flex; width: 16px; height: 11px; }
.meta .tick svg { width: 16px; height: 11px; }
.meta .tick.read { color: var(--read); }
.meta .tick.failed { color: var(--danger); font-weight: 700; font-size: 13px; width: auto; }
.bubble::after { content: ""; display: block; clear: both; }

.bubble.failed { cursor: pointer; }
.row.fail-row { cursor: pointer; }

/* áudio */
.audio { display: flex; align-items: center; gap: 8px; min-width: 210px; padding: 2px 0 0; }
.audio .play { flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; color: #54656F; display: grid; place-items: center; padding: 0; }
.audio .play:disabled { opacity: .4; }
.audio .track { flex: 1; height: 4px; border-radius: 2px; background: rgba(84, 101, 111, .3); overflow: hidden; }
.audio .track i { display: block; height: 100%; width: 0; background: var(--muted); }
.audio .dur { flex: none; font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.bubble.media-meta .meta { float: none; display: flex; justify-content: flex-end; margin: 2px 0 0; top: 0; }
.transcript {
  max-width: 82%; margin: 3px 4px 0; padding: 0 2px;
  font-size: 12.5px; font-style: italic; color: var(--muted); line-height: 1.3;
}
.out .transcript { text-align: right; }

/* imagem */
.pic { display: block; margin: -2px -4px 4px; border-radius: 6px; overflow: hidden; background: #cfd6da; }
.pic img { display: block; width: 100%; max-width: 100%; max-height: 320px; object-fit: cover; }
.pic-ph { display: block; margin: 0 0 2px; padding: 4px 2px; font-size: 14.5px; color: var(--sys-text); }
.cap { white-space: pre-wrap; margin-top: 3px; }

/* sistema */
.sys-row { display: flex; justify-content: center; margin: 8px 0 4px; }
.sys {
  background: var(--sys-bg); color: var(--sys-text);
  font-size: 13px; line-height: 1.35; text-align: center;
  padding: 6px 12px; border-radius: 8px; max-width: 88%;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.sys.tap { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- aviso inline ---------- */
.notice {
  flex: none;
  margin: 0; padding: 9px 14px;
  background: #FDECEA; color: #7A1F17;
  font-size: 13.5px; line-height: 1.35;
  border-top: 1px solid #F5C6C0;
}

/* ---------- barra de digitação ---------- */
.bar {
  flex: none;
  background: var(--bar);
  padding: 6px calc(6px + var(--sar)) calc(6px + var(--sab)) calc(6px + var(--sal));
  z-index: 5;
}
.composer { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; min-width: 0;
  resize: none; border: 0; outline: none;
  background: #fff; color: var(--text);
  border-radius: 22px;
  padding: 11px 16px;
  font: inherit; font-size: 16px; line-height: 22px;
  max-height: 132px; height: 44px;
  overflow-y: auto;
  margin: 1px 0;
  -webkit-appearance: none;
}
.composer .icon-btn, .composer .round { margin-bottom: 0; }

.rec { display: flex; align-items: center; gap: 8px; min-height: 46px; }
.rec .rec-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.rec .rec-time { font-variant-numeric: tabular-nums; font-size: 17px; }
.rec .rec-hint { flex: 1; color: var(--muted); font-size: 14px; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .rec .rec-dot { animation: none; } }

/* ---------- Link inválido ---------- */
.invalid {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--chat-bg);
  padding: 24px;
}
.invalid-box { max-width: 380px; text-align: center; background: #fff; border-radius: 12px; padding: 28px 24px; box-shadow: 0 1px 3px rgba(11, 20, 26, .15); }
.invalid-ic { font-size: 40px; }
.invalid h1 { margin: 6px 0 8px; font-size: 22px; }
.invalid p { margin: 0; color: var(--sys-text); line-height: 1.45; font-size: 16px; }

/* ---------- diálogo de confirmação ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(11, 20, 26, .5); display: grid; place-items: center; padding: 24px; }
.dialog { background: #fff; border-radius: 12px; padding: 20px 20px 10px; max-width: 360px; width: 100%; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 14px; color: var(--sys-text); line-height: 1.4; font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 4px; }
.txt-btn { background: none; border: 0; color: var(--header); font-size: 15px; padding: 12px 14px; border-radius: 8px; font-weight: 500; }
.txt-btn.strong { font-weight: 700; }
.txt-btn:active { background: #F0F2F5; }

/* ---------- prévia de imagem (image.js) ---------- */
.img-preview {
  position: fixed; inset: 0; z-index: 80;
  display: flex; flex-direction: column;
  background: #0B141A; color: #fff;
  padding-top: var(--sat);
}
.img-preview.busy { cursor: progress; }
.ip-top { flex: none; padding: 6px; }
.ip-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 10px; }
.ip-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.ip-error { flex: none; margin: 0 10px 6px; padding: 8px 12px; border-radius: 8px; background: #FDECEA; color: #7A1F17; font-size: 14px; }
.ip-bar { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal)); background: #1F2C34; }
.ip-caption {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none;
  background: #2A3942; color: #E9EDEF;
  border-radius: 22px; padding: 11px 16px;
  font: inherit; font-size: 16px; line-height: 22px; height: 44px; max-height: 110px;
}
.ip-caption::placeholder { color: #8696A0; }
