:root {
  color-scheme: light;
  --ink: #1b2925;
  --muted: #79827d;
  --line: #e8ebe7;
  --green: #173b30;
  --green-soft: #e8f0e9;
  --paper: #fbfcfa;
  --white: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  padding: env(safe-area-inset-top) calc(24px + env(safe-area-inset-right))
    env(safe-area-inset-bottom) calc(24px + env(safe-area-inset-left));
}

button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.app-shell { width: min(100%, 760px); margin: 0 auto; }

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 31px;
  height: 31px;
  border-radius: 10px;
}

.privacy-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #5f7067;
  font-size: 12px;
}

.privacy-label span { color: #65a77c; font-size: 9px; }

.intro { padding: 47px 0 29px; }

.eyebrow {
  margin: 0 0 9px;
  color: #748078;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.25px;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 12px;
  font-family: inherit;
  font-size: clamp(34px, 8vw, 49px);
  font-weight: 700;
  letter-spacing: -2.1px;
  line-height: 1.13;
}

.intro-copy {
  max-width: 470px;
  margin-bottom: 0;
  color: #68736c;
  font-size: 14px;
  line-height: 1.65;
}

.install-guide {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin: 0 0 20px;
  padding: 16px;
  border: 1px solid #dfe9df;
  border-radius: 13px;
  background: #f2f7f1;
}
.install-guide[hidden] { display: none; }
.install-icon { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 11px; background: var(--green); color: white; font-size: 19px; }
.install-guide h2 { margin: 0 0 5px; font-size: 14px; letter-spacing: -0.2px; }
.install-guide p { margin: 0; color: #66736a; font-size: 12px; line-height: 1.55; }

.dashboard { margin-bottom: 24px; }
.dashboard-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; margin-bottom: 13px; }
.dashboard-filters .field label { margin-bottom: 6px; }
.dashboard-filters .field select { height: 42px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }

.summary-card {
  display: flex;
  min-height: 119px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--white);
}

