:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: #18221c; background: #f3f6f3; font-synthesis: none;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; overflow-x: hidden; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: #f3f6f3; }
button, input, select, textarea { font: inherit; }
input, select, textarea { font-size: 16px; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px; background: rgba(243,246,243,.94);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-bottom: 1px solid #dce5dd;
}
.eyebrow, .dialog-kicker { margin: 0 0 3px; font-size: .68rem; letter-spacing: .13em; font-weight: 800; color: #4f6656; }
h1, h2, h3, p { margin-top: 0; }
.topbar h1 { margin: 0; font-size: 1.3rem; }
.icon-button { flex: 0 0 auto; border: 0; background: #fff; border-radius: 50%; width: 44px; height: 44px; font-size: 1.3rem; box-shadow: 0 2px 9px rgba(0,0,0,.08); }
.app-shell { width: 100%; max-width: 720px; margin: 0 auto; padding: 16px 16px calc(34px + env(safe-area-inset-bottom)); }
.balance-hero { padding: 23px; border-radius: 24px; color: white; background: linear-gradient(145deg,#146a38,#238c4f); box-shadow: 0 12px 30px rgba(20,106,56,.22); }
.balance-hero p { margin: 0; opacity: .8; }
.balance-hero > strong { display: block; margin: 4px 0 20px; font-size: 2.75rem; letter-spacing: -.04em; overflow-wrap: anywhere; }
.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.balance-grid div { min-width: 0; padding: 12px 14px; border-radius: 15px; background: rgba(255,255,255,.14); }
.balance-grid span, .summary-strip span { display: block; font-size: .76rem; opacity: .8; }
.balance-grid b { display: block; font-size: 1.15rem; overflow-wrap: anywhere; }
.quick-actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin: 14px 0; }
.quick-actions button { min-width: 0; min-height: 82px; padding: 10px 6px; border: 1px solid #d9e4da; border-radius: 18px; background: white; font-weight: 700; color: #1b4128; }
.quick-actions span { display: block; font-size: 1.7rem; line-height: 1.1; color: #17713d; }
.summary-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-strip div { min-width: 0; padding: 14px 16px; background: white; border-radius: 16px; border: 1px solid #dfe7df; }
.summary-strip span { color: #607066; }
.summary-strip strong { display: block; font-size: 1.05rem; overflow-wrap: anywhere; }
.activity-section { margin-top: 24px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; }
.section-heading h2 { margin: 0; }
.text-button { min-height: 44px; border: 0; background: none; color: #17713d; font-weight: 700; }
.activity-list { display: grid; gap: 9px; margin-top: 12px; }
.activity-row { width: 100%; display: grid; grid-template-columns: 42px minmax(0,1fr) auto; gap: 10px; align-items: center; text-align: left; padding: 13px; border: 1px solid #e0e7e0; border-radius: 16px; background: white; color: inherit; }
.activity-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: #e8f4eb; font-size: 1.2rem; }
.activity-copy { min-width: 0; }
.activity-copy strong, .activity-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.activity-copy small { margin-top: 3px; color: #68756c; }
.activity-amount { font-weight: 800; white-space: nowrap; }
.amount-negative { color: #a33131; }
.amount-transfer { color: #496258; }
.empty-state { padding: 30px; text-align: center; color: #718078; }
.setup-card { width: 100%; max-width: 560px; margin: 30px auto; padding: 26px 20px calc(26px + env(safe-area-inset-bottom)); }
.setup-card form, dialog form { display: grid; gap: 15px; }
label { display: grid; gap: 7px; min-width: 0; font-size: .88rem; font-weight: 700; color: #3f5045; }
.optional { font-weight: 500; color: #7a867e; }
input, select, textarea { width: 100%; min-width: 0; min-height: 50px; border: 1px solid #cfdacf; border-radius: 12px; padding: 12px; background: white; color: #17231b; }
input[type="date"] { display: block; appearance: none; -webkit-appearance: none; min-height: 52px; line-height: 25px; }
textarea { resize: vertical; min-height: 84px; }
.amount-field input { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; }
.primary, .secondary, .danger, .file-button { min-height: 48px; border-radius: 12px; padding: 12px 15px; font-weight: 800; text-align: center; }
.primary { border: 0; background: #17713d; color: white; }
.secondary, .file-button { border: 1px solid #ccd8ce; background: white; color: #264332; }
.danger { border: 1px solid #e7bcbc; background: #fff5f5; color: #a12a2a; }
.wide { width: 100%; }
dialog { width: min(640px, calc(100% - 20px)); max-height: calc(100dvh - 20px); overflow: auto; overscroll-behavior: contain; border: 0; border-radius: 22px; padding: 20px; box-shadow: 0 25px 80px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(15,24,18,.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-heading { position: sticky; top: -20px; z-index: 3; display: flex; align-items: center; justify-content: space-between; padding: 10px 0; background: white; }
.dialog-heading h2 { margin: 0; }
.dialog-heading .dialog-kicker { margin-bottom: 1px; }
.dialog-actions { position: sticky; bottom: -20px; z-index: 3; display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; padding: 12px 0 calc(4px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(255,255,255,.88),#fff 18%); }
.choice-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.choice-field legend { margin-bottom: 7px; font-size: .88rem; font-weight: 700; color: #3f5045; }
.choice-pills { display: grid; gap: 8px; }
.choice-pills.two { grid-template-columns: 1fr 1fr; }
.choice-pills label, .direction-cards label { display: block; }
.choice-pills input, .direction-cards input { position: absolute; opacity: 0; pointer-events: none; }
.choice-pills span { display: grid; place-items: center; min-height: 52px; padding: 10px; border: 1px solid #ccd8ce; border-radius: 13px; background: white; color: #36503f; text-align: center; }
.choice-pills input:checked + span { border-color: #17713d; background: #e9f6ed; color: #0f6334; box-shadow: inset 0 0 0 1px #17713d; }
.direction-cards { display: grid; gap: 10px; }
.direction-cards span { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; align-items: center; padding: 14px; border: 1px solid #ccd8ce; border-radius: 15px; background: white; }
.direction-cards b { font-size: 1rem; }
.direction-cards small { grid-column: 1; color: #68766e; font-weight: 500; }
.direction-cards em { grid-column: 2; grid-row: 1 / span 2; font-style: normal; font-size: .78rem; color: #17713d; }
.direction-cards input:checked + span { border-color: #17713d; background: #e9f6ed; box-shadow: inset 0 0 0 1px #17713d; }
.transfer-preview { display: flex; gap: 12px; align-items: center; padding: 13px; border-radius: 14px; background: #eff6f1; }
.transfer-preview > span { font-size: 1.45rem; }
.transfer-preview small, .transfer-preview strong { display: block; }
.transfer-preview small { color: #6a786e; margin-bottom: 2px; }
.receipt-section { display: grid; gap: 10px; padding-top: 2px; }
.receipt-upload { position: relative; }
.receipt-upload input, .file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.receipt-upload span { display: grid; gap: 4px; min-height: 64px; place-content: center; padding: 13px; border: 1px dashed #83a78c; border-radius: 12px; background: #f5faf6; text-align: center; color: #1f5d35; }
.receipt-upload span small { color: #64736a; font-weight: 600; }
.receipt-preview { width: 100%; max-height: 330px; object-fit: contain; border-radius: 12px; background: #eef2ee; }
.help-text { margin: 0; color: #6b786f; font-size: .78rem; line-height: 1.4; }
.ocr-progress { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: #eef7f0; }
.ocr-progress strong, .ocr-progress small { display: block; }
.ocr-progress small { margin-top: 3px; color: #627068; }
.spinner { width: 24px; height: 24px; border: 3px solid #c9ddce; border-top-color: #17713d; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ocr-result { padding: 12px; border: 1px solid #cfe0d2; border-radius: 12px; background: #f7fbf8; }
.ocr-result-row, .ocr-merchant-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ocr-result-row span { font-size: 1.25rem; font-weight: 900; color: #126435; }
.ocr-merchant-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid #dce9de; }
.ocr-merchant-row b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-button { min-height: 36px; border: 1px solid #bfd4c4; border-radius: 9px; padding: 6px 11px; background: white; color: #1c5130; font-weight: 800; }
.ocr-result > small { display: block; margin-top: 8px; color: #68756c; }
.ocr-alternatives { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ocr-alternatives button { min-height: 42px; border: 1px solid #bfd4c4; border-radius: 999px; padding: 8px 12px; background: white; color: #1c5130; font-weight: 800; }
.settings-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.install-help { padding: 14px; border-radius: 14px; background: #eef7f0; }
.install-help h3 { margin-bottom: 5px; }
.install-help p { margin: 0; font-size: .86rem; line-height: 1.45; }
.version-label { margin: -4px 0 0; text-align: center; color: #778279; font-size: .75rem; }

@media (max-width: 600px) {
  dialog { width: 100vw; max-width: none; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; padding: calc(10px + env(safe-area-inset-top)) 16px 0; }
  dialog form { min-height: calc(100dvh - env(safe-area-inset-top)); align-content: start; }
  .dialog-heading { top: calc(-10px - env(safe-area-inset-top)); margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid #e4ebe5; }
  .dialog-actions { bottom: 0; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid #e4ebe5; }
}
@media (max-width: 430px) {
  .app-shell { padding-inline: 12px; }
  .balance-hero { padding: 19px; }
  .balance-hero > strong { font-size: 2.25rem; }
  .quick-actions { gap: 7px; }
  .quick-actions button { font-size: .79rem; min-height: 78px; }
  .dialog-actions { display: grid; grid-template-columns: repeat(auto-fit,minmax(95px,1fr)); }
  .dialog-actions .primary:last-child:nth-child(2) { grid-column: auto; }
  .settings-buttons { grid-template-columns: 1fr; }
  .activity-row { grid-template-columns: 40px minmax(0,1fr) auto; gap: 8px; padding: 12px 10px; }
}
@media (max-width: 350px) {
  .quick-actions { grid-template-columns: 1fr; }
  .quick-actions button { min-height: 58px; }
  .quick-actions span { display: inline; margin-right: 6px; font-size: 1.15rem; }
  .choice-pills.two { grid-template-columns: 1fr; }
  .dialog-actions { grid-template-columns: 1fr; }
}

/* v1.3: make receipt capture the primary spend action and explain smart categorisation. */
.prominent-scan span {
  min-height: 76px;
  border-width: 2px;
  border-style: solid;
  background: #eaf7ee;
  box-shadow: 0 8px 22px rgba(23,113,61,.10);
}
.prominent-scan span b { font-size: 1.05rem; }
.field-hint {
  display: block;
  margin-top: -1px;
  color: #17713d;
  font-size: .76rem;
  font-weight: 700;
  line-height: 1.35;
}
.ocr-payment {
  margin-top: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #e9f6ed;
  color: #155c32;
  font-weight: 700;
}
.receipt-section .receipt-preview { max-height: 210px; }
