:root {
  --bg: #f5efe3;
  --bg-2: #ebdfc7;
  --panel: rgba(255, 252, 246, 0.92);
  --panel-strong: #10231b;
  --text: #162017;
  --muted: #5e675f;
  --accent: #1f7a55;
  --accent-2: #e88c39;
  --warning: #d98c1d;
  --danger: #b63f2b;
  --line: rgba(22, 32, 23, 0.12);
  --line-strong: rgba(22, 32, 23, 0.2);
  --shadow: 0 24px 60px rgba(40, 28, 12, 0.14);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    "Avenir Next",
    "Segoe UI",
    "Helvetica Neue",
    sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(232, 140, 57, 0.2), transparent 25%),
    radial-gradient(circle at bottom right, rgba(31, 122, 85, 0.18), transparent 22%),
    linear-gradient(135deg, var(--bg), #faf7f0 50%, var(--bg-2));
}

button,
input,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 12px 8px 20px;
}

.eyebrow,
.section-kicker,
.display-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

h1,
h2,
h3,
legend {
  margin: 0;
  font-family:
    "Iowan Old Style",
    "Palatino Linotype",
    "Book Antiqua",
    serif;
  font-weight: 700;
  letter-spacing: -0.03em;
}

h1 {
  font-size: clamp(2.7rem, 7vw, 4.8rem);
  line-height: 0.94;
}

h2 {
  font-size: 1.7rem;
}

.hero-text {
  max-width: 640px;
  margin: 14px 0 0;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--muted);
}

.hero-actions,
.filters,
.dialog-actions,
.transaction-actions,
.segmented,
.entry-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 8px 18px;
}

.tab-button,
.segment {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--panel-strong);
  background: rgba(255, 255, 255, 0.55);
  transition: transform 180ms ease, background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.tab-button.is-active,
.segment.is-active {
  color: #fff9f1;
  background: linear-gradient(135deg, var(--accent), #15553a);
  box-shadow: 0 12px 26px rgba(31, 122, 85, 0.2);
}

.view-stack {
  position: relative;
}

.view {
  display: none;
  animation: view-enter 240ms ease;
}

.view.is-active {
  display: block;
}

@keyframes view-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-accent {
  background:
    linear-gradient(180deg, rgba(31, 122, 85, 0.08), rgba(255, 252, 246, 0.96)),
    var(--panel);
}

.panel-hero {
  grid-column: 1 / -1;
}

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

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16, 35, 27, 0.08);
  color: var(--panel-strong);
  font-size: 0.86rem;
  font-weight: 700;
}

.badge-soft {
  background: rgba(255, 255, 255, 0.68);
}

.grid-form,
.entry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.entry-form {
  grid-template-columns: 1fr;
}

.grid-form label,
.dialog-form label,
.entry-row label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 700;
}

.entry-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 14px;
}

.full-span,
.switch {
  grid-column: 1 / -1;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 16px;
  padding: 14px 16px;
  color: var(--text);
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(31, 122, 85, 0.25);
  outline-offset: 2px;
}

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

.switch input {
  width: 20px;
  height: 20px;
}

