/* ---------------------------------------------------------------------------
   Design tokens — the single source of truth for color, spacing, radius and
   type. Components below reference these via var(); change a value here and it
   propagates everywhere, which is what keeps the UI consistent.
   --------------------------------------------------------------------------- */
:root {
  /* Color — surfaces & text */
  --bg:            #fafafa;
  --surface:       #fff;
  --surface-2:     #f9fafb;
  --surface-3:     #f3f4f6;
  --text:          #222;
  --text-strong:   #111827;
  --text-2:        #374151;
  --muted:         #666;
  --border:        #e5e7eb;
  --border-subtle: #f3f4f6;
  --border-strong: #d1d5db;

  /* Color — intent */
  --primary:       #2058c7;
  --primary-hover: #1c4ba8;
  --primary-soft:  #5b8def;
  --danger:        #dc2626;
  --danger-hover:  #b91c1c;
  --danger-bg:     #fee2e2;
  --danger-text:   #991b1b;
  --success:       #059669;

  /* Color — nav */
  --nav-bg:     #1f2937;
  --nav-border: #111827;
  --nav-link:   #d1d5db;
  --nav-active: #374151;

  /* Color — category accents */
  --warning:            #f97316;
  --warning-bg:         #fff7ed;
  --warning-bg-hover:   #ffedd5;
  --warning-text:       #c2410c;
  --warning-text-hover: #9a3412;
  --accent-bg:          #e0e7ff;
  --accent-text:        #3730a3;
  --uncat-text:         #b45309;
  --cat-auto-text:      #4b5563;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* Radius scale */
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-pill: 999px;

  /* Type scale */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-xs:   0.75rem;
  --fs-sm:   0.85rem;
  --fs-base: 0.95rem;
  --fs-md:   1rem;
  --fs-lg:   1.25rem;
  --fs-xl:   1.5rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
}

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

.app { min-height: 100vh; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
}

h1 { margin-top: 0; }
h2 { margin: 0 0 var(--space-2); }
h3 { font-size: var(--fs-md); }
.muted { color: var(--muted); font-size: var(--fs-sm); margin-top: 0; }

/* Global loading bar — driven by the re-frame :loading? counter */
.loading-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-soft), var(--primary));
  background-size: 200% 100%;
  animation: loading-slide 1s linear infinite;
  z-index: 50;
}
@keyframes loading-slide {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Nav */
.top-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-5);
  background: var(--nav-bg);
  color: #fff;
  border-bottom: 1px solid var(--nav-border);
}
.top-nav .brand { font-weight: 700; letter-spacing: 0.02em; }
.top-nav .links { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.top-nav .nav-link {
  color: var(--nav-link);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}
.top-nav .nav-link.active { background: var(--nav-active); color: #fff; }
.top-nav .nav-link:hover  { background: var(--nav-active); text-decoration: none; }

/* Error banner */
.error {
  background: var(--danger-bg);
  color: var(--danger-text);
  padding: var(--space-2) var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.error button {
  background: transparent;
  border: none;
  color: var(--danger-text);
  cursor: pointer;
  font-size: 1.1rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: var(--space-5);
}
th, td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
th { background: var(--surface-2); font-size: var(--fs-sm); font-weight: 600; }
td.right, th.right { text-align: right; font-variant-numeric: tabular-nums; }

/* Empty state */
.empty {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
}

/* Buttons */
button {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
}
button:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }
button.link {
  background: transparent;
  color: var(--primary);
  padding: 0;
  text-decoration: underline;
  font-size: var(--fs-sm);
}
button.link:hover { background: transparent; }

/* Forms */
form.create {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}
form.create h3 {
  grid-column: 1 / -1;
  margin: 0;
  font-size: var(--fs-md);
}
form.create label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--fs-xs);
  color: var(--text-2);
}
form.create input, form.create select {
  padding: var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
}
form.create button { justify-self: start; }

/* KPI block */
.kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}
.kpi > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.kpi > div div { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }

/* Bulk-action strip above transactions */
.bulk-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-4);
}
.bulk-actions .uncat-count {
  color: var(--uncat-text);
  font-weight: 600;
  font-size: var(--fs-sm);
}

/* Category cell — three visual states for category-source. */
td.cat-cell { padding: var(--space-1) var(--space-2); }

.cat {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--fs-sm);
  line-height: 1.2;
}
.cat:hover { background: var(--surface-3); }

/* User-set: confident, plain. */
.cat-user { color: var(--text-strong); }
.cat-user .cat-icon { color: var(--success); font-weight: 700; }

/* Auto-set: muted italics with a soft pill — clearly different from user-set. */
.cat-auto { color: var(--cat-auto-text); }
.cat-auto em { font-style: italic; }
.cat-auto .cat-badge {
  background: var(--accent-bg);
  color: var(--accent-text);
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Uncategorized: the attention state. Distinct shape (rectangle, not pill),
   warning color, animated pulse so it's hard to overlook. */
.cat-none {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px dashed var(--warning);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  animation: cat-none-pulse 2.4s ease-in-out infinite;
}
.cat-none:hover {
  background: var(--warning-bg-hover);
  color: var(--warning-text-hover);
}
@keyframes cat-none-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.18); }
}

select.cat-select {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  min-width: 12rem;
}

/* Plaid section */
.plaid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin: 0 0 var(--space-5);
}
.plaid h3 { margin: 0 0 var(--space-1); font-size: var(--fs-md); }
.plaid .plaid-actions {
  margin: var(--space-2) 0 var(--space-3);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.plaid table { margin: var(--space-3) 0 var(--space-2); }

/* Nav account menu (right side) */
.top-nav .nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.top-nav .nav-email { color: var(--nav-link); font-size: var(--fs-sm); }
.top-nav .nav-user button.link { color: var(--nav-link); font-size: var(--fs-sm); }
.top-nav .nav-user button.link:hover { color: #fff; }

/* Auth (sign in / register) */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.auth-card h1 { margin: 0 0 var(--space-1); }
.auth-card form { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
.auth-card label { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--fs-xs); color: var(--text-2); }
.auth-card input {
  padding: var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
}
.auth-card button[type="submit"] { margin-top: var(--space-2); }
.auth-error {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  font-size: var(--fs-sm);
  margin: 0;
}
.auth-switch { margin-top: var(--space-4); }

/* Google sign-in button — follows Google's brand guidance: white surface,
   Roboto/system font, 1px gray border, the colored "G" mark on the left. */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  width: 100%;
  padding: 0.55rem 0.85rem;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  transition: background 120ms ease, box-shadow 120ms ease;
}
.google-btn:hover { background: #f8faff; box-shadow: 0 1px 2px rgba(60,64,67,0.18); text-decoration: none; }
.google-btn:active { background: #f1f3f4; }
.google-btn svg { flex: 0 0 auto; }

/* "or" divider between Google and email/password form */
.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0 0;
  color: var(--text-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

/* Responsive: let wide tables scroll instead of overflowing on small screens */
@media (max-width: 640px) {
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .top-nav { gap: var(--space-3); flex-wrap: wrap; }
  .top-nav .nav-user { margin-left: 0; }
}
