/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #e0e7ff;
  --success:       #22c55e;
  --success-light: #dcfce7;
  --danger:        #ef4444;
  --danger-light:  #fee2e2;
  --warning:       #f59e0b;
  --warning-light: #fef3c7;
  --grey-50:       #f9fafb;
  --grey-100:      #f3f4f6;
  --grey-200:      #e5e7eb;
  --grey-300:      #d1d5db;
  --grey-400:      #9ca3af;
  --grey-500:      #6b7280;
  --grey-700:      #374151;
  --grey-900:      #111827;
  --white:         #ffffff;
  --radius:        12px;
  --radius-sm:     6px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
  --font:          'Segoe UI', system-ui, -apple-system, sans-serif;

  /* Category colours */
  --cat-food:          #f97316;
  --cat-transport:     #3b82f6;
  --cat-housing:       #8b5cf6;
  --cat-entertainment: #ec4899;
  --cat-health:        #10b981;
  --cat-shopping:      #f59e0b;
  --cat-other:         #6b7280;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--grey-100);
  color: var(--grey-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  background: var(--primary);
  color: var(--white);
  padding: 0 24px;
  box-shadow: 0 2px 8px rgba(99,102,241,.35);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon { font-size: 1.5rem; }

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.3px;
}

.header-month {
  font-size: .9rem;
  font-weight: 500;
  opacity: .88;
  background: rgba(255,255,255,.15);
  padding: 4px 14px;
  border-radius: 20px;
}

/* ============================================================
   MAIN CONTAINER
   ============================================================ */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  flex: 1;
  width: 100%;
}

/* ============================================================
   SUMMARY BAR
   ============================================================ */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  border-left: 5px solid var(--grey-300);
  transition: transform .15s;
}

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

.stat-spent   { border-left-color: var(--primary); }
.stat-budget  { border-left-color: var(--warning); }
.stat-remaining { border-left-color: var(--success); }
.stat-remaining.over-budget { border-left-color: var(--danger); }

.stat-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--grey-500);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--grey-900);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }

.stat-sub {
  font-size: .78rem;
  color: var(--grey-400);
}

/* ============================================================
   TWO-COLUMN LAYOUT
   ============================================================ */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
  align-items: start;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--grey-900);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-sub {
  font-size: .78rem;
  font-weight: 400;
  color: var(--grey-400);
}

/* ============================================================
   FORM
   ============================================================ */
.form-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--grey-700);
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--grey-900);
  background: var(--grey-50);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
  background: var(--white);
}

.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  margin-top: 4px;
}

.btn-primary:hover  { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }

/* ============================================================
   TRANSACTION LIST
   ============================================================ */
.txn-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.txn-list::-webkit-scrollbar { width: 5px; }
.txn-list::-webkit-scrollbar-track { background: var(--grey-100); border-radius: 4px; }
.txn-list::-webkit-scrollbar-thumb { background: var(--grey-300); border-radius: 4px; }

.txn-empty {
  color: var(--grey-400);
  font-size: .88rem;
  text-align: center;
  padding: 32px 0;
}

.txn-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--grey-50);
  border: 1px solid var(--grey-100);
  transition: background .12s;
  position: relative;
}

.txn-item:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.txn-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

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

.txn-desc {
  font-size: .88rem;
  font-weight: 600;
  color: var(--grey-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.txn-date {
  font-size: .75rem;
  color: var(--grey-400);
}

.txn-amount {
  font-size: .95rem;
  font-weight: 700;
  color: var(--grey-900);
  flex-shrink: 0;
  margin-right: 4px;
}

.btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--grey-300);
  font-size: 1rem;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .12s, background .12s;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
}

.txn-item:hover .btn-delete {
  opacity: 1;
  pointer-events: auto;
}

.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* ============================================================
   CATEGORY BADGES
   ============================================================ */
.badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--white);
}

.badge-Food          { background: var(--cat-food); }
.badge-Transport     { background: var(--cat-transport); }
.badge-Housing       { background: var(--cat-housing); }
.badge-Entertainment { background: var(--cat-entertainment); }
.badge-Health        { background: var(--cat-health); }
.badge-Shopping      { background: var(--cat-shopping); }
.badge-Other         { background: var(--cat-other); }

/* ============================================================
   CHARTS SECTION
   ============================================================ */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.chart-card { }

.chart-wrap {
  height: 280px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrap canvas {
  max-height: 280px;
}

/* ============================================================
   BUDGET TABLE
   ============================================================ */
.budget-card { margin-bottom: 0; }

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

.budget-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

.budget-table thead th {
  text-align: left;
  padding: 8px 12px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--grey-500);
  border-bottom: 2px solid var(--grey-200);
}

.budget-table tbody tr {
  border-bottom: 1px solid var(--grey-100);
  transition: background .1s;
}

.budget-table tbody tr:last-child { border-bottom: none; }
.budget-table tbody tr:hover { background: var(--grey-50); }

.budget-table td {
  padding: 10px 12px;
  vertical-align: middle;
}

.budget-cat-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.budget-spent {
  font-weight: 600;
  color: var(--grey-700);
}

.budget-limit-input {
  width: 90px;
  padding: 5px 8px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-family: var(--font);
  color: var(--grey-900);
  background: var(--grey-50);
  transition: border-color .15s;
  outline: none;
}

.budget-limit-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99,102,241,.12);
  background: var(--white);
}

.progress-wrap {
  min-width: 140px;
}

.progress-bar-bg {
  background: var(--grey-200);
  border-radius: 20px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 3px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 20px;
  background: var(--success);
  transition: width .4s ease, background .3s;
  min-width: 0;
}

.progress-bar-fill.warn  { background: var(--warning); }
.progress-bar-fill.over  { background: var(--danger); }

.progress-label {
  font-size: .72rem;
  color: var(--grey-400);
}

.progress-label.over { color: var(--danger); font-weight: 600; }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: .78rem;
  color: var(--grey-400);
  border-top: 1px solid var(--grey-200);
  background: var(--white);
}

/* ============================================================
   RESPONSIVE — TABLET / MOBILE
   ============================================================ */
@media (max-width: 900px) {
  .charts-section {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .summary-bar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

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

  .charts-section {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .app-main {
    padding: 16px 12px 32px;
  }

  .header-title {
    font-size: 1.05rem;
  }
}

@media (max-width: 480px) {
  .budget-table thead th:last-child,
  .budget-table td:last-child {
    display: none;
  }

  .txn-amount {
    font-size: .85rem;
  }
}
