@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,wght@0,500;0,600;1,500&family=Space+Grotesk:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --paper: #EFE9D8;
  --paper-line: #DED5BC;
  --ink: #22304A;
  --ink-soft: #4A5670;
  --gold: #B8892B;
  --income: #2F6B4F;
  --expense: #9C4A3A;
  --font-display: 'Fraunces', serif;
  --font-body: 'Space Grotesk', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  font-family: var(--font-body);
  color: var(--ink);
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ---- brand mark ---- */
.brand-mark { height: 52px; width: 52px; object-fit: contain; border-radius: 10px; }
.brand-mark.small { height: 44px; width: 44px; margin: 0 auto 10px; display: block; }
.brand-mark.tiny { height: 34px; width: 34px; }
.login-card .brand-mark { margin: 0 auto 10px; display: block; }

/* ---- login / register ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.login-card {
  background: #FBF8EE;
  border-radius: 10px;
  padding: 32px 28px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}
.login-card h1 { font-family: var(--font-display); font-style: italic; margin: 10px 0 4px; font-size: 22px; }
.login-card p { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.login-error { color: var(--expense); font-size: 12px; margin-top: 10px; min-height: 16px; }
.auth-switch { margin-top: 14px; font-size: 12.5px; color: var(--ink-soft); }
.link-btn {
  background: none; border: none; color: var(--gold); font-weight: 600;
  cursor: pointer; font-size: 12.5px; text-decoration: underline; padding: 0 4px;
}

/* ---- onboarding modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(34,48,74,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 500; padding: 16px;
}
.modal-card {
  background: #FBF8EE; border-radius: 12px; padding: 30px 26px; max-width: 360px; width: 100%; text-align: center;
}
.modal-card h2 { font-family: var(--font-display); font-style: italic; font-size: 20px; margin: 4px 0 10px; }
.modal-card p { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; line-height: 1.5; }

.stamp-spin {
  font-family: var(--font-display);
  font-size: 40px;
  color: var(--gold);
  border: 3px solid var(--gold);
  border-radius: 999px;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: spin 1.4s ease-in-out infinite;
  margin: 0 auto;
}
@keyframes spin {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.05); }
}

.cover {
  background: linear-gradient(180deg, var(--ink) 0%, #1a2438 100%);
  padding: 28px 24px 34px;
  position: relative;
}
.cover::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 10px;
  background: repeating-linear-gradient(90deg, var(--gold) 0 14px, transparent 14px 22px);
  opacity: 0.55;
}
.cover-inner { max-width: 760px; margin: 0 auto; }
.cover-title-row { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.cover-title { font-family: var(--font-display); font-size: 28px; color: #F5F0E2; line-height: 1; }
.cover-sub { font-size: 12.5px; color: #A9B2C4; margin-top: 4px; letter-spacing: 0.02em; }
.cover-actions { margin-left: auto; display: flex; gap: 8px; }
.ghost-btn {
  background: transparent; border: 1px solid #3E4B68; color: #C7CEDD;
  border-radius: 20px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--gold); color: var(--gold); }
.ghost-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(184,137,43,0.12); }
.cover-month-nav { display: flex; align-items: center; justify-content: center; gap: 18px; }
.arrow-btn {
  background: transparent; border: 1px solid #3E4B68; color: #F5F0E2;
  width: 34px; height: 34px; border-radius: 50%; font-size: 18px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.arrow-btn:hover { background: #2C374F; border-color: var(--gold); }
.arrow-btn.small { width: 28px; height: 28px; font-size: 15px; border-color: var(--paper-line); color: var(--ink); }
.arrow-btn.small:hover { background: var(--paper-line); }
.month-display {
  font-family: var(--font-display); font-size: 20px; font-style: italic;
  color: var(--gold); min-width: 170px; text-align: center;
}

/* ---- mobile top bar (hidden on desktop) ---- */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--ink);
  position: sticky;
  top: 0;
  z-index: 100;
}
.mobile-month-nav { display: flex; align-items: center; gap: 8px; }
.mobile-month {
  font-family: var(--font-display); font-style: italic; font-size: 15px;
  color: var(--gold); min-width: 108px; text-align: center;
}
.avatar-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--gold);
  background: var(--ink); color: var(--gold); font-family: var(--font-display);
  font-weight: 600; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ---- bottom tab bar (mobile only) ---- */
