:root {
  color-scheme: light;
  --bg: #f7f2ea;
  --surface: #fffefa;
  --ink: #17130f;
  --muted: #6f675f;
  --line: #e7ded2;
  --accent: #c79a4d;
  --accent-strong: #a46624;
  --green: #2f8a5b;
  --red: #c7493f;
  --blue: #557f9f;
  --shadow: 0 12px 28px rgba(59, 39, 21, 0.08);
  --radius: 15px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 26px;
  border-right: 1px solid var(--line);
  background: rgba(250, 246, 239, 0.92);
  padding: 24px 13px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #f1dfbd;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 22px;
}

.brand p {
  margin: 0;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 22px;
}

.brand span,
.eyebrow,
.kpi span,
.triplet b {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

nav {
  display: grid;
  gap: 7px;
}

.nav-link,
.ghost-button,
.secondary-button,
.primary-button,
.text-button,
.danger-button {
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: transparent;
  color: #5d554d;
  font-weight: 750;
  text-align: left;
}

.nav-link.active,
.nav-link:hover {
  background: #efe4d4;
  color: var(--accent-strong);
}

.nav-link span {
  width: 18px;
  font-weight: 900;
}

.sidebar-footer {
  display: grid;
  gap: 9px;
  margin-top: auto;
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: #5d554d;
  padding: 10px 14px;
  font-weight: 800;
}

.primary-button {
  background: #111;
  color: #fff;
  padding: 11px 16px;
  font-weight: 850;
}

.primary-button.small {
  padding: 9px 12px;
}

.danger-button {
  background: #fee8e4;
  color: var(--red);
  padding: 10px 14px;
  font-weight: 850;
}

.text-button {
  background: transparent;
  color: var(--accent-strong);
  font-weight: 850;
}

main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 34px 18px;
}

.menu-toggle {
  display: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  padding: 10px 12px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 8px;
  font-family: Georgia, serif;
  font-size: clamp(30px, 2.6vw, 40px);
  font-weight: 500;
  line-height: 1;
}

h2 {
  margin-bottom: 5px;
  font-size: 20px;
}

h3 {
  margin-bottom: 7px;
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: 500;
}

.subhead,
.muted {
  color: var(--muted);
  line-height: 1.45;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.file-label input {
  display: none;
}

.view {
  display: none;
  padding: 0 34px 38px;
}

.active-view {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(92px, 1fr));
  gap: 9px;
  margin-bottom: 20px;
}

.mini-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.kpi,
.panel,
.budget-card,
.debt-card,
.list-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 249, 0.95);
  box-shadow: var(--shadow);
}

.kpi {
  min-height: 74px;
  padding: 12px 11px;
}

.kpi[data-edit],
.kpi[data-view-jump],
.list-card[data-edit] {
  cursor: pointer;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: 500;
}

.kpi.positive strong,
.amount.positive,
.positive {
  color: var(--green);
}

.kpi.negative strong,
.amount.negative,
.negative {
  color: var(--red);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(310px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.dashboard-grid.lower {
  grid-template-columns: minmax(0, 1fr) minmax(310px, 0.8fr);
}

.panel {
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header.compact {
  margin-bottom: 14px;
}

.stack-list,
.editable-list,
.settings-grid,
.review-grid {
  display: grid;
  gap: 11px;
}

.budget-grid,
.debt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.list-card {
  padding: 14px;
}

.budget-card,
.debt-card {
  padding: 18px;
  cursor: pointer;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.list-row.top {
  align-items: flex-start;
}

.bill-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  cursor: pointer;
}

.date-chip {
  display: grid;
  min-height: 48px;
  place-items: center;
  border-radius: 999px;
  background: #f4eee5;
  color: #5d554d;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.date-chip.done {
  background: #e6f3eb;
  color: var(--green);
  font-size: 11px;
  text-transform: uppercase;
}

.bill-main strong {
  display: block;
  margin-bottom: 3px;
}

.bill-side,
.debt-balance {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.debt-balance strong {
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 500;
}

.debt-balance span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.amount {
  font-weight: 900;
}

.status-badge,
.pill {
  border-radius: 999px;
  padding: 4px 9px;
  background: #f2e3ca;
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-badge.paid {
  background: #e8f5ee;
  color: var(--green);
}

.status-badge.unpaid,
.pill.danger {
  background: #fee8e4;
  color: var(--red);
}

.triplet {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.triplet span {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.bar-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee8df;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-fill.danger {
  background: var(--red);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px;
}

dialog {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(23, 25, 35, 0.28);
}

dialog::backdrop {
  background: rgba(30, 22, 15, 0.45);
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.icon-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1181px) {
  .kpi-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  body.menu-open {
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(330px, 86vw);
    height: 100dvh;
    overflow-y: auto;
    transform: translateX(-105%);
    box-shadow: 20px 0 60px rgba(36, 26, 15, 0.22);
    transition: transform 0.18s ease;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  nav {
    grid-template-columns: 1fr;
  }

  .topbar,
  .view {
    padding-left: 22px;
    padding-right: 22px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .top-actions {
    grid-column: 1 / -1;
  }

  .menu-toggle {
    display: inline-grid;
    place-items: center;
    margin-top: 2px;
  }

  .dashboard-grid,
  .dashboard-grid.lower,
  .budget-grid,
  .debt-grid,
  .mini-kpi-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar {
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .form-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .bill-card {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .bill-side {
    grid-column: 2;
    justify-items: start;
  }
}
