/* ============================================================
   BILLS — main stylesheet
   Design direction: a personal ledger. Warm paper surfaces,
   an editorial serif for structure, tabular numerals for money,
   deep teal (positive) + brick red (negative) as the semantic pair.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

/* ---------------------------------------------------------
   TOKENS
--------------------------------------------------------- */
:root {
  /* surfaces */
  --bg: #faf8f3;
  --bg2: #f1ede4;
  --card-bg: #ffffff;
  --border: #e4dfd3;

  /* text */
  --text: #1c1f26;
  --text-light: #6b6558;

  /* chrome */
  --navbar-bg: #1c1f26;
  --navbar-text: #f5f2ea;
  --sidebar-bg: #f1ede4;

  /* semantic accents */
  --accent: #1f6f5c;
  --accent-hover: #185a4a;
  --income: #2f7a4f;
  --expense: #b5432e;
  --warn: #a8760a;
  --danger: #c23b2a;
  --danger-hover: #a52f21;

  /* type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Menlo, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 31, 38, 0.06), 0 1px 8px rgba(28, 31, 38, 0.04);
}

:root[data-theme="dark"] {
  --bg: #101216;
  --bg2: #16191f;
  --card-bg: #1a1d24;
  --border: #2a2e37;

  --text: #ece8df;
  --text-light: #9b9689;

  --navbar-bg: #05060a;
  --navbar-text: #f5f2ea;
  --sidebar-bg: #14161b;

  --accent: #3aa389;
  --accent-hover: #4bb99d;
  --income: #4caf74;
  --expense: #e07158;
  --warn: #d9a441;
  --danger: #e0654f;
  --danger-hover: #e87f6c;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* ---------------------------------------------------------
   RESET / BASE
--------------------------------------------------------- */
* {
  box-sizing: border-box;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

h1 { font-size: 30px; }
h2 { font-size: 21px; margin-top: 0; }
h3 { font-size: 16px; font-weight: 600; }

/* the signature ledger rule: section headers get a hairline
   sum-line rather than a generic underline */
main h1,
main h2 {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  position: relative;
}

main h1::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 56px;
  height: 2px;
  background: var(--accent);
}

p { margin: 0 0 8px; color: var(--text); }

a { color: var(--accent); }

/* Money / numeric values line up like a ledger */
.card p,
.big-number,
.account-item p,
.account-card p,
td.expense,
td.income,
.income-source-list li,
.payee-list li {
  font-variant-numeric: tabular-nums;
}

button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 7px;
  cursor: pointer;
}

button:hover { border-color: var(--text-light); }
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button.danger:hover { background: var(--danger); color: #fff; }

input,
select {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  width: 100%;
  margin-bottom: 6px;
}

input:disabled { color: var(--text-light); background: var(--bg2); }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  margin-top: 12px;
  margin-bottom: 4px;
}

/* ---------------------------------------------------------
   APP SHELL
--------------------------------------------------------- */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--navbar-bg);
  color: var(--navbar-text);
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.navbar .brand {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.2px;
}

.navbar button {
  margin-left: 8px;
  background: transparent;
  border: 1px solid rgba(245, 242, 234, 0.2);
  color: var(--navbar-text);
}
.navbar button:hover { border-color: rgba(245, 242, 234, 0.5); }

.mobile-toggle { display: none; }

.layout,
.app-shell {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 20px 14px;
  height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  transition: transform 0.3s ease;
}

.sidebar ul { list-style: none; padding: 0; margin: 0; }

.sidebar li {
  padding: 10px 12px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-light);
  font-weight: 500;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
}

.sidebar li:hover {
  background: var(--card-bg);
  color: var(--text);
}

.sidebar li.active {
  border-left-color: var(--accent);
  color: var(--text);
  background: var(--card-bg);
}

.app-content,
main {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
}

/* ---------------------------------------------------------
   CARDS / SUMMARY GRIDS
--------------------------------------------------------- */
.summary-cards,
.accounts-grid,
.goals-grid,
.insight-cards {
  display: grid;
  gap: 16px;
}

