/* ============ Cores e medidas (identidade MV Telecom) ============ */
:root {
  --blue: #005EA2;
  --blue-2: #0382D6;
  --blue-dark: #00457A;
  --orange: #F49A1C;
  --orange-2: #FAAC3D;

  --bg: #EEF3F8;
  --pattern: rgba(0, 94, 162, .05);
  --surface: #FFFFFF;
  --surface-2: #F4F7FA;
  --text: #1C2733;
  --muted: #6B7A89;
  --line: #DDE5EE;

  --bubble-in: #FFFFFF;
  --bubble-in-text: #1C2733;
  --bubble-out: #005EA2;
  --bubble-out-text: #FFFFFF;
  --bubble-bot: #FFF5E6;

  --danger: #E5484D;
  --success: #2FB872;
  --read: #8FD3FF;

  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 40, 70, .08), 0 4px 14px rgba(16, 40, 70, .06);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1620;
    --pattern: rgba(255, 255, 255, .025);
    --surface: #16212D;
    --surface-2: #1D2A38;
    --text: #E6EDF4;
    --muted: #8C9BAB;
    --line: #253445;
    --bubble-in: #1D2A38;
    --bubble-in-text: #E6EDF4;
    --bubble-out: #0B6CB8;
    --bubble-bot: #2A2416;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1620;
  --pattern: rgba(255, 255, 255, .025);
  --surface: #16212D;
  --surface-2: #1D2A38;
  --text: #E6EDF4;
  --muted: #8C9BAB;
  --line: #253445;
  --bubble-in: #1D2A38;
  --bubble-in-text: #E6EDF4;
  --bubble-out: #0B6CB8;
  --bubble-bot: #2A2416;
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* Altura = área visível real (encolhe quando o teclado do celular abre; ver fitViewport no JS) */
.app {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--app-top, 0px));
  display: flex;
  justify-content: center;
}

/* ============ Painel lateral (desktop) ============ */
.side { display: none; }

@media (min-width: 960px) {
  body {
    background:
      radial-gradient(circle at 15% 20%, rgba(244, 154, 28, .35), transparent 40%),
      linear-gradient(135deg, var(--blue-dark), var(--blue) 55%, var(--blue-2));
  }
  .app { align-items: center; gap: 56px; padding: 32px; }
  .side {
    display: flex; flex-direction: column; gap: 18px;
    width: 340px; color: #fff;
  }
  .side__logo { width: 190px; }
  .side__title { font-size: 34px; line-height: 1.1; margin: 8px 0 0; font-weight: 800; }
  .side__text { margin: 0; opacity: .9; line-height: 1.5; }
  .side__list { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 10px; }
  .side__list li { display: flex; gap: 10px; align-items: center; font-weight: 600; }
  .side__ico {
    width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .14);
  }
  .side__hours {
    display: grid; gap: 2px; padding: 14px 16px; border-radius: 14px;
    background: rgba(0, 0, 0, .18); font-size: 14px;
  }
  .side__hours strong { color: var(--orange-2); margin-bottom: 4px; }

  .chat {
    height: min(820px, calc(var(--app-h, 100dvh) - 64px));
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0, 20, 50, .45);
  }
}

/* ============ Janela do chat ============ */
.chat {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 100%;
  display: flex; flex-direction: column;
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--pattern) 1.5px, transparent 1.5px),
    radial-gradient(var(--pattern) 1.5px, transparent 1.5px);
  background-size: 26px 26px;
  background-position: 0 0, 13px 13px;
  overflow: hidden;
}

/* Cabeçalho */
.chat__header {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 10px 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(120deg, var(--blue-dark), var(--blue) 60%, var(--blue-2));
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 40, 80, .25);
}
.chat__header::after { /* faixa laranja da marca */
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px;
  background: linear-gradient(90deg, var(--orange), var(--orange-2));
}
.chat__who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat__who strong { font-size: 16.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__status { font-size: 13px; opacity: .85; transition: color .2s; }
.chat__status.is-typing { color: var(--orange-2); opacity: 1; font-weight: 700; }

.avatar {
  position: relative; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; display: grid; place-items: center;
  font-weight: 800; color: var(--blue); font-size: 17px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}
.avatar img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.avatar.has-photo img { width: 44px; height: 44px; }
.avatar__dot {
  position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--blue);
}
.avatar.pop { animation: pop .45s ease; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: inherit; transition: background .15s;
}
.icon-btn:hover { background: rgba(127, 127, 127, .14); }
.icon-btn--sm { width: 32px; height: 32px; }
.icon-btn--sm svg { width: 18px; height: 18px; }
.icon-btn--danger { color: var(--danger); }

/* Menu */
.menu {
  position: absolute; top: calc(100% - 4px); right: 10px;
  min-width: 220px; padding: 6px; border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  animation: drop .16s ease;
}
.menu button {
  display: flex; gap: 10px; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 10px; font-weight: 600;
}
.menu button:hover { background: var(--surface-2); }
.menu__danger { color: var(--danger); }

