/* ============================================================
   Ledger & Hearth — Household Budget Tracker
   Design system: warm paper ledger aesthetic
   ============================================================ */

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

:root {
  /* Color tokens */
  --paper:        #FBF7F0;
  --paper-raised: #FFFFFF;
  --ink:          #2B2620;
  --ink-soft:     #6B6258;
  --ink-faint:    #9C9286;
  --income:       #1F6F54;
  --income-soft:  #E3EFE9;
  --expense:      #B3492B;
  --expense-soft: #F5E6E0;
  --gold:         #D9A441;
  --gold-soft:    #FAF0DA;
  --border:       #E8E1D3;
  --border-strong:#D7CCB8;
  --danger:       #B3492B;
  --shadow-color: 38 30 12;

  /* Type */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, 'Courier New', monospace;

  /* Layout */
  --sidebar-width: 248px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

input, select, textarea {
  font-family: var(--font-body);
}

::selection {
  background: var(--gold-soft);
  color: var(--ink);
}

/* Focus visibility for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--income);
  outline-offset: 2px;
}

/* ============================================================
   Signature element: ink-swash underline
   Used sparingly — active nav item, section heading accents
   ============================================================ */
.swash {
  position: relative;
  display: inline-block;
}
.swash::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -4px;
  height: 6px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 8' preserveAspectRatio='none'%3E%3Cpath d='M1 5.5C15 2 30 7 45 4.5S75 1 99 5' stroke='%23D9A441' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}

/* ============================================================
   App shell
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--paper-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 22px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(155deg, var(--income), #154f3c);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; stroke: var(--paper); }
.brand-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.brand-text span { display: block; font-family: var(--font-body); font-weight: 500; font-size: 11px; color: var(--ink-faint); letter-spacing: 0.03em; text-transform: uppercase; margin-top: 1px; }

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 10px;
  margin: 18px 0 8px;
}
.nav-section-label:first-of-type { margin-top: 4px; }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-link svg { width: 17px; height: 17px; stroke-width: 1.8; flex-shrink: 0; }
.nav-link:hover { background: var(--gold-soft); color: var(--ink); }
.nav-link.active { color: var(--ink); font-weight: 600; }
.nav-link.active .nav-link-label { position: relative; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.member-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.member-chip-info { min-width: 0; flex: 1; }
.member-chip-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-chip-role { font-size: 11px; color: var(--ink-faint); text-transform: capitalize; }
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 13px;
  font-weight: 500;
}
.logout-btn:hover { background: var(--expense-soft); color: var(--expense); }
.logout-btn svg { width: 15px; height: 15px; }

/* ---------- Main content ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  padding: 28px 36px 60px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 26px; letter-spacing: -0.01em; }
.page-subtitle { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn svg { width: 16px; height: 16px; stroke-width: 2; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #3d3528; }
.btn-accent { background: var(--income); color: #fff; }
.btn-accent:hover { background: #195c46; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--paper); border-color: var(--ink-soft); }
.btn-danger-ghost { background: transparent; color: var(--expense); border-color: var(--expense-soft); }
.btn-danger-ghost:hover { background: var(--expense-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-icon { padding: 8px; }

/* ---------- Summary strip ---------- */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.summary-card {
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.summary-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
}
.summary-card.is-income::before { background: var(--income); }
.summary-card.is-expense::before { background: var(--expense); }
.summary-card.is-balance::before { background: var(--gold); }
.summary-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  display: flex; align-items: center; gap: 6px;
}
.summary-label svg { width: 14px; height: 14px; }
.summary-amount {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.02em;
}
.summary-card.is-income .summary-amount { color: var(--income); }
.summary-card.is-expense .summary-amount { color: var(--expense); }
.summary-meta { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 22px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h2 { font-size: 17px; }
.panel-header-actions { display: flex; gap: 8px; align-items: center; }

.charts-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
}

/* ---------- Filters bar ---------- */
.filters-bar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters-bar select, .filters-bar input[type="text"], .filters-bar input[type="month"] {
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  font-size: 13px;
  color: var(--ink);
}
.search-wrap { position: relative; flex: 1; min-width: 180px; max-width: 280px; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--ink-faint); }
.search-wrap input { width: 100%; padding-left: 32px; }

/* ---------- Transactions table ---------- */
.table-wrap { overflow-x: auto; }
table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.ledger thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.ledger thead th.num { text-align: right; }
table.ledger tbody tr {
  border-bottom: 1px solid var(--border);
  position: relative;
}
table.ledger tbody tr:last-child { border-bottom: none; }
table.ledger tbody td {
  padding: 12px;
  vertical-align: middle;
}
table.ledger tbody tr td:first-child { position: relative; padding-left: 16px; }
table.ledger tbody tr td:first-child::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 2px;
}
table.ledger tbody tr.row-income td:first-child::before { background: var(--income); }
table.ledger tbody tr.row-expense td:first-child::before { background: var(--expense); }

