* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f7f9;
  color: #1f2933;
  display: flex;
  flex-direction: column;
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid #dde3ea;
  display: flex;
  justify-content: space-between;
  padding: 14px 24px;
}

.brand {
  color: #172033;
  font-weight: 700;
  text-decoration: none;
}

.topbar-link {
  color: #2563eb;
  font-weight: 600;
  text-decoration: none;
}

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

.topbar form {
  margin: 0;
}

.page {
  flex: 1;
  margin: 0 auto;
  max-width: 1600px;
  padding: 28px 32px;
  width: 100%;
}

.site-footer {
  color: #667085;
  font-size: 13px;
  padding: 18px 24px 24px;
  text-align: center;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  color: #2563eb;
}

.muted,
.eyebrow {
  color: #667085;
}

.hero {
  align-items: end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
}

.hero h1 {
  font-size: 30px;
  margin: 6px 0 0;
}

.eyebrow {
  margin: 0;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

.month-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.month-picker {
  align-items: center;
  display: flex;
  gap: 8px;
}

.month-picker input {
  min-width: 150px;
}

.summary-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-grid article,
.auth-panel {
  background: #ffffff;
  border: 1px solid #dde3ea;
  border-radius: 8px;
  padding: 20px;
}

.summary-grid span {
  color: #667085;
  display: block;
  margin-bottom: 10px;
}

.summary-grid strong {
  font-size: 26px;
}

.summary-grid small {
  color: #667085;
  display: block;
  margin-top: 8px;
}

.scope-note {
  background: #eef2f7;
  border-radius: 6px;
  color: #475467;
  padding: 9px 12px;
}

.auth-panel {
  margin: 64px auto;
  max-width: 360px;
}

.landing {
  align-items: center;
  display: grid;
  gap: 40px;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 480px);
  min-height: min(680px, calc(100vh - 148px));
  padding: 52px 0 70px;
}

.landing-copy {
  max-width: 560px;
}

.landing h1 {
  font-size: 44px;
  line-height: 1.1;
  margin: 8px 0 16px;
}

.landing-intro {
  color: #475467;
  font-size: 18px;
  line-height: 1.7;
  margin: 0 0 24px;
  max-width: 520px;
}

.landing-visual {
  display: flex;
  justify-content: center;
}

