/* ============================================
   Whole Soul Financial — Budget Tool
   ============================================ */
:root {
  --color-bg: #FAF7F2;
  --color-card: #FFFFFF;
  --color-teal: #2E9DB8;
  --color-teal-light: #8FD0DE;
  --color-teal-dim: #E4F2F5;
  --color-navy: #3E4A56;
  --color-charcoal: #2B2F33;
  --color-muted: #6B7280;
  --color-gold: #B6892F;
  --color-gold-dim: #F9F1E2;
  --color-line: #E6E0D4;
  --color-error: #B3432C;
  --color-green: #2A7E5A;
  --color-green-dim: #E2F4EC;
  --color-red: #B3432C;
  --color-red-dim: #FCEEE9;

  --font-display: 'Lora', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', monospace;

  --radius: 10px;
  --shadow-soft: 0 2px 14px rgba(62, 74, 86, 0.07);
  --max-width: 860px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--color-bg); color: var(--color-charcoal); font-family: var(--font-body); line-height: 1.55; -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
button { font-family: var(--font-body); cursor: pointer; }

/* ---------- Entry / Email lookup screen ---------- */

.entry-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--color-bg);
}

.entry-card {
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
  text-align: center;
}

.entry-card img { height: 36px; margin: 0 auto 28px; }

.entry-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--color-navy);
  margin: 0 0 10px;
}

.entry-card p {
  color: var(--color-muted);
  font-size: 14.5px;
  margin: 0 0 28px;
}

.entry-card .field { text-align: left; margin-bottom: 14px; }
.entry-card label { display: block; font-size: 13.5px; font-weight: 600; color: var(--color-navy); margin-bottom: 6px; }

.entry-card input[type="email"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--color-charcoal);
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.entry-card input[type="email"]:focus { outline: none; border-color: var(--color-teal); box-shadow: 0 0 0 3px var(--color-teal-dim); }

.entry-error { color: var(--color-error); font-size: 13px; margin: 8px 0 0; display: none; }

.btn-primary {
  background: var(--color-teal);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 15px;
  padding: 13px 24px;
  border-radius: var(--radius);
  width: 100%;
  transition: background 0.15s;
  margin-top: 4px;
}
.btn-primary:hover { background: #277E94; }
.btn-primary:disabled { background: var(--color-muted); cursor: not-allowed; }

/* ---------- Main header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--color-line);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.header-logo { height: 28px; width: auto; }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.header-email {
  font-size: 13px;
  color: var(--color-muted);
  padding: 6px 12px;
  background: var(--color-bg);
  border-radius: 20px;
  border: 1px solid var(--color-line);
}

.btn-secondary {
  background: none;
  border: 1.5px solid var(--color-line);
  color: var(--color-navy);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.btn-secondary:hover { border-color: var(--color-teal); background: var(--color-teal-dim); }

.btn-save {
  background: var(--color-navy);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}
.btn-save:hover { background: #2f3a45; }
.btn-save.saved { background: var(--color-green); }

.btn-print {
  background: var(--color-gold);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}
.btn-print:hover { background: #9a7326; }

/* ---------- Budget layout ---------- */

.budget-app { display: none; }
.budget-app.visible { display: block; }

.budget-page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ---------- Summary bar ---------- */

.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.summary-card {
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.summary-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted); font-weight: 600; margin-bottom: 6px; }
.summary-card .amount { font-family: var(--font-display); font-size: 26px; color: var(--color-navy); font-weight: 600; }
.summary-card.remaining .amount { color: var(--color-green); }
.summary-card.remaining.over .amount { color: var(--color-red); }
.summary-card.remaining .sublabel { font-size: 12px; color: var(--color-muted); margin-top: 4px; }

@media (max-width: 560px) { .summary-bar { grid-template-columns: 1fr; } }

/* ---------- Budget sections ---------- */

.budget-section {
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 20px;
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-bg);
  gap: 12px;
}

.section-head-left { display: flex; align-items: center; gap: 12px; }

.section-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.section-title { font-family: var(--font-display); font-size: 17px; color: var(--color-navy); font-weight: 600; }
.section-subtitle { font-size: 12.5px; color: var(--color-muted); margin-top: 1px; }

