:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --primary: #07a35a;
  --primary-deep: #146c43;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: #e5e5ea;
  --income: #16a34a;
  --expense: #ff6b5f;
  --warning: #f5a623;
  --blue: #4a90e2;
  --purple: #7b61ff;
  --shadow: 0 18px 48px rgba(29, 29, 31, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  padding: 56px 20px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 36px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(7, 163, 90, 0.26);
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

.brand-lockup h1 {
  margin: 2px 0 0;
  font-size: 30px;
}

.auth-card,
.entry-card,
.chart-card,
.insight-card,
.settings-card,
.settings-input,
.hero-balance,
.metric-card {
  background: var(--card);
  border: 1px solid rgba(229, 229, 234, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card {
  padding: 24px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
  padding: 4px;
  border-radius: 8px;
  background: #f0f2f3;
}

.auth-tabs button {
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.auth-tabs button.active {
  background: white;
  color: var(--primary-deep);
  box-shadow: 0 8px 18px rgba(29, 29, 31, 0.08);
}

.auth-pane {
  display: none;
}

.auth-pane.active {
  display: block;
}

.auth-card h2,
.panel-title h2 {
  margin-bottom: 8px;
  font-size: 28px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.6;
}

label {
  display: grid;
  gap: 8px;
  color: #3b3b3d;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfd;
  color: var(--text);
  padding: 14px 15px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(7, 163, 90, 0.55);
  box-shadow: 0 0 0 4px rgba(7, 163, 90, 0.1);
}

.auth-card label + label,
.auth-card button,
.entry-card label + label,
.entry-card button {
  margin-top: 14px;
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  min-height: 52px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.secondary-button {
  background: #edf8f3;
  color: var(--primary-deep);
}

.danger-button {
  background: #fff1f0;
  color: #c24135;
}

.hint {
  margin: 16px 0 0;
  font-size: 12px;
}

.inline-auth-button {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
}

.phone-app {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 96px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -16px 8px;
  padding: 14px 16px 12px;
  background: rgba(247, 248, 250, 0.88);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: 24px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.sync-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 7px rgba(7, 163, 90, 0.12);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-balance {
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(7, 163, 90, 0.1), rgba(255, 255, 255, 0) 62%),
    white;
}

.hero-balance p {
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 700;
}

.hero-balance strong {
  display: block;
  font-size: 42px;
  line-height: 1.1;
}

.budget-row,
.section-heading,
.filter-bar,
.record-item,
.settings-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.budget-row {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.budget-track {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  background: #edf0f2;
  overflow: hidden;
}

.budget-track span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.3s ease;
}

.insight-strip,
.insight-card {
  margin-top: 16px;
  padding: 16px;
  border-radius: 8px;
  background: #ebf7f1;
  color: var(--primary-deep);
  line-height: 1.6;
  font-weight: 700;
}

.section-heading {
  margin: 24px 0 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.ghost-button {
  background: transparent;
  color: var(--primary);
  font-weight: 800;
}

.quick-form {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 10px;
}

.quick-form button {
  border-radius: 8px;
  background: var(--text);
  color: white;
  font-weight: 800;
}

.records-list {
  display: grid;
  gap: 10px;
}

.records-list.compact .record-item:nth-child(n + 4) {
  display: none;
}

.record-item {
  padding: 14px;
  border-radius: 8px;
  background: white;
  border: 1px solid rgba(229, 229, 234, 0.86);
  cursor: pointer;
  text-align: left;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease;
}

.record-item:focus-visible {
  border-color: rgba(7, 163, 90, 0.55);
  box-shadow: 0 0 0 4px rgba(7, 163, 90, 0.1);
  outline: none;
}

.record-item:active {
  transform: scale(0.99);
  border-color: rgba(7, 163, 90, 0.35);
}

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

.category-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f0f3f2;
  color: var(--primary-deep);
  font-weight: 900;
  flex: 0 0 auto;
}

.record-title {
  margin: 0 0 4px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.record-amount {
  font-weight: 900;
  white-space: nowrap;
}

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

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

.empty-state {
  padding: 28px 18px;
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  background: white;
  border: 1px dashed var(--line);
}

.panel-title {
  padding-top: 10px;
}

.entry-card {
  padding: 18px;
}

.field-grid,
.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.filter-bar {
  align-items: stretch;
  margin: 14px 0;
}

.filter-bar select {
  max-width: 112px;
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
}

.chart-card {
  margin-top: 16px;
  padding: 18px;
}

.category-chart {
  display: grid;
  gap: 12px;
}

.chart-row {
  display: grid;
  grid-template-columns: 56px 1fr 72px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
}

.chart-track {
  height: 10px;
  border-radius: 999px;
  background: #edf0f2;
  overflow: hidden;
}

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

.day-bars {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 6px;
  align-items: end;
  height: 132px;
}

.day-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: end;
  color: var(--muted);
  font-size: 10px;
}

.day-bar span {
  width: 100%;
  min-height: 6px;
  border-radius: 999px 999px 4px 4px;
  background: var(--primary);
}

.settings-card,
.settings-input {
  margin-top: 12px;
  padding: 16px;
}

.settings-card span,
.settings-input {
  font-weight: 900;
}

.settings-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-card strong {
  color: var(--primary);
  white-space: nowrap;
}

.settings-input input {
  margin-top: 10px;
}

#profileView .secondary-button,
#profileView .danger-button {
  margin-top: 12px;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  min-height: 72px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(229, 229, 234, 0.9);
  box-shadow: 0 20px 60px rgba(29, 29, 31, 0.16);
  backdrop-filter: blur(18px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px;
}

.tab {
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 800;
}

.tab span {
  font-size: 22px;
  line-height: 1;
}

.tab.active {
  background: #edf8f3;
  color: var(--primary-deep);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%) translateY(16px);
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(29, 29, 31, 0.92);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 9;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(29, 29, 31, 0.28);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.detail-sheet {
  width: min(520px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 10px 18px 18px;
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 24px 70px rgba(29, 29, 31, 0.24);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-heading {
  margin-top: 8px;
}

#recordEditForm label + label {
  margin-top: 14px;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 10px;
  margin-top: 16px;
}

.sheet-actions .danger-button,
.sheet-actions .primary-button {
  margin-top: 0;
}

@media (min-width: 760px) {
  body {
    background:
      radial-gradient(circle at top left, rgba(7, 163, 90, 0.12), transparent 32%),
      var(--bg);
  }

  .auth-screen {
    max-width: 460px;
    margin: 0 auto;
  }

  .phone-app {
    padding-top: 28px;
  }
}
