:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --ink: #14202e;
  --muted: #6c7a89;
  --line: #dce4ed;
  --blue: #2267d1;
  --green: #167a55;
  --red: #c44747;
  --amber: #a76200;
  --shadow: 0 18px 48px rgba(29, 45, 68, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  padding: env(safe-area-inset-top) 16px calc(84px + env(safe-area-inset-bottom));
}

.topbar,
.section-heading,
.month-switcher,
.metric-row,
.transaction-main,
.change-title,
.inline-form,
.settings-actions,
.dialog-heading,
.dialog-actions,
.topbar-actions,
.manager-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.transaction-main {
  align-items: flex-start;
}

.topbar {
  padding: 18px 0 10px;
}

.brand-block {
  min-width: 0;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f1ff;
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(34, 103, 209, 0.16);
}

.brand-icon svg {
  width: 23px;
  height: 23px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
}

.eyebrow,
.muted,
small {
  color: var(--muted);
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.panel,
.quick-stats,
.filters {
  margin-top: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(29, 45, 68, 0.06);
}

.month-switcher {
  margin: 8px 0 10px;
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
}

.compact-month-switcher {
  margin-top: 0;
}

.month-center {
  border: 0;
  background: transparent;
  min-height: 62px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink);
  border-radius: 8px;
}

.month-center:active {
  background: var(--surface-strong);
}

.icon-button,
.ghost-button,
.compact-button,
.link-button,
.primary-button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
}

.icon-button {
  width: 40px;
  background: var(--surface);
  color: var(--ink);
  font-size: 26px;
  border: 1px solid var(--line);
}

.ghost-button,
.compact-button,
.secondary-button {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 700;
}

.compact-button,
.primary-button,
.danger-button {
  padding: 0 16px;
}

.link-button {
  background: transparent;
  color: var(--blue);
  padding: 0;
  min-height: auto;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.danger-button {
  background: #fff1f1;
  color: var(--red);
  border: 1px solid #f1caca;
  font-weight: 800;
}

.secondary-button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.budget-panel strong {
  display: block;
  margin-top: 3px;
  font-size: 24px;
}

.status-pill {
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.warning {
  background: #fff5db;
  color: var(--amber);
}

.status-pill.over {
  background: #fff1f1;
  color: var(--red);
}

.progress-track {
  height: 10px;
  background: var(--surface-strong);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 14px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--blue);
  border-radius: inherit;
  transition: width 180ms ease;
}

.progress-fill.warning {
  background: var(--amber);
}

.progress-fill.over {
  background: var(--red);
}

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

.quick-stats div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.quick-stats span,
.transaction-meta,
.change-meta {
  color: var(--muted);
  font-size: 12px;
}

.quick-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 19px;
  overflow-wrap: anywhere;
}

.transaction-list,
.change-list {
  display: grid;
  gap: 10px;
}

.transaction-card,
.change-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.transaction-card {
  text-align: left;
  width: 100%;
  display: grid;
  gap: 8px;
  transition: border-color 140ms ease, transform 140ms ease;
}

.transaction-card:active {
  transform: scale(0.995);
  border-color: #b9c7d7;
}

.transaction-name,
.change-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.transaction-amount {
  font-weight: 900;
  white-space: nowrap;
  padding-top: 2px;
}

.transaction-amount.expense {
  color: var(--red);
}

.transaction-amount.income {
  color: var(--green);
}

.transaction-tags,
.chip-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.date-filter {
  display: grid;
  grid-template-columns: 1fr 46px;
  gap: 8px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 46px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

#amountInput::-webkit-inner-spin-button,
#amountInput::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

#amountInput {
  appearance: textfield;
  -moz-appearance: textfield;
}

#noteInput {
  height: 46px;
  min-height: 46px;
  resize: none;
  overflow-y: auto;
}

.sticky-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 0;
  background: var(--bg);
}

.summary-panel {
  border-left: 4px solid var(--blue);
}

.summary-panel p:last-child {
  margin-top: 8px;
  line-height: 1.5;
}

.bar-track {
  height: 8px;
  background: var(--surface-strong);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.bar-fill {
  height: 100%;
  background: var(--blue);
}

.bar-fill.decrease {
  background: var(--green);
}

.change-delta {
  color: var(--red);
  font-weight: 900;
  white-space: nowrap;
}

.change-delta.decrease {
  color: var(--green);
}

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

.inline-form input {
  flex: 1;
}

.inline-form select {
  flex: 1;
}

.tag-picker {
  position: relative;
  flex: 1;
  min-width: 0;
}

.tag-picker-button {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
}

.tag-picker-button span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-picker-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(29, 45, 68, 0.16);
}

.tag-picker-options {
  display: grid;
  max-height: 180px;
  overflow-y: auto;
  padding: 6px;
}

.tag-picker-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px;
  border-radius: 6px;
}

.tag-picker-option:active {
  background: var(--surface-strong);
}

.tag-picker-option input {
  width: 20px;
  min-height: 20px;
  margin: 0;
}

.tag-picker-empty {
  color: var(--muted);
  padding: 12px 8px;
}

.tag-picker-done {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--blue);
  font-weight: 800;
}

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

.manager-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.manager-row strong {
  display: block;
  overflow-wrap: anywhere;
}

.usage-count {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.manager-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
  font-weight: 800;
}

.mini-button.danger {
  color: var(--red);
  border-color: #f1caca;
  background: #fff7f7;
}

.mini-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.pie-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

.pie-box {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.pie-chart {
  width: 100%;
  max-width: 156px;
  aspect-ratio: 1;
  margin: 0 auto;
}

.pie-legend {
  display: grid;
  gap: 6px;
}

.legend-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.settings-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.storage-health-panel {
  gap: 14px;
}

.health-badge {
  border-radius: 999px;
  padding: 5px 9px;
  background: #e8f6ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.storage-health-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.storage-health-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.storage-health-list dt {
  color: var(--muted);
}

.storage-health-list dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.status-warning {
  color: var(--amber);
}

.backup-reminder {
  border: 1px solid #efd4a7;
  border-radius: 8px;
  padding: 10px;
  background: #fff9ee;
  color: #805600;
  font-size: 13px;
  line-height: 1.5;
}

#importCsvInput,
#importBackupInput {
  display: none;
}

.danger-zone {
  border-color: #f1caca;
}

.update-banner {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 398px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #bdd3f5;
  border-radius: 10px;
  padding: 10px 12px;
  background: #f5f9ff;
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(29, 45, 68, 0.18);
  font-weight: 800;
}

.update-banner button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 430px);
  display: grid;
  grid-template-columns: 1fr 1fr 68px 1fr 1fr;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(244, 247, 251, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.tab {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 6px 18px rgba(29, 45, 68, 0.08);
}

.entry-tab {
  border: 0;
  border-radius: 999px;
  min-height: 58px;
  width: 58px;
  justify-self: center;
  align-self: center;
  background: var(--blue);
  color: #fff;
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(34, 103, 209, 0.32);
}

.eye-button {
  display: grid;
  place-items: center;
}

.eye-button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

dialog {
  width: min(calc(100% - 24px), 430px);
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 25, 38, 0.48);
}

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

.rename-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-strong);
  border-radius: 8px;
}

.segment {
  border: 0;
  min-height: 40px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 4px 12px rgba(29, 45, 68, 0.08);
}

.hidden {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translate(-50%, 16px);
  width: min(calc(100% - 32px), 398px);
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty:empty::before {
  content: "暂无数据";
  display: block;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: start center;
  }

  .app-shell {
    margin-top: 24px;
    min-height: calc(100vh - 48px);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
}
