:root {
  --bg: #eae6df;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --green: #00a884;
  --green-dark: #008069;
  --out: #d9fdd3;
  --in: #ffffff;
  --blue-tick: #53bdeb;
  --danger: #ea0038;
  --wallpaper: #efeae2;
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(300px, 30%) 1fr;
  height: 100vh;
  height: 100dvh; /* altura real da tela no celular (sem contar as barras do navegador) */
  max-width: 1600px;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(11, 20, 26, .05);
}

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.side-header, .chat-header {
  display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 10px 16px; background: var(--panel-2); flex-shrink: 0;
}
.side-title, .chat-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.side-title strong, .chat-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-title small, .chat-title small { color: var(--muted); font-size: 13px; }
.icon-btn { background: none; border: 0; color: #54656f; padding: 8px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 600; font-size: 15px;
  background: #dfe5e7; color: #54656f;
}
.avatar.me { background: var(--green); color: #fff; }

.nova { display: grid; gap: 8px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.nova input, .search input {
  width: 100%; border: 0; border-radius: 8px; background: var(--panel-2); padding: 9px 12px; outline: none;
}
.nova button, .card button {
  border: 0; border-radius: 8px; background: var(--green); color: #fff; padding: 9px 14px; font-weight: 600;
}
.nova button:hover, .card button:hover { background: var(--green-dark); }

.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }

.contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contact { display: flex; gap: 12px; align-items: center; padding: 10px 16px; cursor: pointer; }
.contact:hover { background: #f5f6f6; }
.contact.active { background: #f0f2f5; }
.contact .body { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.contact .row { display: flex; justify-content: space-between; gap: 8px; }
.contact .name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.contact .last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 4px; align-items: center; }
.contact .badge-closed { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; flex-shrink: 0; }
.contacts .none { color: var(--muted); padding: 24px 16px; text-align: center; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--wallpaper); position: relative; }
.chat-header { border-left: 1px solid var(--line); }
.conv-search {
  display: flex; align-items: center; gap: 2px; background: #fff; border-radius: 8px;
  padding: 0 4px 0 10px; height: 36px; width: min(340px, 45%); color: #54656f;
}
.conv-search:focus-within { box-shadow: 0 0 0 2px rgba(0,168,132,.35); }
.conv-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; padding: 0 6px; font-size: 14px; }
.conv-search .contador { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.conv-search .contador.vazio { color: var(--danger); }
.icon-btn.mini { padding: 4px; }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }

/* destaque da busca dentro dos balões */
.msg mark { background: #ffe58f; color: inherit; border-radius: 2px; padding: 0 1px; }
.msg.busca-atual mark { background: #ffb020; }
.msg.piscar { animation: piscar 1.2s ease-out 1; }
@keyframes piscar { 0%, 40% { box-shadow: 0 0 0 4px rgba(255,176,32,.6); } 100% { box-shadow: 0 1px .5px rgba(11,20,26,.13); } }

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 440px; padding: 24px; }
.empty h1 { font-weight: 300; color: #41525d; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 7%;
  display: flex; flex-direction: column; gap: 2px;
  background-color: var(--wallpaper);
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
  background-size: 18px 18px;
}
.day {
  align-self: center; margin: 12px 0 8px; padding: 5px 12px; border-radius: 8px;
  background: #fff; color: #54656f; font-size: 12.5px; box-shadow: 0 1px .5px rgba(11,20,26,.13);
  position: sticky; top: 4px; z-index: 1;
}
.load-more { align-self: center; font-size: 13px; color: var(--muted); padding: 6px; }

.msg {
  max-width: 65%; padding: 6px 7px 8px 9px; border-radius: 7.5px; position: relative;
  box-shadow: 0 1px .5px rgba(11,20,26,.13); font-size: 14.2px; line-height: 19px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.in  { align-self: flex-start; background: var(--in); }
.msg.out { align-self: flex-end;   background: var(--out); }
.msg.first { margin-top: 8px; }
.msg.first.in  { border-top-left-radius: 0; }
.msg.first.out { border-top-right-radius: 0; }
.msg .who { display: block; font-size: 12.8px; font-weight: 600; margin-bottom: 2px; color: var(--green-dark); }
.msg.in .who { color: #1f7aec; }
.msg .meta { float: right; margin: 6px 0 -6px 10px; font-size: 11px; color: var(--muted); display: inline-flex; gap: 3px; align-items: center; }
.tick { font-size: 13px; letter-spacing: -4px; padding-right: 4px; }
.tick.lido { color: var(--blue-tick); }
.tick.falhou { color: var(--danger); letter-spacing: 0; }
.tick.pendente { letter-spacing: 0; font-size: 11px; filter: grayscale(1); opacity: .7; }
.msg.failed { outline: 1px solid rgba(234,0,56,.35); }

.window-banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 16px; background: #fff8e1; border-top: 1px solid #f3e2a9; font-size: 13.5px; line-height: 1.4;
}
.window-banner svg { flex-shrink: 0; margin-top: 1px; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 16px; background: var(--panel-2); }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 8px; padding: 10px 12px; outline: none;
  max-height: 120px; background: #fff; line-height: 20px;
}
.composer button { border: 0; background: none; color: #54656f; padding: 8px; border-radius: 50%; }
.composer button:disabled { opacity: .4; cursor: default; }
.composer button:not(:disabled):hover { color: var(--green-dark); }

/* ---------- Login / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11,20,26,.45); display: grid; place-items: center; z-index: 10;
  overflow-y: auto; padding: 16px 0; }
.overlay[hidden] { display: none; }
.card { background: #fff; padding: 28px; border-radius: 12px; width: min(360px, 92vw); display: grid; gap: 12px; }
.card h2 { margin: 0 0 4px; font-weight: 500; }
.card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.card input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.card .hint { margin: 0; font-size: 12px; color: var(--muted); }
.card .erro { margin: 0; font-size: 13px; color: var(--danger); background: #fdecef; border-radius: 6px; padding: 8px 10px; }
.card button:disabled { opacity: .6; cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: #111b21; color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 90vw; font-size: 14px;
}
.toast.err { background: var(--danger); }

.back { display: none; }
[hidden] { display: none !important; }

/* filhos da grade podem encolher (sem isso, a conversa "vaza" para os lados no celular) */
.app > *, .chat, .sidebar, .chat-header, .messages { min-width: 0; }

/* busca da conversa: no celular vira um botão de lupa */
.buscar-celular, .fechar-busca { display: none; }

/* lista de passos (instalação no iPhone) */
.passos-ios { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14.5px; line-height: 1.45; }
.passos-ios svg { vertical-align: -3px; }

/* app instalado (tela cheia): respeita o "notch" e a barra inferior do iPhone */
.side-header, .chat-header { padding-top: max(10px, env(safe-area-inset-top)); height: calc(60px + env(safe-area-inset-top)); }
.composer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.contacts { padding-bottom: env(safe-area-inset-bottom); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }

@media (max-width: 760px) {
  .back { display: grid; }
  .app { grid-template-columns: 1fr; }
  .app.has-chat .sidebar { display: none; }
  .app:not(.has-chat) .chat { display: none; }
  .side-header, .chat-header { padding-left: 8px; padding-right: 8px; gap: 8px; }
  .messages { padding: 12px 3%; }
  .msg { max-width: 85%; }

  /* lupa no cabeçalho; ao tocar, a busca ocupa o cabeçalho inteiro */
  .buscar-celular { display: grid; }
  .conv-search { display: none; }
  .chat-header.buscando > :not(.conv-search) { display: none; }
  .chat-header.buscando .conv-search { display: flex; width: 100%; }
  .chat-header.buscando .fechar-busca { display: grid; }
  .conv-search .contador { font-size: 11.5px; }
  .conv-search input::-webkit-search-cancel-button { display: none; } /* fica só o X do sistema */

  /* 16px evita o zoom automático do iPhone ao tocar nos campos */
  input, textarea, select, .conv-search input, .composer textarea { font-size: 16px; }
  .composer { padding-left: 8px; padding-right: 8px; }
  .composer button { padding: 10px; }

  .card { padding: 22px; }
  .contact { padding: 10px 12px; }
}

/* ---------- Marca: Vimezap Clinicall ---------- */
.marca { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.marca-logo { width: 64px; height: 64px; object-fit: contain; }
.marca-nome { font-size: 24px; line-height: 1.1; letter-spacing: -.2px; color: #0a5f6b; }
.marca-nome strong { font-weight: 700; }
.marca-nome span { font-weight: 300; color: #0a7c8c; }
.marca small { color: var(--muted); font-size: 13px; }
.marca-login { margin-bottom: 6px; }
.marca-inicio .marca-logo { width: 96px; height: 96px; opacity: .9; }
.marca-inicio .marca-nome { font-size: 32px; }
.empty .marca-inicio { margin-bottom: 14px; }

/* tela de login com fundo próprio (não mostra o chat vazio por trás) */
#login { background: linear-gradient(160deg, #e7f6f2 0%, #eef3f6 55%, #e4eef2 100%); }
#login .card { box-shadow: 0 10px 30px rgba(10, 95, 107, .12); }

/* ---------- Menu ⋮ ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 15; min-width: 210px;
  background: #fff; border-radius: 8px; padding: 6px 0; box-shadow: 0 4px 18px rgba(11,20,26,.2);
}
.menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none;
  padding: 11px 18px; font-size: 14.5px; color: var(--text); text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--panel-2); outline: none; }
.menu button svg { color: #54656f; flex-shrink: 0; }

/* ---------- Janela Alterar senha ---------- */
.card .check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.card .check input { width: 16px; height: 16px; margin: 0; }
.card .botoes { display: flex; gap: 10px; justify-content: flex-end; }
.card .botoes button { flex: 1; }
.card button.secundario { background: #fff; color: var(--green-dark); border: 1px solid #c9d5d9; }
.card button.secundario:hover { background: var(--panel-2); }

/* ---------- Usuários da empresa (administração) ---------- */
.card-largo { width: min(560px, 94vw); max-height: calc(100dvh - 32px); overflow-y: auto; }
.card-topo { display: flex; align-items: center; justify-content: space-between; }
.card-topo h2 { margin: 0; }
.lista-usuarios { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 240px; overflow-y: auto; }
.lista-usuarios li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.lista-usuarios li:last-child { border-bottom: 0; }
.lista-usuarios .avatar { width: 32px; height: 32px; font-size: 12px; }
.lista-usuarios .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lista-usuarios .info small { color: var(--muted); font-size: 12px; }
.selo { font-size: 11px; border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.selo.admin { background: #e1f5ef; color: var(--green-dark); }
.selo.inativo { background: #fdecef; color: var(--danger); }
.novo-usuario { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.novo-usuario h3 { margin: 0; font-size: 16px; font-weight: 600; }
.novo-usuario .campos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
@media (max-width: 520px) { .novo-usuario .campos { grid-template-columns: 1fr; } }

/* botões de ícone dentro das janelas não herdam o botão verde */
.card .icon-btn { background: none; color: #54656f; padding: 8px; border-radius: 50%; font-weight: normal; }
.card .icon-btn:hover { background: rgba(0,0,0,.06); }