/* ============ Mensagens ============ */
.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 12px 10px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(127, 127, 127, .3); border-radius: 3px; }

.welcome {
  text-align: center; margin: 4px auto 18px; padding: 18px 18px 14px; max-width: 330px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  animation: rise .5s ease;
}
.welcome__logo { width: 190px; height: auto; max-width: 100%; margin: 0 auto; }
.welcome__logo--light { display: block; }
.welcome__logo--dark { display: none; }
/* Tema escuro: versão do logo com "INTERNET" em branco */
:root[data-theme="dark"] .welcome__logo--light { display: none; }
:root[data-theme="dark"] .welcome__logo--dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .welcome__logo--light { display: none; }
  :root:not([data-theme="light"]) .welcome__logo--dark { display: block; }
}

.welcome p { margin: 10px 0 6px; line-height: 1.45; font-size: 15px; }
.welcome small { color: var(--muted); font-size: 12px; }

.day {
  display: flex; justify-content: center; margin: 14px 0 10px;
}
.day span, .sys {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface); padding: 5px 12px; border-radius: 999px; box-shadow: var(--shadow);
}
.sys-row { display: flex; justify-content: center; margin: 12px 0; animation: rise .3s ease; }
.sys { color: var(--blue); }
:root[data-theme="dark"] .sys { color: var(--read); }

.row {
  display: flex; gap: 8px; align-items: flex-end;
  margin-top: 2px;
  animation: rise .25s ease;
}
.row.first { margin-top: 12px; }
.row.out { justify-content: flex-end; }

.row__avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
  background: var(--blue); color: #fff; visibility: hidden;
}
.row__avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.row__avatar.bot { background: #fff; box-shadow: var(--shadow); }
.row__avatar.bot img { width: 22px; height: 22px; }
.row.last .row__avatar { visibility: visible; }

.bubble {
  position: relative;
  max-width: min(78%, 400px);
  padding: 8px 12px 6px;
  border-radius: var(--radius);
  background: var(--bubble-in); color: var(--bubble-in-text);
  box-shadow: var(--shadow);
  font-size: 15px; line-height: 1.42;
  overflow-wrap: anywhere;
}
.row.in.last .bubble { border-bottom-left-radius: 6px; }
.row.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.row.out.last .bubble { border-bottom-right-radius: 6px; }
.row.bot .bubble { background: var(--bubble-bot); }

.bubble__name { display: block; font-size: 12.5px; font-weight: 800; color: var(--orange); margin-bottom: 2px; }
.row.bot .bubble__name { color: var(--blue); }
:root[data-theme="dark"] .row.bot .bubble__name { color: var(--read); }
.bubble__text { white-space: pre-wrap; }
.bubble__text a { color: inherit; font-weight: 700; }
.bubble__meta {
  float: right; display: inline-flex; align-items: center; gap: 3px;
  margin: 6px 0 -2px 10px; font-size: 11px; opacity: .7; line-height: 1;
}
.bubble__meta svg { width: 16px; height: 16px; stroke-width: 2.2; }
.tick--read { color: var(--read); opacity: 1; }
.row.out .bubble__meta .tick--sending { animation: pulse 1s infinite; }
.tick--error { color: #FFB4B4; opacity: 1; }
.icon-btn.is-off { opacity: .45; }

/* Botões dentro da mensagem do bot */
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; clear: both; }
.choices button {
  padding: 7px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 700;
  background: var(--surface); color: var(--blue); border: 1.5px solid var(--blue);
  transition: background .15s, color .15s, transform .1s;
}
.choices button:hover { background: var(--blue); color: #fff; }
.choices button:active { transform: scale(.96); }
.choices.used button { opacity: .45; pointer-events: none; }
:root[data-theme="dark"] .choices button { color: var(--read); border-color: var(--read); }

/* Imagem */
.bubble--media { padding: 4px; }
.bubble--media img {
  display: block; width: 100%; max-width: 280px; max-height: 320px; object-fit: cover;
  border-radius: 14px; cursor: zoom-in;
}
.bubble--media .bubble__text { padding: 6px 8px 0; }
.bubble--media .bubble__meta { margin-right: 6px; }

/* Arquivo */
.file {
  display: flex; align-items: center; gap: 10px; min-width: 220px;
  padding: 8px; border-radius: 12px; background: rgba(127, 127, 127, .12);
  text-decoration: none; color: inherit;
}
.file__ico {
  width: 40px; height: 40px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--orange); color: #fff; font-size: 11px; font-weight: 800;
}
.file__name { font-weight: 700; font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.file__size { font-size: 12px; opacity: .7; }

/* Áudio */
.audio { display: flex; align-items: center; gap: 10px; min-width: 230px; padding: 2px 0; }
.audio__play {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--orange); color: #fff;
}
.audio__play svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.audio__track { flex: 1; display: grid; gap: 4px; }
.audio__bar { position: relative; height: 4px; border-radius: 2px; background: rgba(127, 127, 127, .3); cursor: pointer; }
.audio__fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 2px; background: currentColor; }
.audio__fill::after {
  content: ""; position: absolute; right: -6px; top: -4px; width: 12px; height: 12px; border-radius: 50%; background: currentColor;
}
.audio__time { font-size: 11.5px; opacity: .75; }

