/* Kontamex web app. One layer, mobile first.
   Scales: space 4/8/12/16/24/32 · type 12/14/16/20/28/40 · radius 8/12/16/pill · touch target 48. */
:root {
  --zafiro-950: #061335; --zafiro-900: #112659; --zafiro-700: #22428D; --zafiro-600: #3057B1;
  --zafiro-300: #A7C1F6; --zafiro-100: #E4EDFE; --zafiro-50: #F3F7FF;
  --coral-500: #FF5A36; --coral-400: #FF8365; --coral-600: #DA4624;

  --bg: #F9FAFD; --surface: #FFFFFF; --sunken: #F1F3F8; --border: #E3E6ED; --border-strong: #7B808A;
  --ink: #061335; --text: #343840; --muted: #5E636D;
  --own: #112659; --on-own: #FFFFFF;
  --action: #FF5A36; --action-press: #E5502D; --on-action: #061335;
  --focus: #3057B1; --danger: #A41B3D; --danger-soft: #FFE7E8; --success: #03734A; --warning-soft: #FFEFD5;
  --warning-ink: #754B00;
  --ribbon: linear-gradient(115deg, #112659, #3057B1 30%, #A7C1F6 60%, #9E8CEB 82%, #E84363 94%, #FF5A36);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --t12: 12px; --t14: 14px; --t16: 16px; --t20: 20px; --t28: 28px; --t40: 40px;
  --r8: 8px; --r12: 12px; --r16: 16px; --pill: 999px;
  --tap: 48px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --shadow: 0 0 0 1px rgb(6 19 53 / .05), 0 8px 24px -8px rgb(17 38 89 / .16);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --page: 560px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1217; --surface: #181C23; --sunken: #20242B; --border: #343840; --border-strong: #7B808A;
    --ink: #F3F7FF; --text: #D0D4DC; --muted: #A6ABB4;
    --own: #22428D; --on-own: #FFFFFF;
    --ribbon: linear-gradient(115deg, #3057B1, #A7C1F6 35%, #9E8CEB 62%, #E84363 84%, #FF5A36);
    --focus: #A7C1F6; --danger: #FFCCD0; --danger-soft: #4A1220; --success: #BCEBD1; --warning-soft: #3B2A05;
    --warning-ink: #FFDDA1;
    --shadow: 0 0 0 1px rgb(255 255 255 / .06), 0 8px 24px -8px rgb(0 0 0 / .6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 400 var(--t16)/1.5 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.wordmark { font-weight: 700; font-size: var(--t20); line-height: 28px; letter-spacing: -.02em; color: var(--ink); }
.lead { color: var(--muted); }

/* ---------------------------------------------------------------- buttons and fields */
.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: var(--tap);
  padding: var(--s3) var(--s4); border: 0; border-radius: var(--r12); font-weight: 600; text-decoration: none;
  transition: transform 120ms var(--ease), background-color 120ms linear;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--action); color: var(--on-action); }
.btn.primary:active { background: var(--action-press); }
.btn.secondary { background: var(--sunken); color: var(--ink); }
.btn.link { background: none; color: var(--focus); }
.btn[aria-busy="true"] { pointer-events: none; background: var(--sunken); color: var(--muted); }
.ghost { min-width: var(--tap); min-height: var(--tap); border: 0; background: none; color: var(--focus);
         font-size: var(--t14); font-weight: 600; border-radius: var(--r8); }
.icon-btn { display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 0;
            background: none; color: var(--ink); border-radius: var(--pill); }
.icon-btn:active { background: var(--sunken); }

.field { display: grid; gap: var(--s2); }
.field-label { font-size: var(--t14); font-weight: 600; color: var(--ink); }
.field-box {
  display: flex; align-items: center; min-height: 56px; padding: 0 var(--s1) 0 var(--s4);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r12);
}
.field-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 2px var(--focus); }
.field-box.invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.field-box input { flex: 1; width: 0; min-width: 0; height: 54px; border: 0; background: none; outline: 0;
                   font-size: var(--t20); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.field-box input::placeholder, .send-row input::placeholder { color: var(--muted); opacity: 1; letter-spacing: 0; }
.prefix { margin-right: var(--s2); color: var(--muted); font-size: var(--t20); }
.hint, .legal { font-size: var(--t14); line-height: 20px; color: var(--muted); }
.legal { text-align: center; }
.legal a, .msg a { color: var(--focus); text-underline-offset: 2px; }
.error { padding: var(--s3) var(--s4); border-radius: var(--r12); background: var(--danger-soft);
         color: var(--danger); font-size: var(--t14); font-weight: 600; }

/* ---------------------------------------------------------------- sign in */
.auth { min-height: 100dvh; display: grid; place-items: center;
        padding: max(var(--s5), env(safe-area-inset-top)) var(--s4) max(var(--s5), env(safe-area-inset-bottom)); }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: var(--s4); }
