:root {
  color-scheme: dark;
  --bg: #09090f;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --muted: #a1a1aa;
  --line: rgba(255, 255, 255, 0.12);
  --brand: #34d399;
  --brand-dark: #059669;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(52, 211, 153, 0.28), transparent 34rem),
    radial-gradient(circle at 80% 10%, rgba(59, 130, 246, 0.22), transparent 28rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

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

.app-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 10px 0 18px;
}

.eyebrow,
.section-heading p,
.expense-meta,
.total-card span,
#expenseCount {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 10vw, 4.5rem);
  letter-spacing: -0.08em;
  line-height: 0.92;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: -0.03em;
}

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

.panel,
.total-card {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.panel {
  border-radius: var(--radius);
  padding: 18px;
}

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

.total-card {
  align-self: stretch;
  display: grid;
  gap: 4px;
  border-radius: 22px;
  padding: 16px;
}

.total-card.is-over-budget {
  border-color: rgba(251, 113, 133, 0.65);
}

.total-card strong {
  font-size: clamp(1.45rem, 7vw, 2rem);
  letter-spacing: -0.05em;
}

.budget-total-card strong {
  color: var(--brand);
}

.stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.icon-actions {
  display: flex;
  gap: 6px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0;
  color: #bbf7d0;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.icon-button.danger-icon {
  color: #fecdd3;
}

.icon-button:focus-visible {
  outline: none;
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.budget-total-card.is-over-budget strong {
  color: var(--danger);
}

.section-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.actions-heading {
  gap: 12px;
}

form {
  display: grid;
  gap: 12px;
}

.budget-panel form {
  align-items: end;
}

.budget-status {
  margin-top: 12px;
  color: var(--brand);
  font-weight: 800;
}

.budget-status.is-over-budget {
  color: var(--danger);
}

.form-actions.single-action {
  grid-template-columns: 1fr;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 50px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.24);
  outline: none;
}

input:focus {
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.autocomplete-field {
  position: relative;
}

.autocomplete-field input {
  padding-right: 48px;
}

.autocomplete-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-50%);
}

.autocomplete-toggle:focus-visible {
  outline: none;
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 20;
  display: grid;
  max-height: min(240px, 50vh);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 6px;
  background: rgba(17, 24, 39, 0.98);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.autocomplete-option {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.autocomplete-option:hover,
.autocomplete-option:focus-visible {
  outline: none;
  background: rgba(52, 211, 153, 0.18);
}

.amount-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding-left: 14px;
  background: rgba(0, 0, 0, 0.24);
}

.amount-input:focus-within {
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.amount-input input {
  min-height: 48px;
  border: 0;
  padding-left: 8px;
  background: transparent;
  box-shadow: none;
}

.primary-button,
.secondary-button,
.ghost-button,
.edit-button,
.delete-button {
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 900;
}

.primary-button {
  margin-top: 4px;
  color: #052e1d;
  background: linear-gradient(135deg, var(--brand), #a7f3d0);
}

.secondary-button {
  color: #052e1d;
  background: var(--brand);
}

.ghost-button,
.edit-button,
.delete-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
}

.edit-button,
.delete-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.edit-button {
  color: #bbf7d0;
}

.delete-button {
  color: #fecdd3;
}

.form-actions,
.button-row,
.expense-actions {
  display: grid;
  gap: 8px;
}

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

.expense-actions {
  grid-template-columns: auto auto;
}

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

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

.summary-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.2);
}

.summary-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-row strong {
  color: var(--brand);
}

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

.expense-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.22);
}

.expense-title,
.expense-meta {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-title {
  margin-bottom: 4px;
}

.expense-right {
  display: grid;
  justify-items: end;
  gap: 8px;
}

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

.expense-item.is-editing {
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12);
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 16px;
  color: var(--text);
  background: rgba(17, 24, 39, 0.95);
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .app-shell {
    padding: 32px 24px 48px;
  }

  .app-header {
    flex-direction: row;
    align-items: end;
    justify-content: space-between;
  }

  .header-stats {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    align-self: end;
    width: min(100%, 540px);
  }

  .total-card {
    align-self: stretch;
  }

  .budget-panel form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .add-panel form {
    grid-template-columns: 1fr 1.25fr 1.25fr auto;
    align-items: end;
  }

  .primary-button {
    margin-top: 0;
    min-width: 120px;
  }

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

  .actions-heading {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .form-actions,
  .button-row {
    grid-template-columns: auto auto;
  }

  .form-actions.single-action {
    grid-template-columns: auto;
  }
}

@media (display-mode: standalone) {
  body {
    user-select: none;
    -webkit-user-select: none;
  }
}