.button,
.icon-button,
.file-label {
  border: 0;
  cursor: pointer;
  border-radius: 16px;
  padding: 14px 18px;
  font-weight: 800;
  color: #fffaf2;
  background: linear-gradient(135deg, var(--accent), #15553a);
  box-shadow: 0 16px 28px rgba(31, 122, 85, 0.22);
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
  text-decoration: none;
}

.button-secondary,
.file-label,
.icon-button {
  background: rgba(16, 35, 27, 0.08);
  color: var(--panel-strong);
  box-shadow: none;
}

.button-danger,
.keypad-key-danger {
  background: linear-gradient(135deg, var(--danger), #8f2918);
  color: #fffaf2;
}

.button:hover,
.icon-button:hover,
.file-label:hover,
.tab-button:hover,
.segment:hover,
.keypad-key:hover {
  transform: translateY(-1px);
}

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

.summary-card {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}

.summary-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.summary-card strong {
  font-size: 1.4rem;
}

.empty-state,
.callout,
.settings-item,
.history-group,
.stats-row {
  padding: 18px;
  border: 1px dashed rgba(22, 32, 23, 0.18);
  border-radius: 20px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

.progress-card {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.progress-copy strong {
  font-size: 1.2rem;
}

.progress-pill {
  min-width: 70px;
  text-align: center;
  padding: 8px 12px;
  border-radius: 999px;
  color: #fffaf2;
  background: var(--accent);
  font-weight: 800;
}

.progress-track {
  width: 100%;
  height: 16px;
  margin-top: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(16, 35, 27, 0.08);
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, #35a36d, var(--accent));
  transition: width 260ms ease, background 260ms ease;
}

.progress-bar.warning {
  background: linear-gradient(135deg, #f2b34a, var(--warning));
}

.progress-bar.danger,
.progress-pill.danger {
  background: linear-gradient(135deg, #dd6956, var(--danger));
}

.progress-pill.warning {
  background: linear-gradient(135deg, #f2b34a, var(--warning));
}

.progress-caption {
  margin: 12px 0 0;
  color: var(--muted);
}

.amount-display-wrap {
  display: grid;
  gap: 8px;
}

.amount-display {
  font-size: clamp(2rem, 6vw, 3.3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: right;
  padding: 18px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, #fffdf8, #f4ead9);
}

.category-fieldset {
  margin: 0;
  border: 0;
  padding: 0;
}

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

.category-chip {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 10px;
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.category-chip.is-active {
  border-color: var(--chip-color, var(--accent));
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 18%, white);
}

.category-icon,
.transaction-category-badge,
.stats-icon {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  color: white;
}

.category-icon svg,
.stats-icon svg,
.transaction-category-badge svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.keypad-key {
  border: 0;
  border-radius: 18px;
  padding: 18px 12px;
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--panel-strong);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: inset 0 -2px 0 rgba(22, 32, 23, 0.08);
  transition: transform 120ms ease, background 180ms ease;
}

.keypad-key:active {
  transform: scale(0.98);
}

.keypad-key-muted {
  background: rgba(16, 35, 27, 0.08);
}

.legend,
.settings-list,
.grouped-list,
.stats-breakdown,
.compact {
  display: grid;
  gap: 12px;
}

.legend-item,
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.legend-item-copy,
.settings-copy {
  display: grid;
  gap: 4px;
}

.full-width {
  grid-column: 1 / -1;
}

.chart-wrap {
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(248, 244, 237, 0.9));
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.history-group {
  display: grid;
  gap: 12px;
}

.history-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.history-group-header strong {
  font-size: 1rem;
  color: var(--text);
}

.transaction-list {
  display: grid;
  gap: 12px;
}

.transaction-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}

.transaction-main {
  flex: 1;
  min-width: 0;
}

.transaction-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.transaction-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.transaction-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  flex-wrap: wrap;
  justify-content: flex-start;
}

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

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

.transaction-recurring {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(16, 35, 27, 0.08);
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.stats-row strong {
  color: var(--text);
}

.stats-bar {
  width: 150px;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(16, 35, 27, 0.08);
}

.stats-bar-fill {
  height: 100%;
  border-radius: inherit;
}

.dialog {
  width: min(520px, calc(100vw - 24px));
  border: 0;
  border-radius: 24px;
  padding: 0;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(9, 15, 11, 0.42);
  backdrop-filter: blur(6px);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 24px;
  background: #fffaf4;
  border-radius: 24px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.motion-in {
  animation: tile-enter 220ms ease;
}

@keyframes tile-enter {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 960px) {
  .layout,
  .stats-layout,
  .summary-grid,
  .category-grid {
    grid-template-columns: 1fr;
  }

  .hero,
  .panel-header,
  .transaction-row,
  .history-group-header,
  .progress-copy {
    flex-direction: column;
    align-items: flex-start;
  }

  .entry-row,
  .grid-form {
    grid-template-columns: 1fr;
  }

  .transaction-item {
    flex-direction: column;
    align-items: flex-start;
  }
}
