/* Base theme */
:root {
  --bg: #e2e8f9;
  --bg-outer: linear-gradient(180deg, #e2e8f9 0%, #d8e1f5 40%, #cfd9f3 100%);
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6b8a;
  --border: #d7def0;
  --accent: #1f41a9;
  --accent-strong: #1a2f80;
  --table-stripe: #f3f6fb;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --topbar-bg: linear-gradient(90deg, #1e3a8a, #312e81);
  --topbar-text: #e5e7eb;
  --topbar-border: rgba(255, 255, 255, 0.12);
  --ghost-border: rgba(255, 255, 255, 0.2);
  --ghost-bg: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --bg-outer: #0b1220;
  --card: #111827;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1f2937;
  --accent: #60a5fa;
  --accent-strong: #3b82f6;
  --table-stripe: #0f172a;
  --shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  --topbar-bg: #111827;
  --topbar-text: #e2e8f0;
  --topbar-border: #1f2937;
  --ghost-border: #1f2937;
  --ghost-bg: transparent;
  --download-bg: #1f2937;
  --download-border: #24324a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg-outer);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.content { padding: 1.5rem; max-width: 1200px; margin: 0 auto; width: 100%; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
  color: var(--topbar-text);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.nav-links { display: flex; gap: 0.75rem; align-items: center; }
.nav-link { font-weight: 600; color: var(--topbar-text); opacity: 0.8; }
.nav-link:hover { color: var(--topbar-text); opacity: 1; }
.ghost-button {
  border: 1px solid var(--ghost-border);
  background: var(--ghost-bg);
  color: var(--topbar-text);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}

/* Panels / cards */
.panel { display: grid; gap: 1rem; }
.panel-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; }
.account-card { display: grid; grid-template-rows: auto auto; gap: 0.35rem; align-items: center; padding: 1rem; min-width: 260px; }
.account-actions { display: flex; gap: 0.5rem; justify-content: center; }
.account-link { color: inherit; text-decoration: none; }
.account-logo { display: flex; align-items: center; justify-content: flex-start; min-height: 60px; }
.account-logo-img { max-height: 48px; width: auto; }
.card {
  background: var(--card);
  border: 1px solid #cfd8ee;
  border-radius: 16px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.table-card { padding: 0; overflow: hidden; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1rem 0.25rem; }
.card-title { margin: 0.2rem 0; }
.eyebrow { margin: 0; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.05em; text-transform: uppercase; }
.title { margin: 0; }
.pill-group { display: flex; gap: 0.5rem; align-items: center; }
.pill {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-weight: 700;
  color: white;
  font-size: 0.9rem;
}
.pill-blue { background: var(--accent); }
.pill-orange { background: #f97316; }
.pill-red { background: #dc2626; }
.pill-yellow { background: #f59e0b; }
.pill.report {
  padding: 0.35rem 0.75rem;
  border: none;
}
.report-subcard {
  margin: 0.5rem 1rem 0.2rem;
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.report.yellow { background: #f59e0b; }
.report.green { background: #10b981; }
.report.purple { background: #8b5cf6; }
.report.black { background: #be185d; }
.report-subcard {
  margin: 0.5rem 1rem 0.2rem;
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  padding: 0.6rem 0.8rem;
  margin: 0.35rem 1rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--card) 90%, transparent);
}
.report-row {
  display: flex;
  justify-content: center;
  padding: 0.4rem 0.8rem;
  margin: 0 1rem 1rem;
}
.report-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1rem 0;
}
.bar-chart { margin: 0.75rem 0 1.25rem; display: grid; gap: 0.35rem; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 120px; gap: 0.5rem; align-items: center; }
.bar-label { font-size: 0.9rem; color: var(--text); }
.bar-track { background: #e2e8f0; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.blue { background: linear-gradient(90deg, #1e3a8a, #60a5fa); }
.bar-fill.purple { background: linear-gradient(90deg, #6d28d9, #c084fc); }
.bar-fill.green { background: linear-gradient(90deg, #0f766e, #34d399); }
.bar-fill.orange { background: linear-gradient(90deg, #f97316, #fb923c); }
.bar-value { text-align: right; font-weight: 600; color: var(--text); }
.icon-button {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.export-icon { height: 75px; width: auto; display: block; background: transparent; }
.report-icon { height: 113px; width: auto; display: block; }
.report-icon.hero { height: 225px; }
.report-hero { text-align: center; padding: 0.5rem; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 1024px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .card-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}
.card-meta { color: var(--muted); font-size: 0.9rem; }

.two-up {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

/* Flash messages */
.flash {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.flash.notice { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
.flash.alert { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
}

/* Forms */
.filters { display: flex; flex-direction: column; gap: 0.5rem; }
.filters.inset { padding: 0 1rem 1rem; }
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; align-items: end; }
.filter-field label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.2rem; }
.input, select, input[type="date"], input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.filter-actions { display: flex; gap: 0.5rem; }

.form-card {
  display: grid;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}
.form-top-actions { display: flex; justify-content: flex-end; }
.form-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem 0.9rem;
  align-items: end;
}
.field label { display: block; color: var(--muted); margin-bottom: 0.2rem; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.8rem; display: block; margin-top: 0.2rem; }
.actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.actions-inline { justify-self: end; align-self: end; }

.button {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.28rem 0.6rem;
  cursor: pointer;
  font-weight: 600;
  background: var(--card);
  color: var(--text);
  line-height: 1.1;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-strong); color: #fff; }
.button.ghost { background: transparent; }
.button.danger { background: #ef4444; border-color: #ef4444; color: #fff; }
.button.danger:hover { background: #dc2626; color: #fff; }

/* Table */
.table-wrapper { overflow-x: auto; }
table.register { width: 100%; border-collapse: collapse; min-width: 800px; }
table.register th, table.register td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.register th.payee-col,
table.register td.payee-col {
  width: 20%;
}
table.register td.category-cell {
  padding-left: 0.2rem;
  padding-right: 0.4rem;
}
table.register tbody tr:nth-child(odd) { background: var(--table-stripe); }
.narrow { width: 120px; }
.date-cell { font-size: 0.9rem; }
.numeric { text-align: right; white-space: nowrap; }
.actions { white-space: nowrap; display: flex; gap: 0.5rem; }
.link { color: var(--accent); font-weight: 600; }
.icon-button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 0.3rem 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
}
.inline-input { width: 100%; padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.row-form .hint { margin-top: 0.15rem; }
.button.small { padding: 0.3rem 0.6rem; font-size: 0.9rem; }
.row-form td { vertical-align: top; background: var(--table-stripe); padding: 0.4rem 0.5rem; }
.inline-stack { display: flex; flex-direction: column; gap: 0.15rem; }
.micro-label { color: var(--muted); font-size: 0.75rem; }
.category-cell { white-space: nowrap; }
table.register td.category-cell { padding-left: 0.35rem; }
.cat-with-icon { display: flex; align-items: center; gap: 0.25rem; margin-left: 0; transform: translateX(-2px); }
.cat-icon { height: 18px; width: auto; }
.cat-icon-conn { height: 22px; }
.cat-icon-tufts { height: 27px; }
.cat-icon-choate { height: 22px; }
.plain-cat { padding-left: 10%; display: inline-block; }
.pmt-cell { color: #b45309; font-weight: 700; }
.pmt-number-highlight { color: #d97706; font-weight: 700; }
.statement-link {
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  text-decoration: none;
}
.statement-link:hover { color: var(--accent-strong); }
.statement-icon { height: 54px; width: auto; display: block; }

/* Sub-card inside filter */
.sub-card {
  margin: 0.5rem 1rem 1rem;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--card) 90%, transparent);
}
.sub-card-header { margin-bottom: 0.25rem; }
.sub-form { display: flex; flex-direction: column; gap: 0.5rem; }
.sub-grid { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.sub-grid.two-cols { display: flex; gap: 0.5rem; flex-wrap: wrap; }
@media (min-width: 820px) {
  .sub-grid.two-cols { flex-wrap: nowrap; }
}
.sub-stack { display: grid; gap: 0.35rem; align-content: start; flex: 1 1 200px; min-width: 200px; max-width: 320px; }
.sub-card .filter-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.35rem; }
.sub-card .filter-field { max-width: 200px; }
.sub-card .filter-actions { justify-content: flex-start; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 20;
}
.modal-card {
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  min-width: 280px;
  max-width: 420px;
  width: 100%;
}
.stacked-form { display: flex; flex-direction: column; gap: 0.6rem; }
.stacked { display: flex; flex-direction: column; gap: 0.2rem; }
.inline-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.25rem; }
/* Card link */
.card.card { transition: transform 120ms ease, box-shadow 120ms ease; }
.card.card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.12); }

@media (max-width: 720px) {
  .topbar { position: static; }
  .content { padding: 1rem; }
  table.register { min-width: 600px; }
}
