:root {
  color-scheme: light;
  --bg: #f7f8f4;
  --surface: #ffffff;
  --surface-soft: #eef4ef;
  --ink: #19201c;
  --muted: #68736c;
  --line: #d9dfda;
  --green: #247454;
  --green-dark: #15553c;
  --coral: #c95e4d;
  --yellow: #d9a72e;
  --blue: #3d6f9d;
  --shadow: 0 8px 28px rgba(25, 32, 28, 0.08);
  --sidebar-width: 228px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

.muted {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 900;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  border-width: 1px;
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 1rem;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-panel {
  width: min(100%, 420px);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 22px 0 8px;
  font-size: 2rem;
}

.login-panel > p {
  margin: 0 0 28px;
}

.stack-form,
.dialog-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #465149;
  font-size: 0.86rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c8d0ca;
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(36, 116, 84, 0.14);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--coral);
  font-size: 0.82rem;
}

.button,
.text-button,
.icon-button,
.nav-item,
.mobile-nav button,
.segmented button {
  border: 0;
  background: none;
  color: inherit;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 9px 15px;
  font-weight: 800;
  text-decoration: none;
}

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

.button.primary:hover {
  background: var(--green-dark);
}

.button.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
}

.button.secondary:hover {
  border-color: #aeb9b1;
  background: #f4f6f3;
}

.button.danger {
  background: #fff1ee;
  color: #a23f31;
}

.button.wide {
  width: 100%;
}

.text-button {
  padding: 6px 0;
  color: var(--green);
  font-weight: 800;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 1.2rem;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 22px 16px;
}

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

.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
}

.sidebar-brand span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.main-nav {
  display: grid;
  gap: 6px;
  margin-top: 34px;
}

.nav-item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  border-radius: 6px;
  padding: 9px 12px;
  color: #536058;
  font-weight: 750;
  text-align: left;
}

.nav-item span {
  width: 20px;
  color: #6d7970;
  font-size: 1.08rem;
  text-align: center;
}

.nav-item:hover {
  background: #f1f4f1;
}

.nav-item.active {
  background: var(--surface-soft);
  color: var(--green-dark);
}

.logout-button {
  margin-top: auto;
}

.mobile-header,
.mobile-nav {
  display: none;
}

.content {
  width: calc(100% - var(--sidebar-width));
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 38px clamp(24px, 4vw, 64px) 80px;
}

.view {
  display: none;
  width: min(1120px, 100%);
  margin: 0 auto;
}

.view.active {
  display: block;
}

.page-header,
.section-heading,
.toolbar,
.dialog-form header,
.dialog-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header {
  min-height: 58px;
  margin-bottom: 26px;
}

.page-header h2 {
  margin: 0;
  font-size: clamp(1.65rem, 2vw, 2.15rem);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-input {
  width: auto;
  min-height: 40px;
}

.overview-band {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) minmax(320px, 1fr);
  align-items: center;
  gap: 22px;
  min-height: 154px;
  border-block: 1px solid var(--line);
  padding: 24px 0;
}

.completion-ring {
  display: grid;
  width: 104px;
  height: 104px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0deg, var(--green) 0deg, #dfe6e0 0deg);
}

.completion-ring::before {
  grid-area: 1 / 1;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--bg);
  content: "";
}

.completion-ring span {
  z-index: 1;
  grid-area: 1 / 1;
  font-weight: 900;
}

.overview-copy span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.overview-copy strong {
  display: block;
  margin-top: 5px;
  font-size: 1.25rem;
}

.overview-copy p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.overview-metrics,
.finance-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
}

.overview-metrics div,
.finance-totals div {
  min-width: 0;
  border-left: 1px solid var(--line);
  padding: 8px 20px;
}

.overview-metrics dt,
.finance-totals dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.overview-metrics dd,
.finance-totals dd {
  overflow: hidden;
  margin: 7px 0 0;
  font-size: 1.2rem;
  font-weight: 900;
  text-overflow: ellipsis;
}