.section-total {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--color-navy);
  white-space: nowrap;
}

/* ---------- Line items ---------- */

.line-items { padding: 6px 0; }

.line-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--color-line);
  transition: background 0.12s;
}
.line-item:last-child { border-bottom: none; }
.line-item:hover { background: var(--color-bg); }

.line-item-label {
  flex: 1;
  font-size: 14.5px;
  color: var(--color-charcoal);
  border: none;
  background: transparent;
  padding: 4px 6px;
  border-radius: 6px;
  min-width: 0;
  transition: background 0.12s;
}
.line-item-label:focus { outline: none; background: var(--color-teal-dim); }

.line-item-amount-wrap {
  position: relative;
  flex-shrink: 0;
  width: 130px;
}
.line-item-amount-wrap::before {
  content: "$";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  font-size: 14px;
  pointer-events: none;
}

.line-item-amount {
  width: 100%;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--color-charcoal);
  border: 1px solid transparent;
  background: var(--color-bg);
  border-radius: 8px;
  padding: 7px 10px 7px 24px;
  transition: border-color 0.12s, background 0.12s;
}
.line-item-amount:focus { outline: none; border-color: var(--color-teal); background: var(--color-teal-dim); }

.remove-item-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--color-muted);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.remove-item-btn:hover { background: var(--color-red-dim); color: var(--color-red); }

.add-item-row {
  padding: 10px 20px;
  display: flex;
}

.add-item-btn {
  background: none;
  border: 1.5px dashed var(--color-teal-light);
  color: var(--color-teal);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background 0.12s;
}
.add-item-btn:hover { background: var(--color-teal-dim); }

/* ---------- Giving section accent ---------- */
.budget-section.giving .section-icon { background: var(--color-gold-dim); }
.budget-section.giving .section-head { border-left: 4px solid var(--color-gold); }
.budget-section.giving .section-total { color: var(--color-gold); }

/* ---------- Coach notes ---------- */

.coach-notes-section {
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 20px;
  overflow: hidden;
}

.coach-notes-section .section-head { background: var(--color-navy); border-bottom: none; }
.coach-notes-section .section-title { color: #fff; }
.coach-notes-section .section-subtitle { color: rgba(255,255,255,0.6); }
.coach-notes-section .section-icon { background: rgba(255,255,255,0.12); }

.coach-notes-body { padding: 16px 20px; }

.coach-notes-body textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--color-charcoal);
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 12px 14px;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.15s;
}
.coach-notes-body textarea:focus { outline: none; border-color: var(--color-teal); }
.coach-notes-body textarea::placeholder { color: var(--color-muted); }

/* ---------- Hidden on screen, visible when printing ---------- */

.print-header { display: none; }

/* ---------- Print styles ---------- */

@media print {
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  .site-header,
  .add-item-btn,
  .add-item-row,
  .remove-item-btn,
  .entry-screen,
  .coach-notes-section { display: none !important; }

  body { background: #fff; }

  .budget-page { padding: 0; max-width: 100%; }

  .print-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #2E9DB8;
  }

  .print-header img { height: 30px; }
  .print-header .print-meta { font-size: 12px; color: #6B7280; text-align: right; }
  .print-header .print-meta strong { display: block; color: #3E4A56; font-size: 14px; margin-bottom: 2px; }

  .summary-bar { margin-bottom: 20px; gap: 8px; }
  .summary-card { border: 1px solid #E6E0D4; box-shadow: none; }
  .summary-card .amount { font-size: 20px; }

  .budget-section { box-shadow: none; margin-bottom: 14px; break-inside: avoid; }
  .section-head { background: #FAF7F2 !important; }

  .line-item-label, .line-item-amount {
    border: none !important;
    background: transparent !important;
  }

  .line-item-amount { font-size: 13px; }
}

/* ============================================
   Plaid / Bank connection feature additions
   ============================================ */

/* ---------- Tab bar ---------- */

.tab-bar {
  display: flex;
  gap: 4px;
  padding: 0 24px 0;
  border-top: 1px solid var(--color-line);
  background: #fff;
}

.tab-btn {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-muted);
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--color-navy); }
.tab-btn.active { color: var(--color-teal); border-bottom-color: var(--color-teal); }

/* ---------- Plaid banner ---------- */

.plaid-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
  flex-wrap: wrap;
}

.plaid-banner.connected {
  border-color: var(--color-teal-light);
  background: var(--color-teal-dim);
}

.plaid-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--color-charcoal);
}