.auth-card h1 { font-size: var(--t28); line-height: 1.15; letter-spacing: -.02em; color: var(--ink); }
.auth-card .wordmark { margin-bottom: var(--s2); }
.auth-card .wordmark::after { content: ""; display: block; width: 48px; height: 4px; margin-top: var(--s2);
                              border-radius: var(--pill); background: var(--ribbon); }

#proof { margin-top: 0; }
#proof [data-step] { display: grid; gap: var(--s4); }
#proof [data-step][hidden] { display: none; }
.proof-code { padding: var(--s4); border-radius: var(--r12); background: var(--sunken); color: var(--ink); text-align: center;
              font-size: var(--t40); font-weight: 700; letter-spacing: .12em; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- app frame */
.app { height: 100vh; height: var(--vvh, 100dvh); display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto;
       max-width: var(--page); margin: 0 auto; }
.app > * { min-width: 0; }
.bar { display: flex; align-items: center; gap: var(--s3); height: 56px; box-sizing: content-box;
       padding: env(safe-area-inset-top) max(var(--s2), env(safe-area-inset-right)) 0 max(var(--s4), env(safe-area-inset-left)); }
.bar .wordmark { margin-right: auto; }
.net { padding: var(--s1) var(--s3); border-radius: var(--pill); background: var(--warning-soft);
       color: var(--warning-ink); font-size: var(--t12); font-weight: 600; }

/* ---------------------------------------------------------------- pinned summary */
.summary { position: relative; margin: 0 max(var(--s4), env(safe-area-inset-right)) 0 max(var(--s4), env(safe-area-inset-left)); padding: var(--s4); background: var(--surface);
           border-radius: var(--r16); box-shadow: var(--shadow); overflow: hidden; }
.summary::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--ribbon); }
.summary.busy::before { background-image: linear-gradient(90deg, #3057B1, #A7C1F6, #9E8CEB, #E84363, #FF5A36, #E84363, #9E8CEB, #A7C1F6, #3057B1);
                        background-size: 200% 100%; animation: flow 1400ms linear infinite; }
.summary.landed::before { animation: ribbon 900ms var(--ease); }
.sum-head { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%; min-height: var(--tap);
            padding: 0; border: 0; background: none; text-align: left; border-radius: var(--r8); }
.sum-label { grid-column: 1; font-size: var(--t14); font-weight: 600; color: var(--muted); }
.sum-amount { grid-column: 1; font-size: var(--t40); line-height: 1.1; font-weight: 700; letter-spacing: -.03em;
              color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-amount.neg { color: var(--danger); }
.short { margin-top: var(--s1); font-size: var(--t14); line-height: 20px; color: var(--muted); }
.chev { grid-column: 2; grid-row: 1 / span 2; color: var(--muted); transition: transform 200ms var(--ease); }
.sum-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); margin-top: var(--s3);
         padding-top: var(--s3); border-top: 1px solid var(--border); }
.stats > div { margin: calc(-1 * var(--s1)); padding: var(--s1); border-radius: var(--r8); }
.stats > div.tick { animation: tick 900ms var(--ease); }
.stats.long { grid-template-columns: 1fr; gap: var(--s1); }
.stats.long > div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.stats.long dd { overflow: visible; }
.stats dt { font-size: var(--t12); line-height: 16px; color: var(--muted); }
.delta { position: absolute; right: 40px; top: 0; padding: 2px var(--s2); border-radius: var(--pill);
         font-size: var(--t14); font-weight: 700; font-variant-numeric: tabular-nums; background: var(--sunken);
         color: var(--success); animation: delta 1600ms var(--ease) forwards; pointer-events: none; }
