@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
  --outer: #16241F;
  --panel: #F3EFE2;
  --ink: #20211C;
  --muted: #8A8572;
  --line: #D9D2BC;
  --brass: #C9A227;
  --stamp: #B14231;
  --income: #2F6E62;
  --hairline: rgba(0,0,0,0.07);
}

body.dark {
  --outer: #0A0E0B;
  --panel: #1E2420;
  --ink: #ECE6D2;
  --muted: #8D9284;
  --line: #333A2F;
  --brass: #DFC15A;
  --stamp: #DD7A6E;
  --income: #6FBFA0;
  --hairline: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--outer);
  min-height: 100vh;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
}

.layout {
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 12px 100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.wrap { width: 100%; }

@media (min-width: 900px) {
  .layout {
    max-width: 1080px;
    flex-direction: row;
    align-items: flex-start;
    padding: 32px 24px 100px;
    gap: 24px;
  }
  .layout > .wrap { flex: 1 1 640px; max-width: 660px; }
  .layout > .stats-panel { width: 320px; flex-shrink: 0; position: sticky; top: 32px; }
}

.range-label { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

.range-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

.range-nav { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.range-nav .icon-btn { color: var(--ink); font-size: 13px; opacity: 0.75; }
.range-nav .icon-btn:hover { opacity: 1; }

.stats-panel { display: block; }
.stats-card {
  background: var(--panel);
  border-radius: 12px;
  padding: 18px 18px 16px;
}
.stat-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px dashed var(--line);
  font-size: 13px;
}
.stat-line:first-of-type { border-top: none; padding-top: 0; }
.stat-value {
  font-family: 'Space Mono', monospace;
  font-weight: 600;
  text-align: right;
}

.eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
}

.eyebrow {
  font-family: 'Space Mono', monospace;
  color: var(--brass);
  letter-spacing: 2px;
  font-size: 11px;
  text-transform: uppercase;
}

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

.ledger-switch-wrap { position: relative; }
.ledger-switch-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  font-family: 'Space Mono', monospace; color: var(--brass); letter-spacing: 2px;
  font-size: 11px; text-transform: uppercase;
}
.ledger-menu {
  position: absolute; top: 100%; left: 0; margin-top: 8px; z-index: 55;
  background: var(--panel); border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  min-width: 200px; overflow: hidden; padding: 4px;
}
.ledger-menu-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  padding: 9px 10px; border-radius: 6px; font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px; color: var(--ink);
}
.ledger-menu-item:hover { background: var(--hairline); }
.ledger-menu-item.active { font-weight: 600; }
.ledger-menu-role { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.ledger-menu-new { color: var(--brass); border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 10px; }

.grant-ledger-list { margin-top: 2px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--panel);
  opacity: 0.85;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px;
  padding: 0;
}
.icon-btn:hover { opacity: 1; }

.torn { height: 14px; background-repeat: repeat-x; }
.torn-down {
  background-image:
    linear-gradient(135deg, transparent 50%, var(--panel) 50%),
    linear-gradient(45deg, var(--panel) 50%, transparent 50%);
  background-size: 16px 16px;
  background-position: bottom;
}
.torn-up {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--panel) 50%),
    linear-gradient(135deg, var(--panel) 50%, transparent 50%);
  background-size: 16px 16px;
  background-position: top;
}

.panel {
  background: var(--panel);
  padding: 16px 16px 8px;
}

.month-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.month-total { font-family: 'Space Mono', monospace; font-size: 36px; font-weight: 700; margin-bottom: 16px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  margin-bottom: 16px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 0 8px 8px;
  margin-bottom: -1px;
  white-space: nowrap;
  cursor: pointer;
}
.tab-btn.active { color: var(--ink); border-bottom-color: var(--stamp); }

.group-block { margin-bottom: 12px; }

.meter-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.meter-label { font-size: 14px; font-weight: 500; }
.meter-amount { font-family: 'Space Mono', monospace; font-size: 14px; }
.meter-track { height: 8px; border-radius: 4px; background: var(--hairline); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 4px; }
.meter-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.expand-btn {
  background: none; border: none; color: var(--muted); font-size: 12px;
  display: flex; align-items: center; gap: 4px; margin: 4px 0; cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif; padding: 0;
}

.expense-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px dashed var(--line);
}
.expense-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.expense-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-title .sub { color: var(--muted); font-weight: 400; }
.expense-meta { display: flex; align-items: center; gap: 6px; }
.expense-date { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--muted); }
.expense-amount { font-family: 'Space Mono', monospace; font-size: 14px; font-weight: 700; flex-shrink: 0; margin-left: 8px; }

.card-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; color: #F3EFE2;
}
.card-chip .swatch { width: 8px; height: 6px; border-radius: 1px; background: var(--brass); }