.section-heading {
  margin: 34px 0 14px;
}

.section-heading h3 {
  margin: 0;
  font-size: 1.05rem;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.task-list,
.transaction-list,
.note-list {
  display: grid;
  gap: 9px;
}

.task-row,
.transaction-row,
.note-index-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.task-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  min-height: 72px;
  padding: 12px 14px;
}

.task-check {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid #aab5ad;
  border-radius: 50%;
  background: #fff;
  color: transparent;
  font-size: 1rem;
  font-weight: 900;
}

.task-check:hover {
  border-color: var(--green);
}

.task-check-disabled {
  border-style: dashed;
  background: #f1f3f1;
  color: #b2bab4;
}

.task-row.completed .task-check {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.task-row.completed .task-copy strong {
  color: var(--muted);
  text-decoration: line-through;
}

.task-copy {
  min-width: 0;
}

.task-copy strong,
.transaction-copy strong,
.note-index-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.task-copy p,
.transaction-copy p,
.note-index-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 4px;
  background: #edf1ee;
  color: #526059;
  padding: 3px 7px;
  font-size: 0.68rem;
  font-weight: 800;
}

.tag.urgent {
  background: #fff0ed;
  color: #a33f32;
}

.tag.important {
  background: #fff7dd;
  color: #886411;
}

.task-actions,
.transaction-actions,
.note-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: 6px 9px;
  color: #48534c;
  font-size: 0.74rem;
  font-weight: 800;
}

.mini-button:hover {
  background: #f2f5f2;
}

.mini-button.danger {
  border-color: #f0cbc4;
  color: #9c4033;
}

