:root {
  /* Paleta verde inspirada no WhatsApp, com tons próprios (não idênticos) */
  --green-deep: #0a7d6b;     /* barra superior (WhatsApp usa #075E54) */
  --green: #14b88a;          /* botão flutuante/ação (WhatsApp usa #25D366) */
  --green-ink: #075249;
  --sent: #e4f7d2;           /* balão enviado (WhatsApp usa #DCF8C6) */
  --chat-bg: #e8e2d8;        /* fundo do chat (WhatsApp usa #ECE5DD) */
  --surface: #ffffff;
  --ink: #10231f;
  --muted: #667781;
  --line: #e9edef;
  --danger: #c0392b;
  --tick-read: #34b7f1;      /* tique azul de "lido" */
  --shadow: 0 1px 1px rgba(11,20,26,.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--chat-bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--green-deep), #0c5a4e);
}
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 12px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; color: var(--green-deep); }
.login-sub { color: var(--muted); margin: 8px 0 22px; font-size: 14px; }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
form input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fafafa; color: var(--ink); }
form input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: transparent; }
#login-btn, #client-save { width: 100%; padding: 13px; border: 0; border-radius: 24px; background: var(--green-deep); color: #fff; font-weight: 600; }
#login-btn:hover { background: var(--green-ink); }
.error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }

/* ---------- App ---------- */
.app { display: grid; grid-template-columns: 360px 1fr; height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; background: var(--green-deep); color: #fff; }
.me { display: flex; flex-direction: column; line-height: 1.25; }
.me-name { font-weight: 600; }
.me-role { font-size: 12px; opacity: .8; }
.ghost { background: transparent; border: 1px solid rgba(255,255,255,.35); color: inherit; border-radius: 18px; padding: 7px 12px; font-size: 13px; }
.chat-head .ghost { border-color: var(--green-deep); color: var(--green-deep); }
.new-client { margin: 10px 12px; padding: 11px; border: 0; background: var(--green); color: #fff; border-radius: 24px; font-weight: 600; box-shadow: var(--shadow); }
.convo-list { overflow-y: auto; flex: 1; min-height: 0; }
.convo { display: flex; gap: 13px; align-items: center; padding: 12px 16px; border-bottom: 1px solid #f1f3f5; cursor: pointer; background: #fff; }
.convo:hover { background: #f5f6f6; }
.convo.active { background: #f0f2f2; }
.avatar { width: 49px; height: 49px; border-radius: 50%; flex: none; display: grid; place-items: center; background: #cfd8d6; color: #fff; font-weight: 700; font-size: 18px; }
.convo-main { min-width: 0; flex: 1; }
.convo-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.convo-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-time { font-size: 12px; color: var(--muted); flex: none; }
.convo-last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--green); color: #fff; border-radius: 999px; font-size: 12px; min-width: 21px; height: 21px; padding: 0 6px; display: grid; place-items: center; flex: none; font-weight: 600; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.5) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(11,20,26,.04) 0 1px, transparent 1px);
  background-size: 26px 26px, 32px 32px;
}
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--green-deep); color: #fff; }
.chat-head .contact-name { color: #fff; }
.chat-head .ghost { border-color: rgba(255,255,255,.5); color: #fff; }
.back { display: none; background: transparent; border: 0; font-size: 28px; line-height: 1; color: #fff; padding: 0 4px; }
.chat-contact { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.contact-name { font-weight: 600; font-size: 16px; }
.contact-status { font-size: 12px; color: rgba(255,255,255,.85); min-height: 14px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 8% 20px; display: flex; flex-direction: column; gap: 4px; }
.empty { margin: auto; color: var(--muted); font-size: 14px; background: rgba(255,255,255,.6); padding: 8px 16px; border-radius: 16px; }
.bubble { max-width: min(70%, 520px); padding: 6px 9px 8px; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); position: relative; font-size: 14.5px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--sent); }
/* rabicho dos balões */
.bubble::after { content: ""; position: absolute; top: 0; width: 10px; height: 13px; }
.bubble:not(.me)::after { left: -8px; background: radial-gradient(circle at top left, transparent 10px, var(--surface) 11px) top left/12px 13px no-repeat; clip-path: polygon(100% 0, 0 0, 100% 100%); background: var(--surface); border-radius: 0 0 12px 0; }
.bubble.me::after { right: -8px; background: var(--sent); clip-path: polygon(0 0, 100% 0, 0 100%); border-radius: 0 0 0 12px; }
.bubble .meta { display: inline-block; float: right; font-size: 11px; color: var(--muted); margin: 6px 0 -2px 10px; }
.tick { color: var(--muted); font-weight: 700; margin-left: 2px; }
.tick.read { color: var(--tick-read); }
.composer { display: flex; gap: 8px; padding: 8px 12px; background: var(--chat-bg); align-items: center; }
.composer input { flex: 1; padding: 11px 16px; border: 0; border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.composer input:focus { outline: 2px solid var(--green); }
.send { width: 48px; height: 48px; border-radius: 50%; flex: none; padding: 0; font-size: 18px; background: var(--green); color: #fff; border: 0; box-shadow: var(--shadow); display: grid; place-items: center; }
.send:hover { background: #0fa377; }

/* ---------- Modal ---------- */
dialog { border: 0; border-radius: 14px; padding: 24px; max-width: 380px; width: calc(100% - 32px); box-shadow: 0 12px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(11,20,26,.5); }
dialog h2 { margin: 0 0 16px; font-size: 18px; color: var(--green-deep); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-actions .ghost { border-color: var(--line); color: var(--muted); }
#client-save { width: auto; padding: 10px 20px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.viewing-chat .sidebar { display: none; }
  .app:not(.viewing-chat) .chat { display: none; }
  .back { display: block; }
  .bubble { max-width: 82%; }
  .messages { padding: 12px 12px 18px; }
}
@media (prefers-reduced-motion: no-preference) {
  .convo, #login-btn, .send { transition: background .15s ease; }
}
