/* Kontamex UI — Stripe-like visual language, Apple-like interaction principles.
   Tokens first; light/dark; no external assets. */
:root {
  --ink: #0a2540; --body: #425466; --muted: #5a6b82; --line: #e6ebf1; --bg: #f6f9fc; --card: #ffffff;
  --brand: #5146ff; --brand-ink: #3a30e6; --brand-text: #4338ca; --mint: #00785c; --mint-soft: rgba(0,166,126,.14);
  --amber: #b86e00; --amber-soft: rgba(255,176,32,.16); --danger: #d6343b; --danger-soft: rgba(214,52,59,.1);
  --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-bg: #efeae2; --wa-ink: #111b21;
  --shadow: 0 13px 27px -5px rgba(50,50,93,.18), 0 8px 16px -8px rgba(0,0,0,.2);
  --radius: 16px; --tap: 44px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f3f6fb; --body: #b6c2d3; --muted: #8796ab; --line: #26334a; --bg: #0b1220; --card: #111a2c;
    --brand-text: #a5a0ff; --mint: #2dd4a7; --mint-soft: rgba(45,212,167,.14); --amber: #f5b042; --amber-soft: rgba(245,176,66,.14);
    --danger: #ff6b72; --danger-soft: rgba(255,107,114,.14);
    --wa-in: #202c33; --wa-out: #005c4b; --wa-bg: #0b141a; --wa-ink: #e9edef;
    --shadow: 0 13px 27px -5px rgba(0,0,0,.55), 0 8px 16px -8px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--body); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 8px; }
a { color: var(--brand-text); text-decoration: none; } a:hover { text-decoration: underline; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 14px 20px; max-width: 1120px; margin: 0 auto; }
.wordmark { font-weight: 800; letter-spacing: -.045em; font-size: 24px; color: var(--ink); line-height: 1; }
.pill { margin-left: auto; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; color: var(--body); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; background: var(--card); }
.top a.link { font-size: 14px; font-weight: 600; }

/* ---------- login ---------- */
.login { max-width: 460px; margin: 6vh auto; padding: 0 20px; }
.hero-card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; position: relative; overflow: hidden; }
.hero-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: linear-gradient(90deg, #5146ff, #a259ff, #ff5c8a, #ffb020, #00c48c); }
.hero-card h1 { margin: 6px 0 8px; color: var(--ink); font-size: 28px; line-height: 1.15; letter-spacing: -.03em; }
.hero-card p { margin: 0 0 20px; }
.field { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); transition: border-color .15s, box-shadow .15s; }
.field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(81,70,255,.18); }
.field .prefix { padding-left: 14px; color: var(--ink); font-weight: 600; }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 18px; padding: 14px; }
.btn { appearance: none; border: 0; min-height: var(--tap); padding: 0 20px; border-radius: 12px; font-weight: 700; background: var(--ink); color: var(--card); transition: transform .08s, opacity .15s; }
.btn:active { transform: scale(.98); } .btn[disabled] { opacity: .5; cursor: default; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 600; }
.help { font-size: 13px; color: var(--muted); margin-top: 12px; }

/* ---------- stage ---------- */
.stage { max-width: 1120px; margin: 0 auto; padding: 8px 20px calc(88px + env(safe-area-inset-bottom)); display: grid; gap: 20px; }
@media (min-width: 900px) { .stage { grid-template-columns: 400px 1fr; align-items: start; padding-bottom: 40px; } }
.panel { display: none; }
.stage[data-view="chat"] .chat-card, .stage[data-view="biz"] .business { display: flex; }
.stage[data-view="biz"] .chat-card { display: none; } .stage[data-view="chat"] .business { display: none; }
@media (min-width: 900px) { .stage[data-view] .chat-card, .stage[data-view] .business { display: flex; } }

