:root {
  --ink: #172526;
  --muted: #607072;
  --line: #d8e1df;
  --surface: #ffffff;
  --page: #f3f7f5;
  --soft: #e9f3ef;
  --brand: #0b6b61;
  --brand-dark: #07554d;
  --accent: #d5a13a;
  --danger: #a62d2d;
  --danger-soft: #fff1ef;
  --positive: #137a4a;
  --shadow: 0 12px 32px rgba(24, 54, 49, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--page); color: var(--ink); line-height: 1.5; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--brand-dark); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.75rem, 2.6vw, 2.35rem); line-height: 1.15; }
h2 { margin-bottom: 8px; font-size: 1.15rem; }
h3 { margin-bottom: 5px; }

.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 14px; transform: translateY(-150%); border-radius: 8px; background: var(--ink); color: white; }
.skip-link:focus { transform: translateY(0); }
.app-header { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 76px; padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 auto; border-radius: 13px; background: linear-gradient(135deg, var(--brand), #0f8b7e); color: white; font-size: .76rem; font-weight: 800; letter-spacing: .02em; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; }
.brand small { color: var(--muted); font-size: .78rem; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.sandbox-badge { padding: 6px 10px; border: 1px solid #97c6b7; border-radius: 999px; background: #ecf8f3; color: #075847; font-size: .76rem; font-weight: 750; white-space: nowrap; }

.main-nav { position: sticky; z-index: 19; top: 76px; display: flex; gap: 4px; padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--surface); scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.nav-button { min-width: max-content; min-height: 52px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 720; }
.nav-button:hover { color: var(--brand); }
.nav-button.active { border-bottom-color: var(--brand); color: var(--brand-dark); }

.workspace { width: min(1240px, 100%); min-height: 75vh; margin: 0 auto; padding: 28px 22px 60px; }
.view { display: none; }
.view.active { display: block; animation: enter .16s ease-out; }
@keyframes enter { from { opacity: .2; transform: translateY(3px); } }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading p:not(.eyebrow) { margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 5px; color: var(--brand); font-size: .75rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.muted { color: var(--muted); }
.save-note { align-self: center; padding: 8px 12px; border-radius: 999px; background: var(--soft); color: var(--brand-dark); font-size: .8rem; white-space: nowrap; }
.status-message { position: fixed; z-index: 60; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; transform: translateY(150%); border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); transition: transform .2s ease; }
.status-message.show { transform: translateY(0); }
.status-message.error { background: var(--danger); }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.metric-card { min-height: 140px; padding: 20px; }
.metric-card > span, .metric-card small { display: block; color: var(--muted); }
.metric-card > span { font-size: .82rem; font-weight: 700; }
.metric-card strong { display: block; margin: 10px 0 7px; font-size: clamp(1.55rem, 2.6vw, 2.1rem); line-height: 1; }
.metric-card small { font-size: .75rem; }
.metric-card.accent { border-color: transparent; background: linear-gradient(135deg, var(--brand), #0d8174); color: white; }
.metric-card.accent > span, .metric-card.accent small { color: #d9f1eb; }
.panel { padding: 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-heading p { margin-bottom: 0; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 18px 0; }
.stack { display: grid; align-content: start; gap: 18px; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-action { display: grid; grid-template-columns: 38px 1fr; grid-template-rows: auto auto; gap: 0 10px; min-height: 82px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; color: var(--ink); text-align: left; }
.quick-action:hover { border-color: var(--brand); background: var(--soft); }
.quick-action > span { grid-row: 1 / 3; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--soft); color: var(--brand); font-size: 1.3rem; }
.quick-action strong { align-self: end; }
.quick-action small { color: var(--muted); }
.text-button { min-height: 40px; padding: 4px 6px; border: 0; background: transparent; color: var(--brand); font-weight: 750; }
.progress { height: 11px; overflow: hidden; border-radius: 999px; background: #e6ecea; }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--brand); transition: width .25s ease; }
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.mini-stats > div { padding: 10px; border-radius: 10px; background: var(--soft); }
.mini-stats span, .mini-stats strong { display: block; }
.mini-stats span { color: var(--muted); font-size: .72rem; }

.button { min-height: 44px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); font-weight: 720; }
.button:hover { border-color: var(--brand); color: var(--brand-dark); }
.button.primary { border-color: var(--brand); background: var(--brand); color: white; }
.button.primary:hover { background: var(--brand-dark); color: white; }
.button.danger { border-color: #dfaaa5; color: var(--danger); }
.button.danger:hover { background: var(--danger-soft); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(11,107,97,.25); outline-offset: 2px; }

.transaction-list { display: grid; gap: 8px; }
.transaction-row { display: grid; grid-template-columns: minmax(160px, 2fr) minmax(110px, 1fr) minmax(90px, .7fr) minmax(95px, .7fr); align-items: center; gap: 12px; width: 100%; min-height: 66px; padding: 10px 12px; border: 1px solid transparent; border-radius: 11px; background: #fbfdfc; color: var(--ink); text-align: left; }
.transaction-row:hover { border-color: var(--line); background: var(--soft); }
.transaction-main strong, .transaction-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transaction-main small, .transaction-date, .transaction-category { color: var(--muted); font-size: .8rem; }
.transaction-amount { justify-self: end; font-weight: 800; }
.transaction-amount.income { color: var(--positive); }
.empty-state { padding: 32px 16px; color: var(--muted); text-align: center; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px auto; align-items: end; gap: 14px; margin-bottom: 16px; }
.toolbar label > span, .form-grid label > span:first-child, .money-input > span:first-child, .budget-fields label > span:first-child { display: block; margin-bottom: 6px; color: #405151; font-size: .78rem; font-weight: 750; }
.toolbar input, .toolbar select, .form-grid input, .form-grid select, .budget-fields input, .money-input input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #bccac7; border-radius: 10px; background: white; color: var(--ink); }
.toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: white; }
.summary-strip > span { padding: 14px 18px; border-right: 1px solid var(--line); }
.summary-strip > span:last-child { border: 0; }
.summary-strip small, .summary-strip strong { display: block; }
.summary-strip small { color: var(--muted); }
.table-panel { padding: 10px; }

.budget-layout { display: grid; grid-template-columns: minmax(320px, .8fr) minmax(0, 1.2fr); gap: 18px; }
.money-input { display: block; margin-bottom: 18px; }
.money-input.prominent { padding: 14px; border-radius: 12px; background: var(--soft); }
.input-wrap { position: relative; display: block; }
.input-wrap b { position: absolute; z-index: 1; top: 50%; left: 13px; transform: translateY(-50%); color: var(--muted); }
.input-wrap input { padding-left: 28px; }
.budget-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary-grid.compact { grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 18px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.summary-grid.compact > div { padding: 14px; background: white; }
.summary-grid.compact span, .summary-grid.compact strong { display: block; }
.summary-grid.compact span { color: var(--muted); font-size: .74rem; }
.summary-grid.compact strong { margin-top: 5px; }
.notice { padding: 12px 14px; border-left: 4px solid var(--brand); border-radius: 8px; background: var(--soft); }
.notice.warning { border-left-color: var(--accent); background: #fff8e8; }
.comparison-list { display: grid; gap: 13px; }
.comparison-item { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 10px; }
.comparison-track { height: 9px; overflow: hidden; border-radius: 999px; background: #e7eceb; }
.comparison-track span { display: block; height: 100%; background: var(--brand); }
.comparison-track span.over { background: var(--danger); }
.comparison-item small { color: var(--muted); }

.goal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.goal-card { padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.goal-card button { width: 100%; min-height: 44px; margin-top: 14px; }
.goal-amounts { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .82rem; }
.goal-progress { height: 10px; margin: 15px 0 8px; overflow: hidden; border-radius: 999px; background: #e5ece9; }
.goal-progress span { display: block; height: 100%; background: var(--brand); }
.goal-date { margin: 12px 0 0; color: var(--muted); font-size: .8rem; }
.coach-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.coach-card { padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.coach-card .coach-label { color: var(--brand); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.coach-card p:last-child { margin-bottom: 0; color: var(--muted); }
.coach-disclaimer { margin-top: 18px; }

.trust-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.trust-card { box-shadow: none; }
.trust-card p { margin-bottom: 0; color: var(--muted); }
.trust-icon { display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 14px; border-radius: 12px; background: var(--soft); color: var(--brand); font-size: 1.2rem; font-weight: 800; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 18px; border-color: #ecc3bf; background: var(--danger-soft); }
.danger-zone p { margin-bottom: 0; }
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px; padding: 24px 0 0; font-size: .88rem; }

.modal { width: min(660px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto; border: 0; border-radius: 18px; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.modal::backdrop { background: rgba(12,30,28,.62); backdrop-filter: blur(2px); }
.modal form { padding: 22px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--soft); color: var(--ink); font-size: 1.6rem; }
.type-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 16px; padding: 0; border: 0; }
.type-choice legend { margin-bottom: 7px; color: #405151; font-size: .78rem; font-weight: 750; }
.type-choice label { position: relative; }
.type-choice input { position: absolute; opacity: 0; }
.type-choice span { display: grid; place-items: center; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; font-weight: 750; }
.type-choice input:checked + span { border-color: var(--brand); background: var(--soft); color: var(--brand-dark); }
.type-choice input:focus-visible + span { outline: 3px solid rgba(11,107,97,.25); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label.wide { grid-column: 1 / -1; }
.form-error { min-height: 24px; margin: 10px 0 0; color: var(--danger); font-size: .86rem; }
.modal-actions { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 9px; margin-top: 18px; }
.small-modal { width: min(480px, calc(100% - 28px)); }

@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .two-column, .budget-layout { grid-template-columns: 1fr; }
  .goal-grid, .trust-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr 180px; }
  .toolbar-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 620px) {
  .app-header { min-height: 70px; }
  .brand strong { font-size: .9rem; }
  .brand-mark { width: 40px; height: 40px; }
  .sandbox-badge { display: none; }
  .header-actions .button { min-width: 44px; padding: 9px 11px; font-size: 0; }
  .header-actions .button::after { content: "+"; font-size: 1.3rem; }
  .main-nav { top: 70px; }
  .nav-button { min-height: 49px; padding: 0 12px; }
  .workspace { padding: 22px 14px 50px; }
  .page-heading { display: block; }
  .page-heading > .button { width: 100%; margin-top: 12px; }
  .save-note { display: inline-block; margin-top: 8px; white-space: normal; }
  .summary-grid { gap: 10px; }
  .metric-card { min-height: 120px; padding: 15px; }
  .metric-card strong { font-size: 1.45rem; }
  .quick-grid, .budget-fields, .form-grid, .coach-grid, .goal-grid, .trust-grid { grid-template-columns: 1fr; }
  .form-grid label.wide { grid-column: auto; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar-actions { grid-column: auto; display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar-actions .primary { grid-column: 1 / -1; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .summary-strip > span:nth-child(2) { border-right: 0; }
  .summary-strip > span:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .transaction-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .transaction-date, .transaction-category { grid-row: 2; }
  .transaction-category { justify-self: end; }
  .transaction-amount { grid-column: 2; grid-row: 1; }
  .summary-grid.compact { grid-template-columns: 1fr; }
  .comparison-item { grid-template-columns: 90px 1fr; }
  .comparison-item small { grid-column: 1 / -1; }
  .danger-zone { display: block; }
  .danger-zone .button { width: 100%; margin-top: 12px; }
  .modal form { padding: 18px; }
  .modal-actions { grid-template-columns: 1fr 1fr; }
  .modal-actions span { display: none; }
  .modal-actions .danger { grid-column: 1 / -1; grid-row: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