.plaid-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-muted);
  flex-shrink: 0;
}

.plaid-dot.connected { background: var(--color-green); }

.plaid-connect-btn {
  background: var(--color-teal);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.plaid-connect-btn:hover { background: #277E94; }
.plaid-connect-btn:disabled { background: var(--color-muted); cursor: not-allowed; }

.plaid-sync-btn {
  background: var(--color-navy);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.plaid-sync-btn:hover { background: #2f3a45; }
.plaid-sync-btn:disabled { background: var(--color-muted); cursor: not-allowed; }

/* ---------- Budget/actual/diff columns ---------- */

.section-totals {
  display: flex;
  gap: 20px;
}

.section-total-col {
  text-align: right;
  min-width: 90px;
}

.section-total-col .col-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  font-weight: 600;
  margin-bottom: 3px;
}

.diff-positive { color: var(--color-green); font-weight: 600; }
.diff-negative { color: var(--color-red);   font-weight: 600; }

.line-item-header {
  display: flex;
  align-items: center;
  padding: 6px 20px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-line);
  gap: 8px;
}

.line-item-header .li-label-col  { flex: 1; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
.line-item-header .li-num-col    { width: 90px; text-align: right; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
.line-item-header .li-remove-col { width: 28px; }

/* Line items with actuals */
.line-item.has-actuals .li-amounts {
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-item.has-actuals .line-item-amount-wrap { width: 100px; }

.li-actual,
.li-diff {
  width: 90px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--color-charcoal);
  flex-shrink: 0;
}

.li-diff { font-weight: 600; }

/* ---------- Transactions tab ---------- */

.tx-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.tx-count {
  font-size: 13px;
  color: var(--color-muted);
}

.tx-list-header {
  display: grid;
  grid-template-columns: 100px 1fr 100px 180px;
  gap: 12px;
  padding: 8px 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: 8px 8px 0 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
}

.tx-list {
  border: 1px solid var(--color-line);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.tx-row {
  display: grid;
  grid-template-columns: 100px 1fr 100px 180px;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-card);
  transition: background 0.1s;
}
.tx-row:last-child { border-bottom: none; }
.tx-row:hover { background: var(--color-bg); }
.tx-row.tx-pending { opacity: 0.65; }

.tx-date     { font-size: 13px; color: var(--color-muted); white-space: nowrap; }
.tx-merchant { font-size: 14px; color: var(--color-charcoal); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount   { font-family: var(--font-mono); font-size: 13.5px; text-align: right; font-weight: 600; }
.tx-expense  { color: var(--color-red); }
.tx-income   { color: var(--color-green); }

.tx-category-select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--color-charcoal);
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.tx-category-select:focus { outline: none; border-color: var(--color-teal); }

.tx-pending-badge {
  font-size: 10.5px;
  background: var(--color-gold-dim);
  color: var(--color-gold);
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.tx-empty {
  text-align: center;
  color: var(--color-muted);
  font-size: 14.5px;
  padding: 60px 24px;
}

.tx-footnote {
  font-size: 12.5px;
  color: var(--color-muted);
  font-style: italic;
  text-align: center;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .tx-list-header { grid-template-columns: 80px 1fr 80px; }
  .tx-row { grid-template-columns: 80px 1fr 80px; }
  .tx-category-select { display: none; }
  .section-totals { gap: 12px; }
  .section-total-col { min-width: 70px; }
}

/* ============================================
   Mobile optimizations (≤ 520px)
   ============================================ */

@media (max-width: 520px) {

  /* ---------- Header ---------- */
  .header-inner {
    padding: 10px 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .header-logo { height: 22px; }
  .header-email { display: none; }
  .header-actions { gap: 6px; flex-wrap: wrap; }
  .btn-secondary { font-size: 12px; padding: 6px 10px; }
  .btn-save, .btn-print { font-size: 12px; padding: 7px 12px; }

  /* ---------- Tab bar ---------- */
  .tab-bar { padding: 0 14px; }
  .tab-btn { padding: 8px 14px; font-size: 13px; }

  /* ---------- Budget page ---------- */
  .budget-page { padding: 14px 14px 60px; }

  /* ---------- Summary bar ---------- */
  .summary-bar { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card.remaining { grid-column: 1 / -1; }
  .summary-card .amount { font-size: 20px; }

  /* ---------- Plaid banner ---------- */
  .plaid-banner { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* ---------- Section headers ---------- */
  .section-head { padding: 12px 14px; gap: 8px; flex-wrap: wrap; }
  .section-icon { width: 30px; height: 30px; font-size: 15px; }
  .section-title { font-size: 15px; }
  .section-subtitle { font-size: 11.5px; }

  /* 3-column totals — stack on mobile */
  .section-totals { gap: 12px; flex-wrap: wrap; }
  .section-total-col { min-width: 80px; }
  .section-total-col .col-label { font-size: 9.5px; }
  .section-total { font-size: 14px; }

  /* ---------- Line item header ---------- */
  .line-item-header { padding: 5px 14px; font-size: 9.5px; }
  .line-item-header .li-num-col { width: 68px; }

  /* ---------- Line items ---------- */
  .line-item { padding: 9px 14px; }
  .line-item-label { font-size: 13.5px; }
  .line-item-amount-wrap { width: 90px; }
  .line-item-amount { font-size: 13px; padding: 6px 8px 6px 22px; }

  /* Line items WITH actuals — stack amounts below label */
  .line-item.has-actuals {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 6px;
    align-items: start;
  }
  .line-item.has-actuals .line-item-label {
    grid-column: 1;
    grid-row: 1;
  }
  .line-item.has-actuals .remove-item-btn {
    grid-column: 2;
    grid-row: 1;
  }
  .line-item.has-actuals .li-amounts {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }
  .line-item.has-actuals .line-item-amount-wrap { width: 100%; }
  .line-item.has-actuals .line-item-amount { width: 100%; }
  .li-actual, .li-diff { width: auto; font-size: 13px; text-align: center; }

  /* ---------- Add item ---------- */
  .add-item-row { padding: 8px 14px; }
  .add-item-btn { font-size: 13px; padding: 9px 14px; }

  /* ---------- Goal total bar ---------- */
  .goal-total-bar { padding: 12px 14px; }
  .goal-total-bar .amount { font-size: 18px; }

  /* ---------- Transactions tab — card layout ---------- */
  .tx-list-header { display: none; }

  .tx-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 10px;
    padding: 12px 14px;
  }

  .tx-merchant {
    grid-column: 1;
    grid-row: 1;
    font-size: 14px;
    font-weight: 600;
  }

  .tx-amount {
    grid-column: 2;
    grid-row: 1;
    font-size: 14px;
    white-space: nowrap;
  }

  .tx-date {
    grid-column: 1;
    grid-row: 2;
    font-size: 12px;
    color: var(--color-muted);
  }

  .tx-category-select {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 2px;
    font-size: 13px;
    padding: 7px 10px;
  }

  .tx-pending-badge {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
  }

  /* ---------- Coach notes ---------- */
  .coach-notes-body { padding: 12px 14px; }
  .coach-notes-body textarea { font-size: 14px; }

  /* ---------- Entry screen ---------- */
  .entry-card { padding: 36px 22px; }
  .entry-card h1 { font-size: 21px; }
  .entry-card p { font-size: 14px; }

  /* ---------- Admin (graceful fallback) ---------- */
  .admin-budget-inner { padding: 16px 16px 60px; }
  .admin-panel-header { flex-direction: column; gap: 10px; }
  .admin-btn-row { flex-wrap: wrap; }
  .plaid-admin-bar { flex-direction: column; align-items: flex-start; }
}