.toolbar {
  flex-wrap: wrap;
  margin-bottom: 20px;
  border-block: 1px solid var(--line);
  padding: 13px 0;
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.segmented button {
  min-height: 36px;
  border-right: 1px solid var(--line);
  padding: 7px 13px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.segmented button:last-child {
  border-right: 0;
}

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

.finance-toolbar {
  justify-content: flex-start;
}

.finance-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.finance-totals {
  border-block: 1px solid var(--line);
  padding: 18px 0;
}

.finance-totals div:first-child {
  border-left: 0;
}

.finance-totals .income dd {
  color: var(--green);
}

.finance-totals .expense dd {
  color: var(--coral);
}

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

.account-item {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 15px;
}

.account-item span {
  color: var(--muted);
  font-size: 0.76rem;
}

.account-item strong {
  display: block;
  margin-top: 9px;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.transaction-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 11px 14px;
}

.transaction-type {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: #eef3ef;
  color: var(--green);
  font-weight: 900;
}

.transaction-type.expense {
  background: #fff0ed;
  color: var(--coral);
}

.transaction-type.transfer {
  background: #edf3f8;
  color: var(--blue);
}

.transaction-amount {
  text-align: right;
  white-space: nowrap;
}

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

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

.transaction-list.compact .transaction-actions {
  display: none;
}

.notes-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  min-height: 560px;
  border-block: 1px solid var(--line);
}

.notes-index {
  border-right: 1px solid var(--line);
  padding: 18px 18px 18px 0;
}

.search-field input {
  background: var(--surface);
}

.note-list {
  margin-top: 14px;
}

.note-index-item {
  width: 100%;
  padding: 12px;
  color: inherit;
  text-align: left;
}

.note-index-item.active {
  border-color: #9db9a8;
  background: var(--surface-soft);
}

.note-detail {
  min-width: 0;
  padding: 22px 0 22px 28px;
}

.note-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.note-detail h3 {
  margin: 0;
  font-size: 1.35rem;
  overflow-wrap: anywhere;
}

.note-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.note-entries {
  display: grid;
  gap: 20px;
  margin-top: 22px;
}

.note-entry {
  border-left: 3px solid #a8c4b2;
  padding-left: 14px;
}

.note-entry p {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.note-entry footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.72rem;
}

.timeline-frame-wrap {
  min-height: 650px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.timeline-frame {
  width: 100%;
  min-height: 760px;
  border: 0;
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-content: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.empty-state p {
  max-width: 440px;
  margin: 7px auto 0;
  line-height: 1.6;
}

dialog {
  width: min(92vw, 620px);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(20, 28, 23, 0.22);
  padding: 0;
}

dialog::backdrop {
  background: rgba(23, 29, 25, 0.52);
}

.dialog-form {
  padding: 24px;
}

.dialog-form header {
  margin-bottom: 2px;
}

.dialog-form h3 {
  margin: 0;
  font-size: 1.35rem;
}

.dialog-form footer {
  justify-content: flex-end;
  padding-top: 5px;
}

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

.field-grid:has(> :nth-child(3)) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.weekday-fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.weekday-fieldset legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.weekday-grid label {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 3px;
  font-size: 0.72rem;
}

.weekday-grid input,
.toggle-row input {
  width: auto;
  min-height: auto;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.form-segmented {
  width: 100%;
}

.form-segmented button {
  flex: 1;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: min(360px, calc(100vw - 32px));
  translate: 0 20px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  padding: 11px 15px;
  pointer-events: none;
  transition: opacity 160ms ease, translate 160ms ease;
}

.toast.show {
  translate: 0;
  opacity: 1;
}

.toast.error {
  background: #9f3f32;
}

@media (max-width: 820px) {
  .sidebar {
    display: none;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 15;
    display: flex;
    min-height: 60px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: rgba(247, 248, 244, 0.96);
    padding: 10px 16px;
  }

  .content {
    width: 100%;
    margin-left: 0;
    padding: 24px 16px 98px;
  }

  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-height: 64px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding: 5px max(5px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(5px, env(safe-area-inset-left));
  }

  .mobile-nav button {
    display: grid;
    min-width: 0;
    place-items: center;
    align-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
  }

  .mobile-nav button span {
    font-size: 1.05rem;
  }

  .mobile-nav button.active {
    color: var(--green);
  }

  .page-header {
    align-items: flex-end;
  }

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

  .overview-metrics {
    grid-column: 1 / -1;
  }

  .overview-metrics div:first-child {
    border-left: 0;
    padding-left: 0;
  }

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

  .task-actions {
    grid-column: 2;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .account-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .transaction-actions {
    grid-column: 2 / -1;
    justify-content: flex-end;
  }

  .transaction-list.compact .transaction-actions {
    display: none;
  }

  .notes-layout {
    display: block;
    min-height: 0;
  }

  .notes-index {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 16px;
  }

  .note-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .note-index-item {
    min-width: 210px;
  }

  .note-detail {
    padding: 22px 0;
  }

  .timeline-frame-wrap {
    min-height: 520px;
  }

  .timeline-frame {
    min-height: 640px;
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 28px 22px;
  }

  .page-header {
    align-items: flex-start;
  }

  .header-actions {
    display: grid;
    justify-items: end;
  }

  .overview-band {
    gap: 16px;
  }

  .completion-ring {
    width: 88px;
    height: 88px;
  }

  .completion-ring::before {
    width: 64px;
    height: 64px;
  }

  .overview-metrics dd,
  .finance-totals dd {
    font-size: 0.96rem;
  }

  .overview-metrics div,
  .finance-totals div {
    padding-inline: 10px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > * {
    max-width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
    padding-inline: 8px;
  }

  .finance-toolbar label {
    width: 100%;
    justify-content: space-between;
  }

  .finance-toolbar .date-input {
    flex: 1;
  }

  .finance-totals {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .finance-totals div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
  }

  .finance-totals div:last-child {
    border-bottom: 0;
  }

  .finance-totals dd {
    margin: 0;
  }

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

  .transaction-amount {
    font-size: 0.86rem;
  }

  .field-grid,
  .field-grid:has(> :nth-child(3)) {
    grid-template-columns: 1fr;
  }

  .weekday-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .dialog-form {
    padding: 19px;
  }

  .toast {
    right: 16px;
    bottom: 82px;
  }
}
