:root {
  --forest: #18392f;
  --forest-2: #245244;
  --mint: #bfe3d5;
  --lime: #dcefa8;
  --paper: #f4f2ec;
  --card: #fffefa;
  --ink: #17211d;
  --muted: #6f7b76;
  --line: #dfe3dd;
  --danger: #b64542;
  --warning: #f1d39b;
  --shadow: 0 14px 45px rgba(25, 53, 44, .08);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; margin: 0; background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--forest-2); text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .3rem; font-size: clamp(1.75rem, 3vw, 2.6rem); line-height: 1.05; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.15rem; letter-spacing: -.02em; }
small { color: var(--muted); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 248px;
  flex-direction: column;
  padding: 24px 18px;
  color: #f6fbf8;
  background:
    radial-gradient(circle at 20% 0, rgba(191, 227, 213, .18), transparent 30%),
    var(--forest);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; }
.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 16px;
  font-family: Georgia, serif;
  font-size: 1.15rem;
  background: rgba(255,255,255,.08);
}
.brand-mark span, .login-monogram span { color: var(--lime); }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand small { color: rgba(255,255,255,.62); }

.sidebar nav { display: grid; gap: 3px; margin-top: 34px; }
.sidebar nav a {
  padding: 11px 14px;
  border-radius: 12px;
  color: rgba(255,255,255,.74);
  font-size: .92rem;
  transition: .15s ease;
}
.sidebar nav a:hover, .sidebar nav a.active { color: #fff; background: rgba(255,255,255,.11); }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 5px 0; border-top: 1px solid rgba(255,255,255,.13); }
.sidebar-user > span:nth-child(2) { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.sidebar-user small { color: rgba(255,255,255,.58); }
.avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; color: var(--forest); background: var(--mint); font-weight: 800; }
.icon-button { border: 0; color: white; background: transparent; cursor: pointer; }

.app-main { width: calc(100% - 248px); min-height: 100vh; margin-left: 248px; padding: 40px clamp(24px, 4vw, 64px) 70px; }
.auth-main { min-height: 100vh; }
.mobile-header, .bottom-nav { display: none; }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.eyebrow { margin-bottom: 7px; color: #658074; font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.period-picker, .period-nav, .quick-actions { display: flex; align-items: center; gap: 8px; }
.period-picker select, .period-picker input { width: auto; min-width: 100px; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 15px;
  border: 0;
  border-radius: 12px;
  color: var(--forest);
  background: var(--card);
  font-weight: 750;
  cursor: pointer;
}
.button.primary { color: #fff; background: var(--forest); }
.button.soft { border: 1px solid var(--line); background: rgba(255,255,255,.65); }
.button.light { color: var(--forest); background: var(--lime); }
.button.danger { color: #fff; background: var(--danger); }
.button.wide { width: 100%; }
.button:disabled { opacity: .45; cursor: not-allowed; }

.hero-balance, .house-hero, .import-hero {
  display: flex;
  min-height: 180px;
  align-items: end;
  justify-content: space-between;
  gap: 25px;
  margin-bottom: 20px;
  padding: clamp(24px, 4vw, 42px);
  border-radius: 28px;
  color: #fff;
  background:
    radial-gradient(circle at 75% 0, rgba(220,239,168,.28), transparent 35%),
    linear-gradient(135deg, #18392f, #285a49);
  box-shadow: var(--shadow);
}
.hero-balance > div, .house-hero > div, .import-hero > div { display: flex; flex-direction: column; }
.hero-balance strong, .house-hero > div > strong, .import-hero strong { margin: 6px 0; font-size: clamp(2.2rem, 5vw, 4rem); letter-spacing: -.06em; }
.hero-balance small, .house-hero small, .import-hero small { color: rgba(255,255,255,.68); }
.negative { color: #c94d46 !important; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 20px 0; }
.metric, .panel, .debt-card, .annual-card, .attachment-card {
  border: 1px solid rgba(24,57,47,.08);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 8px 30px rgba(25,53,44,.035);
}
.metric { display: flex; min-height: 142px; flex-direction: column; padding: 22px; }
.metric > span { color: var(--muted); font-size: .86rem; }
.metric strong { margin: auto 0 8px; font-size: clamp(1.25rem, 2vw, 1.7rem); letter-spacing: -.04em; }
.metric small { line-height: 1.35; }
.metric.accent { background: #e7f3ed; }
.metric.warning { background: #f8eddc; }

.two-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 18px 0; }
.panel { min-width: 0; margin: 18px 0; padding: clamp(19px, 2.5vw, 28px); }
.two-cols > .panel { margin: 0; }
.panel.narrow { max-width: 780px; margin-inline: auto; }
.panel-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.panel-head > strong { font-size: 1.2rem; }
.stat-list { display: grid; gap: 13px; }
.stat-list > div, .split { display: flex; justify-content: space-between; gap: 15px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.stat-list > div:last-child { border: 0; padding-bottom: 0; }
.house-total { display: flex; flex-direction: column; margin: 4px 0 18px; }
.house-total strong { font-size: 2.2rem; letter-spacing: -.05em; }
.house-total span { color: var(--muted); }
.split { font-size: .86rem; }

.due-list, .payment-timeline, .ledger-list { display: grid; }
.due-list > div, .payment-timeline > div, .ledger-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.due-list > div:last-child, .payment-timeline > div:last-child, .ledger-item:last-child { border-bottom: 0; }
.due-list span:nth-child(2), .payment-timeline span:nth-child(2), .ledger-item > div:nth-child(2) { display: flex; min-width: 0; flex-direction: column; }
.date-badge { min-width: 48px; padding: 8px; border-radius: 10px; text-align: center; background: #eef2ef; font-weight: 750; }
.empty { padding: 25px; border: 1px dashed #cbd2cd; border-radius: 15px; color: var(--muted); text-align: center; }

.month-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; overflow: hidden; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--line); }
.month-summary > div { display: flex; min-width: 0; flex-direction: column; padding: 18px; background: var(--card); }
.month-summary span { color: var(--muted); font-size: .78rem; }
.month-summary strong { margin-top: 5px; font-size: 1.1rem; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 22px 0; }
.segmented { display: flex; gap: 2px; padding: 4px; border-radius: 13px; background: #e7e9e5; }
.segmented button { padding: 7px 12px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; }
.segmented button.active { color: var(--forest); background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.paid-toggle, .movement-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid #c5cfca;
  border-radius: 50%;
  color: #89938f;
  background: #fff;
  cursor: pointer;
}
.paid-toggle.is-paid { border-color: var(--forest-2); color: #fff; background: var(--forest-2); }
.ledger-item .amount { display: flex; align-items: end; flex-direction: column; white-space: nowrap; }
.ledger-item .amount a { margin-top: 3px; font-size: .76rem; }
.owner { display: inline-flex; width: max-content; margin-right: 4px; padding: 2px 7px; border-radius: 20px; color: #29483e; background: #e4efea; font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.owner-alex { color: #654126; background: #f6e4cf; }
.owner-couple { color: #46416d; background: #e9e6f7; }
.ledger-item.linked { margin: 10px -10px -3px; padding-inline: 10px; border: 1px dashed #9fbaae; border-radius: 14px; background: #f0f6f3; }
.muted-item { opacity: .55; }

details summary { list-style: none; cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
.form-panel > summary { display: flex; align-items: center; justify-content: space-between; }
.form-panel > summary span { font-size: 1.5rem; }
.form-panel[open] > summary { margin-bottom: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0,1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: #52615b; font-size: .8rem; font-weight: 650; }
label small { font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid #d6dcd8;
  border-radius: 11px;
  outline: none;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #4f7869; box-shadow: 0 0 0 3px rgba(79,120,105,.12); }
label.check { display: flex; align-items: center; gap: 8px; align-self: center; }
label.check input { width: 19px; min-height: 19px; }
.source-box { display: grid; gap: 5px; padding: 15px; border-radius: 13px; background: #eef1ee; }
.source-box span, .source-box code { overflow-wrap: anywhere; font-size: .8rem; }
.danger-zone { margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--line); }

.annual-cards { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.annual-card { display: flex; min-width: 0; flex-direction: column; padding: 19px; color: inherit; }
.annual-card > span { color: var(--muted); }
.annual-card > strong { margin: 12px 0 4px; font-size: 1.3rem; }
.annual-card > div, .progress { height: 7px; overflow: hidden; margin: 15px 0 8px; border-radius: 20px; background: #e7eae7; }
.annual-card i, .progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--forest-2); }
.annual-card p { display: flex; flex-direction: column; gap: 3px; margin: 7px 0 0; color: var(--muted); font-size: .72rem; }
.table-scroll { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, .items-table td:nth-child(2) { text-align: left; }
td small { display: block; }
.status { display: inline-flex; padding: 4px 8px; border-radius: 20px; color: #775d22; background: #f7e9c9; font-size: .72rem; font-weight: 800; }
.status.paid { color: #285b49; background: #dceddf; }

.debt-grid, .attachment-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin: 18px 0; }
.debt-card { padding: 24px; }
.debt-card .panel-head h2 { margin-top: 8px; }
.debt-card .panel-head > strong { font-size: 1.25rem; white-space: nowrap; }
.edit-link { display: inline-block; margin-top: 10px; font-size: .78rem; font-weight: 750; }
.progress i { background: #b99451; }
.savings-progress i { background: var(--forest-2); }
.progress i.p-0 { width: 0; }.progress i.p-10 { width: 10%; }.progress i.p-20 { width: 20%; }.progress i.p-30 { width: 30%; }.progress i.p-40 { width: 40%; }.progress i.p-50 { width: 50%; }.progress i.p-60 { width: 60%; }.progress i.p-70 { width: 70%; }.progress i.p-80 { width: 80%; }.progress i.p-90 { width: 90%; }.progress i.p-100 { width: 100%; }
.movement-icon { border: 0; color: var(--forest); background: var(--mint); font-weight: 900; }

.house-hero { align-items: center; }
.house-shares { display: grid !important; grid-template-columns: 1fr 1fr; gap: 12px; flex-direction: unset !important; }
.house-shares > div { display: flex; min-width: 145px; flex-direction: column; padding: 20px; border: 1px solid rgba(255,255,255,.16); border-radius: 18px; background: rgba(255,255,255,.08); }
.house-shares strong { margin-top: 5px; font-size: 1.35rem; }
.read-only-note { margin: 18px 0 0; padding: 12px; border-radius: 10px; color: var(--muted); background: #eef1ee; font-size: .78rem; }

.attachment-card { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 14px; align-items: center; padding: 18px; }
.attachment-card > div { display: flex; min-width: 0; flex-direction: column; }
.attachment-card strong { overflow: hidden; text-overflow: ellipsis; }
.file-icon { display: grid; width: 48px; height: 58px; place-items: center; border-radius: 9px; color: var(--forest); background: var(--mint); font-size: .67rem; font-weight: 900; }
.attachment-card .button, .attachment-card form { grid-column: 2; justify-self: start; }
.link-danger { padding: 0; border: 0; color: var(--danger); background: transparent; cursor: pointer; }

.import-hero { min-height: 155px; align-items: center; }
.import-hero strong { font-size: clamp(1.5rem,3vw,2.5rem); }
.reconcile-list { display: grid; }
.reconcile-list > div { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 15px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.reconcile-list > div > span { display: flex; flex-direction: column; }
.note-list { display: grid; gap: 10px; }
.note-list article { padding: 14px; border-radius: 12px; background: #f0f2ef; }
.note-list p { margin: 6px 0; color: #53635d; font-size: .86rem; }
.warning-list { display: grid; gap: 8px; margin: 0; padding-left: 20px; color: #5a625f; }

.account-list { display: grid; gap: 7px; }
.account-list > div { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.inline-details { margin-top: 16px; }
.inline-details > summary { color: var(--forest-2); font-weight: 750; }
.inline-details[open] > summary { margin-bottom: 15px; }

.flash, .security-banner, .form-error { display: block; margin: 0 0 16px; padding: 13px 16px; border-radius: 12px; }
.flash-success { color: #244d3f; background: #dfeee7; }
.flash-error, .form-error { color: #7b302d; background: #f7dfdd; }
.security-banner { color: #644b19; background: #f7e7bd; font-weight: 700; }
.muted { color: var(--muted); }

.login-shell { display: grid; min-height: 100vh; grid-template-columns: 1.05fr .95fr; }
.login-art {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #fff;
  background:
    linear-gradient(rgba(24,57,47,.5), rgba(24,57,47,.75)),
    radial-gradient(circle at 25% 25%, #5f917e, transparent 35%),
    linear-gradient(145deg, #214c3e, #10271f);
}
.login-monogram { font-family: Georgia, serif; font-size: clamp(5rem,12vw,10rem); letter-spacing: -.08em; }
.login-art p { color: rgba(255,255,255,.72); letter-spacing: .08em; }
.login-card { width: min(430px, calc(100% - 45px)); align-self: center; justify-self: center; }
.login-card h1 { font-size: 3.6rem; }
.login-card .stack { margin-top: 30px; }
.privacy { display: block; margin-top: 24px; text-align: center; }
.error-page { display: grid; max-width: 500px; min-height: 70vh; align-content: center; justify-items: start; }
.error-page > strong { color: var(--mint); font-size: 7rem; line-height: 1; }

@media (max-width: 1180px) {
  .metric-grid, .annual-cards { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .debt-grid, .attachment-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 820px) {
  body { padding-bottom: 74px; }
  .sidebar { display: none; }
  .app-main { width: 100%; margin: 0; padding: 82px 16px 28px; }
  .mobile-header {
    position: fixed;
    inset: 0 0 auto;
    z-index: 30;
    display: flex;
    height: 66px;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    color: white;
    background: rgba(24,57,47,.96);
    backdrop-filter: blur(14px);
  }
  .brand.compact { gap: 8px; }
  .brand.compact .brand-mark { width: 40px; height: 40px; flex-basis: 40px; border-radius: 12px; }
  .user-chip { padding: 6px 10px; border-radius: 20px; background: rgba(255,255,255,.1); font-size: .8rem; }
  .bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 35;
    display: grid;
    height: calc(65px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(5,1fr);
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid rgba(24,57,47,.12);
    background: rgba(255,254,250,.96);
    backdrop-filter: blur(16px);
  }
  .bottom-nav a { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px; color: var(--muted); font-size: .64rem; }
  .bottom-nav a span { color: var(--forest); font-size: 1.25rem; line-height: 1; }
  .two-cols, .ledger-cols, .form-grid.four { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .month-summary { grid-template-columns: repeat(2,1fr); }
  .desktop-table { display: none; }
  .hero-balance { min-height: 210px; align-items: start; flex-direction: column; }
  .house-hero { align-items: stretch; flex-direction: column; }
  .form-grid.four .button { width: 100%; }
}

@media (max-width: 570px) {
  .page-head { align-items: stretch; flex-direction: column; }
  .period-picker { display: grid; grid-template-columns: 1fr 92px auto; }
  .period-picker select, .period-picker input { width: 100%; min-width: 0; }
  .metric-grid, .annual-cards, .debt-grid, .attachment-grid { grid-template-columns: 1fr; }
  .metric { min-height: 122px; }
  .two-cols { gap: 12px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { min-width: 0; flex: 1; padding-inline: 5px; font-size: .75rem; }
  .quick-actions { width: 100%; }
  .quick-actions .button { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .month-summary > div { padding: 14px 12px; }
  .ledger-item { gap: 9px; }
  .ledger-item .amount strong { font-size: .84rem; }
  .hero-balance strong { font-size: 2.35rem; }
  .house-shares { grid-template-columns: 1fr !important; }
  .house-shares > div { min-width: 0; }
  .login-shell { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-card { min-height: 100vh; padding-top: 18vh; }
  .login-card h1 { font-size: 3rem; }
  .reconcile-list > div { grid-template-columns: 1fr auto; }
  .reconcile-list > div .status { grid-column: 1 / -1; justify-self: start; }
}
