/* Finance Tracker — Mobile-First Design */
/* Aesthetic: Clean utilitarian with warm accents. Fonts: DM Sans + JetBrains Mono for numbers. */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg: #f8f7f4;
  --surface: #ffffff;
  --surface-hover: #fafaf8;
  --border: #e8e5df;
  --border-light: #f0ede8;
  --text: #2c2a26;
  --text-muted: #8a867e;
  --text-light: #b5b1a9;
  --nav-bg: #1e1e2a;
  --nav-text: #d4d2cd;
  --accent: #d97b4a;
  --accent-light: #f5e6db;
  --charge: #c44d3f;
  --charge-bg: #fdf0ee;
  --credit: #3a855e;
  --credit-bg: #edf7f1;
  --pending-bg: #fffbeb;
  --pending-border: #f0d76e;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ── Sidebar ── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  background: var(--nav-bg);
  color: var(--nav-text);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo { font-size: 1.4rem; }
.sidebar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.5rem;
  flex: 1;
  overflow-y: auto;
}
.sidebar-logout {
  padding: 0.5rem;
  margin-top: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}

.sidebar-link:hover { background: rgba(255,255,255,0.08); }
.sidebar-link.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.sidebar-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke-width: 1.8;
}

.sidebar-label { overflow: hidden; text-overflow: ellipsis; }

/* Sidebar groups */
.sidebar-group { margin-top: 2px; }
.sidebar-group-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--nav-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  user-select: none;
}
.sidebar-group-header:hover { background: rgba(255,255,255,0.08); }
.sidebar-chevron {
  margin-left: auto;
  flex-shrink: 0;
  transition: transform 0.2s;
  opacity: 0.5;
}
.sidebar-group.open .sidebar-chevron { transform: rotate(180deg); }
.sidebar-group-items {
  display: none;
  flex-direction: column;
  gap: 1px;
}
.sidebar-group.open .sidebar-group-items { display: flex; }
.sidebar-sub {
  padding-left: 2.5rem;
  font-size: 0.82rem;
  font-weight: 400;
  opacity: 0.85;
}
.sidebar-sub:hover { opacity: 1; }

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 250;
  background: var(--nav-bg);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.4rem;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 190;
}

main {
  margin-left: 220px;
  max-width: 900px;
  padding: 1rem 1.5rem;
}

/* ── Institution Logo ── */

.inst-logo {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.inst-logo-fallback {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgb(33, 131, 88);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Sidebar responsive: collapse on tablets ── */

@media (max-width: 1024px) and (min-width: 769px) {
  .sidebar { width: 56px; }
  .sidebar-title,
  .sidebar-label { display: none; }
  .sidebar-header { justify-content: center; padding: 1rem 0.5rem; }
  .sidebar-link { justify-content: center; padding: 0.6rem; }
  .sidebar-group-header { justify-content: center; padding: 0.6rem; }
  .sidebar-chevron { display: none; }
  .sidebar-group-items { display: none !important; }
  .sidebar-sub { display: none; }
  main { margin-left: 56px; }
}

/* ── Sidebar responsive: mobile drawer ── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .sidebar-overlay.open { display: block; }
  main { margin-left: 0; padding: 3.5rem 1rem 1rem; }
}

/* ── Transactions Page ── */

.txn-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
}

.txn-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.txn-running-total {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Filter Bar ── */

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.filter-row:last-child { margin-bottom: 0; }

.filter-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.filter-group input,
.filter-group select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* ── Transaction Cards ── */

.txn-list { display: flex; flex-direction: column; gap: 0.375rem; }

.txn-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow 0.15s, border-color 0.15s;
  box-shadow: var(--shadow-sm);
}

.txn-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

.txn-card.txn-pending {
  background: var(--pending-bg);
  border-color: var(--pending-border);
}

.txn-card-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.875rem;
  cursor: pointer;
  min-height: 60px;
  -webkit-tap-highlight-color: transparent;
}

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

.txn-merchant {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.txn-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.15rem;
  flex-wrap: wrap;
}

.txn-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.txn-account {
  font-size: 0.7rem;
  color: var(--text-light);
  background: var(--border-light);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.txn-badge-pending {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a68307;
  background: #fef3c7;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.txn-card-right {
  text-align: right;
  flex-shrink: 0;
  padding-left: 0.75rem;
}

.txn-amount {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
}

.txn-amount.charge { color: var(--charge); }
.txn-amount.credit { color: var(--credit); }

.txn-cat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ── Inline Category Editor ── */

.cat-editor {
  padding: 0.75rem 0.875rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cat-editor-select,
.cat-editor-note {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.85rem;
  background: var(--surface);
}

.cat-editor-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-save, .btn-cancel {
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-save {
  background: var(--accent);
  color: #fff;
}

.btn-save:hover { background: #c46b3c; }

.btn-cancel {
  background: var(--border);
  color: var(--text);
}

.btn-cancel:hover { background: #ddd8d0; }

/* ── Load More / Empty ── */

.txn-load-more {
  text-align: center;
  padding: 1rem;
}

.btn-load-more {
  padding: 0.6rem 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.btn-load-more:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.txn-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.9rem;
}

/* ── Monarch-style Page Layout ── */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.03em;
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 0 2rem 1rem;
}

@media (max-width: 768px) {
  .page-header { padding: 1rem 1rem 0.5rem; }
  .content-card { margin: 0 1rem 1rem; }
}

/* ── Responsive (sidebar-aware) ── */

@media (min-width: 769px) {
  main { padding: 1.5rem 2rem; }
  .txn-title { font-size: 1.75rem; }
  .filter-row { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
}

@media (max-width: 480px) {
  .txn-header { flex-direction: column; gap: 0.25rem; }
  .filter-row { grid-template-columns: 1fr; }
  .txn-card-main { padding: 0.6rem 0.75rem; }
}