.delta.down { background: var(--danger-soft); color: var(--danger); }
.stats dd { font-size: var(--t16); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums;
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.details { margin-top: var(--s3); max-height: 40dvh; overflow-y: auto; overscroll-behavior: contain; }
.details h2 { margin: var(--s4) 0 var(--s1); font-size: var(--t12); font-weight: 600; letter-spacing: .04em;
              text-transform: uppercase; color: var(--muted); }
.details li { display: flex; justify-content: space-between; gap: var(--s3); padding: 10px 0;
              border-bottom: 1px solid var(--border); font-size: var(--t14); line-height: 20px; }
.details li:last-child { border-bottom: 0; }
.details li span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.details li b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.details li.empty { color: var(--muted); }
.details .in { color: var(--success); }

/* ---------------------------------------------------------------- conversation */
.chat { min-height: 0; overflow-y: auto; overscroll-behavior: contain;
        padding: var(--s5) max(var(--s4), env(safe-area-inset-right)) var(--s4) max(var(--s4), env(safe-area-inset-left));
        -webkit-mask-image: linear-gradient(#0000, #000 20px); mask-image: linear-gradient(#0000, #000 20px); }
.app.sum-open { grid-template-rows: auto minmax(0, 1fr) 0 auto; }
.app.sum-open .summary { display: flex; flex-direction: column; min-height: 0; margin-bottom: var(--s2); }
.app.sum-open .details { max-height: none; flex: 1; min-height: 0; }
.app.sum-open .chat { visibility: hidden; padding: 0; }
.log { display: flex; flex-direction: column; gap: var(--s2); min-height: 100%; justify-content: flex-end; }
.day { align-self: center; margin: var(--s2) 0; font-size: var(--t12); line-height: 16px; font-weight: 600; color: var(--muted); }
.day.time { margin: var(--s1) 0 0; font-weight: 400; }
.msg { max-width: min(88%, 44ch); padding: var(--s3) var(--s4); border-radius: var(--r12);
       overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.new { animation: rise 240ms var(--ease); }
.msg.them { align-self: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--border);
            border-left: 4px solid var(--zafiro-300); border-radius: var(--r8) var(--r12) var(--r12) var(--r8); }
.msg.me { align-self: flex-end; background: var(--own); color: var(--on-own); }
.msg b { font-weight: 700; color: inherit; }
.msg.them b { color: var(--ink); }
.meta { display: block; margin-top: var(--s1); font-size: var(--t12); line-height: 16px; }
.msg.pending { opacity: .8; }
.msg.failed { background: var(--danger-soft); color: var(--danger); cursor: pointer; }
.choices { display: flex; flex-wrap: wrap; gap: var(--s2); align-self: flex-start; }
.choices button, .quick button {
  min-height: var(--tap); padding: 0 var(--s4); border: 1px solid var(--border-strong); border-radius: var(--pill);
  background: var(--surface); color: var(--ink); font-size: var(--t14); font-weight: 600; white-space: nowrap;
}
.choices button:active, .quick button:active { background: var(--zafiro-100); color: var(--zafiro-950); }
.choices button { border-radius: var(--r12); }
.choices button.strong { background: var(--zafiro-900); border-color: var(--zafiro-600); color: #fff; }
@media (hover: hover) {
  .btn.secondary:hover, .quick button:hover, .choices button:not(.strong):hover, .icon-btn:hover { background: var(--zafiro-100); color: var(--zafiro-950); }
  .btn.primary:hover, .send:hover { background: var(--coral-400); }
}

/* ---------------------------------------------------------------- composer */
.composer { padding: var(--s2) max(var(--s4), env(safe-area-inset-right)) max(var(--s3), env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left));
            background: var(--bg); border-top: 1px solid var(--border); }
.quick { display: flex; gap: var(--s2); margin: 0 calc(-1 * var(--s4)) var(--s2); padding: 0 var(--s4);
         overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-left: var(--s4);
         -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 32px), #0000); mask-image: linear-gradient(90deg, #000 calc(100% - 32px), #0000); }
.quick button { scroll-snap-align: start; }
.quick::-webkit-scrollbar { display: none; }
.send-row { display: flex; gap: var(--s2); }
.send-row input { flex: 1; min-width: 0; height: var(--tap); padding: 0 var(--s4); background: var(--surface);
                  border: 1px solid var(--border-strong); border-radius: var(--pill); outline: 0; text-overflow: ellipsis; }
.send-row input:focus { border-color: var(--focus); box-shadow: 0 0 0 2px var(--focus); }
.send { display: grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
        background: var(--action); color: var(--on-action); transition: transform 120ms var(--ease); }
.send:active { transform: scale(.92); background: var(--action-press); }

/* ---------------------------------------------------------------- account sheet and toast */
#logout-all, .btn.link.danger { color: var(--danger); }
.account { margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--border); }
.account h2 { margin-top: 0; }
.menu-list { display: grid; gap: var(--s2); margin: var(--s3) 0 var(--s2); }
/* ---------------------------------------------------------------- adding or changing a payment, inside the card */
.setup-form { display: grid; gap: var(--s3); margin: var(--s3) 0; }
#plan-add { margin-top: var(--s3); }
.pick { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pick button { min-height: var(--tap); padding: 0 var(--s4); border: 1px solid var(--border-strong); border-radius: var(--r12);
               background: var(--surface); color: var(--ink); font-size: var(--t14); font-weight: 600; }
.pick button[aria-pressed="true"] { background: var(--zafiro-900); border-color: var(--zafiro-600); color: #fff; }
.field-box select { flex: 1; min-width: 0; height: 54px; border: 0; background: none; outline: 0; font-size: var(--t16); color: inherit; }
.field-box input[type="date"] { font-size: var(--t16); }
.details li.total { font-weight: 600; color: var(--ink); }
.details li button { all: unset; display: flex; justify-content: space-between; gap: var(--s3); width: 100%; cursor: pointer; }
.details li button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.toast { position: fixed; left: var(--s4); right: var(--s4); top: calc(env(safe-area-inset-top) + var(--s2)); width: fit-content;
         margin-inline: auto; padding: var(--s3) var(--s4); border-radius: var(--r12); background: var(--ink); color: var(--bg);
         font-size: var(--t14); line-height: 20px; font-weight: 600; box-shadow: var(--shadow); z-index: 10; }
.noscript { padding: var(--s5); text-align: center; }

/* ---------------------------------------------------------------- wide screens: summary beside the chat */
@media (min-width: 900px) {
  :root { --page: 1040px; }
  .app { grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: auto minmax(0, 1fr) auto; column-gap: var(--s5);
         padding: 0 var(--s5); }
  .bar { grid-column: 1 / -1; padding-left: 0; padding-right: 0; }
  .summary { grid-column: 2; grid-row: 2 / span 2; align-self: start; margin: 0; }
  .chat { grid-column: 1; grid-row: 2; padding-left: 0; }
  .composer { grid-column: 1; grid-row: 3; padding-left: 0; padding-right: 0; }
  .quick { margin-left: 0; margin-right: 0; padding: 0; }
  .details { max-height: 60dvh; }
  .chev { display: none; }
  .sum-head:disabled { cursor: default; color: inherit; }
}
@media (max-height: 520px) {
  .stats { display: none; }
  .sum-amount { font-size: var(--t28); }
  .bar { height: 48px; }
}

@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes ribbon { from { background-size: 300% 100%; background-position: 100% 0; } to { background-size: 100% 100%; background-position: 0 0; } }
@keyframes flow { to { background-position: -200% 0; } }
@keyframes tick { from { background: var(--zafiro-100); } to { background: transparent; } }
@keyframes delta { 0% { opacity: 0; transform: translateY(8px); } 15%, 70% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