.summary-cards { grid-template-columns: repeat(4, 1fr); margin-bottom: 28px; }
.accounts-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.goals-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.insight-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.card,
.account-card,
.account-item,
.goal-card,
.insight-card,
.ai-summary,
.budget-total,
.budget-category-item,
.profile-card,
.pref-card,
.onboarding {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.card h3,
.account-card h3,
.goal-card h3 {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 6px;
}

.card p {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

.card.income p { color: var(--income); }
.card.expenses p { color: var(--expense); }
.card.net p { color: var(--text); }
.card.net-worth p { color: var(--accent); }

.account-item .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ---------------------------------------------------------
   CHARTS
--------------------------------------------------------- */
.charts-section h2 { margin-top: 28px; }

.chart-placeholder {
  background: var(--bg2);
  border: 1px dashed var(--border);
  color: var(--text-light);
  height: 220px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}

canvas {
  max-width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 28px;
}

/* ---------------------------------------------------------
   TABLES
--------------------------------------------------------- */
.table-responsive { overflow-x: auto; }

.transactions-table,
.forecast-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.transactions-table th,
.transactions-table td,
.forecast-table th,
.forecast-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.transactions-table th,
.forecast-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  background: var(--bg2);
}

.transactions-table td.expense,
td.expense { color: var(--expense); font-family: var(--font-mono); }
.transactions-table td.income,
td.income { color: var(--income); font-family: var(--font-mono); }

.transactions-table .actions button { margin-right: 8px; }

/* ---------------------------------------------------------
   LIST-STYLE PAGES (categories, payees, income sources)
--------------------------------------------------------- */
.category-list,
.payee-list,
.income-source-list {
  list-style: none;
  padding: 0;
  margin-top: 16px;
}

.category-list li,
.payee-list li,
.income-source-list li {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.category-list .actions button,
.payee-list .actions button,
.income-source-list .actions button {
  margin-left: 8px;
}

/* ---------------------------------------------------------
   RECURRING
--------------------------------------------------------- */
.recurring-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.recurring-item .left p { margin: 3px 0; color: var(--text-light); font-size: 13px; }
.recurring-item .left p:first-of-type { color: var(--text); font-family: var(--font-mono); font-size: 15px; }
.recurring-item .right button { margin-left: 8px; }

/* ---------------------------------------------------------
   OCCURRENCES
--------------------------------------------------------- */
.occurrence-day { margin-bottom: 28px; }
.occurrence-day h2 { margin-bottom: 10px; }

.occurrence-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.occurrence-item .right button { margin-left: 8px; }

.occurrence-item.pending { border-left-color: var(--warn); }
.occurrence-item.pending .status { color: var(--warn); font-weight: 600; }

.occurrence-item.paid { border-left-color: var(--income); }
.occurrence-item.paid .status { color: var(--income); font-weight: 600; }

.occurrence-item.skipped { border-left-color: var(--text-light); }
.occurrence-item.skipped .status { color: var(--text-light); font-weight: 600; }

.occurrence-item.overdue { border-left-color: var(--expense); }
.occurrence-item.overdue .status { color: var(--expense); font-weight: 600; }

/* ---------------------------------------------------------
   TRANSFER
--------------------------------------------------------- */
.transfer-page button.primary { margin-bottom: 20px; }

#transferModal label { font-weight: 600; }
#transferModal select,
#transferModal input { margin-top: 4px; }

/* ---------------------------------------------------------
   SETTINGS
--------------------------------------------------------- */
.profile-card,
.pref-card { margin-bottom: 20px; }

.profile-card input,
.pref-card select { margin-top: 4px; margin-bottom: 4px; }

.logout-section { margin-top: 8px; }
.logout-section button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.logout-section button.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

/* ---------------------------------------------------------
   MODAL
--------------------------------------------------------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 22, 0.55);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 24px;
  width: 420px;
  max-width: 92vw;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------------------------------------------------------
   NOTIFICATIONS
--------------------------------------------------------- */
.notif-bell { position: relative; font-size: 19px; }

.notif-count {
  position: absolute;
  top: -6px;
  right: -10px;
  background: var(--danger);
  color: #fff;
  padding: 1px 6px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}

.notif-list { list-style: none; padding: 0; }

.notif-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 15px 18px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
}

.notif-item.unread { border-left: 3px solid var(--accent); }
.notif-item .right button { margin-left: 8px; }

/* ---------------------------------------------------------
   ONBOARDING
--------------------------------------------------------- */
.onboarding { max-width: 560px; margin: 40px auto; }
.onboarding .subtitle { color: var(--text-light); margin-bottom: 20px; }

.onboarding input,
.onboarding select { margin-bottom: 12px; }

.onboarding-actions {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
}

/* ---------------------------------------------------------
   ACCOUNTS DASHBOARD SELECTOR
--------------------------------------------------------- */
.account-selector { margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 8px; }

.selector-btn {
  padding: 9px 14px;
  border-radius: 7px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-light);
  cursor: pointer;
  font-weight: 500;
}

