/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  background: #f0f2f5;
  color: #222;
  font-size: 14px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: #1a2236;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #4f83cc;
  color: #fff;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s;
}
.upload-btn:hover {
  background: #3a6bb5;
}
.upload-btn input[type="file"] {
  display: none;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #444;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Charts row */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.chart-card canvas {
  display: block;
  width: 100% !important;
  height: 260px !important;
}

/* Info row */
.info-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Top Merchants ────────────────────────────────────────────────────────── */
#top-merchants {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#top-merchants li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #f7f8fa;
  border-radius: 6px;
  font-size: 0.88rem;
}

.merch-name {
  color: #333;
}
.merch-amt {
  font-weight: 700;
  color: #1a2236;
}

/* ── Budget Controls ─────────────────────────────────────────────────────── */
#budget-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.budget-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.budget-row label {
  flex: 1;
  color: #444;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.budget-row input[type="number"] {
  width: 90px;
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 0.85rem;
  text-align: right;
  color: #222;
}

.budget-row input[type="number"]:focus {
  outline: none;
  border-color: #4f83cc;
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-card {
  padding-bottom: 10px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.row-count {
  font-size: 0.78rem;
  font-weight: 400;
  color: #888;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 8px;
}

#search-input {
  padding: 7px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.88rem;
  width: 280px;
  max-width: 100%;
  color: #222;
}

#search-input:focus {
  outline: none;
  border-color: #4f83cc;
}

.table-wrap {
  overflow-x: auto;
}

#tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

#tx-table thead th {
  background: #f4f5f7;
  color: #555;
  font-weight: 700;
  padding: 9px 12px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 2px solid #e0e0e0;
}

#tx-table thead th:hover {
  background: #eaecf0;
}

#tx-table thead th.sort-asc::after {
  content: " ▲";
  color: #4f83cc;
}
#tx-table thead th.sort-desc::after {
  content: " ▼";
  color: #4f83cc;
}

#tx-table tbody tr:nth-child(even) {
  background: #fafbfc;
}
#tx-table tbody tr:hover {
  background: #eef3fb;
}

#tx-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.amount-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Over-budget row highlight */
#tx-table tbody tr.over-budget {
  background: #fff3f3 !important;
  border-left: 3px solid #e06c75;
}

#tx-table tbody tr.over-budget td {
  color: #c0392b;
}

/* ── Hint text ───────────────────────────────────────────────────────────── */
.hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: #aaa;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .charts-row,
  .info-row {
    grid-template-columns: 1fr;
  }
  #search-input {
    width: 100%;
  }
  .table-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
