:root {
  --bg: #f4f6fb;
  --bg-accent: radial-gradient(circle at 15% 0%, #eef0ff 0%, transparent 45%),
    radial-gradient(circle at 85% 0%, #fdf2f8 0%, transparent 40%);
  --surface: #ffffff;
  --surface-muted: #f0f2f8;
  --border: #e3e7f0;
  --text: #1c2233;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  --success: #16a34a;
  --success-bg: #ecfdf3;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.07);
  --shadow-hover: 0 4px 8px rgba(16, 24, 40, 0.06), 0 12px 28px rgba(16, 24, 40, 0.1);
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #10121c;
  --bg-accent: radial-gradient(circle at 15% 0%, rgba(79, 70, 229, 0.16) 0%, transparent 45%),
    radial-gradient(circle at 85% 0%, rgba(236, 72, 153, 0.1) 0%, transparent 40%);
  --surface: #191c29;
  --surface-muted: #212436;
  --border: #2b2f45;
  --text: #eef0fb;
  --text-muted: #9096b3;
  --primary: #6366f1;
  --primary-dark: #818cf8;
  --primary-light: #a5b4fc;
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.22), 0 12px 28px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

/* Safety net: if any single element ever ends up a little wider than the
   viewport (a native date-picker control, a long unbreakable word, a
   fixed-width chart before it's had a chance to measure its container,
   etc.), this stops it from dragging the whole page into a horizontally
   scrollable state — which is what actually clips content off the left
   edge on phones, not just that one element looking slightly too wide. */
html {
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  width: 100%;
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  padding-left: max(32px, env(safe-area-inset-left));
  padding-right: max(32px, env(safe-area-inset-right));
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.brand-mark .icon {
  width: 19px;
  height: 19px;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: background-color 0.25s ease, color 0.25s ease;
}

.streak-badge.streak-active {
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  color: #c2410c;
}

:root[data-theme="dark"] .streak-badge.streak-active {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(217, 119, 6, 0.18));
  color: #fbbf24;
}

.streak-flame {
  display: inline-flex;
  align-items: center;
  filter: grayscale(1) opacity(0.5);
  transition: filter 0.25s ease, transform 0.25s ease;
}

.streak-flame .icon {
  width: 16px;
  height: 16px;
}

.streak-flame-lit {
  filter: grayscale(0) opacity(1);
  animation: flicker 1.8s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.12) rotate(-3deg); }
}

nav.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 10px;
  overflow-x: auto;
  max-width: 100%;
}

nav.tabs a {
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.2s ease, color 0.2s ease;
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
    gap: 10px;
  }

  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    row-gap: 10px;
  }

  /* flex-basis: 100% forces this onto its own line within the wrapping
     row above — `order` alone (the previous approach) doesn't wrap,
     it just reorders items within the same line, which squeezed the
     tabs into whatever space was left after the icon buttons. */
  nav.tabs {
    order: 2;
    flex: 1 1 100%;
    width: 100%;
  }

  .streak-badge,
  .install-btn,
  .theme-toggle {
    order: 1;
  }

  nav.tabs a {
    padding: 7px 12px;
    font-size: 0.83rem;
  }
}

nav.tabs a.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.install-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 8px 14px;
  font-size: 0.83rem;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25);
  white-space: nowrap;
}

.install-btn .icon {
  width: 15px;
  height: 15px;
}

.install-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(79, 70, 229, 0.32);
}

@media (max-width: 640px) {
  .install-btn {
    padding: 8px 10px;
    font-size: 0.78rem;
  }
}

.account-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .account-label {
    display: none;
  }
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-muted);
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.theme-toggle .icon {
  width: 17px;
  height: 17px;
}

.theme-toggle:hover {
  background: var(--border);
  transform: rotate(15deg);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}

@media (max-width: 480px) {
  main {
    padding-top: 20px;
    padding-bottom: 40px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .card {
    padding: 18px;
  }

  .balance-ring-wrap {
    width: 150px;
    height: 150px;
  }

  .balance-amount {
    font-size: clamp(1.05rem, 6.5vw, 1.5rem);
  }

  .stat-row {
    gap: 8px;
  }

  .stat {
    padding: 10px 6px;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  min-width: 0;
  transition: box-shadow 0.25s ease, transform 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.fade-in {
  animation: fadeIn 0.4s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.grid-top {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
  align-items: stretch;
}

@media (max-width: 700px) {
  .grid-top {
    grid-template-columns: 1fr;
  }
}

.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.page-heading {
  font-size: 1.2rem;
  font-weight: 800;
}

.date-row input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: max(0.95rem, 16px);
  color: var(--text);
  background: var(--surface-muted);
  max-width: 100%;
}

@media (max-width: 400px) {
  .date-row input[type="date"] {
    width: 100%;
  }
}

.balance-card {
  display: flex;
  flex-direction: column;
}

.balance-ring-wrap {
  position: relative;
  width: 170px;
  height: 170px;
  margin: 4px auto 0;
}

.balance-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--surface-muted);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.3s ease;
}

.ring-progress.ring-warning {
  stroke: var(--warning);
}

.ring-progress.ring-danger {
  stroke: var(--danger);
}

.balance-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 14px;
  box-sizing: border-box;
}

