:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1677ff;
  --primary-dark: #0958d9;
  --income: #16803c;
  --expense: #d93025;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 28px);
}

.topbar,
.section-header,
.month-row,
.summary-grid,
.record-item,
.filters {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  letter-spacing: -0.04em;
}

h2 {
  font-size: 20px;
  letter-spacing: -0.02em;
}

main {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, 0.8);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.summary-card {
  display: grid;
  gap: 16px;
}

.month-row {
  justify-content: space-between;
}

.icon-button,
.ghost-button,
.delete-button {
  border: 0;
  background: #eef4ff;
  color: var(--primary-dark);
  border-radius: 999px;
}

.icon-button {
  width: 42px;
  height: 42px;
  font-size: 28px;
  line-height: 1;
}

.ghost-button,
.delete-button {
  padding: 9px 13px;
  font-weight: 600;
}

.danger,
.delete-button {
  background: #fff1f0;
  color: var(--expense);
}

.balance {
  display: grid;
  gap: 4px;
}

.balance span,
.summary-grid span,
.field span,
.field-title,
.record-meta,
.empty-state,
.photo-box p {
  color: var(--muted);
  font-size: 13px;
}

.balance strong {
  font-size: 40px;
  letter-spacing: -0.05em;
}

.summary-grid {
  justify-content: space-between;
  gap: 12px;
}

.summary-grid > div {
  flex: 1;
  display: grid;
  gap: 4px;
  border-radius: 18px;
  background: #f8fafc;
  padding: 14px;
}

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

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

form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 16px;
  background: #eef2f7;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: block;
  border-radius: 12px;
  padding: 10px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.segmented input:checked + span {
  background: var(--card);
  color: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(22, 119, 255, 0.12);
}

textarea {
  resize: vertical;
}

.photo-box {
  display: grid;
  gap: 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 18px;
  padding: 14px;
}

#photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 14px;
}

.primary-button {
  border: 0;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  padding: 14px;
  font-weight: 800;
  box-shadow: 0 10px 20px rgba(22, 119, 255, 0.22);
}

.primary-button:active {
  background: var(--primary-dark);
}

.section-header {
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.filters {
  align-items: stretch;
  gap: 8px;
  margin-bottom: 12px;
}

.filters input {
  flex: 1.4;
}

.filters select {
  flex: 1;
}

.record-list {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.record-item {
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
}

.record-icon {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1677ff, #69b1ff);
}

.record-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 3px;
}

.record-note {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-photo {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  object-fit: cover;
}

.record-side {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.delete-button {
  padding: 6px 10px;
  font-size: 12px;
}

.empty-state {
  padding: 24px 0 8px;
  text-align: center;
}

@media (max-width: 520px) {
  .filters {
    display: grid;
  }

  .record-item {
    align-items: flex-start;
  }

  .record-side {
    align-self: stretch;
  }
}
