:root {
  --bg: #f3f1eb;
  --elev: #ffffff;
  --surface: #ffffff;
  --border: #d3cdc2;
  --text: #1c1917;
  --muted: #44403c;
  --navy: #1b365d;
  --navy-2: #2c5282;
  --gold: #8a6914;
  --gold-soft: #a67c1a;
  --ink: #1c1917;
  --danger: #b42318;
  --teal: #0f6b4c;
  --row: #faf8f4;
  --edit: #fff8d6;
  --sidebar: 240px;
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}
a { color: var(--navy-2); text-decoration: none; }
a:hover { color: var(--navy); text-decoration: underline; }

.app-body { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy);
  color: #f7f4ec;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar a { color: #e8e4d9; text-decoration: none; }
.sidebar a:hover { color: #fff; text-decoration: none; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; font-weight: 650; }
.brand em { display: block; font-style: normal; color: #d6d1c4; font-weight: 400; font-size: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: #fff; color: var(--navy);
  display: grid; place-items: center; font-weight: 800;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  color: #d9d4c7;
  padding: 8px 10px;
  border-radius: 8px;
}
.sidebar nav a.on, .sidebar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-badge {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f5d76e;
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}
.warn-banner {
  background: #fff6d8;
  border: 1px solid #e4c56a;
  border-left: 4px solid var(--gold);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 0 16px;
  color: var(--text);
}
.warn-banner a { font-weight: 700; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: #c9c3b4; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot a { color: #fff; }
.main { padding: 28px 32px 80px; min-width: 0; }
.mobile-bar { display: none; }
.nav-scrim { display: none; }

.page-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 22px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 11px; color: var(--navy); margin: 0 0 6px; font-weight: 700; }
h1 { font-family: var(--serif); font-size: 34px; margin: 0; letter-spacing: -.02em; color: var(--navy); }
h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 10px; color: var(--navy); }
.lede { color: var(--muted); max-width: 48em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; }