.balance-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-amount {
  font-size: clamp(1.15rem, 5.5vw, 1.9rem);
  font-weight: 800;
  margin-top: 4px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.balance-amount.positive { color: var(--success); }
.balance-amount.negative { color: var(--danger); }
.balance-amount.neutral { color: var(--text); }

.balance-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 14px;
}

.stat-row {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.stat {
  flex: 1;
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  transition: background-color 0.25s ease;
}

.stat .stat-value {
  font-size: 1.15rem;
  font-weight: 800;
}

.stat .stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

form.inline-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.field-row {
  display: flex;
  gap: 12px;
  min-width: 0;
}

@media (max-width: 420px) {
  .field-row {
    flex-direction: column;
  }
}

.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* Flex/grid items default to min-width: auto, which floors their size at
     their content's intrinsic minimum. A file input's native "Choose File"
     control has a wide intrinsic minimum, which otherwise forces this
     field — and every ancestor up through the card and grid — wider than
     the viewport on phones instead of shrinking to fit. */
  min-width: 0;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.optional-tag {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  /* 16px minimum stops iOS Safari auto-zooming the page in on focus. */
  font-size: max(0.95rem, 16px);
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="file"] {
  padding: 8px 10px;
  font-size: 0.85rem;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

button {
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.32);
}

button.primary:active {
  transform: translateY(0);
}

button.secondary {
  background: var(--surface-muted);
  color: var(--text);
}

button.secondary:hover {
  background: var(--border);
}

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

button.danger:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.setup-card {
  text-align: center;
  padding: 44px 24px;
}

.setup-card .setup-icon {
  display: flex;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 8px;
  animation: bounceIn 0.5s ease;
}

.setup-card .setup-icon .icon {
  width: 40px;
  height: 40px;
}

@keyframes bounceIn {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.setup-card form {
  max-width: 320px;
  margin: 16px auto 0;
}

.setup-options {
  display: flex;
  gap: 6px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 10px;
  max-width: 360px;
  margin: 18px auto 0;
}

.setup-option {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 8px;
  font-size: 0.82rem;
  border-radius: 8px;
  box-shadow: none;
  white-space: nowrap;
}

@media (max-width: 360px) {
  .setup-options {
    flex-wrap: wrap;
  }

  .setup-option {
    flex: 1 1 40%;
  }
}

.setup-option .icon {
  width: 15px;
  height: 15px;
}

.setup-option:hover {
  background: var(--border);
  transform: none;
}

.setup-option.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.carry-preview {
  text-align: center;
  padding: 16px;
  background: var(--surface-muted);
  border-radius: 10px;
}

.carry-amount {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--success);
}

.carry-amount.negative {
  color: var(--danger);
}

.carry-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

h1, h2, h3 {
  margin: 0;
}

.section-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 14px;
}

.expense-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-muted);
  animation: slideIn 0.3s ease both;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.expense-item:hover {
  transform: translateX(2px);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

svg.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
}

.category-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.category-dot .icon {
  width: 15px;
  height: 15px;
}

.category-dot.small {
  width: 20px;
  height: 20px;
}

.category-dot.small .icon {
  width: 11px;
  height: 11px;
}

.expense-info {
  flex: 1;
  min-width: 0;
}

.expense-desc {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.expense-amount {
  font-weight: 700;
  color: var(--danger);
  white-space: nowrap;
}

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

.receipt-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  flex-shrink: 0;
}

.receipt-link .icon {
  width: 15px;
  height: 15px;
}

.receipt-link:hover {
  color: var(--primary);
}

.row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.edit-btn,
.delete-btn {
  background: transparent;
  color: var(--text-muted);
  min-width: 36px;
  min-height: 36px;
  padding: 6px;
  border-radius: 6px;
  line-height: 1;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-btn .icon,
.delete-btn .icon {
  width: 15px;
  height: 15px;
}

.edit-btn:hover {
  background: var(--surface);
  color: var(--primary);
  transform: none;
}

.delete-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
  transform: none;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 12px;
  font-size: 0.9rem;
}