/* ---------- chat (phone) ---------- */
.chat-card { flex-direction: column; background: var(--card); border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; height: min(720px, calc(100dvh - 190px)); min-height: 480px; border: 1px solid var(--line); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--ink); color: var(--card); display: grid; place-items: center; font-weight: 800; letter-spacing: -.04em; }
.chat-head b { display: block; color: var(--ink); line-height: 1.2; } .chat-head small { color: var(--muted); font-size: 13px; }
.restart { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; min-height: 36px; padding: 0 6px; }
.log { flex: 1; overflow-y: auto; padding: 14px 12px; background: var(--wa-bg); display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; }
.msg { max-width: 84%; padding: 8px 12px; border-radius: 14px; color: var(--wa-ink); box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 15px; line-height: 1.4; word-wrap: break-word; animation: pop .22s ease-out both; }
.msg.in { align-self: flex-start; background: var(--wa-in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--wa-out); border-top-right-radius: 4px; }
.msg time { display: block; text-align: right; font-size: 12px; opacity: .7; margin-top: 2px; }
.msg strong { font-weight: 700; } .msg a { word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; max-width: 92%; animation: pop .22s ease-out both; }
.chip { min-height: var(--tap); padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--brand-text); background: var(--card); color: var(--brand-text); font-weight: 600; }
.chip:hover { background: rgba(81,70,255,.08); } .chip[disabled] { opacity: .45; cursor: default; }
.typing { align-self: flex-start; background: var(--wa-in); border-radius: 14px; padding: 12px 14px; display: flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.suggest { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px 0; background: var(--card); scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
.suggest button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--body); font-size: 14px; }
.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--card); }
.composer input { flex: 1; min-width: 0; min-height: var(--tap); border: 1.5px solid var(--line); border-radius: 999px; padding: 0 16px; font: inherit; font-size: 16px; background: var(--bg); color: var(--ink); outline: 0; }
.composer input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(81,70,255,.18); }
.send { width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 18px; display: grid; place-items: center; }
.send[disabled] { opacity: .4; cursor: not-allowed; }
.amount-big { font-size: 48px; font-weight: 800; letter-spacing: -.04em; color: var(--ink); font-variant-numeric: tabular-nums; margin: 2px 0 4px; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand-text); text-decoration: underline; font: inherit; cursor: pointer; }
.chip:hover, .suggest button:hover, .btn:hover { filter: brightness(1.06); }
@media (max-width: 520px) { .pill { display: none; } .chat-card { height: calc(100dvh - 150px); } }

/* ---------- business dashboard ---------- */
.business { flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card h2 { margin: 0 0 12px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.free { position: relative; overflow: hidden; }
.free::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, #5146ff, #a259ff, #ff5c8a, #ffb020, #00c48c); }
.free .label { color: var(--muted); font-weight: 600; }
.free .amount { font-size: clamp(38px, 8vw, 56px); font-weight: 800; letter-spacing: -.04em; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.05; margin: 4px 0 6px; }
.free.negative .amount { color: var(--danger); } .free.positive .amount { color: var(--mint); }
.note { display: inline-block; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--mint-soft); color: var(--mint); font-weight: 600; }
.free.negative .note { background: var(--danger-soft); color: var(--danger); }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.trio > div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.trio span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.trio b { display: block; font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.list { list-style: none; margin: 0; padding: 0; } .list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; } .list .amt { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); white-space: nowrap; }
.list .in { color: var(--mint); } .list .out { color: var(--ink); } .list small { color: var(--muted); display: block; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

/* ---------- tab bar (mobile) ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { flex: 1; min-height: 56px; border: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: 12px; display: grid; place-items: center; gap: 2px; }
.tabs button[aria-selected="true"] { color: var(--brand-text); } .tabs span { font-size: 20px; }
@media (min-width: 900px) { .tabs { display: none; } }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); z-index: 10; max-width: 90vw; }

/* ---------- panel ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric b { display: block; font-size: 30px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.metric span { color: var(--muted); font-size: 13px; font-weight: 600; }

@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* focus + funnel */
.btn:focus-visible, .chip:focus-visible, .send:focus-visible, .restart:focus-visible, .suggest button:focus-visible, .linklike:focus-visible { outline: 3px solid var(--brand-text); outline-offset: 2px; }
.btn, .chip, .send { transition: background-color .15s, box-shadow .15s, transform .08s, opacity .15s, filter .15s; }
.btn[disabled] { cursor: not-allowed; }
.funnel { display: grid; gap: 12px; }
.funnel .step { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 12px; font-size: 14px; }
.funnel .bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.funnel .bar i { display: block; height: 100%; width: var(--w, 0%); background: var(--brand); border-radius: 999px; transition: width .4s ease; }
.funnel .n { text-align: right; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.foot { max-width: 1120px; margin: 0 auto; padding: 0 20px 24px; font-size: 13px; color: var(--muted); }

/* round 3: touch targets, funnel semantics, success state */
.suggest button, .restart, .top a.link, .foot a { min-height: var(--tap); display: inline-flex; align-items: center; padding-inline: 12px; }
.linklike { min-height: 32px; padding: 6px 4px; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--brand-text); outline-offset: 2px; }
.funnel .bar.paid i { background: var(--mint); }
.funnel .bar.expired i { background: var(--amber); }
.funnel .pct { color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 12px; }
.check { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--mint-soft); color: var(--mint); font-size: 26px; margin-bottom: 8px; }
.testnote { font-size: 13px; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin: 0 0 12px; }