.cell-desc { font-weight: 500; }
.cell-desc-notes { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.cell-date { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-amount { font-family: var(--font-mono); font-weight: 600; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-amount.income { color: var(--income); }
.cell-amount.expense { color: var(--expense); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.member-pill { display: flex; align-items: center; gap: 7px; }
.member-pill .avatar { width: 24px; height: 24px; font-size: 10px; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint);
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--paper); color: var(--ink); }
.icon-btn.danger:hover { background: var(--expense-soft); color: var(--expense); }

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--ink-faint);
}
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { margin: 4px 0 0; font-size: 14px; }
.empty-state .empty-title { font-family: var(--font-display); font-size: 17px; color: var(--ink-soft); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink-soft);
}
.pagination-controls { display: flex; gap: 6px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(43, 38, 32, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--paper-raised);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px -16px rgba(var(--shadow-color) / 0.35);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; }
.modal-close { width: 30px; height: 30px; border-radius: 8px; border: none; background: var(--paper); display: flex; align-items: center; justify-content: center; color: var(--ink-soft); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.form-field .hint { font-size: 11.5px; color: var(--ink-faint); }
.form-field input, .form-field select, .form-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: 14px;
  color: var(--ink);
  width: 100%;
}
.form-field textarea { resize: vertical; min-height: 64px; font-family: var(--font-body); }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--income);
  background: var(--paper-raised);
}
.form-field input[type="color"] {
  padding: 4px;
  cursor: pointer;
}
.form-field input:disabled, .form-field select:disabled {
  background: var(--border);
  color: var(--ink-faint);
  cursor: not-allowed;
}
.form-field.error input, .form-field.error select { border-color: var(--expense); }
.field-error { font-size: 12px; color: var(--expense); }

.type-toggle { display: flex; gap: 8px; }
.type-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--paper);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.type-toggle button svg { width: 15px; height: 15px; }
.type-toggle button.active.type-income { background: var(--income-soft); border-color: var(--income); color: var(--income); }
.type-toggle button.active.type-expense { background: var(--expense-soft); border-color: var(--expense); color: var(--expense); }

.amount-input-wrap { position: relative; }
.amount-input-wrap .currency-prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-weight: 600; color: var(--ink-faint); font-size: 14px;
}
.amount-input-wrap input { padding-left: 28px; font-family: var(--font-mono); font-weight: 600; }

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  background: var(--paper);
}
.login-art {
  flex: 1.1;
  background: linear-gradient(165deg, #1F6F54 0%, #154f3c 55%, #0f3a2c 100%);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px;
  color: var(--paper);
  position: relative;
  overflow: hidden;
}
.login-art::before {
  content: '';
  position: absolute;
  width: 480px; height: 480px;
  border-radius: 50%;
  border: 1px solid rgba(251,247,240,0.12);
  right: -160px; top: -160px;
}
.login-art::after {
  content: '';
  position: absolute;
  width: 340px; height: 340px;
  border-radius: 50%;
  border: 1px solid rgba(251,247,240,0.1);
  right: -80px; top: -80px;
}
.login-art-brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.login-art-brand .brand-mark { background: rgba(251,247,240,0.14); }
.login-art-brand .brand-mark svg { stroke: var(--paper); }
.login-art-brand-text { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.login-art-quote {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  font-style: italic;
  line-height: 1.35;
  max-width: 420px;
  position: relative; z-index: 1;
}
.login-art-quote span { opacity: 0.7; font-style: normal; font-family: var(--font-body); font-size: 14px; display: block; margin-top: 14px; font-weight: 500; }

.login-form-side {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.login-form-box { width: 100%; max-width: 360px; }
.login-form-box h1 { font-size: 26px; margin-bottom: 6px; }
.login-form-box .login-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 30px; }
.login-form-box .form-field { margin-bottom: 16px; }
.login-form-box .btn { width: 100%; padding: 12px; font-size: 14.5px; margin-top: 6px; }
.login-error {
  background: var(--expense-soft);
  color: var(--expense);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.login-error.show { display: block; }
.login-demo-hint {
  margin-top: 24px;
  padding: 12px 14px;
  background: var(--gold-soft);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.login-demo-hint strong { color: var(--ink); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 22px; right: 22px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  display: flex; align-items: center; gap: 9px;
  box-shadow: 0 12px 30px -8px rgba(var(--shadow-color) / 0.4);
  animation: toast-in 0.2s ease;
  max-width: 340px;
}
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast.success svg { stroke: #6FCF97; }
.toast.error { background: var(--expense); }
.toast.error svg { stroke: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Members page ---------- */
.members-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.member-card {
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.member-card-top { display: flex; align-items: center; gap: 12px; }
.member-card-top .avatar { width: 44px; height: 44px; font-size: 16px; }
.member-card-name { font-weight: 600; font-size: 15px; }
.member-card-email { font-size: 12.5px; color: var(--ink-faint); }
.member-card-stats { display: flex; gap: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
.member-card-stat { flex: 1; }
.member-card-stat-label { font-size: 11px; text-transform: uppercase; color: var(--ink-faint); letter-spacing: 0.04em; }
.member-card-stat-value { font-family: var(--font-mono); font-weight: 700; font-size: 15px; margin-top: 2px; }
.role-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 100px;
  background: var(--gold-soft); color: #8a6213;
  align-self: flex-start;
}

/* ---------- Mobile nav toggle ---------- */
.mobile-nav-toggle {
  display: none;
  position: fixed; top: 16px; left: 16px; z-index: 50;
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--paper-raised);
  align-items: center; justify-content: center;
}
.mobile-nav-toggle svg { width: 18px; height: 18px; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 39;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 980px) {
  .charts-row { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 76px 18px 50px; }
  .mobile-nav-toggle { display: flex; }
  .sidebar.open ~ .sidebar-backdrop { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-form-side { padding: 24px; }
}

@media (max-width: 600px) {
  table.ledger thead { display: none; }
  table.ledger, table.ledger tbody, table.ledger tr, table.ledger td { display: block; width: 100%; }
  table.ledger tbody tr { padding: 12px 0; }
  table.ledger tbody td { padding: 3px 12px; }
  .cell-amount { text-align: left; }
  .row-actions { justify-content: flex-start; margin-top: 6px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
