/* pages.css — page-specific overrides */

/* ── Dashboard ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-6);
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.recent-tx-row td:nth-child(1) {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.needs-review-banner {
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #664d03;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ── Transactions ── */
.filters-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  background: var(--color-surface);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.filter-item label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-filter {
  flex-grow: 1;
  min-width: 200px;
}

.hover-bg-raised:hover {
  background: var(--color-surface-raised);
}

.tx-filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  align-items: flex-end;
}

.tx-bulk-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.tx-row-ignored td {
  opacity: .45;
  text-decoration: line-through;
}

.tx-row-review td:first-child {
  border-left: 3px solid var(--color-budget-warn);
}

.tx-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-table .col-date {
  width: 110px;
}

.tx-table .col-amount {
  width: 110px;
  text-align: right;
}

.tx-table .col-check {
  width: 40px;
}

.tx-table .col-action {
  width: 80px;
}

/* ── Monthly ── */
.monthly-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.month-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.month-label {
  font-size: var(--text-xl);
  font-weight: 700;
  min-width: 160px;
  text-align: center;
}

.budget-row {
  display: grid;
  grid-template-columns: 160px 1fr 80px 80px 80px;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.budget-row:last-child {
  border-bottom: none;
}

.budget-cat-name {
  font-size: var(--text-sm);
  font-weight: 500;
}

.budget-amounts {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  justify-content: flex-end;

  /* Ensures minus sign stays attached to number, prevents line break between sign and digits */
  .budget-number {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
}

/* ── Yearly ── */
.yearly-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.year-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.year-label {
  font-size: var(--text-xl);
  font-weight: 700;
  min-width: 80px;
  text-align: center;
}

.yearly-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

#sankey-container {
  width: 100%;
}

/* ── Accounts ── */
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
}

.account-card.archived {
  opacity: .5;
}

.account-info {
  flex: 1;
}

.account-name {
  font-weight: 600;
}

.account-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.account-balance {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-lg);
  font-weight: 600;
}

.account-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: var(--space-4);
}

.plaid-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e7f5ff;
  color: #1864ab;
}

/* ── Categories ── */
.group-header {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 600;
  cursor: default;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.cat-row:last-child {
  border-bottom: none;
}

.cat-name {
  flex: 1;
}

.cat-system {
  opacity: .5;
  font-style: italic;
}

/* ── Rules ── */
.rule-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.rule-pattern {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* ── Auth page ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: var(--space-4);
}

.auth-card {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-12) var(--space-10);
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-3xl);
}

.auth-card>p {
  color: var(--color-text-muted);
  margin: 0 0 var(--space-8);
  line-height: 1.5;
}

.btn-google {
  width: 100%;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
  font-weight: 500;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), background var(--transition-fast);
}

.btn-google:hover:not(:disabled) {
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}

.auth-notice {
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  text-align: left;
}

.auth-notice--warn {
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #664d03;
}

.auth-notice--error {
  background: #f8d7da;
  border: 1px solid #f5c2c7;
  color: #842029;
}

/* ── Split modal ── */
.split-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.split-row {
  display: grid;
  grid-template-columns: 1fr 120px 36px;
  gap: var(--space-2);
  align-items: center;
}

.split-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  font-weight: 600;
}

/* ── Keyboard shortcuts overlay ── */
.shortcuts-overlay {
  max-width: 640px;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-sm);
}

kbd {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

/* ── Month-over-month collapsible ── */
.mom-details {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  overflow: hidden;
}

.mom-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.mom-summary::-webkit-details-marker {
  display: none;
}

.mom-summary::before {
  content: '▶';
  font-size: .6rem;
  transition: transform 0.15s;
  color: var(--color-text-muted);
}

.mom-details[open] .mom-summary::before {
  transform: rotate(90deg);
}

.mom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0;
  border-top: 1px solid var(--color-border);
}

.mom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border);
}

.mom-row:last-child {
  border-bottom: none;
}

.mom-cat-name {
  color: var(--color-text);
}

.mom-delta {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.mom-up {
  color: var(--color-danger, #ef4444);
}

.mom-down {
  color: var(--color-success, #22c55e);
}

/* ── Trend category chips ── */
.trend-chip {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  border: 2px solid var(--chip-color, #888);
  transition: background 0.1s, opacity 0.1s;
  white-space: nowrap;
  line-height: 1.4;
}

.trend-chip-on {
  background: var(--chip-color, #888);
  color: #fff;
  opacity: 1;
}

.trend-chip-off {
  background: transparent;
  color: var(--color-text-muted);
  opacity: 0.55;
}

.trend-chip:hover {
  opacity: 1;
}

/* ── Anomaly badge ── */
.badge-warn {
  background: #fff3cd;
  color: #664d03;
}

[data-theme="dark"] .badge-warn {
  background: #3d2f00;
  color: #ffc107;
}

/* ── Section heading ── */
.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0 0 var(--space-4);
}

.page-content {
  padding: var(--space-6);
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Mobile Layout Overrides ── */
@media (max-width: 640px) {
  .summary-card .value {
    font-size: var(--text-lg);
  }

  /* Make header wrap cleanly */
  .app-header {
    height: auto;
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  /* Fix fixed-width grid rows */
  .budget-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start;
    padding: var(--space-4) var(--space-4);
    gap: var(--space-2);
  }

  .budget-row>div:empty {
    display: none;
  }

  .budget-row>div {
    justify-content: flex-start !important;
    width: 100%;
  }

  /* Show inline label/value pairs on mobile for budget rows */
  .budget-amounts[data-label] {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center;
    width: 100%;
  }

  .budget-amounts[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    font-variant-numeric: normal;
    flex-shrink: 0;
    margin-right: var(--space-4);
  }

  .rule-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .rule-row>* {
    flex: 1 1 auto;
  }

  .rule-row>div {
    width: 100%;
    margin-top: 0.5rem;
  }

  .tx-bulk-bar,
  .monthly-header,
  .yearly-header,
  .account-card,
  .group-header,
  .cat-row {
    flex-wrap: wrap;
  }

  .account-actions {
    margin-left: 0;
    margin-top: 0.5rem;
    width: 100%;
  }

  .hide-on-mobile {
    display: none !important;
  }

  /* ── Responsive Table Card Layout ── */
  .table-responsive table,
  .table-responsive thead,
  .table-responsive tbody,
  .table-responsive th,
  .table-responsive td,
  .table-responsive tr {
    display: block;
    width: 100%;
  }

  .table-responsive thead tr {
    display: none;
  }

  .table-responsive tbody tr {
    margin-bottom: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    position: relative;
    box-shadow: var(--shadow-sm);
  }

  .table-responsive tbody tr.tx-row-ignored {
    opacity: 0.6;
  }

  .table-responsive tbody tr.tx-row-review {
    border-left: 4px solid var(--color-warning);
  }

  .table-responsive td {
    border: none;
    border-bottom: 1px solid var(--color-border);
    position: relative;
    padding: var(--space-3) var(--space-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
  }

  .table-responsive td:last-child {
    border-bottom: 0;
  }

  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: left;
    margin-right: var(--space-4);
    flex-shrink: 0;
  }

  .table-responsive td .select,
  .table-responsive td input[type="checkbox"] {
    margin: 0;
  }
}