/* ─────────────────────────────────────────────────────────────────────────────
   LanaBot · Chat público de cada negócio
   Cor do negócio injetada em :root (--marca, --marca-forte, --marca-suave, ...)
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --cal: #f4f5f2;          /* fundo — calcário */
  --papel: #ffffff;
  --tinta: #1d2126;
  --tinta-2: #565d66;
  --tinta-3: #8a9098;
  --linha: #e3e5e0;
  --ok: #1f7a4d;
  --ok-suave: #e6f3ec;
  --aviso: #9a5b00;
  --r-grande: 22px;
  --r-medio: 14px;
  --r-pequeno: 10px;
  --sombra: 0 1px 2px rgba(29, 33, 38, .06), 0 8px 24px -12px rgba(29, 33, 38, .18);
  --f-titulo: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
  --f-texto: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --lateral: 360px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cal);
  color: var(--tinta);
  font: 400 16px/1.5 var(--f-texto);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--marca-forte); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--marca-forte); outline-offset: 2px; border-radius: 6px; }

/* ── Estrutura ─────────────────────────────────────────────────────────────── */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--lateral);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "topo topo" "conversa lateral";
}

/* ── Topo ──────────────────────────────────────────────────────────────────── */

.topo {
  grid-area: topo;
  display: flex; align-items: center; gap: 12px;
  padding: 12px clamp(16px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--papel);
  border-bottom: 1px solid var(--linha);
}
.monograma {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--marca);
  color: var(--sobre-marca);
  font: 800 21px/1 var(--f-titulo);
}
.monograma.pequeno { width: 36px; height: 36px; border-radius: 11px; font-size: 17px; }
.topo-info { flex: 1; min-width: 0; }
.topo-nome {
  margin: 0;
  font: 700 18px/1.2 var(--f-titulo);
  letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topo-estado { margin: 2px 0 0; font-size: 13px; color: var(--tinta-2); display: flex; align-items: center; gap: 6px; }
.topo-estado .ponto { width: 8px; height: 8px; border-radius: 50%; background: var(--tinta-3); flex: none; }
.topo-estado .extra::before { content: " · "; }
@media (max-width: 420px) { .topo-estado .extra { display: none; } }
.topo-estado[data-aberto="sim"] .ponto { background: #22a06b; box-shadow: 0 0 0 3px #22a06b22; }
.topo-acoes { display: flex; align-items: center; gap: 6px; }
.icone-btn {
  width: 42px; height: 42px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--linha); border-radius: 12px;
  background: var(--papel); color: var(--tinta-2);
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.icone-btn:hover { background: var(--marca-suave); color: var(--marca-forte); border-color: var(--marca-linha); }
.demo { font-size: 12px; font-weight: 600; color: #2f5bb7; background: #e8eefb; padding: 4px 9px; border-radius: 999px; }
.so-movel { display: none; }

/* ── Conversa ──────────────────────────────────────────────────────────────── */

.conversa {
  grid-area: conversa;
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
}
.mensagens {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 40px) 12px;
  display: flex; flex-direction: column; gap: 6px;
  scroll-behavior: smooth;
}
.mensagens > * { width: 100%; max-width: 680px; margin-inline: auto; }

/* Boas-vindas: apresentação + serviços clicáveis */
.boas-vindas { margin-bottom: 18px; }
.bv-titulo {
  margin: 0 0 6px;
  font: 800 clamp(28px, 5vw, 40px)/1.05 var(--f-titulo);
  letter-spacing: -.025em;
  text-wrap: balance;
}
.bv-texto { margin: 0 0 20px; color: var(--tinta-2); max-width: 52ch; }
.bv-servicos { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.servico {
  width: 100%;
  display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 14px;
  padding: 14px 16px;
  text-align: left;
  background: var(--papel);
  border: 1px solid var(--linha); border-radius: var(--r-medio);
  transition: border-color .15s, background .15s, transform .15s;
}
.servico:hover { border-color: var(--marca-linha); background: var(--marca-suave); }
.servico:active { transform: scale(.99); }
.servico-nome { font-weight: 600; min-width: 0; }
.servico-desc { display: block; font-weight: 400; font-size: 13px; color: var(--tinta-3); line-height: 1.35; margin-top: 2px; }
.servico.com-foto {
  grid-template-columns: 72px minmax(0, 1fr) auto; grid-template-areas: "foto nome preco" "foto meta preco";
  align-items: center; column-gap: 14px; row-gap: 2px; padding: 10px 14px 10px 10px;
}
.servico.com-foto .servico-foto { grid-area: foto; }
.servico.com-foto .servico-nome { grid-area: nome; align-self: end; }
.servico.com-foto .servico-meta { grid-area: meta; align-self: start; margin: 0; }
.servico.com-foto .servico-preco { grid-area: preco; }
.servico-foto { position: relative; display: block; width: 72px; height: 54px; border-radius: 10px; overflow: hidden; background: var(--marca-suave); }
.servico-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bv-promo { margin: 0 0 10px; padding: 10px 14px; border-radius: var(--r-medio); background: var(--marca-suave); color: var(--marca-forte); font-size: 14.5px; }
.monograma.com-logo { background: #fff; border: 1px solid var(--linha); overflow: hidden; }
.monograma.com-logo img { width: 100%; height: 100%; object-fit: contain; }
.servico-meta { font-size: 13px; color: var(--tinta-3); }
.servico-preco { font: 700 17px/1 var(--f-titulo); color: var(--marca-forte); min-width: 3.5ch; text-align: right; }

/* Mensagens */
.msg { display: flex; flex-direction: column; gap: 3px; }
.msg + .msg { margin-top: 6px; }
.msg.ia { align-items: flex-start; }
.msg.eu { align-items: flex-end; }
.msg.eu + .msg.eu, .msg.ia + .msg.ia { margin-top: 0; }
.bolha {
  max-width: min(84%, 560px);
  padding: 11px 15px;
  border-radius: 20px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.ia .bolha { background: var(--papel); border: 1px solid var(--linha); border-top-left-radius: 6px; }
.msg.eu .bolha { background: var(--marca-forte); color: #fff; border-top-right-radius: 6px; }
.msg.erro .bolha { background: #fff7ed; border-color: #f2d3a9; color: #7a3f00; }
.msg .hora { font-size: 11.5px; color: var(--tinta-3); padding: 0 6px; }
.msg.nova { animation: entrar .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes entrar { from { opacity: 0; transform: translateY(6px); } }

.escrever {
  width: fit-content;
  margin: 0 auto 8px;
  max-width: 680px; align-self: center;
  display: flex; gap: 5px;
  padding: 13px 16px;
  background: var(--papel); border: 1px solid var(--linha);
  border-radius: 20px; border-top-left-radius: 6px;
}
.conversa .escrever { margin-left: max(clamp(16px, 4vw, 40px), calc((100% - 680px) / 2)); align-self: flex-start; }
.escrever span { width: 7px; height: 7px; border-radius: 50%; background: var(--tinta-3); animation: saltar 1.2s infinite ease-in-out; }
.escrever span:nth-child(2) { animation-delay: .15s; }
.escrever span:nth-child(3) { animation-delay: .3s; }
@keyframes saltar { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; background: var(--marca-forte); } }

/* ── Rodapé: talão (móvel), sugestões, caixa ───────────────────────────────── */

.rodape-conversa {
  padding: 8px clamp(12px, 4vw, 40px) max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.rodape-conversa > * { width: 100%; max-width: 680px; margin-inline: auto; }

.sugestoes { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.sugestoes::-webkit-scrollbar { display: none; }
.sugestao {
  flex: none;
  padding: 8px 14px;
  border: 1px solid var(--linha); border-radius: 999px;
  background: var(--papel);
  font-size: 14px; font-weight: 500; color: var(--tinta);
  transition: background .15s, border-color .15s, color .15s;
}
.sugestao:hover { background: var(--marca-suave); border-color: var(--marca-linha); color: var(--marca-forte); }

.caixa {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 6px 6px 16px;
  background: var(--papel);
  border: 1.5px solid var(--linha); border-radius: 20px;
  box-shadow: var(--sombra);
  transition: border-color .15s;
}
.caixa:focus-within { border-color: var(--marca-forte); }
.caixa textarea {
  flex: 1; min-width: 0;
  border: 0; outline: 0; resize: none; background: transparent;
  padding: 10px 0; max-height: 140px; line-height: 1.45;
}
.caixa textarea::placeholder { color: var(--tinta-3); }
.caixa textarea:focus-visible { outline: none; }
.enviar {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 14px;
  background: var(--marca-forte); color: #fff;
  transition: opacity .15s, transform .15s;
}
.enviar:disabled { opacity: .35; cursor: not-allowed; }
.enviar:not(:disabled):active { transform: scale(.94); }

/* ── Lateral: talão + informações ──────────────────────────────────────────── */

.lateral {
  grid-area: lateral;
  overflow-y: auto;
  padding: 24px 22px 32px;
  background: var(--papel);
  border-left: 1px solid var(--linha);
  display: flex; flex-direction: column; gap: 22px;
}
.lateral > * { flex-shrink: 0; }

/* O talão — o elemento memorável: preenche-se ao vivo e recebe um carimbo */
.talao {
  position: relative;
  background: var(--papel);
  border: 1px solid var(--linha);
  border-radius: 18px;
  box-shadow: var(--sombra);
  overflow: hidden;
}
.talao-topo::before, .talao-topo::after {  /* picotado lateral, preso à linha tracejada */
  content: ""; position: absolute; bottom: -10px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--cal); border: 1px solid var(--linha);
}
.lateral .talao-topo::before, .lateral .talao-topo::after { background: var(--papel); }
.talao-topo::before { left: -10px; }
.talao-topo::after { right: -10px; }
.talao-topo {
  position: relative;
  padding: 18px 20px 16px;
  background: var(--marca-suave);
  border-bottom: 2px dashed var(--marca-linha);
}
.talao-topo h2 { margin: 0; font: 800 20px/1.15 var(--f-titulo); letter-spacing: -.015em; }
.talao-estado { margin: 4px 0 0; font-size: 13.5px; color: var(--tinta-2); }
.talao-campos { margin: 0; padding: 10px 20px 18px; }
.talao-campos > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dotted var(--linha);
}
.talao-campos > div:last-child { border-bottom: 0; }
.talao-campos dt { font-size: 13px; color: var(--tinta-3); flex: none; }
.talao-campos dd { margin: 0; text-align: right; font-weight: 600; color: var(--tinta-3); overflow-wrap: anywhere; white-space: pre-line; }
.talao-campos > div.preenchido dd { color: var(--tinta); }
.talao-campos > div.acabou dd { animation: realce 1.2s ease-out; }
@keyframes realce { from { background: var(--marca-suave); } to { background: transparent; } }

.talao-carimbo {
  position: absolute; right: 16px; top: 16px;
  padding: 4px 10px;
  border: 2.5px solid var(--ok); border-radius: 8px;
  color: var(--ok);
  font: 800 15px/1.1 var(--f-titulo); letter-spacing: .02em;
  transform: rotate(-8deg) scale(1.6);
  opacity: 0;
  pointer-events: none;
}
.talao[data-estado="confirmada"] .talao-topo { background: var(--ok-suave); border-bottom-color: #b9dcc8; padding-right: 128px; }
.talao[data-estado="confirmada"] .talao-carimbo {
  opacity: .92; transform: rotate(-8deg) scale(1);
  transition: transform .35s cubic-bezier(.2, 1.4, .4, 1), opacity .2s;
}
.talao-acoes { display: grid; gap: 8px; padding: 0 20px 20px; }
.talao-cal, .talao-mais { display: grid; gap: 8px; }
.talao-mais:empty { display: none; }
.talao-cal[hidden], .talao-no-cal[hidden], #lnkGerir[hidden] { display: none; }
.talao-no-cal { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--ok-suave, #e8f5ee);
  color: var(--ok, #1e7a4c); font-weight: 600; font-size: 14.5px; }

.btn-primario, .btn-secundario {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600; font-size: 15px;
  text-decoration: none;
  transition: filter .15s, background .15s;
}
.btn-primario { background: var(--marca-forte); color: #fff; border: 0; }
.btn-primario:hover { filter: brightness(1.08); }
.btn-secundario { background: var(--papel); color: var(--tinta); border: 1px solid var(--linha); }
.btn-secundario:hover { background: var(--cal); }

.info { display: flex; flex-direction: column; gap: 20px; }
.info-bloco h3 { margin: 0 0 8px; font: 700 15px/1.2 var(--f-titulo); }
.info-bloco p { margin: 0 0 6px; color: var(--tinta-2); font-size: 14.5px; }
.link { font-size: 14px; font-weight: 600; }
.horario { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.horario li { display: flex; justify-content: space-between; padding: 5px 0; color: var(--tinta-2); }
.horario li.hoje { color: var(--tinta); font-weight: 600; }
.horario li.hoje span:first-child::after { content: " · hoje"; font-weight: 400; color: var(--marca-forte); }
.lista-servicos { list-style: none; margin: 0; padding: 0; }
.linha-servico {
  width: 100%;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 0;
  background: none; border: 0; border-bottom: 1px solid var(--linha);
  text-align: left; font-size: 14.5px;
}
.linha-servico small { display: block; font-size: 12.5px; color: var(--tinta-3); }
.linha-servico strong { font: 700 15px/1 var(--f-titulo); color: var(--marca-forte); }
.linha-servico:hover span { color: var(--marca-forte); }
.info-legal { font-size: 12.5px; margin: 0; }
.info-legal a { color: var(--tinta-3); }
.lateral-fechar { display: none; }

/* ── Folhas, avisos e instalação ───────────────────────────────────────────── */

.folha {
  width: min(520px, calc(100% - 24px));
  border: 0; border-radius: var(--r-grande);
  padding: 26px 24px 22px;
  background: var(--papel); color: var(--tinta);
  box-shadow: 0 30px 80px -20px rgba(29, 33, 38, .45);
}
.folha::backdrop { background: rgba(29, 33, 38, .45); backdrop-filter: blur(3px); }
.folha h2 { margin: 0 0 10px; font: 800 24px/1.15 var(--f-titulo); letter-spacing: -.02em; }
.folha p { margin: 0 0 12px; color: var(--tinta-2); font-size: 15px; }
.folha-links { font-size: 14px; }
.folha-acoes { display: grid; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px; border-radius: 12px;
  background: var(--tinta); color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--sombra);
}
.toast.ok { background: var(--ok); }

.instalar {
  position: fixed; z-index: 40;
  left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 14px;
  background: var(--papel); border: 1px solid var(--linha); border-radius: 18px;
  box-shadow: 0 20px 50px -20px rgba(29, 33, 38, .35);
}
.instalar p { flex: 1; margin: 0; font-size: 14px; color: var(--tinta-2); }
.instalar .btn-primario { min-height: 40px; padding: 8px 14px; }

/* ── Móvel ─────────────────────────────────────────────────────────────────── */

.talao-tira {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--papel);
  border: 1px dashed var(--marca-linha); border-radius: 14px;
  text-align: left;
}
.tira-rotulo { flex: 1; font-weight: 600; font-size: 14px; }
.tira-passos { display: flex; gap: 4px; }
.tira-passos i { width: 18px; height: 5px; border-radius: 3px; background: var(--linha); }
.tira-passos i.on { background: var(--marca-forte); }
.talao-tira[data-estado="confirmada"] { border-style: solid; border-color: #b9dcc8; background: var(--ok-suave); }
.talao-tira[data-estado="confirmada"] .tira-passos i.on { background: var(--ok); }
.tira-ver { font-size: 13px; font-weight: 600; color: var(--marca-forte); }

@media (max-width: 979px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topo" "conversa"; }
  .so-movel { display: inline-grid; }
  .lateral {
    position: fixed; inset: auto 0 0 0; z-index: 60;
    max-height: 86dvh;
    border-left: 0; border-radius: 24px 24px 0 0;
    box-shadow: 0 -20px 60px -20px rgba(29, 33, 38, .4);
    padding-top: 52px;
    transform: translateY(105%);
    transition: transform .32s cubic-bezier(.2, .8, .2, 1);
    visibility: hidden;
  }
  .lateral.aberta { transform: translateY(0); visibility: visible; }
  .lateral-fechar { display: inline-grid; position: absolute; top: 10px; right: 12px; }
  .lateral-fechar { width: 40px; height: 40px; place-items: center; border: 0; background: var(--cal); border-radius: 12px; }
  .veu { position: fixed; inset: 0; z-index: 59; background: rgba(29, 33, 38, .38); }
}
@media (min-width: 980px) { .talao-tira { display: none !important; } }

@media (max-width: 420px) {
  .topo { gap: 10px; }
  .topo-acoes { gap: 4px; }
  .icone-btn { width: 38px; height: 38px; }
  .servico { grid-template-columns: 1fr auto; }
  .servico-meta { grid-column: 1; grid-row: 2; margin-top: -8px; }
  .servico-preco { grid-row: 1 / span 2; align-self: center; }
}

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

.sugestao-humano { text-decoration: none; color: var(--marca-forte); border-style: dashed; display: inline-flex; align-items: center; }

.link { display: inline-block; padding: 8px 0; }
.info-legal a { display: inline-block; padding: 8px 0; }

/* Telemóvel deitado: o espaço vertical é precioso */
@media (max-height: 480px) and (orientation: landscape) {
  .topo { padding-block: 6px; }
  .monograma { width: 34px; height: 34px; font-size: 17px; }
  .topo-estado .extra { display: none; }
  .mensagens { padding-top: 12px; }
  .bv-titulo { font-size: 24px; }
  .bv-texto { margin-bottom: 12px; }
  .sugestoes { display: none; }
  .rodape-conversa { gap: 6px; padding-bottom: 8px; }
  .caixa textarea { padding-block: 6px; }
  .lateral { max-height: 94dvh; }
}
/* Ecrãs muito largos: conversa e lateral mais generosas */
@media (min-width: 1600px) {
  :root { --lateral: 420px; }
  .mensagens > *, .rodape-conversa > * { max-width: 760px; }
}