/* Digitando... */
.typing .bubble { padding: 12px 14px; }
.dots { display: flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

/* Botão de rolar para baixo */
.scroll-down {
  position: absolute; right: 14px; bottom: 140px; z-index: 4;
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); color: var(--blue); box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  animation: rise .2s ease;
}
.scroll-down__badge {
  position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--orange); color: #fff; font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
}

/* ============ Atalhos ============ */
.shortcuts {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 12px 4px;
  mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 24px), transparent);
}
.shortcuts::-webkit-scrollbar { display: none; }
.shortcuts button {
  flex: none; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  transition: transform .1s, border-color .15s;
}
.shortcuts button:hover { border-color: var(--orange); }
.shortcuts button:active { transform: scale(.95); }

/* ============ Prévia de anexo ============ */
.attach-preview {
  display: flex; align-items: center; gap: 10px;
  margin: 6px 12px 0; padding: 8px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow);
  animation: rise .2s ease;
}
.attach-preview__body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.attach-preview__body img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }

/* ============ Barra de digitação / gravação ============ */
.composer, .recorder {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.composer__field {
  flex: 1; display: flex; align-items: flex-end;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 2px 4px; color: var(--muted);
  border: 1.5px solid transparent; transition: border-color .15s;
}
.composer__field:focus-within { border-color: var(--blue-2); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 16px; color: var(--text); line-height: 1.4;
  padding: 10px 8px 10px 2px; max-height: 130px;
}
.composer textarea::placeholder { color: var(--muted); }

.send-btn {
  position: relative; width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--orange-2), var(--orange));
  box-shadow: 0 4px 12px rgba(244, 154, 28, .45);
  transition: transform .12s, background .2s;
}
.send-btn:active { transform: scale(.92); }
.send-btn svg { position: absolute; transition: transform .2s, opacity .2s; }
.send-btn .ico-send { fill: currentColor; stroke-width: 1.5; }
.send-btn .ico-mic, .send-btn .ico-send { opacity: 1; transform: none; }
.send-btn[data-mode="mic"] .ico-send,
.send-btn[data-mode="send"] .ico-mic { opacity: 0; transform: scale(.3) rotate(-45deg); visibility: hidden; }
#sendBtn[data-mode="send"] { background: linear-gradient(135deg, var(--blue-2), var(--blue)); box-shadow: 0 4px 12px rgba(0, 94, 162, .45); }

.recorder { align-items: center; animation: rise .2s ease; }
.recorder__info {
  flex: 1; display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 16px;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.recorder__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.recorder__wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 26px; overflow: hidden; justify-content: flex-end; }
.recorder__wave i { width: 3px; border-radius: 2px; background: var(--blue-2); flex: none; }

/* ============ Lightbox e modal ============ */
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 12, 20, .92); animation: fade .2s ease;
}
.lightbox img { max-width: 100%; max-height: 90dvh; border-radius: 10px; }
.lightbox__close { position: absolute; top: 14px; right: 14px; color: #fff; }

.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(5, 12, 20, .55); animation: fade .2s ease;
}
.modal__card {
  width: 100%; max-width: 360px; padding: 22px; border-radius: 20px;
  background: var(--surface); box-shadow: 0 20px 50px rgba(0, 0, 0, .3); animation: rise .25s ease;
}
.modal__card h2 { margin: 0 0 8px; font-size: 19px; }
.modal__card p { margin: 0 0 18px; color: var(--muted); line-height: 1.45; }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.btn { padding: 10px 16px; border-radius: 12px; font-weight: 800; }
.btn--primary { background: var(--danger); color: #fff; }
.btn--ghost { background: var(--surface-2); }

/* Tela de encerrado */
.ended {
  margin: 18px auto 8px; max-width: 320px; text-align: center; padding: 18px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); animation: rise .3s ease;
}
.ended p { margin: 0 0 12px; font-weight: 700; }
.ended .stars { display: flex; justify-content: center; gap: 6px; margin-bottom: 12px; }
.ended .stars button { font-size: 28px; filter: grayscale(1); opacity: .5; transition: transform .1s; }
.ended .stars button.on { filter: none; opacity: 1; }
.ended .stars button:hover { transform: scale(1.15); }
.ended .btn { background: var(--blue); color: #fff; }

/* ============ Animações ============ */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
