:root {
  color-scheme: light;
  --bg: #f2f5f3;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #6f7872;
  --line: #dde5df;
  --green: #2f9d69;
  --green-2: #48b88a;
  --coral: #e9725d;
  --teal: #238d95;
  --gold: #d79b24;
  --violet: #7367d8;
  --shadow: 0 18px 52px rgba(41, 58, 49, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: radial-gradient(circle at 20% 12%, rgba(72, 184, 138, 0.16), transparent 32%),
    linear-gradient(135deg, #eef5f0 0%, #f6f1ec 48%, #edf4f5 100%);
}

body {
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  font: inherit;
}

.phone-shell {
  width: min(100%, 430px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 0;
}

.app-screen {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.app-screen::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 168px;
  background: linear-gradient(160deg, rgba(47, 157, 105, 0.14), rgba(35, 141, 149, 0.08));
  pointer-events: none;
}

.topbar,
.balance-card,
.toolbar,
.budget-section,
.cashflow-panel,
.transactions {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 20px 14px;
}

.profile {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: #193d31;
  color: #f7fbf8;
  font-weight: 800;
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 3px;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: #fff;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.icon-button.light {
  background: #eef4f0;
}

.alert-dot::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 11px;
  width: 7px;
  height: 7px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--coral);
}

.balance-card {
  margin: 4px 16px 14px;
  padding: 18px 18px 15px;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 8px;
  background: linear-gradient(145deg, #183d32, #24634f 52%, #2f8068);
  color: #f7fbf8;
  box-shadow: 0 18px 36px rgba(32, 94, 72, 0.24);
}

.balance-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.balance-card .muted {
  color: rgba(247, 251, 248, 0.72);
}

.balance-amount {
  display: block;
  margin-top: 6px;
  font-size: clamp(30px, 8vw, 38px);
  line-height: 1;
  letter-spacing: 0;
}

.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.chip svg {
  width: 15px;
  height: 15px;
}

.chip.positive {
  background: rgba(222, 255, 237, 0.18);
  color: #dfffea;
}

.sparkline {
  display: block;
  width: 100%;
  height: 86px;
  margin: 12px 0 8px;
}

.spark-area {
  fill: url("#lineFill");
}

.spark-path {
  fill: none;
  stroke: #9cf0c4;
  stroke-linecap: round;
  stroke-width: 4;
}

.sparkline circle {
  fill: #effff6;
  stroke: #45c18d;
  stroke-width: 3;
}

.balance-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.balance-metrics span,
.balance-metrics strong {
  display: block;
}

.balance-metrics span {
  color: rgba(247, 251, 248, 0.66);
  font-size: 11px;
}

.balance-metrics strong {
  margin-top: 5px;
  font-size: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 14px;
}

.segmented,
.entry-type {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 1;
  min-height: 40px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.segmented button,
.entry-type button {
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.segmented button.active,
.entry-type button.active {
  background: #193d31;
  color: #fff;
  box-shadow: 0 6px 14px rgba(25, 61, 49, 0.16);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 12px;
}

.text-button {
  min-height: 30px;
  padding: 0 2px;
  background: transparent;
  color: var(--green);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.budget-section {
  padding-bottom: 16px;
}

.budget-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px;
}

.budget-item {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.category-icon,
.row-icon {
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.category-icon {
  width: 34px;
  height: 34px;
  margin-bottom: 10px;
}

.category-icon svg,
.row-icon svg {
  width: 18px;
  height: 18px;
}

.budget-item p {
  color: var(--muted);
  font-size: 12px;
}

.budget-item strong {
  display: block;
  margin: 4px 0 10px;
  font-size: 18px;
  line-height: 1.1;
}

.progress {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecf0ed;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.accent-green .category-icon,
.accent-green .progress span,
.row-icon.green {
  background: rgba(47, 157, 105, 0.14);
  color: var(--green);
}

.accent-green .progress span {
  background: var(--green);
}

.accent-coral .category-icon,
.accent-coral .progress span,
.row-icon.coral {
  background: rgba(233, 114, 93, 0.14);
  color: var(--coral);
}

.accent-coral .progress span {
  background: var(--coral);
}

.accent-teal .category-icon,
.accent-teal .progress span,
.row-icon.teal {
  background: rgba(35, 141, 149, 0.14);
  color: var(--teal);
}

.accent-teal .progress span {
  background: var(--teal);
}

.accent-gold .category-icon,
.accent-gold .progress span {
  background: rgba(215, 155, 36, 0.17);
  color: var(--gold);
}

.accent-gold .progress span {
  background: var(--gold);
}

.cashflow-panel {
  padding: 0 0 16px;
}

.cashflow-bars {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin: 0 16px;
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.cashflow-bars > div {
  display: grid;
  min-width: 0;
  grid-template-rows: auto auto 86px;
  justify-items: center;
  gap: 5px;
}

.cashflow-bars span {
  color: var(--muted);
  font-size: 11px;
}

.cashflow-bars strong {
  font-size: 13px;
}

.vertical-bar {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 40px;
  height: 86px;
  align-items: flex-end;
  overflow: hidden;
  border-radius: 8px;
  background: #edf1ee;
}

.vertical-bar span {
  display: block;
  width: 100%;
  border-radius: 8px 8px 0 0;
}

.vertical-bar.income span {
  background: var(--green);
}

.vertical-bar.fixed span {
  background: var(--coral);
}

.vertical-bar.flexible span {
  background: var(--teal);
}

.vertical-bar.invest span {
  background: var(--violet);
}

.transactions {
  padding-bottom: 104px;
}

.transaction-list {
  display: grid;
  gap: 10px;
  padding: 0 16px;
}

.transaction-row {
  display: grid;
  min-height: 66px;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.row-icon {
  width: 42px;
  height: 42px;
}

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

.row-main strong,
.row-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-main strong {
  font-size: 14px;
}

.row-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.transaction-row em {
  color: #cc5f50;
  font-size: 14px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.transaction-row em.income-text {
  color: var(--green);
}

.fab {
  position: fixed;
  right: max(18px, calc((100vw - 430px) / 2 + 18px));
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 50%;
  background: #193d31;
  color: #fff;
  box-shadow: 0 16px 34px rgba(25, 61, 49, 0.32);
  cursor: pointer;
}

.fab svg {
  width: 27px;
  height: 27px;
  stroke-width: 2.6;
}

.bottom-nav {
  position: fixed;
  right: max(0px, calc((100vw - 430px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 430px) / 2));
  z-index: 5;
  display: grid;
  max-width: 430px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 auto;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  display: grid;
  min-width: 0;
  min-height: 52px;
  place-items: center;
  gap: 3px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.bottom-nav button.active {
  color: var(--green);
}

.bottom-nav svg {
  width: 21px;
  height: 21px;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: none;
  background: rgba(23, 32, 28, 0.38);
}

.entry-sheet {
  position: fixed;
  right: max(0px, calc((100vw - 430px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 430px) / 2));
  z-index: 8;
  max-width: 430px;
  margin: 0 auto;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  background: #fff;
  box-shadow: 0 -22px 48px rgba(23, 32, 28, 0.18);
  transform: translateY(104%);
  transition: transform 240ms ease;
}

.entry-sheet.open {
  transform: translateY(0);
}

.scrim.open {
  display: block;
}

.sheet-handle {
  width: 44px;
  height: 5px;
  margin: 0 auto 14px;
  border-radius: 999px;
  background: #d7dfda;
}

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

.entry-type {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.amount-field {
  display: flex;
  min-height: 58px;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.amount-field span {
  color: var(--muted);
  font-size: 24px;
  font-weight: 800;
}

.amount-field output {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.category-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.category-strip button {
  display: grid;
  min-width: 0;
  min-height: 68px;
  place-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.category-strip button.selected {
  border-color: rgba(47, 157, 105, 0.3);
  background: rgba(47, 157, 105, 0.1);
  color: var(--green);
}

.category-strip svg {
  width: 20px;
  height: 20px;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 12px;
  padding: 0 12px;
  border-radius: 8px;
  background: #f4f7f5;
  color: var(--muted);
  font-size: 13px;
}

.account-row strong {
  color: var(--ink);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.keypad button {
  display: grid;
  min-width: 0;
  min-height: 48px;
  place-items: center;
  border-radius: 8px;
  background: #f0f4f1;
  color: var(--ink);
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
}

.keypad svg {
  width: 20px;
  height: 20px;
}

.keypad .save-key {
  grid-row: span 2;
  background: #193d31;
  color: #fff;
  font-size: 15px;
}

@media (min-width: 560px) {
  body {
    display: grid;
    min-height: 100svh;
    place-items: center;
    padding: 24px;
  }

  .phone-shell {
    min-height: min(900px, calc(100svh - 48px));
  }

  .app-screen {
    min-height: min(900px, calc(100svh - 48px));
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 28px;
  }

  .app-screen::-webkit-scrollbar {
    width: 0;
  }
}

@media (max-width: 360px) {
  .balance-metrics,
  .cashflow-bars {
    gap: 6px;
  }

  .balance-card,
  .budget-grid,
  .transaction-list,
  .cashflow-bars {
    margin-right: 12px;
    margin-left: 12px;
  }

  .budget-grid {
    padding: 0;
  }

  .balance-card {
    padding-right: 14px;
    padding-left: 14px;
  }

  .balance-amount {
    font-size: 29px;
  }

  .amount-field output {
    font-size: 36px;
  }
}
