:root {
  --bg: #FAF8F2; /* marfim */
  --surface: #ffffff;
  --bar: #175C63; /* petróleo */
  --bar-ink: #ffffff;
  --ink: #1f2522;
  --muted: #6b726e;
  --mine: #dcefd9;
  --theirs: #ffffff;
  --accent: #2f8f6a;
  --accent-ink: #ffffff;
  --danger: #c4452f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --line: #e2dcd2;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #121614;
    --surface: #1c2220;
    --bar: #1d3a32;
    --ink: #eef2ef;
    --muted: #9aa49f;
    --mine: #1f4a3b;
    --theirs: #232b28;
    --line: #2c3532;
    --warn-bg: #3a2f12;
    --warn-ink: #f5d78a;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #121614; --surface: #1c2220; --bar: #1d3a32; --ink: #eef2ef; --muted: #9aa49f;
  --mine: #1f4a3b; --theirs: #232b28; --line: #2c3532; --warn-bg: #3a2f12; --warn-ink: #f5d78a; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Chat ---------- */
.chat-page { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bar); color: var(--bar-ink);
}
.avatar { width: 52px; height: 52px; border-radius: 50%; background: #fff3; flex: none; object-fit: cover; }
.who { flex: 1; min-width: 0; }
.nome { font-weight: 700; font-size: 20px; }
.status { font-size: 14px; opacity: 0.85; }
.icon-btn { background: #fff2; border: 0; border-radius: 12px; padding: 8px 12px; color: var(--bar-ink); font-weight: 700; }
.icon-btn[aria-pressed='false'] { opacity: 0.5; }

.banner { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 16px; font-size: 14px; text-align: center; }

.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.day { align-self: center; font-size: 13px; color: var(--muted); background: var(--surface); padding: 4px 12px; border-radius: 10px; box-shadow: var(--shadow); }

.row { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.row.mine { align-self: flex-end; flex-direction: row-reverse; }
.row .mini { width: 34px; height: 34px; border-radius: 50%; flex: none; }
.bubble {
  background: var(--theirs); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
  min-width: 0; display: flex; flex-direction: column; gap: 6px;
}
.row.mine .bubble { background: var(--mine); }
.bubble .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .time { font-size: 12px; color: var(--muted); align-self: flex-end; }
.hide-text .bubble .text.from-audio { display: none; }
.bubble img.photo { display: block; width: min(260px, 62vw); border-radius: 12px; }

.audio { display: flex; align-items: center; gap: 10px; min-width: min(240px, 58vw); }
.play {
  width: 52px; height: 52px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.play svg { width: 26px; height: 26px; fill: currentColor; }
.track { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.track > div { height: 100%; width: 0; background: var(--accent); }
.dur { font-size: 13px; color: var(--muted); min-width: 34px; text-align: right; }
.audio.unplayed .play { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }

.contact-btn {
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 14px; padding: 12px 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px;
}
.contact-btn svg { width: 22px; height: 22px; fill: currentColor; }

.typing { align-self: flex-start; color: var(--muted); font-size: 15px; display: flex; gap: 8px; align-items: center; }
.typing .dots span { display: inline-block; width: 7px; height: 7px; margin: 0 1px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.text-form { flex: 1; min-width: 0; }
.text-form input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 24px; padding: 12px 16px; font-size: 16px;
}
.mic {
  width: 76px; height: 76px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 3px 10px rgb(0 0 0 / 0.18); touch-action: none; user-select: none; -webkit-user-select: none;
}
.mic svg { width: 38px; height: 38px; fill: currentColor; }
.mic.recording { background: var(--danger); transform: scale(1.08); }

.rec-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); display: grid; place-items: center; z-index: 10; padding: 16px; }
.rec-card { background: var(--surface); border-radius: 24px; padding: 28px 24px; width: min(340px, 100%); text-align: center; display: grid; gap: 10px; justify-items: center; }
.rec-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.6; } }
.rec-to { font-weight: 700; font-size: 20px; }
.rec-time { font-size: 34px; font-variant-numeric: tabular-nums; }
.rec-hint { color: var(--muted); }
.rec-actions { display: flex; gap: 28px; margin-top: 8px; }
.round { width: 76px; height: 76px; border-radius: 50%; border: 0; font-size: 32px; color: #fff; }
.round.cancel { background: #8a8f8c; }
.round.send { background: var(--accent); }

/* ---------- Lista de amigos ---------- */
.view { display: flex; flex-direction: column; height: 100dvh; min-height: 0; }
.contacts { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.contact {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface);
}
.contact:active { background: var(--mine); }
.avatar.big { width: 68px; height: 68px; }
.contact-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.contact-top, .contact-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.contact-name { font-weight: 700; font-size: 20px; }
.contact-time { font-size: 13px; color: var(--muted); flex: none; }
.contact-preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact.unread .contact-time { color: var(--accent); font-weight: 700; }
.badge { background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 15px; min-width: 28px; height: 28px; border-radius: 14px; display: grid; place-items: center; padding: 0 8px; flex: none; }
.back { background: none; border: 0; color: var(--bar-ink); width: 40px; height: 52px; display: grid; place-items: center; margin-left: -8px; flex: none; }
.back svg { width: 30px; height: 30px; fill: currentColor; }

/* Encontrar amigos */
#lista { position: relative; }
.fab {
  position: absolute; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 40px;
  padding: 16px 22px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 18px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.22);
}
.fab-emoji { font-size: 28px; line-height: 1; }
.cat-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 16px; align-content: start; }
.cat { border: 0; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); padding: 18px 8px; display: grid; justify-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.cat .emoji { font-size: 52px; line-height: 1; }
.cat:active { background: var(--mine); }
.cand-list { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 12px; align-content: start; }
.cand { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 16px; display: grid; gap: 12px; }
.cand-head { display: flex; align-items: center; gap: 14px; }
.cand-head .avatar { width: 84px; height: 84px; }
.cand-name { font-weight: 700; font-size: 22px; }
.cand-desc { color: var(--muted); font-size: 16px; }
.cand-actions { display: flex; gap: 10px; }
.cand-actions button { flex: 1; justify-content: center; }
.btn-ouvir { display: flex; align-items: center; gap: 8px; border: 2px solid var(--accent); border-radius: 14px; padding: 12px 14px; background: none; color: var(--accent); font-weight: 700; font-size: 17px; }
.btn-ouvir svg { width: 22px; height: 22px; fill: currentColor; }
.empty-note { text-align: center; padding: 32px 16px; color: var(--muted); font-size: 18px; display: grid; gap: 10px; }
.empty-note .emoji { font-size: 56px; }

/* Cartão de contato (amigo apresentado) */
.vcard { display: grid; gap: 10px; min-width: min(240px, 60vw); }
.vcard-head { display: flex; align-items: center; gap: 10px; }
.vcard-head .avatar { width: 56px; height: 56px; }
.vcard-name { font-weight: 700; font-size: 18px; }
.vcard-desc { font-size: 13px; color: var(--muted); }

/* ---------- Painel do cuidador ---------- */
.panel-page { min-height: 100dvh; }
.panel-page header { background: var(--bar); color: var(--bar-ink); padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.panel-page header h1 { font-size: 20px; margin: 0; flex: 1; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.tabs button { border: 0; background: none; padding: 10px 14px; border-radius: 10px; white-space: nowrap; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected='true'] { background: var(--mine); color: var(--ink); }
.tabs .count { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.wrap { max-width: 860px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.card { background: var(--surface); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; min-width: 0; }
.card h2 { font-size: 17px; margin: 0; }
.card p { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.sev { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--line); }
.sev.media { background: #ffe6a8; color: #5c4200; }
.sev.alta { background: #ffc9b8; color: #6d1f0e; }
.sev.emergencia { background: var(--danger); color: #fff; }
.alert.seen { opacity: 0.55; }
label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
input, textarea, select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 700; justify-self: start; }
.btn.ghost { background: var(--line); color: var(--ink); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.trusted-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.mem { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 8px 0; }
.mem:last-child { border-bottom: 0; }
.tag { font-size: 12px; color: var(--muted); }
.lab-msg { border-left: 3px solid var(--line); padding: 4px 10px; display: grid; gap: 4px; }
.lab-msg.person { border-color: var(--accent); }
.lab-msg pre { margin: 0; font-size: 12px; white-space: pre-wrap; color: var(--muted); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos figure { margin: 0; font-size: 12px; color: var(--muted); }
.photos img, .photos .ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--line); display: grid; place-items: center; }
.friend-head { display: flex; align-items: center; gap: 12px; }
.friend-head .avatar { width: 52px; height: 52px; }
.pin-gate { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.pin-gate form { width: min(320px, 100%); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; }

/* ---------- Conta, conexão do celular e instalação ---------- */
.small { font-size: 13px; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }
.btn.big { padding: 16px 22px; font-size: 18px; border-radius: 14px; justify-self: stretch; }
.btn.whatsapp { background: #25d366; color: #0b2e17; }
.danger-text { color: var(--danger) !important; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head-actions { display: flex; gap: 8px; }
.panel-page header .btn.ghost { background: rgb(255 255 255 / 0.16); color: var(--bar-ink); }
.auth-card { width: min(380px, 100%); }
.auth-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.auth-err { color: var(--danger); font-size: 14px; margin: 0; }
.pin-gate .auth-card { width: min(380px, 100%); }
.invite-box { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 10px; overflow-wrap: anywhere; font-size: 13px; }
.code-input { font: 700 22px/1 ui-monospace, monospace; letter-spacing: 4px; width: 9.5em; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.device-row:first-of-type { border-top: 0; }

.setup-page, .setup-view { min-height: 100dvh; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); background: var(--bar); }
.setup-card { background: var(--surface); border-radius: 22px; padding: 24px 20px; width: min(420px, 100%); display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.setup-card h1 { font-size: 22px; margin: 0; }
.setup-card p { margin: 0; }
.setup-card section { display: grid; gap: 12px; }
.setup-tag { justify-self: center; background: var(--warn-bg); color: var(--warn-ink); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; }
.setup-ico { font-size: 54px; line-height: 1; }
.setup-sheet { text-align: left; width: min(400px, 100%); justify-items: stretch; }
.setup-sheet h2 { margin: 0; font-size: 20px; }
.setup-sheet .btn { justify-self: stretch; padding: 14px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.share-ico { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1.5px solid currentColor; border-radius: 6px; font-size: 13px; }
.qr-box { justify-self: center; width: min(260px, 72vw); aspect-ratio: 1; background: #fff; border-radius: 14px; padding: 10px; border: 1px solid var(--line); }
.qr-box svg { width: 100%; height: 100%; display: block; }
.code-big { font: 800 34px/1 ui-monospace, monospace; letter-spacing: 6px; color: var(--ink); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tela cheia / app instalado: respeita o recorte da câmera (notch) */
.chat-page .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
.chat-page .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.setup-sheet .setup-ico { justify-self: center; }

/* ---------- Review de UX ---------- */
:root { --fs: 1; }
.msgs, .contacts, .cand-list { zoom: var(--fs); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; display: block; }
.icon-btn.font-size { display: flex; align-items: baseline; gap: 1px; line-height: 1; }
.icon-btn.font-size .a-small { font-size: 13px; }
.icon-btn.font-size .a-big { font-size: 20px; }
.icon-btn.font-size[data-step='1'], .icon-btn.font-size[data-step='2'] { background: #fff4; }
.topbar .icon-btn + .icon-btn { margin-left: 6px; }
.send-btn { background: var(--accent); }
.send-btn svg { width: 30px; height: 30px; }
.day-sep { align-self: center; margin: 6px 0; }
.day-sep span { background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px; box-shadow: var(--shadow); }
.cat-grid > .empty-note { grid-column: 1 / -1; }
.btn-big { justify-self: center; border: 0; border-radius: 16px; padding: 16px 22px; background: var(--accent); color: var(--accent-ink); font-size: 18px; font-weight: 700; display: inline-flex; gap: 10px; align-items: center; }

/* ---------- Cadastro ---------- */
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
label.check input { width: 20px; height: 20px; margin-top: 1px; flex: none; }
.plan-badge { font-size: 12px; font-weight: 700; background: rgb(255 255 255 / 0.18); padding: 3px 8px; border-radius: 999px; vertical-align: 3px; margin-left: 6px; }
.auth-card .setup-ico { text-align: center; }
.legal { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; line-height: 1.6; }
.legal h1 { color: var(--bar); }
.legal .draft { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.contact-main { grid-template-columns: minmax(0, 1fr); }
.contact-sub > .contact-preview { min-width: 0; flex: 1; }

.auth-input { font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); min-height: 48px; flex: 1; min-width: 160px; }

/* ---------- Identidade Alô ELO (Agência MKT, ALO-D007) ----------
   Texto grafite sobre marfim (12,45:1); ações em petróleo (7,20:1); coral só decorativo. */
:root {
  --ink: #243238; --muted: #4F5E63; --mine: #DCECE5; --theirs: #FFFFFF; --accent: #175C63; --accent-ink: #FFFFFF;
  --danger: #A8372B; --line: #E3E0D6; --coral: #E88C76; --petroleo-escuro: #11474D;
  --brand-font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
body, button, input, select, textarea { font-family: var(--brand-font); }
.brand-title { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.panel-page header h1.brand-title { gap: 10px; }
.btn:hover, .mic:hover { filter: brightness(0.95); }
:focus-visible { outline: 3px solid #A84B36; outline-offset: 3px; border-radius: 6px; }
.setup-tag { background: #FBE9E3; color: #A84B36; }
/* Cabeçalho do painel no celular: título numa linha, selo e botões abaixo */
.panel-page header { flex-wrap: wrap; row-gap: 8px; }
.plan-badge { white-space: nowrap; }
@media (max-width: 520px) {
  .panel-page header h1 { flex: 1 1 100%; font-size: 19px; flex-wrap: wrap; }
  .panel-page header .head-actions { margin-left: auto; }
}

/* A permissão pode estar pendente: ainda não há gravação. */
.rec-overlay.preparing .rec-dot { animation: none; background: var(--muted); }
.rec-actions button:disabled { opacity: .4; cursor: wait; }
