:root {
  --canvas: #f4f5f2;
  --surface: #ffffff;
  --ink: #171a18;
  --muted: #70756f;
  --line: #dfe2dc;
  --line-strong: #c8cdc6;
  --green: #187451;
  --green-soft: #e4f2eb;
  --red: #b4473d;
  --red-soft: #f8e9e6;
  --blue: #315f9f;
  --focus: #111411;
  --shadow: 0 16px 48px rgb(21 27 23 / 14%);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

input {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: #9a9f99;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

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

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: rgb(244 245 242 / 92%);
  backdrop-filter: blur(14px);
}

.header-inner {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  min-height: 72px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-lockup,
.header-actions {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 12px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  line-height: 1;
}

.header-actions {
  gap: 8px;
}

.header-actions form {
  margin: 0;
}

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}

.icon-button {
  width: 40px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover,
.text-button:hover {
  background: #e7e9e4;
}

.text-button {
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.secondary-button,
.danger-button {
  gap: 5px;
  padding: 0 15px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 650;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.primary-button:hover {
  background: #343936;
}

.secondary-button {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: #aeb4ac;
  background: #fafbf9;
}

.danger-button {
  border-color: #e6bcb6;
  background: var(--red-soft);
  color: var(--red);
}

.full-width {
  width: 100%;
}

.app-main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 40px 0 80px;
}

.month-toolbar {
  display: grid;
  grid-template-columns: 40px minmax(150px, 220px) 40px;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 34px;
  text-align: center;
}

.month-toolbar .icon-button {
  border-color: var(--line);
  background: var(--surface);
  font-size: 27px;
}

.month-heading p {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
}

.month-heading h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 680;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 52px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
}

.summary-item {
  min-width: 0;
  padding: 24px 28px;
}

.summary-item + .summary-item {
  border-left: 1px solid var(--line);
}

.summary-item span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  display: block;
  overflow: hidden;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.income-summary strong {
  color: var(--green);
}

.expense-summary strong {
  color: var(--red);
}

.balance-summary strong {
  color: var(--blue);
}

.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 54px;
  align-items: start;
}

.ledger-column,
.insight-column {
  min-width: 0;
}

.insight-column {
  position: sticky;
  top: 104px;
}

.section-heading {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-heading.compact {
  min-height: 40px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 680;
}

.count-label {
  display: inline-block;
  min-width: 24px;
  margin-left: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  vertical-align: 2px;
}

.filters {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  gap: 10px;
  margin-bottom: 16px;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eaede8;
}

.segmented-control button {
  min-width: 58px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.segmented-control button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgb(25 33 28 / 10%);
  font-weight: 650;
}

.search-field input {
  min-height: 44px;
  background: var(--surface);
  font-size: 13px;
}

.filters .secondary-button {
  min-height: 44px;
  white-space: nowrap;
}

.transaction-list {
  border-top: 1px solid var(--line-strong);
}

.transaction-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto 38px;
  min-height: 76px;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.transaction-date {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}

.transaction-date strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 680;
}

.transaction-detail {
  min-width: 0;
}

.transaction-detail strong,
.transaction-detail span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-detail strong {
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 650;
}

.transaction-detail span {
  color: var(--muted);
  font-size: 11px;
}

.transaction-amount {
  min-width: 100px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 680;
  text-align: right;
  white-space: nowrap;
}

.transaction-amount.income {
  color: var(--green);
}

.transaction-amount.expense {
  color: var(--red);
}

.edit-entry {
  width: 34px;
  height: 34px;
  min-height: 34px;
  color: var(--muted);
  font-size: 16px;
}

.status-state {
  display: grid;
  min-height: 190px;
  place-content: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status-state strong,
.status-state span {
  display: block;
}

.status-state strong {
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 15px;
}

.category-breakdown {
  border-top: 1px solid var(--line-strong);
}

.category-item {
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.category-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.category-line strong {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.category-track {
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: #e3e6e1;
}

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

.width-5 { width: 5%; }
.width-10 { width: 10%; }
.width-15 { width: 15%; }
.width-20 { width: 20%; }
.width-25 { width: 25%; }
.width-30 { width: 30%; }
.width-35 { width: 35%; }
.width-40 { width: 40%; }
.width-45 { width: 45%; }
.width-50 { width: 50%; }
.width-55 { width: 55%; }
.width-60 { width: 60%; }
.width-65 { width: 65%; }
.width-70 { width: 70%; }
.width-75 { width: 75%; }
.width-80 { width: 80%; }
.width-85 { width: 85%; }
.width-90 { width: 90%; }
.width-95 { width: 95%; }
.width-100 { width: 100%; }

.category-empty {
  padding: 28px 0;
  color: var(--muted);
  font-size: 12px;
}

.sheet-dialog {
  width: min(620px, calc(100% - 32px));
  max-height: min(820px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet-dialog.narrow {
  width: min(440px, calc(100% - 32px));
}

.sheet-dialog::backdrop {
  background: rgb(20 23 21 / 46%);
  backdrop-filter: blur(3px);
}

.entry-form,
.sheet-dialog > form {
  padding: 28px;
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 20px;
}

.kind-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0 0 22px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eceeea;
}

.kind-control label {
  position: relative;
  cursor: pointer;
}

.kind-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.kind-control span {
  display: grid;
  min-height: 40px;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
}

.kind-control input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgb(22 28 24 / 10%);
  font-weight: 680;
}

.kind-control input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-grid.single-column {
  grid-template-columns: 1fr;
}

.form-grid label,
.login-form label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.form-grid label > span,
.login-form label > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.form-grid small {
  color: var(--muted);
  font-size: 11px;
}

.full-span {
  grid-column: 1 / -1;
}

.amount-field > div {
  display: flex;
  align-items: baseline;
  border-bottom: 1px solid var(--line-strong);
}

.amount-field b {
  color: var(--muted);
  font-size: 24px;
  font-weight: 500;
}

.amount-field input {
  min-height: 62px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-size: 34px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.amount-field input:focus-visible {
  outline: 0;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.action-spacer {
  flex: 1;
}

.form-message {
  margin-top: 18px;
  padding: 11px 12px;
  border-radius: 6px;
  font-size: 12px;
}

.form-message-error {
  border: 1px solid #edc7c1;
  background: var(--red-soft);
  color: #8b342c;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100% - 44px));
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--ink);
  box-shadow: 0 10px 34px rgb(15 18 16 / 22%);
  color: #fff;
  font-size: 13px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: var(--canvas);
}

.login-shell {
  width: min(420px, calc(100% - 32px));
  padding: 40px 0;
}

.login-panel {
  padding: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgb(25 30 27 / 9%);
}

.login-panel .brand-mark {
  margin-bottom: 28px;
}

.login-panel h1 {
  margin: 0;
  font-size: 28px;
}

.login-intro {
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 18px;
}

.login-form .primary-button {
  min-height: 46px;
  margin-top: 4px;
}

@media (max-width: 860px) {
  .content-layout {
    grid-template-columns: 1fr;
    gap: 44px;
  }

  .insight-column {
    position: static;
  }

  .category-breakdown {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 24px;
  }
}

@media (max-width: 640px) {
  .header-inner,
  .app-main {
    width: min(100% - 28px, 1180px);
  }

  .header-inner {
    min-height: 64px;
  }

  .brand-mark.small {
    width: 32px;
    height: 32px;
  }

  .brand-lockup .eyebrow {
    display: none;
  }

  .app-main {
    padding-top: 28px;
  }

  .month-toolbar {
    gap: 10px;
    margin-bottom: 24px;
  }

  .month-heading h2 {
    font-size: 19px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
    margin-bottom: 38px;
  }

  .summary-item {
    padding: 18px 14px;
  }

  .summary-item strong {
    font-size: 20px;
  }

  .balance-summary {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-left: 0 !important;
  }

  .filters {
    grid-template-columns: 1fr auto;
  }

  .segmented-control {
    grid-column: 1 / -1;
  }

  .search-field input {
    min-width: 0;
  }

  .transaction-row {
    grid-template-columns: 40px minmax(0, 1fr) auto 32px;
    gap: 9px;
  }

  .transaction-amount {
    min-width: 0;
    font-size: 14px;
  }

  .category-breakdown {
    grid-template-columns: 1fr;
  }

  .sheet-dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100vh - 48px);
    margin: auto 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .entry-form,
  .sheet-dialog > form {
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  }

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

  .full-span {
    grid-column: auto;
  }

  .amount-field input {
    font-size: 30px;
  }

  .login-panel {
    padding: 30px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