.btn, button.btn {
  display: inline-block;
  border: 1px solid var(--navy);
  color: var(--navy);
  background: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.btn-primary, button.btn-primary { background: var(--navy); color: #fff; }
.btn-ghost { border-color: var(--border); color: var(--text); }
.btn-danger, button.btn-danger { border-color: var(--danger); color: var(--danger); background: #fff; }
.role-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  background: #e8eef6;
  color: var(--navy);
  padding: 2px 8px;
  border-radius: 999px;
}
.row-actions { text-align: right; white-space: nowrap; }
.invite-form { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.invite-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.invite-box input { flex: 1; min-width: 16rem; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.stat-pill { background: #fff; border: 1px solid var(--border); padding: 10px 14px; border-radius: 10px; }
.stat-pill strong { display: block; font-size: 20px; color: var(--navy); }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.cards article {
  background: #fff;
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 10px;
}
.cards span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.cards strong { display: block; font-family: var(--serif); font-size: 26px; margin: 6px 0; color: var(--navy); }
.cards em { color: var(--muted); font-style: normal; font-size: 13px; }

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--navy); }
input, select {
  font: inherit;
  background: #fff;
  color: var(--text);
  border: 1px solid #b8b2a6;
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus { outline: 2px solid var(--navy); outline-offset: 1px; }
.table-wrap { overflow: auto; background: #fff; }
.table-wrap.tall { max-height: 70vh; }
table.sheet { width: 100%; border-collapse: collapse; font-size: 13.5px; background: #fff; color: var(--text); }
.sheet th, .sheet td { border-bottom: 1px solid #e6e1d6; padding: 8px 10px; text-align: left; white-space: nowrap; }
.sheet tbody tr:nth-child(even) { background: var(--row); }
.sheet thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--navy); color: #fff; font-weight: 650;
}
.sheet.sticky th:first-child, .sheet.sticky td:first-child {
  position: sticky; left: 0; background: #fff; z-index: 1; font-weight: 650;
}
.sheet.sticky thead th:first-child { background: var(--navy); color: #fff; z-index: 3; }
.sheet .num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet .muted { color: #57534e; }
.sheet .section td { background: #e8eef6; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: 11px; color: var(--navy); }
.sheet .section.expense td { background: #fde8e6; color: var(--danger); }
.sheet .total { background: #e7f4ee; font-weight: 700; }
.sheet .net { background: #fff4d6; font-weight: 700; }
.sheet tr.alert { background: #fde8e6; }
.sheet.edit input, .sheet.edit select {
  width: 100%; min-width: 72px; padding: 6px 8px;
  background: var(--edit); color: var(--text); border-color: #e0c36a;
}
.sheet .cell { width: 88px; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 90px 90px; gap: 8px; align-items: center; margin: 8px 0; font-size: 13px; }
.bar { height: 10px; background: #e7e2d8; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--navy); }
.facts { display: grid; gap: 8px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.facts dt { color: var(--muted); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }

.status { margin-top: 10px; padding: 10px 12px; background: #e7f4ee; border-left: 4px solid var(--teal); color: var(--text); }
.status.bad { background: #fde8e6; border-left-color: var(--danger); }
.error { color: var(--danger); font-weight: 650; }

.drop { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-style: dashed; border-color: var(--navy); }
.drop.over { background: var(--edit); }
.banks { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.banks li {
  font-size: 12px; font-weight: 650;
  background: #e8eef6; color: var(--navy);
  border: 1px solid #c5d2e3;
  padding: 4px 8px; border-radius: 999px;
}
.review-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.inline { flex-direction: row; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 12px; }
.stats div { background: #fff; border: 1px solid var(--border); padding: 12px; border-radius: 10px; }
.debit { color: var(--danger); font-weight: 650; }
.credit { color: var(--teal); font-weight: 650; }

.marketing { background: var(--bg); color: var(--text); }
.marketing .m-head { display: flex; justify-content: space-between; padding: 20px 28px; align-items: center; background: #fff; border-bottom: 1px solid var(--border); }
.marketing .m-head .brand { color: var(--navy); }
.marketing .m-head nav { display: flex; gap: 16px; align-items: center; }
.hero, .auth { max-width: 860px; margin: 40px auto; padding: 0 20px 80px; }
.hero h1, .auth h1 { font-family: var(--serif); font-size: clamp(32px, 5vw, 52px); color: var(--navy); }
.features { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0; list-style: none; margin-top: 36px; }
.features li { background: #fff; border: 1px solid var(--border); padding: 14px; border-radius: 12px; }
.hero-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; align-items: center; }
.hero-actions form { margin: 0; }
.auth form { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }

.head-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.text-btn {
  background: none; border: 0; color: var(--navy-2); font: inherit; font-weight: 650;
  cursor: pointer; text-decoration: underline; padding: 0;
}
.year-switch {
  border-top: 1px solid rgba(255,255,255,.15);
  padding-top: 14px;
  color: #e8e4d9;
  font-size: 13px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.year-switch strong { font-size: 18px; color: #fff; }
.year-switch a { color: #fff; font-weight: 700; padding: 0 6px; }
.year-chips { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
.year-chips a {
  background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px 8px; font-size: 12px;
}
.year-chips a.on { background: #fff; color: var(--navy); }
.help-link {
  background: none; border: 0; color: #fff; font: inherit; font-weight: 650;
  cursor: pointer; text-align: left; padding: 0; text-decoration: underline;
}
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(27, 54, 93, .45);
  display: grid; place-items: center; padding: 20px;
}
.overlay[hidden] { display: none !important; }
.overlay-card {
  background: #fff; color: var(--text);
  max-width: 560px; width: min(560px, 100%);
  border-radius: 16px; padding: 28px 28px 22px;
  box-shadow: 0 16px 50px rgba(27, 54, 93, .25);
}
.overlay-card h2 { margin: 0 0 8px; }
.overlay-actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; }
.overlay-actions .btn-primary { margin-left: auto; }
.tour-count { color: var(--muted); font-size: 13px; }
.wizard { max-width: 620px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.chips button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--navy);
  border-radius: 999px; padding: 6px 12px; font-weight: 650;
}
.chips button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.choice-row { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.choice {
  flex-direction: row; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-weight: 600; color: var(--text);
}
.choice select { width: auto; }

.today-banner {
  background: #e8eef6; border: 1px solid #c5d2e3; color: var(--navy);
  padding: 10px 14px; border-radius: 10px; margin: -8px 0 18px; font-weight: 650;
}
.cal-layout { display: grid; grid-template-columns: 1fr 280px; gap: 16px; align-items: start; }
.cal-weekdays, .cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: center; }
.cal-day {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  min-height: 110px; padding: 8px; display: flex; flex-direction: column; gap: 4px;
}
.cal-day header { display: flex; justify-content: space-between; align-items: baseline; }
.cal-day .num { font-weight: 700; color: var(--navy); }
.cal-day.mute { opacity: .45; }
.cal-day.past { background: #f6f4ef; }
.cal-day.today { border: 2px solid var(--navy); background: #eef3fa; }
.cal-day.today em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--navy); }
.cal-pill {
  display: block; font-size: 11px; font-weight: 650; border-radius: 6px;
  padding: 3px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-pill.pay { background: #e7f4ee; color: var(--teal); }
.cal-pill.bill { background: #fde8e6; color: var(--danger); }
.cal-legend { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.agenda { list-style: none; padding: 0; margin: 0; }
.agenda li {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
  gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.agenda .when, .agenda em { font-size: 12px; color: var(--muted); font-style: normal; }
.agenda strong { grid-column: 1; }
.agenda b { grid-row: 1 / span 2; align-self: center; }

@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  .app-body {
    display: block;
    padding-top: calc(58px + env(safe-area-inset-top, 0px));
  }
  body.nav-open { overflow: hidden; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 45;
    min-height: 58px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    background: var(--navy);
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.12);
  }
  .mobile-bar .brand { color: #fff; min-width: 0; flex: 1; }
  .mobile-bar .brand strong, .mobile-bar .brand em {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mobile-bar .brand em { font-size: 11px; }
  .mobile-file {
    min-width: 32px; height: 32px; border-radius: 999px;
    background: #f5d76e; color: var(--navy) !important;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 800; text-decoration: none !important;
  }
  .menu-btn {
    width: 44px; height: 44px; flex-shrink: 0;
    border: 0; background: transparent; color: #fff;
    display: grid; place-content: center; gap: 5px; cursor: pointer; padding: 0;
  }
  .menu-btn span {
    display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px;
  }

  .nav-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 48;
    border: 0; padding: 0; margin: 0;
    background: rgba(15, 23, 42, .45);
    cursor: pointer;
  }
  .nav-scrim[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(300px, 88vw);
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform .2s ease;
    overflow-y: auto;
    padding-top: max(22px, env(safe-area-inset-top));
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: none; }
  .sidebar nav a { padding: 12px 12px; min-height: 44px; display: flex; align-items: center; }

  .main {
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
  }
  h1 { font-size: 26px; }
  h2 { font-size: 20px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; text-align: center; }

  .cards { grid-template-columns: 1fr 1fr; }
  .cards strong { font-size: 20px; }
  .split, .grid-2, .features, .stats, .cal-layout, .invite-form { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }

  .bar-row {
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
  }
  .bar-row .bar { grid-column: 1 / -1; }
  .bar-row small { grid-column: 1 / -1; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .table-wrap.panel { padding: 0; }
  .table-wrap::before {
    content: "Swipe sideways to see the rest →";
    display: block;
    font-size: 12px;
    color: var(--muted);
    padding: 8px 12px 4px;
    background: #fff;
  }
  .sheet th, .sheet td { padding: 8px; }
  .sheet.edit input, .sheet.edit select, .js-recat {
    min-width: 5.5rem;
    font-size: 16px;
  }
  .sheet .cell { width: 72px; min-width: 72px; }

  input, select, textarea, .btn, button.btn {
    font-size: 16px;
    min-height: 44px;
  }
  .btn, button.btn { padding: 10px 14px; }

  .drop { flex-direction: column; align-items: stretch; text-align: left; }
  .drop .btn { width: 100%; text-align: center; }
  .review-bar { flex-direction: column; align-items: stretch; }
  .review-bar .btn, .review-bar select { width: 100%; }
  .tabs { display: flex; flex-wrap: wrap; gap: 6px; }

  .cal-layout { display: flex; flex-direction: column-reverse; gap: 12px; }
  .cal-day { min-height: 52px; padding: 6px 4px; }
  .cal-day .cal-pill {
    width: 7px; height: 7px; padding: 0; font-size: 0; color: transparent;
    border-radius: 50%; display: inline-block; overflow: hidden;
  }
  .cal-weekdays span { font-size: 10px; letter-spacing: 0; }
  .cal-legend { flex-wrap: wrap; }

  .overlay { padding: 12px; align-items: end; }
  .overlay-card { padding: 20px 16px 16px; max-height: 92dvh; overflow: auto; }
  .overlay-actions { flex-wrap: wrap; }
  .overlay-actions .btn-primary { margin-left: 0; width: 100%; }

  .marketing .m-head {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .hero, .auth { margin: 20px auto; padding: 0 16px 48px; }
  .hero h1, .auth h1 { font-size: 28px; }
  .auth form { max-width: none; }
  .warn-banner, .today-banner { font-size: 14px; font-weight: 500; }
  .invite-box input { min-width: 0; width: 100%; }
}

@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .mobile-bar .brand strong { font-size: 14px; }
}
