/* Mini App. Mobile first; tap targets >= 44px (most 48px); text contrast >= 4.5:1 in both themes; honours
   prefers-reduced-motion and prefers-color-scheme (or Telegram's colorScheme / #theme=). No inline styles needed. */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #eeede8;
  --text: #1b1d1f;
  --muted: #555b61;          /* 6.9:1 on --surface */
  --line: #d9d7d0;
  --accent: #0f5c57;         /* 7.4:1 with white text */
  --accent-ink: #ffffff;
  --accent-soft: #dcefec;
  --danger: #a32a1f;         /* 6.9:1 on white */
  --danger-soft: #fbe5e1;
  --warn-soft: #fff1cc;
  --warn-ink: #6a4a00;
  --ok: #1d6b38;
  --rec: #c0261a;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06);
  --radius: 16px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111416; --surface: #1b1f22; --surface-2: #252a2e; --text: #eef0f1; --muted: #aab2b8; --line: #343b40;
    --accent: #5cc8bd; --accent-ink: #062b28; --accent-soft: #163a37; --danger: #ff8a7d; --danger-soft: #3a1d1a;
    --warn-soft: #3a3014; --warn-ink: #ffd877; --ok: #7ad69a; --rec: #ff6b5e; color-scheme: dark;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #111416; --surface: #1b1f22; --surface-2: #252a2e; --text: #eef0f1; --muted: #aab2b8; --line: #343b40;
  --accent: #5cc8bd; --accent-ink: #062b28; --accent-soft: #163a37; --danger: #ff8a7d; --danger-soft: #3a1d1a;
  --warn-soft: #3a3014; --warn-ink: #ffd877; --ok: #7ad69a; --rec: #ff6b5e; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 99; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* icons */
.ico { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ico svg { width: 100%; height: 100%; }

/* buttons */
.btn, .btn-secondary, .btn-danger {
  min-height: var(--tap); padding: 12px 20px; border-radius: 999px; border: 0; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-text { background: none; border: 0; color: var(--accent); font-weight: 600; min-height: var(--tap); padding: 0 12px; cursor: pointer; }
.btn-chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; gap: 6px; align-items: center; font-size: .875rem; font-weight: 600; cursor: pointer;
}
.btn-chip .ico { width: 18px; height: 18px; }
.topbar .btn-chip { white-space: nowrap; flex: none; }
.onb-art > .ico { width: 72px; height: 72px; color: var(--accent); }
.icon-btn { width: var(--tap); height: var(--tap); border: 0; border-radius: 50%; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--surface-2); }
.row-btns { display: flex; gap: 10px; }
.row-btns > * { flex: 1; }
.stack { display: grid; gap: 10px; }
.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.is-busy::after { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; border: 3px solid currentColor; border-color: var(--accent-ink) transparent var(--accent-ink) transparent; animation: spin .8s linear infinite; }
.btn-secondary.is-busy::after { border-color: var(--text) transparent var(--text) transparent; }

/* gate */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { max-width: 380px; width: 100%; text-align: center; display: grid; gap: 14px; justify-items: center; }
.gate-card p { color: var(--muted); }
.logo { width: 64px; height: 64px; border-radius: 20px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 30px; font-weight: 800; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* onboarding */
.onboarding { min-height: 100%; display: flex; flex-direction: column; padding: 12px 16px calc(16px + var(--safe-b)); max-width: 520px; margin: 0 auto; }
.onb-top { display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); }
.dots { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.dots li { width: 8px; height: 8px; border-radius: 4px; background: var(--line); transition: width .2s; }
.dots li.on { width: 22px; background: var(--accent); }
.dots li.done { background: var(--accent); }
.onb-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 16px 0; outline: none; }
.onb-art { width: 100%; aspect-ratio: 16/10; border-radius: 24px; background: var(--accent-soft); display: grid; place-items: center; padding: 18px; }
.onb-body h2 { font-size: 1.6rem; line-height: 1.2; }
.onb-body p { color: var(--muted); font-size: 1.05rem; }
.onb-actions { display: grid; gap: 10px; }
.mock-bubble { background: var(--surface); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); font-size: .9rem; max-width: 280px; width: 100%; }
.mock-bubble + .mock-bubble { margin-top: 8px; }
.mock-bubble b { color: var(--accent); }
.consent-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; max-height: 34vh; overflow: auto; font-size: .9rem; color: var(--muted); }
.check { display: flex; gap: 12px; align-items: flex-start; min-height: var(--tap); padding: 8px 0; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }

/* app shell */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px 10px; }
.eyebrow { color: var(--muted); font-size: .85rem; font-weight: 600; }
.title { font-size: 1.5rem; line-height: 1.2; }
main { flex: 1; padding: 0 16px calc(96px + var(--safe-b)); outline: none; max-width: 640px; width: 100%; margin: 0 auto; }
.panel { display: grid; gap: 14px; align-content: start; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + var(--safe-b));
}
.tab { min-height: 56px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; font-weight: 600; color: var(--muted); cursor: pointer; border-radius: 12px; padding: 4px 2px; }
.tab[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }
.tab .ico { width: 24px; height: 24px; }

/* cards & lists */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h3 { font-size: 1rem; margin-bottom: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.section-head h2 { font-size: 1.05rem; }
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; overflow-wrap: anywhere; }
.li-sub { color: var(--muted); font-size: .875rem; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 52px; color: var(--accent); }
.badge { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.badge.kind-reminder { background: var(--warn-soft); color: var(--warn-ink); }
.badge.kind-payment { background: var(--accent-soft); color: var(--accent); }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.big-num { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav strong { font-size: 1.05rem; }
.done .li-title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.checkbox-btn { width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; }
.checkbox-btn span { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted); display: grid; place-items: center; }
.done .checkbox-btn span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }
.inline-add .btn { width: auto; }