.selector-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------------------------------------------------------
   FORECAST / INSIGHTS
--------------------------------------------------------- */
.forecast-summary { margin-bottom: 32px; }

/* ---------------------------------------------------------
   BUDGET
--------------------------------------------------------- */
.big-number {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 600;
  color: var(--text);
}

.budget-category-list { list-style: none; padding: 0; }
.budget-category-item { margin-bottom: 12px; }

.progress {
  background: var(--bg2);
  height: 8px;
  border-radius: 5px;
  margin: 10px 0;
  overflow: hidden;
}

.progress .bar {
  height: 8px;
  background: var(--accent);
  border-radius: 5px;
}

/* ---------------------------------------------------------
   GOALS
--------------------------------------------------------- */
.goal-card .bar { background: var(--income); }
.goal-date { color: var(--text-light); font-size: 13px; }

/* ---------------------------------------------------------
   ALERTS
--------------------------------------------------------- */
.alert-list { list-style: none; padding: 0; }

.alert-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.alert-item.high { border-left: 4px solid var(--danger); }
.alert-item.medium { border-left: 4px solid var(--warn); }
.alert-item.low { border-left: 4px solid var(--accent); }

/* ---------------------------------------------------------
   AUTH (login / signup)
--------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  border: none;
  padding: 0;
  margin-bottom: 20px;
  font-size: 24px;
}

.auth-card button[type="submit"] {
  width: 100%;
  margin-top: 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 11px;
}
.auth-card button[type="submit"]:hover { background: var(--accent-hover); }
.auth-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-switch {
  text-align: center;
  margin-top: 18px;
  color: var(--text-light);
  font-size: 14px;
}

.error-message {
  background: rgba(194, 59, 42, 0.1);
  color: var(--danger);
  border: 1px solid rgba(194, 59, 42, 0.25);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 13px;
  margin-top: 14px;
}

/* ---------------------------------------------------------
   404
--------------------------------------------------------- */
.not-found-page {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-light);
}

.not-found-page h1 {
  font-size: 64px;
  border: none;
  color: var(--border);
}

/* ---------------------------------------------------------
   MOBILE
--------------------------------------------------------- */
@media (max-width: 900px) {
  .layout,
  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 240px;
    height: calc(100vh - 60px);
    transform: translateX(-100%);
    z-index: 1500;
  }

  .sidebar.open { transform: translateX(0); }

  .navbar .nav-right button { display: none; }

  .mobile-toggle {
    display: inline-block;
    font-size: 22px;
    margin-right: 8px;
    background: transparent;
    border: none;
  }

  .app-content,
  main { padding: 18px; }
}

@media (max-width: 600px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .accounts-grid { grid-template-columns: 1fr; }

  h1 { font-size: 24px; }
  h2 { font-size: 19px; }
  h3 { font-size: 15px; }
  p, li, input, select, button { font-size: 15px; }

  .modal-content { width: 90%; padding: 18px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }

  .occurrence-item { flex-direction: column; align-items: flex-start; gap: 10px; }
  .occurrence-item .right { width: 100%; display: flex; gap: 8px; }
  .occurrence-item .right button { flex: 1; margin-left: 0; }
}

@media (max-width: 700px) {
  table thead { display: none; }

  table tr {
    display: block;
    margin-bottom: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: var(--radius);
  }

  table td {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border: none;
  }

  table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-light);
  }
}

/* ---------------------------------------------------------
   REDUCED MOTION
--------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}