:root {
  --bg: #f5f7fb;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --text: #101828;
  --muted: #667085;
  --border: rgba(16, 24, 40, 0.08);

  --primary: #5b7cff;
  --primary-dark: #4a67dd;
  --income: #12b76a;
  --income-soft: rgba(18, 183, 106, 0.12);
  --expense: #f04438;
  --expense-soft: rgba(240, 68, 56, 0.12);
  --warning: #f59e0b;

  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  --transition: 180ms ease;
}

body.dark {
  --bg: #0b1020;
  --surface: rgba(17, 24, 39, 0.78);
  --surface-solid: #111827;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(91, 124, 255, 0.14), transparent 35%),
    radial-gradient(circle at top right, rgba(18, 183, 106, 0.10), transparent 30%),
    var(--bg);
  color: var(--text);
  transition: background 220ms ease, color 220ms ease;
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.top-actions {
  display: flex;
  gap: 18px;
  align-items: end;
  flex-wrap: wrap;
}

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

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.month-picker-wrap,
.theme-switch-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

.month-picker-wrap label,
.field label,
.theme-switch-wrap span {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.switch {
  position: relative;
  width: 56px;
  height: 32px;
  display: inline-block;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  left: 4px;
  top: 4px;
  background: white;
  border-radius: 50%;
  transition: 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(24px);
}

.dashboard {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 20px;
}

.card {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 20px;
  transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.card-header {
  margin-bottom: 16px;
}

.card-header h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.card-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.form-card {
  grid-column: 1 / 2;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.segmented {
  display: inline-flex;
  background: rgba(91, 124, 255, 0.12);
  padding: 6px;
  border-radius: 999px;
  width: fit-content;
  gap: 6px;
}

.segment-btn {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  transition: transform var(--transition), background var(--transition), color var(--transition);
}

.segment-btn:hover {
  transform: translateY(-1px);
}

.segment-btn.active[data-type="income"] {
  background: var(--income);
  color: white;
}

.segment-btn.active[data-type="expense"] {
  background: var(--expense);
  color: white;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: #101828;
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition), background 220ms ease;
}

body.dark input,
body.dark select {
  background: rgba(31, 41, 55, 0.95);
  color: #f9fafb;
}

input:focus,
select:focus {
  border-color: rgba(91, 124, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(91, 124, 255, 0.12);
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition), background var(--transition), color var(--transition);
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c5cff);
  color: white;
  box-shadow: 0 12px 24px rgba(91, 124, 255, 0.24);
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text);
}

.import-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stats-grid {
  grid-column: 2 / 3;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 120px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 10px;
}

.stat-card strong {
  font-size: 1.8rem;
  line-height: 1.1;
}

.stat-card.balance strong {
  color: var(--primary);
}

.stat-card.income {
  background: linear-gradient(180deg, rgba(18, 183, 106, 0.08), rgba(255,255,255,0.4));
}

.stat-card.expense {
  background: linear-gradient(180deg, rgba(240, 68, 56, 0.08), rgba(255,255,255,0.4));
}

.stat-card.result {
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), rgba(255,255,255,0.4));
}

.chart-card,
.list-card {
  grid-column: 1 / -1;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 80px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  align-items: center;
  gap: 12px;
  animation: fadeInUp 320ms ease;
}

.bar-label {
  font-weight: 600;
  color: var(--text);
}

.bar-track {
  width: 100%;
  height: 14px;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 300ms ease;
}

.bar-value {
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filters,
.import-export {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.entries-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entry-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 14px;
  align-items: center;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(16, 24, 40, 0.06);
  border-radius: 18px;
  padding: 14px;
  transition: transform var(--transition), box-shadow var(--transition), opacity 240ms ease, background 220ms ease;
  animation: fadeInUp 280ms ease;
}

body.dark .entry-item {
  background: rgba(31, 41, 55, 0.68);
}

.entry-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
}

.entry-accent {
  width: 10px;
  height: 52px;
  border-radius: 999px;
}

.entry-accent.income {
  background: var(--income);
}

.entry-accent.expense {
  background: var(--expense);
}

.entry-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entry-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.entry-note {
  font-weight: 700;
}

.entry-meta {
  font-size: 0.9rem;
  color: var(--muted);
}

.entry-amount {
  font-size: 1.05rem;
  font-weight: 800;
}

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

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

.action-btn {
  border: none;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  min-width: 42px;
  height: 42px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.action-btn:hover {
  transform: scale(1.05);
}

.edit-btn:hover {
  background: rgba(91, 124, 255, 0.16);
  color: var(--primary);
}

.delete-btn:hover {
  background: #fee4e2;
  color: var(--expense);
}

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

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

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

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

  .form-card,
  .stats-grid,
  .chart-card,
  .list-card {
    grid-column: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 18px 14px 36px;
  }

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

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

  .bar-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .entry-item {
    grid-template-columns: 10px 1fr auto auto;
  }

  .entry-amount {
    grid-column: 2 / 3;
  }

  .month-picker-wrap,
  .theme-switch-wrap {
    width: 100%;
  }
}
