*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #222;
  --surface3: #2a2a2a;
  --border: #2e2e2e;
  --border2: #3a3a3a;
  --text: #e8e8e8;
  --text2: #999;
  --text3: #666;
  --accent: #6366f1;
  --accent-hover: #7577f3;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.12);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
}

html, body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.num { font-variant-numeric: tabular-nums; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* Top nav */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 0 20px; height: 52px;
  display: flex; align-items: center; gap: 20px;
}
.nav-brand {
  font-weight: 600; font-size: 15px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.nav-brand:hover { color: var(--text); text-decoration: none; }
.nav-link {
  color: var(--text2); font-size: 13px; font-weight: 500;
  padding: 6px 10px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
.nav-link.active { color: var(--text); background: var(--surface3); }
.nav-spacer { flex: 1; }

/* Main container */
.container {
  max-width: 1280px; margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
}
.container-narrow { max-width: 480px; margin: 60px auto; padding: 0 20px; }

/* Headings */
h1.page-title {
  font-size: 22px; font-weight: 600;
  margin-bottom: 20px;
}
h2.section-title {
  font-size: 14px; font-weight: 600;
  color: var(--text); margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}

/* Cards / panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-compact { padding: 14px; }
.card + .card { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
@media (min-width: 901px) and (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* Metric cards (dashboard KPIs) */
.metric { display: flex; flex-direction: column; gap: 4px; }
.metric-label {
  font-size: 11px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.6px; font-weight: 500;
}
.metric-value {
  font-size: 24px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.metric-value.positive { color: var(--success); }
.metric-value.negative { color: var(--danger); }
.metric-value.neutral { color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; outline: none; font-family: inherit;
  transition: background 0.15s, opacity 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface3); color: var(--text);
  border: 1px solid var(--border2);
}
.btn-secondary:hover:not(:disabled) { background: var(--border2); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* Inputs */
.input, .select, textarea.input {
  width: 100%; padding: 8px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; font-family: inherit; outline: none;
  transition: border-color 0.15s;
}
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }
.input-sm { padding: 5px 8px; font-size: 12px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* Form */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group + .form-group { margin-top: 14px; }
.form-label {
  font-size: 11px; color: var(--text2); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.form-error { font-size: 12px; color: var(--danger); }
.checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text2); cursor: pointer; user-select: none;
}
.checkbox input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

/* Filter bar */
.filter-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; align-items: end;
}
.filter-bar .actions {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 12px;
}

/* Tables */
.table-wrap {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; background: var(--surface);
}
table.t {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.t th {
  background: var(--surface2); color: var(--text2); font-weight: 500;
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border);
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px;
  position: sticky; top: 0; z-index: 1;
}
table.t td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.t tr:last-child td { border-bottom: none; }
table.t tbody tr:hover { background: var(--surface2); }
table.t td.r, table.t th.r { text-align: right; }
table.t td.c, table.t th.c { text-align: center; }
.amount-pos { color: var(--success); }
.amount-neg { color: var(--danger); }

/* Inline editable */
.cell-edit {
  background: transparent; border: 1px solid transparent;
  color: var(--text); padding: 4px 6px; border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; outline: none;
  width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.cell-edit:hover { border-color: var(--border2); }
.cell-edit:focus { border-color: var(--accent); background: var(--surface2); }
.cell-edit.cell-edit-narrow { width: 140px; }
.cell-edit.saved { background: var(--success-soft); }
.cell-edit.error { background: var(--danger-soft); }

/* Flash messages */
.flash {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 13px; border: 1px solid;
  display: flex; align-items: center; gap: 8px;
}
.flash-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.flash-error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.flash-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }

/* Description cell pattern (transaction list) */
.desc { display: flex; flex-direction: column; gap: 2px; max-width: 380px; }
.desc-merchant { color: var(--text); font-weight: 500; }
.desc-raw { color: var(--text3); font-size: 11px; }
.desc-raw, .desc-merchant { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pagination */
.pager { display: flex; gap: 4px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a {
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text2); font-size: 12px;
  border: 1px solid var(--border);
}
.pager a:hover { color: var(--text); background: var(--surface3); text-decoration: none; }
.pager a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Badges */
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-muted   { background: var(--surface3);     color: var(--text2); }

/* Empty state */
.empty {
  text-align: center; padding: 40px 20px; color: var(--text3);
  font-size: 13px;
}

/* Utilities */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--text2); }
.text-faint { color: var(--text3); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