.summary-primary { border-color: var(--green); background: var(--green); color: white; }
.summary-label, .summary-footnote { font-size: 11px; }
.summary-label { color: #748078; }
.summary-primary .summary-label, .summary-primary .summary-footnote { color: #b9cdc2; }
.summary-card strong { font-family: inherit; font-size: clamp(24px, 6vw, 31px); letter-spacing: -1px; }
.summary-footnote { color: #8a938d; }

.panel {
  margin-top: 24px;
  padding: 25px 26px 23px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--white);
  box-shadow: 0 8px 28px rgb(27 41 37 / 3%);
}

.statement-intro { margin: 14px 0 18px; color: #68736c; font-size: 13px; line-height: 1.6; }
.statement-form { display: grid; gap: 14px; }
.statement-form input[type="file"] { min-height: 46px; padding: 10px; font-size: 12px; }
.statement-form input[type="password"] { height: 46px; padding: 0 12px; font-size: 16px; }
.statement-privacy { margin: 0; color: #818b84; font-size: 11px; line-height: 1.5; }
.statement-form .save-button { margin-top: 0; }
.statement-status { margin: 12px 0 0; color: #53665a; font-size: 12px; line-height: 1.5; }
.statement-status:empty { display: none; }
.statement-status.error { color: #a43737; }
.statement-review { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.statement-review[hidden] { display: none; }
.review-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.review-heading h3 { margin: 0 0 5px; font-size: 16px; letter-spacing: -0.3px; }
.review-heading .text-button { min-height: 40px; }
.statement-rows { display: grid; gap: 12px; }
.statement-row { padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.statement-row-exclude { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 11px; }
.statement-row-exclude input { width: 18px; height: 18px; accent-color: var(--green); }
.statement-row-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, .7fr); gap: 10px; }
.statement-row-fields .field-wide { grid-column: 1 / -1; }
.statement-row-fields label { font-size: 11px; }
.statement-row-fields input, .statement-row-fields select { min-width: 0; height: 44px; padding: 0 9px; font-size: 16px; }
.statement-row-fields input[type="date"] { font-size: 14px; }
.statement-row-fields .amount-input > span { top: 15px; }
.statement-row-fields .kind-field { grid-column: 1 / -1; }
.statement-row-fields .kind-field select { font-size: 14px; }
.import-selected-button { margin-top: 16px; }
.statement-panel > .statement-status { margin-top: 12px; }

.rules-intro { margin: 14px 0 18px; color: #68736c; font-size: 12px; line-height: 1.6; }
.rule-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .8fr); gap: 12px; align-items: end; }
.rule-form .save-button { grid-column: 1 / -1; margin-top: 0; }
.category-rule-list { display: grid; gap: 8px; margin-top: 14px; }
.category-rule-list:empty { display: none; }
.category-rule-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 12px; }
.category-rule-item strong { font-weight: 700; }
.category-rule-item span { color: #68736c; }
.category-rule-delete { flex: 0 0 auto; padding: 7px 9px; border: 0; border-radius: 6px; background: #f6f7f5; color: #68736c; font-size: 11px; cursor: pointer; }
.category-rule-delete:hover { background: #f8eeee; color: #a43737; }
.category-create-section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.category-create-section h3 { margin: 0 0 12px; font-size: 14px; }
.category-create-section .rule-form { grid-template-columns: minmax(0, 1fr) minmax(140px, auto); }
.category-create-section .rule-form .save-button { grid-column: auto; }

.section-heading, .ledger-heading { display: flex; align-items: center; justify-content: space-between; }
h2 { margin-bottom: 0; font-family: inherit; font-size: 20px; letter-spacing: -0.6px; }
.step-badge { display: grid; width: 33px; height: 33px; place-items: center; border-radius: 50%; background: #f1f4f0; color: #68736c; font-size: 11px; font-weight: 700; }

.message-form { margin-top: 22px; }
label { display: block; margin-bottom: 8px; color: #46534c; font-size: 12px; font-weight: 600; }
textarea, input, select {
  width: 100%;
  border: 1px solid #e3e7e2;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 86px; padding: 12px; resize: vertical; font-size: 13px; line-height: 1.5; }
textarea::placeholder, input::placeholder { color: #a0a8a2; }
textarea:focus, input:focus, select:focus { border-color: #71927e; box-shadow: 0 0 0 3px rgb(113 146 126 / 12%); }
.form-hint-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; color: #8a938d; font-size: 10px; }
.text-button { flex-shrink: 0; padding: 5px 0; border: 0; background: transparent; color: var(--green); font-size: 11px; font-weight: 700; cursor: pointer; }
.text-button span { margin-left: 3px; }

.divider { display: flex; align-items: center; gap: 12px; margin: 21px 0 19px; color: #9aa29c; font-size: 9px; font-weight: 700; letter-spacing: 1px; }
.divider::before, .divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.field-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 13px; margin-bottom: 14px; }
.field-row:nth-of-type(2) { grid-template-columns: 1fr 1fr 0.82fr; }
.field { min-width: 0; }
.field input, .field select { height: 42px; padding: 0 10px; font-size: 12px; }
.amount-input { position: relative; }
.amount-input > span { position: absolute; top: 13px; left: 11px; color: #748078; font-size: 12px; }
.amount-input input { padding-left: 25px; }
.save-button {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.save-button:hover { background: #214c3e; }
.save-button span { font-size: 14px; }
.form-error { margin: 0 0 10px; color: #a43737; font-size: 12px; }

.ledger-section { margin-top: 37px; }
.ledger-heading { margin-bottom: 15px; }
.ledger-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.ledger-actions [hidden] { display: none; }
.ledger-privacy { margin: -4px 0 8px; text-align: right; }
.export-button { padding: 8px 11px; border: 1px solid #e1e6e1; border-radius: 7px; background: white; color: #4d5c53; font-size: 10px; font-weight: 600; cursor: pointer; }
.export-button.dedupe-button { border-color: #d9b8a7; color: #8b4a2b; }
.export-button:hover { border-color: #9fb3a3; }
.export-button span { margin-left: 4px; }

.transaction-list { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.empty-state { padding: 30px 20px; color: #7c8780; text-align: center; font-size: 12px; line-height: 1.6; }
.transaction-item { display: grid; grid-template-columns: 40px 1fr auto auto; align-items: center; gap: 12px; padding: 15px 16px; border-bottom: 1px solid #edf0ed; }
.transaction-item:last-child { border-bottom: 0; }
.transaction-icon { display: grid; width: 37px; height: 37px; place-items: center; border-radius: 11px; background: #f1f5f1; color: #537461; font-size: 15px; }
.transaction-meta { min-width: 0; }
.transaction-name { overflow: hidden; margin: 0 0 4px; color: #2c3933; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.transaction-detail { margin: 0; color: #8a938d; font-size: 10px; }
.transaction-amount { color: #26362e; font-size: 12px; font-weight: 700; white-space: nowrap; }
.transaction-amount.income { color: #4d8a60; }
.delete-button { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: #9aa29c; font-size: 17px; cursor: pointer; }
.delete-button:hover { background: #f8eeee; color: #a43737; }
.footer-note { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 24px 0 32px; color: #89928c; font-size: 10px; }
.footer-note span { color: #5f8269; font-size: 16px; }

@media (max-width: 520px) {
  body {
    padding-right: calc(17px + env(safe-area-inset-right));
    padding-left: calc(17px + env(safe-area-inset-left));
  }
  .topbar { min-height: 66px; }
  .intro { padding-top: 36px; }
  .panel { padding: 20px 17px; }
  .field-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 10px; }
  .field-row:nth-of-type(2) { grid-template-columns: 1fr 1fr; }
  .field-row:nth-of-type(2) .field:last-child { grid-column: 1 / -1; }
  .field input, .field select, textarea { font-size: 16px; }
  .field input, .field select { height: 44px; }
  .dashboard-filters, .rule-form { grid-template-columns: 1fr; }
  .rule-form .save-button { grid-column: auto; }
  .transaction-item { grid-template-columns: 37px minmax(0, 1fr) auto 40px; gap: 8px; padding: 13px 10px; }
  .form-hint-row { align-items: flex-start; }
  .text-button { min-height: 44px; }
  .export-button { min-height: 44px; }
  .delete-button { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: no-preference) {
  button, input, select, textarea { transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease; }
}
.cloud-panel { margin-top: 1rem; }
.cloud-signin-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 1rem; }
.cloud-signin-form .save-button { min-height: 48px; }
.cloud-account { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 0; font-weight: 650; }
.cloud-signin-form[hidden], .cloud-account[hidden] { display: none; }
@media (max-width: 600px) { .cloud-signin-form { grid-template-columns: 1fr; } }
