:root {
  --background: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --text: #18221e;
  --muted: #66736d;
  --border: #dce4e0;
  --primary: #176b4d;
  --primary-dark: #10513a;
  --primary-soft: #e5f4ed;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(25, 60, 45, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 48px 20px;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #e1f0e9 0, transparent 34rem),
    var(--background);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.app-container {
  width: min(100%, 960px);
  margin: 0 auto;
}

.page-header {
  margin-bottom: 32px;
}

.eyebrow,
.step-label {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.intro {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.budget-panel,
.expense-panel,
.summary-section,
.category-panel,
.history-panel {
  padding: 28px;
  border: 1px solid rgba(220, 228, 224, 0.9);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.budget-panel,
.expense-panel {
  margin-bottom: 22px;
}

.category-panel,
.history-panel {
  margin-top: 22px;
}

.section-heading,
.summary-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.currency-badge {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 750;
}

.budget-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.expense-form {
  display: grid;
  gap: 18px;
}

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

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

.form-control {
  width: 100%;
  min-height: 52px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: 0;
  color: var(--text);
  background: var(--surface-soft);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 77, 0.12);
}

.form-control::placeholder {
  color: #97a39e;
}

select.form-control {
  cursor: pointer;
}

[aria-invalid="true"] {
  border-color: var(--danger);
}

.currency-input:has(input[aria-invalid="true"]) {
  border-color: var(--danger);
}

.currency-input {
  display: flex;
  align-items: center;
  min-height: 52px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.currency-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 77, 0.12);
}

.currency-input > span {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  color: var(--primary);
  font-weight: 750;
}

.currency-input input {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.currency-input input::placeholder {
  color: #97a39e;
}

button {
  min-height: 52px;
  padding: 0 24px;
  border: 0;
  border-radius: 12px;
  color: #ffffff;
  background: var(--primary);
  font-weight: 750;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.expense-form button {
  justify-self: end;
}

.expense-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.edit-mode-message {
  margin: 0;
  padding: 11px 14px;
  border: 1px solid #bfe0d1;
  border-radius: 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-soft);
}

.secondary-button:hover {
  background: #e8eeeb;
}

[hidden] {
  display: none !important;
}

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

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(23, 107, 77, 0.3);
  outline-offset: 3px;
}

.validation-message {
  min-height: 24px;
  margin: 9px 0 -5px;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 650;
}

.summary-heading {
  align-items: end;
}

.summary-note {
  max-width: 280px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

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

.summary-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.summary-card p {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

.summary-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  letter-spacing: -0.03em;
}

.remaining-card {
  border-color: #bfe0d1;
  background: var(--primary-soft);
}

.remaining-card p,
.remaining-card strong {
  color: var(--primary-dark);
}

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

.category-total-card {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.category-total-card dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.category-total-card dd {
  min-width: 0;
  margin: 0;
  color: var(--primary-dark);
  font-weight: 750;
  overflow-wrap: anywhere;
  text-align: right;
}

.expense-history-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item,
.empty-state {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 28px;
  padding: 18px 20px;
}

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

.history-main h3 {
  margin: 0 0 7px;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.4;
}

.category-label {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.75rem;
  font-weight: 700;
}

.history-detail {
  min-width: 116px;
}

.history-detail p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.history-detail strong,
.history-detail time {
  display: block;
  white-space: nowrap;
  font-size: 0.9rem;
}

.history-detail strong {
  color: var(--primary-dark);
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-action-button {
  min-height: 38px;
  padding: 0 13px;
  font-size: 0.82rem;
}

.edit-button {
  border: 1px solid var(--border);
  color: var(--primary-dark);
  background: var(--surface);
}

.edit-button:hover {
  background: var(--primary-soft);
}

.delete-button {
  border: 1px solid #f0c5c1;
  color: var(--danger);
  background: #fff5f4;
}

.delete-button:hover {
  color: #ffffff;
  background: var(--danger);
}

.empty-state {
  padding: 34px 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 700px) {
  body {
    padding: 32px 16px;
  }

  .budget-panel,
  .expense-panel,
  .summary-section,
  .category-panel,
  .history-panel {
    padding: 22px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

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

  .expense-fields {
    grid-template-columns: 1fr;
  }

  .summary-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .summary-note {
    text-align: left;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
  }

  .history-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .budget-form {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .expense-form button {
    justify-self: stretch;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-actions {
    grid-column: auto;
    justify-content: stretch;
  }

  .history-detail strong,
  .history-detail time {
    white-space: normal;
  }

  .category-totals-grid {
    grid-template-columns: 1fr;
  }

  .expense-form-actions {
    flex-direction: column;
  }

  .expense-form-actions button,
  .history-action-button {
    width: 100%;
  }
}
