:root {
  color-scheme: light;
  --bg: #f6f3eb;
  --surface: #fffdf7;
  --surface-2: #ebe5d8;
  --ink: #1f2523;
  --muted: #69706c;
  --faint: #9b9990;
  --line: #ded7c9;
  --positive: #2f8054;
  --negative: #b9433f;
  --amber: #c7801f;
  --cyan: #367b86;
  --shadow: 0 16px 40px rgba(31, 37, 35, 0.12);
  --radius: 8px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(199, 128, 31, 0.08), transparent 280px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
  width: min(100vw, 460px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(31, 37, 35, 0.04);
}

.screen {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 14px calc(92px + env(safe-area-inset-bottom));
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 10px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.icon-button,
.text-button {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 120ms ease, background 160ms ease, border-color 160ms ease;
}

.text-button {
  padding: 0 12px;
  font-weight: 700;
}

.icon-button:active,
.text-button:active,
.quick-add:active,
.tab-button:active {
  transform: scale(0.97);
}

.metric-panel,
.panel,
.row-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 247, 0.92);
}

.metric-panel {
  min-height: 150px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.money-xl {
  margin: 0;
  font-size: 38px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.money-lg {
  font-size: 26px;
  line-height: 1.05;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.money-md,
.number {
  font-variant-numeric: tabular-nums;
}

.metric-subgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.micro-card {
  min-height: 62px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.micro-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.micro-card strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.section {
  margin-top: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.ledger-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(82px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.strip-item {
  min-width: 82px;
  min-height: 72px;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.strip-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.strip-item strong {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--negative);
}

.neutral {
  color: var(--muted);
}

.progress-shell {
  height: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--amber), #e0b35c);
}

.panel {
  padding: 12px;
}

.row-list {
  display: grid;
  gap: 8px;
}

.data-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.row-main {
  min-width: 0;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
}

.row-title span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-value {
  text-align: right;
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.good {
  color: var(--positive);
  background: rgba(47, 128, 84, 0.12);
}

.pill.warn {
  color: var(--amber);
  background: rgba(199, 128, 31, 0.14);
}

.pill.bad {
  color: var(--negative);
  background: rgba(185, 67, 63, 0.12);
}

.allocation {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.allocation-item {
  min-height: 76px;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.allocation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
}

.bar {
  height: 7px;
  border-radius: 7px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 7px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(31, 37, 35, 0.08);
}

.tab-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100vw, 460px);
  min-height: calc(64px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.94);
  backdrop-filter: blur(14px);
}

.tab-button {
  min-height: 52px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.tab-button.is-active {
  color: var(--ink);
  background: var(--surface-2);
}

.tab-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  font-size: 11px;
}

.quick-add {
  position: fixed;
  right: max(16px, calc((100vw - 460px) / 2 + 16px));
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 25;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 120ms ease, opacity 160ms ease;
}

.quick-add span {
  transform: translateY(-1px);
  font-size: 28px;
  line-height: 1;
}

.quick-add.is-hidden {
  pointer-events: none;
  opacity: 0;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(31, 37, 35, 0.38);
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 45;
  width: min(100vw, 460px);
  max-height: 88vh;
  overflow: auto;
  transform: translateX(-50%);
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  box-shadow: 0 -18px 48px rgba(31, 37, 35, 0.2);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-title {
  margin: 0;
  font-size: 18px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.type-grid button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.type-grid button.is-active {
  background: var(--ink);
  color: var(--surface);
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.primary-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 800;
}

.secondary-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.assumption-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.setting-row {
  min-height: 54px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #171b1a;
    --surface: #222725;
    --surface-2: #2d332f;
    --ink: #f3efe4;
    --muted: #b2b5ad;
    --faint: #7f837d;
    --line: #3b423d;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  }

  .app-shell {
    background: var(--bg);
  }

  .tab-bar {
    background: rgba(34, 39, 37, 0.94);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