.chip-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.chip {
  flex-shrink: 0; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 13px; color: var(--muted); background: none; cursor: pointer; white-space: nowrap;
  font-family: 'IBM Plex Sans', sans-serif; display: flex; align-items: center; gap: 6px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.active { color: var(--ink); border-color: var(--ink); }

.chip.dashed { border-style: dashed; }
.chip-input {
  font-family: 'IBM Plex Sans', sans-serif; font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; width: 120px; background: none;
}
.chip-confirm {
  width: 28px; height: 28px; border-radius: 50%; border: none; background: var(--brass);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}

.empty-note { font-size: 14px; color: var(--muted); text-align: center; padding: 24px 0; }
.footer-note { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--muted); text-align: center; margin-top: 12px; opacity: 0.7; }

.fab {
  position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--brass); border: none; box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 40;
  font-size: 28px; color: var(--outer); line-height: 1;
}

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--panel); width: 100%; max-width: 460px; border-radius: 16px 16px 0 0;
  padding: 20px 20px 24px; max-height: 88vh; overflow-y: auto;
}
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sheet-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; }

.field-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field-group { margin-bottom: 16px; }

.amount-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.amount-sign { font-family: 'Space Mono', monospace; font-size: 30px; margin-right: 4px; }
.amount-input {
  font-family: 'Space Mono', monospace; font-size: 30px; border: none; outline: none;
  background: none; color: var(--ink); width: 100%; padding: 4px 0;
}

.text-input {
  width: 100%; font-family: 'IBM Plex Sans', sans-serif; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: none;
}

.two-col { display: flex; gap: 12px; }
.two-col > div { flex: 1; }

.save-btn {
  width: 100%; padding: 13px; border-radius: 10px; border: none; background: var(--stamp);
  color: white; font-weight: 600; font-size: 15px; cursor: pointer; font-family: 'IBM Plex Sans', sans-serif;
}

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 8px 16px; border-radius: 999px;
  font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.3); z-index: 60;
  font-family: 'IBM Plex Sans', sans-serif;
}

.error-text { color: var(--stamp); font-size: 12px; margin-top: 4px; }

.save-btn.danger {
  background: transparent;
  border: 1px solid var(--stamp);
  color: var(--stamp);
  margin-bottom: 10px;
}

.settings-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
}
.settings-name { flex: 1; }
.settings-name-static { flex: 1; font-size: 14px; }
.color-dot {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--hairline);
  cursor: pointer; flex-shrink: 0; padding: 0;
}
.trash-btn {
  background: none; border: none; cursor: pointer; font-size: 14px; opacity: 0.7; flex-shrink: 0;
}
.trash-btn:hover { opacity: 1; }
.settings-add-row { display: flex; gap: 8px; margin-top: 8px; }
.settings-add-row .text-input { flex: 1; }

.title-input {
  background: none; border: none; border-bottom: 1px dashed var(--line); color: var(--ink);
  font-family: 'Space Mono', monospace; font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  width: 140px; padding: 0 0 2px;
}

/* -- auth screens -- */
.auth-wrap { max-width: 400px; margin: 60px auto; padding: 0 16px; }
.auth-panel { padding-bottom: 20px; }

/* -- users management -- */
.user-row { flex-wrap: wrap; gap: 8px; }
.user-row-main { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 8px; }
.pending-row { gap: 8px; }
.pending-tag {
  font-size: 10px; font-weight: 600; color: var(--brass); border: 1px solid var(--brass);
  border-radius: 4px; padding: 1px 5px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 6px;
}
.admin-toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.admin-toggle input { margin: 0; }

/* -- bulk select -- */
.select-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.row-checkbox { width: 17px; height: 17px; margin-right: 10px; flex-shrink: 0; accent-color: var(--stamp); }
.bulk-bar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); border-radius: 999px;
  padding: 10px 10px 10px 18px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4); z-index: 45; font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
}
.bulk-bar-actions { display: flex; gap: 6px; }
.bulk-bar-btn {
  background: var(--brass); color: var(--outer); border: none; border-radius: 999px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: 'IBM Plex Sans', sans-serif;
}
.bulk-bar-btn.danger { background: var(--stamp); color: white; }

/* -- income -- */
.income-color { color: var(--income) !important; }
.income-tag {
  font-size: 10px; font-weight: 600; color: var(--income); border: 1px solid var(--income);
  border-radius: 4px; padding: 1px 5px; text-transform: uppercase; letter-spacing: 0.5px;
}
.stat-value.positive { color: var(--income); }
.stat-value.negative { color: var(--stamp); }
.budget-row { margin-bottom: 12px; }
.budget-row:last-child { margin-bottom: 0; }
.meter-sub.positive { color: var(--income); }
.meter-sub.negative { color: var(--stamp); font-weight: 600; }
.kind-chip.active { border-color: var(--stamp); }
.kind-chip.income.active { border-color: var(--income); color: var(--income); background: color-mix(in srgb, var(--income) 15%, transparent); }

/* -- trends -- */
.trend-legend { display: flex; gap: 18px; margin-bottom: 10px; }
.trend-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }
.trend-toggle .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.trend-chart { width: 100%; height: auto; display: block; margin-bottom: 12px; }
.trend-summary .stat-line:first-of-type { border-top: 1px dashed var(--line); padding-top: 9px; }
