:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --soft: #94a3b8;
  --green: #0f766e;
  --red: #dc2626;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.active {
  background: #e6f4f2;
  color: var(--green);
  font-weight: 800;
}

.nav-icon {
  width: 24px;
  text-align: center;
}

.main {
  width: min(100%, 980px);
  padding: 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.page-header.compact {
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 14px;
  font-weight: 800;
  line-height: 20px;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 28px;
  line-height: 38px;
}

h3 {
  font-size: 18px;
  line-height: 26px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.primary,
.secondary,
.text-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary {
  background: var(--green);
  color: #fff;
}

.primary.small,
.secondary {
  min-height: 42px;
  padding: 0 18px;
}

.secondary {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
}

.primary.wide {
  width: 100%;
  min-height: 48px;
}

.text-button {
  background: transparent;
  color: var(--green);
}

.summary-card {
  padding: 26px 24px 28px;
}

.summary-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.summary-top span,
.summary-grid span,
.mini-summary span,
.total-card span {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.summary-top strong {
  font-size: 34px;
  line-height: 42px;
}

.summary-grid,
.mini-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.summary-grid {
  padding-top: 24px;
}

.summary-grid div,
.mini-summary div {
  min-width: 0;
}

.summary-grid strong,
.mini-summary strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  line-height: 28px;
  overflow-wrap: anywhere;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 12px;
}

.record-list,
.rank-list {
  overflow: hidden;
}

.empty {
  padding: 34px 18px;
  color: var(--soft);
  text-align: center;
}

.record-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 78px;
  padding: 16px 18px;
  border-bottom: 1px solid #f1f5f9;
}

.record-item:last-child {
  border-bottom: 0;
}

.dot {
  width: 10px;
  height: 10px;
  margin-top: 9px;
  border-radius: 50%;
}

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

.record-title {
  display: block;
  font-size: 17px;
  font-weight: 800;
  line-height: 24px;
}

.record-meta {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--soft);
  font-size: 14px;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-side {
  display: flex;
  min-width: 120px;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.record-amount {
  font-size: 17px;
  font-weight: 800;
  line-height: 24px;
}

.delete-button {
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

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

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

.entry-form {
  max-width: 620px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.segmented button.active {
  background: #f1f5f9;
  color: var(--red);
}

.segmented button[data-type="income"].active,
.segmented button[data-stats-type="income"].active {
  color: var(--green);
}

.amount-card {
  display: block;
  margin-top: 18px;
  padding: 24px;
}

.amount-card > span {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.amount-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.amount-row span {
  color: #334155;
  font-size: 30px;
  font-weight: 800;
}

.amount-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 42px;
  font-weight: 800;
  line-height: 50px;
}

.field-group {
  margin-top: 28px;
}

.field-group h3 {
  margin-bottom: 14px;
}

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

.category-chip {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font-weight: 800;
}

.category-chip.active {
  border-width: 2px;
  background: #fff;
}

.form-card {
  margin: 26px 0;
  overflow: hidden;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid #f1f5f9;
}

.form-row:last-child {
  border-bottom: 0;
}

.form-row span {
  flex: 0 0 78px;
  color: var(--muted);
}

.form-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  text-align: right;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="month"],
input[type="date"] {
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.mini-summary {
  margin-bottom: 22px;
  padding: 22px 20px;
}

.stats-switch {
  max-width: 520px;
}

.total-card {
  display: flex;
  min-height: 128px;
  flex-direction: column;
  justify-content: center;
  margin-top: 18px;
  padding: 0 24px;
}

.total-card strong {
  display: block;
  margin-top: 12px;
  font-size: 34px;
  line-height: 42px;
}

.rank-item {
  padding: 18px;
  border-bottom: 1px solid #f1f5f9;
}

.rank-item:last-child {
  border-bottom: 0;
}

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

.rank-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 800;
}

.rank-amount {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.bar-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.bar-fill {
  height: 8px;
  min-width: 6px;
  border-radius: 999px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    padding-bottom: 72px;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    height: 64px;
    padding: 0;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .brand {
    display: none;
  }

  .nav {
    display: grid;
    height: 100%;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
  }

  .nav-item {
    justify-content: center;
    min-height: 64px;
    flex-direction: column;
    gap: 3px;
    border-radius: 0;
    padding: 0;
    font-size: 13px;
  }

  .nav-icon {
    width: auto;
    font-size: 16px;
  }

  .main {
    width: 100%;
    padding: 22px 16px;
  }

  .page-header,
  .page-header.compact {
    align-items: flex-start;
    flex-direction: column;
  }

  h2 {
    font-size: 26px;
    line-height: 34px;
  }

  .summary-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-grid,
  .mini-summary {
    gap: 12px;
  }

  .record-item {
    grid-template-columns: 14px minmax(0, 1fr);
  }

  .record-side {
    grid-column: 2;
    min-width: 0;
    align-items: flex-start;
  }

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

  .toolbar {
    width: 100%;
  }

  .toolbar input {
    flex: 1;
  }
}

@media (max-width: 460px) {
  .summary-grid,
  .mini-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-grid strong,
  .mini-summary strong {
    font-size: 17px;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .amount-row input {
    font-size: 36px;
  }
}