.ledger-sheet {
  background: #ffffff;
  border: 1px solid #dde3ea;
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(31, 41, 51, 0.12);
  display: grid;
  gap: 16px;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.ledger-sheet-header,
.ledger-row,
.ledger-total {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.ledger-sheet-header span,
.ledger-row span,
.ledger-row strong,
.ledger-total span,
.ledger-total strong {
  border-radius: 999px;
  display: block;
  height: 12px;
}

.ledger-sheet-header span {
  background: #cbd5e1;
}

.ledger-sheet-header span:first-child {
  width: 42%;
}

.ledger-sheet-header span:last-child {
  width: 24%;
}

.ledger-row {
  background: #f8fafc;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  min-height: 54px;
  padding: 0 14px;
}

.ledger-row span {
  background: #dbe4ef;
  width: 46%;
}

.ledger-row strong {
  width: 28%;
}

.income-row strong {
  background: #16a34a;
}

.expense-row strong {
  background: #e11d48;
}

.balance-row strong {
  background: #0f766e;
}

.ledger-total {
  border-top: 1px solid #dde3ea;
  padding-top: 16px;
}

.ledger-total span {
  background: #94a3b8;
  width: 30%;
}

.ledger-total strong {
  background: #172033;
  width: 36%;
}

.auth-panel form,
.auth-panel label {
  display: grid;
  gap: 10px;
}

.auth-panel form {
  gap: 16px;
}

input {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 10px 12px;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

button {
  background: #2563eb;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  padding: 9px 14px;
}

a.button {
  background: #2563eb;
  border-radius: 6px;
  color: #ffffff;
  display: inline-flex;
  font-weight: 600;
  padding: 9px 14px;
  text-decoration: none;
}

.button.secondary {
  background: #e8eef8;
  color: #1d4ed8;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.panel {
  background: #ffffff;
  border: 1px solid #dde3ea;
  border-radius: 8px;
  margin-top: 16px;
  overflow-x: auto;
  padding: 20px;
}

.workspace-shell {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: 220px minmax(0, 1fr);
  margin-top: 18px;
}

.workspace-nav {
  background: #ffffff;
  border: 1px solid #dde3ea;
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 12px;
  position: sticky;
  top: 18px;
}

.nav-group {
  display: grid;
  gap: 8px;
}

.workspace-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #253041;
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
  width: 100%;
}

.workspace-root {
  background: #f8fafc;
  font-weight: 700;
}

.workspace-tab:hover,
.workspace-tab.is-active {
  background: #edf4ff;
  border-color: #bfd7ff;
  color: #174ea6;
}

.workspace-tab span {
  font-weight: 700;
}

.workspace-tab small {
  color: #667085;
  font-size: 12px;
  line-height: 1.4;
}

.workspace-subnav {
  display: grid;
  gap: 6px;
  padding-left: 10px;
}

.month-subnav {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding-left: 0;
}

.workspace-subitem {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #475467;
  display: block;
  font-size: 14px;
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
}

button.workspace-subitem {
  width: 100%;
}

.workspace-subitem:hover,
.workspace-subitem.is-active {
  background: #edf4ff;
  border-color: #bfd7ff;
  color: #174ea6;
}

.month-subnav .workspace-subitem {
  text-align: center;
}

.workspace-content {
  min-width: 0;
}

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

.section-header h1 {
  font-size: 28px;
  margin: 6px 0 0;
}

.workspace-panel[hidden] {
  display: none;
}

.workspace-panel .content-grid,
.workspace-panel .panel:first-child {
  margin-top: 0;
}

.workspace-panel .summary-grid {
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 18px;
  margin: 0 0 16px;
}

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

.panel-heading h2 {
  margin: 0;
}

.panel-heading strong {
  color: #174ea6;
  font-size: 15px;
}

.overview-stack {
  display: grid;
  gap: 16px;
}

.account-breakdown,
.member-breakdown {
  display: grid;
  gap: 14px;
}

.account-group,
.member-group {
  border: 1px solid #e4e9f0;
  border-radius: 8px;
  overflow: hidden;
}

.account-group-header,
.member-group-header {
  align-items: center;
  background: #f8fafc;
  border-bottom: 1px solid #e4e9f0;
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.account-group-header h3,
.member-group-header h3 {
  font-size: 15px;
  margin: 0;
}

.account-group-header strong,
.member-group-header strong {
  color: #172033;
}

.member-group-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.balance-import-form {
  margin: 0;
}

.balance-import-form button {
  padding: 7px 10px;
}

.overview-totals {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  margin-top: 16px;
}

.overview-totals div {
  background: #f8fafc;
  border: 1px solid #e4e9f0;
  border-radius: 8px;
  padding: 12px;
}

.overview-totals span {
  color: #667085;
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.overview-totals strong {
  color: #172033;
  font-size: 18px;
}

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

.entry-form label {
  color: #344054;
  display: grid;
  font-size: 14px;
  gap: 8px;
}

.form-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.drawer-backdrop {
  align-items: stretch;
  background: rgba(15, 23, 42, 0.28);
  display: flex;
  inset: 0;
  justify-content: flex-end;
  position: fixed;
  z-index: 900;
}

.drawer-backdrop[hidden] {
  display: none;
}

.edit-drawer {
  background: #ffffff;
  box-shadow: -18px 0 38px rgba(15, 23, 42, 0.18);
  display: grid;
  grid-template-rows: auto 1fr;
  max-width: min(560px, 100vw);
  overflow-y: auto;
  padding: 20px;
  width: 520px;
}

.drawer-header {
  align-items: center;
  border-bottom: 1px solid #e4e9f0;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
}

.drawer-header h2 {
  font-size: 18px;
  margin: 0;
}

.drawer-form {
  align-content: start;
  grid-template-columns: 1fr;
}

.inline-edit-row td {
  background: #f8fafc;
  white-space: normal;
}

.inline-edit-form {
  display: grid;
  gap: 14px;
  grid-template-columns: auto 180px 180px minmax(220px, 1fr) auto;
}

.inline-edit-title {
  align-self: center;
  color: #172033;
  font-size: 15px;
}

.inline-edit-form label {
  color: #344054;
  display: grid;
  font-size: 14px;
  gap: 8px;
}

.inline-edit-form textarea {
  min-height: 42px;
}

.balance-date-form {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 18px;
}

.balance-date-form button[hidden] {
  display: none;
}

.balance-date-form label,
.balance-inline-form {
  color: #344054;
  display: grid;
  font-size: 14px;
  gap: 8px;
}

.balance-amount-cell {
  display: grid;
  min-height: 40px;
  width: 180px;
}

[data-balance-amount-display] {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  box-sizing: border-box;
  display: flex;
  min-height: 40px;
  padding: 0 12px;
  width: 100%;
}

.balance-inline-form {
  width: 180px;
}

.balance-inline-form input {
  box-sizing: border-box;
  height: 40px;
  min-width: 0;
  width: 100%;
}

.balance-inline-form[hidden],
[data-balance-amount-display][hidden],
.table-actions[hidden] {
  display: none;
}

.entry-form label:has(textarea),
.entry-form button {
  align-self: end;
}

select,
textarea {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.errorlist {
  color: #b42318;
  font-size: 13px;
  list-style: none;
  margin: 0;
  padding: 0;
}

table {
  border-collapse: collapse;
  font-size: 14px;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid #e4e9f0;
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

td:nth-child(2) {
  white-space: normal;
}

table:has(th:nth-child(6)) td:nth-child(6),
table:has(th:nth-child(5)):not(:has(th:nth-child(6))) td:nth-child(4),
table:has(th:nth-child(3)):not(:has(th:nth-child(4))) td:nth-child(3) {
  min-width: 180px;
  white-space: normal;
}

.member-group table {
  min-width: 900px;
}

.member-group .transaction-table {
  min-width: 780px;
}

.transaction-table td:nth-child(5) {
  min-width: 180px;
  white-space: normal;
}

.transaction-table th:nth-child(3),
.transaction-table td:nth-child(3) {
  text-align: right;
}

.transaction-table th:nth-child(6),
.transaction-table td:nth-child(6) {
  min-width: 128px;
  white-space: nowrap;
}

.overview-table {
  table-layout: fixed;
}

.overview-table th,
.overview-table td {
  overflow-wrap: anywhere;
}

.overview-table .overview-col-date {
  width: 20%;
}

.overview-table .overview-col-title {
  width: 17%;
}

.overview-table .overview-col-category {
  width: 12%;
}

.overview-table .overview-col-member {
  width: 9%;
}

.overview-table .overview-col-amount {
  width: 14%;
}

.overview-table .overview-col-note {
  width: 28%;
}

.overview-table .overview-col-period {
  width: 72%;
}

.overview-table .overview-col-account {
  width: 38%;
}

.overview-table-balance .overview-col-date {
  width: 20%;
}

.overview-table-balance .overview-col-amount {
  width: 16%;
}

.overview-table-balance .overview-col-note {
  width: 26%;
}

.overview-table-period_transaction .overview-col-amount {
  width: 28%;
}

.overview-table td:nth-child(2),
.overview-table td:last-child {
  white-space: normal;
}

.overview-table-transaction th:nth-child(5),
.overview-table-transaction td:nth-child(5),
.overview-table-balance th:nth-child(3),
.overview-table-balance td:nth-child(3),
.overview-table-period_transaction th:nth-child(2),
.overview-table-period_transaction td:nth-child(2) {
  text-align: right;
}

.balance-table th:nth-child(3),
.balance-table td:nth-child(3) {
  width: 196px;
}

.balance-table th:nth-child(4),
.balance-table td:nth-child(4) {
  width: 136px;
}

th {
  color: #475467;
  font-weight: 700;
}

td form {
  margin: 0;
}

.table-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-actions .button,
.table-actions button {
  padding: 7px 10px;
}

.balance-actions {
  display: grid;
  flex-wrap: nowrap;
  grid-template-columns: repeat(2, 58px);
  width: 124px;
}

.balance-actions form {
  display: block;
  width: 100%;
}

.balance-actions .button,
.balance-actions button,
.balance-action-placeholder {
  align-items: center;
  box-sizing: border-box;
  display: inline-flex;
  justify-content: center;
  min-height: 34px;
  padding: 7px 0;
  width: 100%;
}

.balance-action-placeholder {
  visibility: hidden;
}

.danger {
  background: #dc2626;
}

.toast-stack {
  display: grid;
  gap: 10px;
  left: 50%;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
  position: fixed;
  top: 72px;
  transform: translateX(-50%);
  width: max-content;
  z-index: 1000;
}

.toast {
  animation: toast-in 180ms ease-out;
  background: rgba(23, 32, 51, 0.94);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 16px;
  text-align: center;
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.success {
  background: rgba(6, 118, 71, 0.95);
}

.toast.error {
  background: rgba(180, 35, 24, 0.95);
}

.toast.is-hiding {
  opacity: 0;
  transform: translateY(-8px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty {
  color: #667085;
  padding: 24px 8px;
  text-align: center;
}

@media (max-width: 760px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace-shell {
    grid-template-columns: 1fr;
  }

  .workspace-nav {
    position: static;
  }

  .content-grid,
  .entry-form,
  .inline-edit-form {
    grid-template-columns: 1fr;
  }

  .edit-drawer {
    max-width: 100vw;
    width: 100vw;
  }

  .hero {
    align-items: start;
    flex-direction: column;
    gap: 16px;
  }

  .landing {
    gap: 28px;
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 24px 0 44px;
  }

  .landing h1 {
    font-size: 36px;
  }

  .section-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .month-tools {
    justify-content: flex-start;
    width: 100%;
  }

  .panel-heading,
  .account-group-header,
  .member-group-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