/* empty & error & skeleton */
.empty { text-align: center; padding: 28px 16px; display: grid; gap: 10px; justify-items: center; }
.empty > .ico { width: 44px; height: 44px; color: var(--accent); }
.empty h3 { font-size: 1.1rem; }
.empty p { color: var(--muted); max-width: 300px; }
.empty .btn { max-width: 260px; }
.error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.error .btn-secondary { width: auto; justify-self: start; }
.skel { height: 56px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* forms */
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, select, textarea {
  min-height: var(--tap); border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); padding: 10px 12px; width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.form-error { color: var(--danger); font-size: .9rem; font-weight: 600; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--surface); border-radius: 22px 22px 0 0;
  max-height: 92vh; overflow: auto; padding: 6px 16px calc(18px + var(--safe-b)); max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 4px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-size: 1.2rem; }
.sheet-body { display: grid; gap: 14px; padding-top: 4px; }
.preview-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.preview-list li { background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; gap: 10px; }
.preview-list .num { font-weight: 800; color: var(--accent); }
.heard { border-left: 4px solid var(--accent); padding: 8px 12px; background: var(--accent-soft); border-radius: 0 12px 12px 0; }
.heard small { display: block; color: var(--muted); font-weight: 600; }
.strict-note { background: var(--warn-soft); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: .9rem; font-weight: 600; }
.privacy-note { display: flex; gap: 10px; color: var(--muted); font-size: .875rem; }
.privacy-note .ico { color: var(--accent); width: 20px; height: 20px; }

/* chat */
.panel-chat { min-height: calc(100vh - 230px); grid-template-rows: 1fr auto; }
.msgs { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.composer { position: sticky; bottom: calc(72px + var(--safe-b)); background: var(--bg); padding: 8px 0; display: grid; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-row input { flex: 1; border-radius: 999px; padding-left: 16px; }
.send-btn { width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; flex: none; }
.ptt {
  width: 100%; min-height: 64px; border-radius: 999px; border: 2px dashed var(--accent); background: var(--accent-soft); color: var(--accent);
  font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
}
.ptt.recording { background: var(--rec); border-color: var(--rec); color: #fff; border-style: solid; }
.ptt .ico { width: 26px; height: 26px; }

/* recording indicator: always on top while capturing */
.rec-indicator { position: fixed; top: 0; left: 0; right: 0; z-index: 40; background: var(--rec); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #fff; animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { opacity: .3; } }

/* toast */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 30; background: var(--text); color: var(--bg); border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; box-shadow: var(--shadow); max-width: 600px; margin: 0 auto; }
.toast .btn-text { color: var(--bg); text-decoration: underline; min-height: 44px; }

/* onboarding: persona cards and example phrases */
.onb-body h2:focus { outline: none; }
.persona-grid { display: grid; gap: 10px; }
.persona-card {
  display: flex; gap: 14px; align-items: flex-start; text-align: left; width: 100%; min-height: 72px; padding: 14px 16px;
  border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); cursor: pointer;
}
.persona-card.on { border-color: var(--accent); background: var(--accent-soft); }
.persona-card[aria-disabled="true"] { opacity: .6; }
.persona-check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted); display: grid; place-items: center; flex: none; margin-top: 2px; }
.persona-card.on .persona-check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.persona-check .ico { width: 18px; height: 18px; }
.persona-main { display: grid; gap: 4px; }
.persona-title { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.persona-text { color: var(--muted); font-size: .92rem; }
.btn-example {
  min-height: 56px; width: 100%; border-radius: var(--radius); border: 1.5px solid var(--accent); background: var(--surface);
  color: var(--text); display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-align: left; font-weight: 600; cursor: pointer;
}
.btn-example .ico { color: var(--accent); }

/* inline preview card (all writes are confirmed here) */
.pending-wrap { display: grid; margin-bottom: 14px; scroll-margin-top: 80px; }
.pending-wrap:empty { display: none; }
.pending-card { display: grid; gap: 12px; border: 2px solid var(--accent); }
.pending-title { display: flex; gap: 8px; align-items: center; font-size: 1.05rem; color: var(--accent); }
.pending-title:focus { outline: none; }
.pending-title:focus-visible { outline: 3px solid var(--accent); }
.write-hint { display: grid; gap: 8px; padding: 4px 2px 8px; }
.write-hint > p { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .9rem; }
.write-hint .ico { width: 18px; height: 18px; color: var(--accent); }
.tick { width: 26px; height: 26px; display: grid; place-items: center; flex: none; }
.tick::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }   /* a bullet, not a checkbox: read-only */
.done .tick { border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.done .tick::before { display: none; }
.tick .ico { width: 18px; height: 18px; }

/* offline banner, pull to refresh */
.offline { position: sticky; top: 0; z-index: 7; background: var(--warn-soft); color: var(--warn-ink); font-weight: 600; padding: 10px 16px; text-align: center; }
.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; gap: 8px; color: var(--muted); font-size: .85rem; transition: height .15s; }
.ptr-spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); margin-bottom: 6px; }
.ptr.armed .ptr-spin { border-color: var(--accent); }
.ptr.loading .ptr-spin { animation: spin .8s linear infinite; }
.ptr > span:last-child { margin-bottom: 6px; }
.error > .ico { width: 28px; height: 28px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media (min-width: 700px) { .tab { font-size: .8rem; } }