.bottom-tabbar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #FBF8EE; border-top: 1px solid var(--paper-line);
  justify-content: space-around; padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 100;
}
.tab-btn {
  background: none; border: none; display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 11px; color: var(--ink-soft); font-family: var(--font-body); font-weight: 600;
  padding: 4px 14px; cursor: pointer;
}
.tab-btn.active { color: var(--gold); }
.tab-icon { font-size: 18px; }

.page-body { max-width: 760px; margin: 0 auto; padding: 22px 20px 60px; }

.history-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 18px; }
.history-tab {
  flex: 0 0 auto; background: #F7F3E6; border: 1px solid var(--paper-line);
  border-bottom: 3px solid var(--paper-line); border-radius: 8px 8px 4px 4px;
  padding: 8px 12px; display: flex; flex-direction: column; align-items: center;
  cursor: pointer; min-width: 76px; font-family: var(--font-body);
}
.history-tab.active { border-bottom-color: var(--gold); background: #FBF8EE; box-shadow: 0 2px 6px rgba(184,137,43,0.18); }
.history-month { font-size: 13px; font-weight: 600; color: var(--ink); }
.history-year { font-size: 10px; color: var(--ink-soft); }
.history-balance { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); margin-top: 3px; }

.ledger-sheet {
  background: #FBF8EE; border: 1px solid var(--paper-line); border-radius: 6px;
  padding: 26px 24px 30px;
  background-image: repeating-linear-gradient(180deg, transparent 0, transparent 38px, var(--paper-line) 39px);
  box-shadow: 0 3px 14px rgba(34,48,74,0.08);
}

.sheet-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 14px; }

.opening-row, .ledger-row, .subtotal-row, .savings-balance-line { display: flex; align-items: baseline; gap: 8px; min-height: 38px; }
.ruled-label {
  font-weight: 600; font-size: 13px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.ruled-dots { flex: 1; border-bottom: 1.5px dotted #B7AD8F; margin-bottom: 5px; }
.opening-amount { font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: var(--ink); }

.info-dot {
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--ink-soft);
  background: none; color: var(--ink-soft); font-size: 10px; font-style: italic; font-family: var(--font-display);
  cursor: pointer; line-height: 1; padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.info-dot:hover { border-color: var(--gold); color: var(--gold); }
.info-panel {
  background: #F3EED9; border: 1px dashed var(--gold); border-radius: 6px;
  padding: 10px 12px; font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); margin: 4px 0 10px;
}

.adjust-row { margin: -4px 0 6px; }
.adjustments-list-row {
  display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--ink-soft);
  padding: 3px 0;
}
.adjustments-list-row .amt-pos { color: var(--income); font-family: var(--font-mono); }
.adjustments-list-row .amt-neg { color: var(--expense); font-family: var(--font-mono); }

