:root {
  --green: #008069;
  --bg: #efeae2;
  --in: #fff;
  --out: #d9fdd3;
  --text: #111b21;
  --muted: #5b6c75;
  --tick: #53bdeb;
}
* { box-sizing: border-box; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 "Segoe UI", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  color: var(--text);
  background: #d1d7db;
  overflow: hidden;
}
button, a { touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}
@media (min-width: 520px) {
  body { background: linear-gradient(var(--green) 0 130px, #d1d7db 130px); }
  .app { height: calc(100dvh - 40px); margin-top: 20px; box-shadow: 0 6px 24px rgb(11 20 26 / .2); border-radius: 6px; overflow: hidden; }
}

/* Header */
.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--green);
  color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  min-height: 56px;
  flex-shrink: 0;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; overflow: hidden; position: relative;
  background: #dfe5e7; color: var(--green); display: grid; place-items: center; font-weight: 600; font-size: 18px;
}
.avatar::before { content: "J"; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.acts { display: flex; gap: 14px; flex-shrink: 0; pointer-events: none; }
.acts svg { width: 22px; height: 22px; }
.who { flex: 1; min-width: 0; margin-left: 4px; }
.who h1 { font-size: 17px; font-weight: 500; margin: 0; line-height: 1.2; }
.who p { font-size: 13px; margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat pane with doodle wallpaper */
.chat {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0 12px;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' fill='none' stroke='%23000' stroke-opacity='.045' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='24' cy='26' r='9'/%3E%3Cpath d='M20 24h.01M28 24h.01M20 30q4 3 8 0'/%3E%3Cpath d='M70 14l6 12 13 2-9 9 2 13-12-6-12 6 2-13-9-9 13-2z'/%3E%3Cpath d='M120 20c8-8 22 4 10 14l-10 9-10-9c-12-10 2-22 10-14z'/%3E%3Cpath d='M14 90q10-20 20 0t20 0'/%3E%3Crect x='80' y='76' width='22' height='16' rx='4'/%3E%3Cpath d='M86 76v-4h10v4'/%3E%3Ccircle cx='134' cy='92' r='10'/%3E%3Cpath d='M134 86v6l4 3'/%3E%3Cpath d='M30 132l10-10 10 10-10 10z'/%3E%3Cpath d='M86 130h24M98 118v24'/%3E%3Cpath d='M128 140c0-10 16-10 16 0'/%3E%3C/svg%3E");
  background-size: 160px;
}
.chips { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 4px 16px 10px; }
.chip {
  background: #fff; border-radius: 7.5px; padding: 5px 12px; font-size: 12.5px; color: #54656f;
  box-shadow: 0 1px .5px rgb(11 20 26 / .13); text-align: center;
}

/* Bubbles */
.row { display: flex; padding: 0 16px; margin-top: 2px; }
.row.first { margin-top: 10px; }
.row.out { justify-content: flex-end; }
.bubble {
  position: relative;
  max-width: 82%;
  background: var(--in);
  border-radius: 7.5px;
  padding: 6px 7px 8px 9px;
  box-shadow: 0 1px .5px rgb(11 20 26 / .13);
  overflow-wrap: anywhere;
  animation: pop .18s ease-out;
}
.out .bubble { background: var(--out); }
.first.in .bubble { border-top-left-radius: 0; }
.first.out .bubble { border-top-right-radius: 0; }
.first .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: inherit;
}
.first.in .bubble::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.first.out .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.text strong { font-weight: 600; }
/* Timestamp floats bottom-right; the invisible spacer reserves room on the last line. */
.text::after { content: ""; display: inline-block; width: 52px; }
.out .text::after { width: 70px; }
.meta {
  position: absolute; right: 7px; bottom: 3px;
  font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 3px; white-space: nowrap;
}
.ticks { width: 16px; height: 11px; color: var(--tick); }

/* Typing */
.typing .bubble { display: flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #8696a0; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }

/* Cards */
.doc, .pay { width: 260px; max-width: 100%; margin-bottom: 14px; }
.doc-row { display: flex; gap: 10px; align-items: center; background: #f5f6f6; border-radius: 6px; padding: 10px; }
.pdf { width: 30px; height: 38px; flex-shrink: 0; }
.doc-name { font-size: 14px; color: var(--text); word-break: break-all; }
.doc-meta, .pay-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pay { padding: 4px 2px 0; }
.pay-label { font-size: 13px; color: var(--muted); }
.pay-price { font-size: 26px; font-weight: 600; color: var(--text); margin-top: 2px; }
.card-actions { display: flex; border-top: 1px solid #e9edef; margin: 10px -7px -4px -9px; }
.card-actions > * {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 6px;
  font: inherit; font-weight: 500; font-size: 14px; line-height: 1.2; color: #027eb5; text-decoration: none; text-align: center;
  background: none; border: 0; cursor: pointer;
}
.card-actions > * + * { border-left: 1px solid #e9edef; }
.card-actions > :active { background: rgb(0 0 0 / .05); }
.card-actions button:disabled { color: var(--muted); cursor: default; }
/* Primary CTA: solid button, the strongest element on screen once the price is shown. */
.pay .card-actions { border-top: 0; margin: 12px 0 0; }
.pay .card-actions a { min-height: 48px; border-radius: 24px; background: var(--green); color: #fff; font-weight: 600; font-size: 16px; }
.pay .card-actions a:active { background: #006e5a; }
.pay .card-actions button:disabled { border-top: 1px solid #e9edef; }
.pic { display: block; max-width: 100%; border-radius: 6px; margin-bottom: 14px; }

/* Footer: quick replies + fake input */
.foot { flex-shrink: 0; padding: 0 8px calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--bg); }
#replies { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }
#replies:not(:empty) { padding: 8px 0 4px; }
.qr {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px;
  background: #fff; color: var(--green); border: 0; border-radius: 22px;
  font: inherit; font-weight: 500; font-size: 15px; line-height: 1.25; text-align: center; text-decoration: none; cursor: pointer;
  box-shadow: 0 1px .5px rgb(11 20 26 / .13);
  transition: transform .1s ease-out, background-color .1s;
  animation: pop .2s ease-out both;
}
.qr:active { transform: scale(.97); background: #f0f2f5; }
.qr:focus-visible, .card-actions > :focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  .qr:hover { background: #f5f6f6; }
  .card-actions > :hover { background: rgb(0 0 0 / .03); }
  .pay .card-actions a:hover { background: #006e5a; }
}
.inputbar { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.fake-input {
  flex: 1; background: #fff; border-radius: 24px; min-height: 46px; display: flex; align-items: center;
  padding: 0 18px; color: var(--muted); font-size: 15px; box-shadow: 0 1px .5px rgb(11 20 26 / .13);
}
.mic { width: 46px; height: 46px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.mic svg { width: 24px; height: 24px; }

@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes blink { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .bubble, .qr { animation: none; }
  .typing i { animation: none; opacity: .6; }
  .qr { transition: none; }
}