/* round 4: visible tracks, busy state, targets, readable minimums */
.funnel .bar { background: color-mix(in srgb, var(--muted) 35%, transparent); height: 12px; }
.funnel .bar.paid i::after { content: ""; }
.funnel .pct { font-size: 13px; font-variant-numeric: tabular-nums; }
.linklike { min-height: 44px; min-width: 44px; padding: 10px 6px; }
.wordmark { display: inline-flex; align-items: center; min-height: 44px; }
.help, .note, .chat-head small, .pill { font-size: 14px; }
.card h2 { font-size: 13px; letter-spacing: .06em; }
#pay-btn[aria-busy="true"] { opacity: .7; cursor: progress; position: relative; }
#pay-btn[aria-busy="true"]::after { content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 10px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#error { font-size: 14px; font-weight: 600; }

/* round 6: track contrast >= 3:1, CTA link in chat, busy label */
:root { --track: #7f8ea6; }
@media (prefers-color-scheme: dark) { :root { --track: #5b6b86; } }
.funnel .bar { background: var(--track); }
.funnel .bar i { box-shadow: 0 0 0 1px var(--card); }
.cta { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 18px; margin: 8px 0 4px;
  border-radius: 12px; background: var(--brand); color: #fff !important; font-weight: 700; text-decoration: none !important; }
.cta:hover { filter: brightness(1.08); }

/* round 7 UI: debts stand out, readable timestamps, separated funnel numbers */
.trio > div:nth-child(3) { border-left: 3px solid var(--amber); }
.trio > div:nth-child(3) b { color: var(--amber); }
.msg time { font-size: 13px; opacity: .8; }
.funnel .pct { display: inline-block; margin-left: 8px; }
.msg { max-width: min(84%, 36ch); }
.msg strong { font-weight: 800; }

/* round 8 (measured): type scale 12/14/16/20/28/56, readable disabled chips, 44px summary, inherited form fonts */
button, input, select, textarea { font: inherit; }
.msg { font-size: 16px; }
.chip[disabled] { opacity: .72; }
.list small, .trio span { font-size: 13px; }
.free .label { color: var(--body); font-size: 14px; }
.testcards summary, details > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.testcards button, .linklike { min-height: 44px; }
.top, .log, .composer { padding-block: 16px; }

/* round 10 (measured): finish the 12/14/16/20/28/56 scale and the 4/8 grid, focus on every control, owed tile */
.restart, .msg time, .list small, .trio span, .card h2, .funnel .pct, .testnote, .help.small { font-size: 14px; }
.send { font-size: 20px; padding: 8px; }
.wordmark { font-size: 28px; }
.metric b { font-size: 28px; }
.amount-big { font-size: 56px; }
.pill { padding: 8px 12px; }
.note { padding: 8px 12px; }
.chat-head, .log, .composer { padding-inline: 16px; }
.trio { margin-bottom: 4px; }
.card + .card, .business > .card { margin-top: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible, [data-card]:focus-visible {
  outline: 2px solid var(--brand-text); outline-offset: 2px; }
.trio > div:nth-child(3) { background: color-mix(in srgb, var(--amber) 12%, var(--card)); border-color: var(--amber); }
.funnel .bar i { background: var(--brand-text); }
.funnel .bar.paid i { background: var(--mint); }
.funnel .bar.expired i { background: var(--amber); }

/* round 11 (measured): funnel track, test-card focus, footer scale, owed tile cue, 8px grid */
:root { --track: #d5dce8; }
@media (prefers-color-scheme: dark) { :root { --track: #243247; } }
.funnel .bar { background: var(--track); }
.funnel .bar i { box-shadow: none; }
.linklike:focus-visible, [data-card]:focus-visible { outline: 3px solid var(--brand-text); outline-offset: 2px; }
.foot, .foot a { font-size: 12px; }
.trio > div:nth-child(3) { border-width: 2px; border-left-width: 4px; }
.trio > div:nth-child(3) b { font-weight: 800; }
.trio { gap: 16px; }
.card { padding: 24px; }
.list li { padding-block: 8px; }
.msg { padding: 8px 16px; }
