/* Chat Tradutor — visual inspirado no WhatsApp, claro e escuro. */

:root {
  --bar: #008069;
  --bar-text: #ffffff;
  --bg: #efeae2;
  --pattern: rgba(0, 0, 0, 0.035);
  --mine: #d9fdd3;
  --theirs: #ffffff;
  --text: #111b21;
  --muted: #667781;
  --trans: #3b4a54;
  --line: rgba(0, 0, 0, 0.08);
  --composer: #f0f2f5;
  --field: #ffffff;
  --accent: #00a884;
  --read: #53bdeb;
  --danger: #ea0038;
  --note-bg: #fff6d6;
  --note-text: #6b5300;
  --day: #ffffffd9;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bar: #202c33;
    --bar-text: #e9edef;
    --bg: #0b141a;
    --pattern: rgba(255, 255, 255, 0.025);
    --mine: #005c4b;
    --theirs: #202c33;
    --text: #e9edef;
    --muted: #8696a0;
    --trans: #c5d0d6;
    --line: rgba(255, 255, 255, 0.09);
    --composer: #202c33;
    --field: #2a3942;
    --note-bg: #3a3313;
    --note-text: #f3dd8b;
    --day: #182229;
    --shadow: 0 1px 0.5px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; }

.muted { color: var(--muted); }

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--theirs);
  border-radius: 12px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 8px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 18px; color: var(--text); font-size: 14px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  font-size: 16px;
}
.login-card button {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: 0;
  border-radius: 24px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.login-error { color: var(--danger); min-height: 1.4em; margin: 12px 0 0 !important; }

/* -------------------------------------------------------------------- app */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  position: relative;
  background:
    radial-gradient(var(--pattern) 1.2px, transparent 1.3px) 0 0 / 22px 22px,
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bar);
  color: var(--bar-text);
  flex: none;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dfe5e7;
  color: #54656f;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
  flex: none;
}
.peer { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 13px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status.typing { opacity: 1; font-style: italic; }

.icon-btn {
  background: none;
  border: 0;
  padding: 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.15); }
.icon-btn.danger { color: var(--danger); }

/* --------------------------------------------------------------- mensagens */

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 4% 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.intro {
  align-self: center;
  max-width: 440px;
  margin: 8px 0 14px;
  padding: 8px 12px;
  background: var(--note-bg);
  color: var(--note-text);
  border-radius: 8px;
  font-size: 12.5px;
  text-align: center;
  box-shadow: var(--shadow);
}

.day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 5px 12px;
  background: var(--day);
  color: var(--muted);
  border-radius: 8px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.msg {
  max-width: min(78%, 560px);
  padding: 6px 8px 4px 9px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  margin-top: 2px;
}
.msg.first { margin-top: 8px; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg.theirs { align-self: flex-start; background: var(--theirs); }
.msg.mine.first { border-top-right-radius: 0; }
.msg.theirs.first { border-top-left-radius: 0; }

.msg-main { white-space: pre-wrap; }

.msg-sub {
  white-space: pre-wrap;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--trans);
  font-size: 13.5px;
}
.msg-sub .flag { font-size: 11px; font-weight: 700; color: var(--muted); margin-right: 4px; letter-spacing: 0.03em; }
.msg-sub.pending { color: var(--muted); font-style: italic; }

.msg-note {
  margin-top: 5px;
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--note-bg);
  color: var(--note-text);
  font-size: 12.5px;
}

.msg-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
}
.msg-foot .tools { margin-right: auto; display: flex; gap: 2px; }
.link-btn {
  background: none;
  border: 0;
  padding: 2px 4px;
  font-size: 11.5px;
  color: var(--accent);
  border-radius: 4px;
}
.link-btn:hover { background: rgba(127, 127, 127, 0.12); }

.ticks { display: inline-flex; color: var(--muted); }
.ticks.read { color: var(--read); }
.ticks.failed { color: var(--danger); font-weight: 700; }

.msg.failed { cursor: pointer; outline: 1px solid var(--danger); }
.fail-text { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* ------------------------------------------------------------------ áudio */

.audio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  padding: 2px 0 4px;
}
.audio-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}
.audio-track {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  position: relative;
  cursor: pointer;
}
.audio-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 2px; background: var(--accent); }
.audio-time { font-size: 11.5px; color: var(--muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- pular p/ baixo */

.jump-btn {
  position: absolute;
  right: 16px;
  bottom: 84px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--theirs);
  color: var(--muted);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  z-index: 3;
}
.jump-count {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ----------------------------------------------------------------- prévia */

.preview {
  flex: none;
  margin: 0 8px;
  padding: 8px 12px;
  background: var(--theirs);
  border-left: 4px solid var(--accent);
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  max-height: 34dvh;
  overflow-y: auto;
}
.preview-head { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 600; font-size: 12.5px; }
.preview-text { white-space: pre-wrap; margin-top: 2px; }
.preview-text.stale { opacity: 0.5; }
.preview-fix { margin-top: 4px; color: var(--muted); font-size: 12.5px; white-space: pre-wrap; }
.preview-fix b { color: var(--text); font-weight: 600; }
.preview-note { margin-top: 5px; padding: 4px 7px; border-radius: 6px; background: var(--note-bg); color: var(--note-text); font-size: 12.5px; }

.spin {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- composer */

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--composer);
}
.input-wrap {
  flex: 1;
  background: var(--field);
  border-radius: 22px;
  padding: 10px 16px;
  display: flex;
}
.input-wrap textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px evita o zoom automático do iPhone ao focar */
  line-height: 1.35;
  max-height: 140px;
  padding: 0;
}

.action-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}
.action-btn .ico-send { display: none; }
.action-btn.send .ico-send { display: block; }
.action-btn.send .ico-mic { display: none; }
.action-btn:disabled { opacity: 0.5; cursor: default; }

.rec-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--field);
  border-radius: 22px;
  padding: 4px 14px 4px 4px;
  min-height: 46px;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 15px; }
.rec-hint { color: var(--muted); font-size: 12.5px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #323739;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@media (min-width: 700px) {
  .msg { max-width: 65%; }
}