.ledger-section { margin-top: 22px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 2px solid var(--ink); padding-bottom: 6px; margin-bottom: 8px; flex-wrap: wrap; gap: 8px;
}
.section-head h3 { font-family: var(--font-display); font-style: italic; font-size: 19px; margin: 0; color: var(--ink); }
.savings-btns { display: flex; gap: 6px; }
.add-btn {
  border: 1px solid var(--ink); background: transparent; border-radius: 20px;
  padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink);
  transition: all 0.15s;
}
.add-btn.income:hover { background: var(--income); border-color: var(--income); color: #fff; }
.add-btn.expense:hover { background: var(--expense); border-color: var(--expense); color: #fff; }

.empty-row { font-size: 13px; color: #9A9280; font-style: italic; padding: 8px 0; }

.row-label { font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { font-family: var(--font-mono); font-size: 14.5px; font-weight: 500; margin-bottom: 5px; }
.income-amount { color: var(--income); }
.expense-amount { color: var(--expense); }

.remove-x { background: none; border: none; color: #B7AD8F; font-size: 16px; cursor: pointer; line-height: 1; padding: 0 2px; }
.remove-x:hover { color: var(--expense); }

.category-block { margin-bottom: 6px; }
.category-name {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--gold); margin-top: 8px;
}

.subtotal-row { margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--ink); }
.subtotal-row .row-label { font-weight: 600; }

.draft-row {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  background: #F3EED9; border: 1px dashed var(--gold); border-radius: 6px; padding: 8px; margin-top: 6px;
}
.draft-input { font-family: var(--font-body); font-size: 13px; border: 1px solid var(--paper-line); border-radius: 4px; padding: 6px 8px; background: #fff; }
.draft-input.label { flex: 1; min-width: 110px; }
.draft-input.amount { width: 130px; font-family: var(--font-mono); }
.tiny-btn {
  background: var(--ink); color: #F5F0E2; border: none; border-radius: 4px;
  padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tiny-btn:hover { background: var(--gold); }

.savings-balance-line { margin-bottom: 6px; }

.balance-wrap { display: flex; justify-content: center; margin-top: 30px; }
.stamp {
  border: 3px solid var(--income); color: var(--income); border-radius: 50%;
  width: 168px; height: 168px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; transform: rotate(-4deg); position: relative;
}
.stamp::before { content: ""; position: absolute; inset: 6px; border: 1px solid var(--income); border-radius: 50%; opacity: 0.5; }
.stamp.stamp-negative { border-color: var(--expense); color: var(--expense); }
.stamp.stamp-negative::before { border-color: var(--expense); }
.stamp-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; }
.stamp-amount { font-family: var(--font-mono); font-size: 22px; font-weight: 500; margin: 4px 0; }
.stamp-month { font-family: var(--font-display); font-style: italic; font-size: 12px; }

/* ---- reports table ---- */
.report-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; margin-top: 10px; }
.report-table th, .report-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--paper-line); }
.report-table th:first-child, .report-table td:first-child { text-align: left; font-family: var(--font-body); }
.report-table thead th { font-family: var(--font-body); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); border-bottom: 2px solid var(--ink); }
.report-table tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: none; }
.report-savings-total { margin-top: 14px; font-family: var(--font-mono); font-size: 14px; text-align: right; color: var(--income); }

/* ---- profile view ---- */
.profile-sheet { max-width: 480px; margin: 0 auto; }
.profile-header { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: var(--gold);
  border: 2px solid var(--gold); display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 22px; font-weight: 600; flex-shrink: 0;
}
.profile-name { font-family: var(--font-display); font-style: italic; font-size: 20px; color: var(--ink); }
.profile-email { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.profile-since { font-size: 11px; color: #9A9280; margin-top: 2px; }
.profile-form { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.profile-form .tiny-btn { align-self: flex-start; margin-top: 4px; }

/* ---- print ---- */
.print-header { text-align: center; margin-bottom: 18px; }
.print-title { font-family: var(--font-display); font-style: italic; font-size: 22px; }
.print-sub { font-size: 12px; color: var(--ink-soft); }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .cover { background: none; padding: 0 0 16px; display: block !important; }
  .cover::after { display: none; }
  .cover-title { color: var(--ink); }
  .cover-sub { color: var(--ink-soft); }
  .ledger-sheet { box-shadow: none; border: none; background: none; background-image: none; }
  .print-header { display: block !important; }
  .page-body { padding: 0; }
  .history-strip { display: none !important; }
}

/* ---- responsive: switch desktop nav <-> mobile nav ---- */
@media (max-width: 700px) {
  .cover { display: none; }
  .mobile-topbar { display: flex; }
  .bottom-tabbar { display: flex; }
  .page-body { padding: 16px 14px 90px; }
  .ledger-sheet { padding: 20px 14px 24px; }
  .stamp { width: 140px; height: 140px; }
}
@media (min-width: 701px) {
  .mobile-topbar { display: none; }
  .bottom-tabbar { display: none; }
}