.empty-icon {
  width: 34px;
  height: 34px;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  display: none;
}

.error-banner.visible {
  display: block;
}

/* Category spending breakdown */
.breakdown-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-muted);
}

.breakdown-segment {
  height: 100%;
  transition: width 0.4s ease;
}

.breakdown-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
}

.legend-item .category-dot {
  width: 20px;
  height: 20px;
}

.legend-item .category-dot .icon {
  width: 11px;
  height: 11px;
}

.legend-amount {
  margin-left: auto;
  color: var(--text-muted);
  font-weight: 600;
}

/* History page */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 10px;
  background: var(--surface-muted);
  text-decoration: none;
  color: var(--text);
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.history-row:hover {
  background: var(--border);
  transform: translateX(2px);
}

.history-date {
  font-weight: 700;
  min-width: 130px;
}

.history-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-metrics strong {
  color: var(--text);
}

.history-balance {
  font-weight: 700;
  font-size: 1.05rem;
  min-width: 100px;
  text-align: right;
}

@media (max-width: 480px) {
  .history-row {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .history-date {
    min-width: 0;
    flex: 1 1 100%;
  }

  .history-metrics {
    flex: 1 1 auto;
  }

  .history-balance {
    flex: 0 0 auto;
    min-width: 0;
  }
}

/* Transactions page */
.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.secondary-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-muted);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.2s ease;
}

.secondary-link-btn:hover {
  background: var(--border);
}

.secondary-link-btn .icon {
  width: 14px;
  height: 14px;
}

.filter-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-row .field {
  flex: 1;
  min-width: 90px;
}

.filter-search {
  flex: 2;
  min-width: 180px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap .icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding-left: 36px;
}

#filter-category {
  flex: 1;
  min-width: 140px;
}

.table-wrap {
  overflow-x: auto;
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.txn-table th {
  text-align: left;
  padding: 14px 20px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.txn-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .txn-table th,
  .txn-table td {
    padding: 10px 12px;
  }
}

.txn-table tbody tr {
  transition: background-color 0.15s ease;
}

.txn-table tbody tr:last-child td {
  border-bottom: none;
}

.txn-table tbody tr:hover {
  background: var(--surface-muted);
}

.txn-amount-col {
  text-align: right;
  font-weight: 700;
  color: var(--danger);
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

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

@media (max-width: 600px) {
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.summary-comparison {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.trend-chart-wrap {
  overflow-x: auto;
}

.trend-chart-wrap svg {
  display: block;
}

/* Budgets & recurring */
.budgets-list,
.recurring-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.budget-item {
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 14px 16px;
}

.budget-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.budget-item-header strong {
  flex: 1;
  font-size: 0.92rem;
}

.tag-pill {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.tag-pill.paused {
  color: var(--warning);
}

.tag-pill.suspended {
  color: var(--danger);
  background: var(--danger-bg);
}

.tag-pill.active {
  color: var(--success);
  background: var(--success-bg);
}

.budget-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.4s ease;
}

.budget-bar-fill.warning {
  background: var(--warning);
}

.budget-bar-fill.danger {
  background: var(--danger);
}

.budget-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.recurring-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-muted);
}

.recurring-item.paused {
  opacity: 0.6;
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-card .error-banner.visible {
  margin-bottom: 14px;
}

.auth-switch {
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* Account suspension */
.suspended-notice {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--warning-bg);
  color: var(--text);
  border: 1px solid var(--warning);
  text-align: left;
  white-space: pre-line;
  line-height: 1.5;
}

/* Admin: users */
.admin-user-name {
  font-weight: 700;
}

.admin-user-email {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.admin-users-table td {
  vertical-align: top;
}

.admin-actions {
  text-align: right;
}

.admin-actions button {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.suspend-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--danger);
  list-style: none;
}

.suspend-details summary::-webkit-details-marker {
  display: none;
}

.suspend-details form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  width: 280px;
  max-width: 70vw;
  text-align: left;
  white-space: normal;
}

.suspend-details label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.suspend-details textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 28, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 500;
  animation: fadeIn 0.2s ease both;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  animation: bounceIn 0.25s ease both;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  align-items: center;
  max-width: calc(100vw - 32px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  background: var(--text);
  color: var(--bg);
  padding: 11px 12px 11px 20px;
  border-radius: 999px;
  font-size: 0.87rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-action {
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 999px;
  box-shadow: none;
  white-space: nowrap;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: none;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-success {
  background: var(--success);
  color: white;
}

/* Confetti */
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2000;
}
