:root {
  color-scheme: light;
  --ink: #1d2823;
  --muted: #66716b;
  --paper: #f7f3e9;
  --paper-deep: #eee8da;
  --card: #fffdf7;
  --line: #ddd6c7;
  --green: #24483b;
  --green-soft: #dfe9df;
  --green-bright: #3d765f;
  --red: #a4483d;
  --red-soft: #f1ded8;
  --gold: #a87825;
  --shadow: 0 18px 50px rgba(45, 52, 42, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, rgba(188, 164, 105, 0.15), transparent 31rem),
    radial-gradient(circle at 100% 12%, rgba(57, 103, 83, 0.1), transparent 32rem),
    var(--paper);
}

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

button,
select,
input[type="radio"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(61, 118, 95, 0.28);
  outline-offset: 2px;
}

.page-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  border-bottom: 1px solid rgba(127, 117, 96, 0.2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark,
.assistant-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: #fffdf7;
  background: var(--green);
  font-family: ui-serif, "Songti SC", serif;
  font-size: 20px;
  box-shadow: 0 8px 18px rgba(36, 72, 59, 0.2);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: ui-serif, "Songti SC", serif;
  font-size: 20px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid rgba(36, 72, 59, 0.14);
  border-radius: 999px;
  color: var(--green);
  background: rgba(255, 253, 247, 0.6);
  font-size: 13px;
  font-weight: 650;
}

.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a8b70;
  box-shadow: 0 0 0 4px rgba(74, 139, 112, 0.13);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  gap: 28px;
  align-items: start;
  padding: 48px 0 36px;
}

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

.intro-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 28px;
}

.eyebrow,
.assistant-kicker {
  margin: 0 0 8px;
  color: var(--green-bright);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

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

h1,
h2 {
  font-family: ui-serif, "Songti SC", "STSong", serif;
}

h1 {
  max-width: 620px;
  margin-bottom: 10px;
  font-size: clamp(34px, 4.2vw, 56px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.intro-copy {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
}

.month-control {
  flex: 0 0 auto;
}

.month-control span,
.field > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.month-control input,
.field input,
.field select,
.chat-form textarea {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 253, 247, 0.92);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.month-control input {
  min-height: 44px;
  padding: 0 13px;
  border-radius: 12px;
  font-weight: 650;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.summary-card {
  position: relative;
  overflow: hidden;
  min-height: 145px;
  padding: 22px;
  border: 1px solid rgba(129, 119, 98, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 247, 0.78);
  box-shadow: 0 10px 30px rgba(45, 52, 42, 0.04);
}

.summary-card::after {
  position: absolute;
  right: -28px;
  bottom: -38px;
  width: 105px;
  height: 105px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.055;
}

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

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

.balance-card {
  color: var(--gold);
}

.summary-label,
.summary-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-card strong {
  display: block;
  overflow: hidden;
  margin: 16px 0 10px;
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(25px, 2.5vw, 34px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card,
.assistant-card {
  border: 1px solid rgba(129, 119, 98, 0.2);
  border-radius: var(--radius-lg);
  background: rgba(255, 253, 247, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.card {
  margin-top: 18px;
  padding: 26px;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.1;
}

.section-note {
  color: var(--muted);
  font-size: 12px;
}

.type-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  width: 210px;
  margin: 0 0 22px;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: var(--paper-deep);
}

.type-switch label {
  position: relative;
}

.type-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-switch span {
  display: block;
  padding: 9px 16px;
  border-radius: 9px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  transition: 150ms ease;
}

.type-switch input:checked + span {
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 3px 10px rgba(58, 58, 47, 0.08);
}

.type-switch input:focus-visible + span {
  outline: 3px solid rgba(61, 118, 95, 0.28);
}

.entry-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 16px;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border-radius: 12px;
}

.field input:hover,
.field select:hover,
.chat-form textarea:hover {
  border-color: #bcb29f;
}

.note-field {
  grid-column: 1 / -1;
}

.field small {
  color: #91978f;
  font-weight: 500;
}

.amount-input-wrap {
  position: relative;
  display: block;
}

.amount-input-wrap b {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 14px;
  color: var(--green);
  transform: translateY(-50%);
}

.amount-input-wrap input {
  padding-left: 34px;
  font-family: ui-serif, Georgia, serif;
  font-size: 20px;
  font-weight: 700;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
}

.form-status,
.chat-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.form-status.error,
.chat-status.error {
  color: var(--red);
}

.primary-button,
.send-button {
  border: 0;
  border-radius: 12px;
  color: #fffef8;
  background: var(--green);
  font-weight: 720;
  box-shadow: 0 8px 18px rgba(36, 72, 59, 0.18);
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
}

.primary-button:hover,
.send-button:hover {
  background: #193a2f;
  transform: translateY(-1px);
}

.primary-button:active,
.send-button:active {
  transform: translateY(0);
}

.category-breakdown {
  display: grid;
  gap: 16px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(70px, 0.8fr) minmax(130px, 2.5fr) minmax(100px, 0.8fr);
  gap: 14px;
  align-items: center;
}

.category-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 690;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-track {
  overflow: hidden;
  height: 9px;
  border-radius: 99px;
  background: var(--paper-deep);
}

.category-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3e7660, #77a38b);
}

.category-value {
  color: var(--muted);
  text-align: right;
  font-family: ui-serif, Georgia, serif;
  font-size: 13px;
}

.empty-state {
  padding: 46px 20px 34px;
  color: var(--muted);
  text-align: center;
}

.empty-state > span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 15px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--green);
  font-family: ui-serif, "Songti SC", serif;
  font-size: 18px;
}

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

.empty-state p {
  margin-bottom: 0;
  font-size: 13px;
}

.compact-empty {
  padding: 20px 10px 8px;
}

.compact-empty > span {
  width: 38px;
  height: 38px;
  margin-bottom: 10px;
}

.transaction-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.transaction-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  padding: 16px 0;
  border-top: 1px solid rgba(221, 214, 199, 0.72);
}

.transaction-item:first-child {
  border-top: 0;
}

.transaction-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: var(--red);
  background: var(--red-soft);
  font-family: ui-serif, "Songti SC", serif;
  font-weight: 700;
}

.transaction-item.income .transaction-icon {
  color: var(--green);
  background: var(--green-soft);
}

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

.transaction-title,
.transaction-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-title {
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 720;
}

.transaction-meta {
  color: var(--muted);
  font-size: 12px;
}

.transaction-amount {
  font-family: ui-serif, Georgia, serif;
  font-size: 16px;
  font-weight: 750;
  white-space: nowrap;
}

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

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

.delete-button,
.icon-button {
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
}

.delete-button {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 18px;
}

.delete-button:hover {
  border-color: #e8ccc5;
  color: var(--red);
  background: #fff5f2;
}

.assistant-card {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  min-height: min(760px, calc(100vh - 40px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
}

.assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px;
  border-bottom: 1px solid rgba(221, 214, 199, 0.72);
}

.assistant-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.assistant-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(145deg, #24483b, #4d7a65);
  font-size: 17px;
}

.assistant-kicker {
  margin-bottom: 3px;
  font-size: 9px;
}

.assistant-header h2 {
  overflow: hidden;
  margin-bottom: 0;
  font-family: inherit;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  flex: 0 0 auto;
  padding: 7px 9px;
  border-radius: 9px;
  font-size: 12px;
}

.icon-button:hover {
  border-color: var(--line);
  color: var(--ink);
  background: var(--paper);
}

.assistant-privacy {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 18px 0;
  padding: 10px 12px;
  border-radius: 11px;
  color: #5d695f;
  background: #edf2ea;
  font-size: 11px;
  line-height: 1.55;
}

.chat-log {
  flex: 1 1 auto;
  min-height: 220px;
  overflow-y: auto;
  padding: 18px;
  overscroll-behavior: contain;
  scrollbar-color: #c6bfaf transparent;
}

.message {
  width: fit-content;
  max-width: 90%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 16px;
}

.message p {
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.68;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-role {
  display: block;
  margin-bottom: 5px;
  color: #748078;
  font-size: 10px;
  font-weight: 720;
}

.assistant-message {
  margin-right: auto;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  background: #fffefa;
}

.user-message {
  margin-left: auto;
  border-bottom-right-radius: 5px;
  color: #fefcf6;
  background: var(--green);
}

.user-message .message-role {
  color: rgba(255, 255, 255, 0.65);
}

.loading-message p {
  letter-spacing: 0.18em;
  animation: pulse 1.2s infinite ease-in-out;
}

.suggestion-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 18px 10px;
  scrollbar-width: none;
}

.suggestion-row::-webkit-scrollbar {
  display: none;
}

.suggestion-row button {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green);
  background: transparent;
  font-size: 11px;
}

.suggestion-row button:hover {
  border-color: #aabdad;
  background: var(--green-soft);
}

.chat-status {
  padding: 0 18px;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
  padding: 10px 18px 12px;
}

.chat-form textarea {
  width: 100%;
  min-height: 78px;
  max-height: 150px;
  resize: vertical;
  padding: 12px;
  border-radius: 13px;
  line-height: 1.5;
}

.send-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 14px;
}

.send-button:disabled,
.primary-button:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.assistant-disclaimer {
  margin: 0;
  padding: 0 20px 18px;
  color: #878d87;
  text-align: center;
  font-size: 10px;
  line-height: 1.5;
}

footer {
  padding: 16px 0 35px;
  border-top: 1px solid rgba(127, 117, 96, 0.18);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

footer p {
  margin-bottom: 0;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100% - 48px));
  padding: 12px 16px;
  border-radius: 12px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 12px 32px rgba(26, 46, 38, 0.28);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.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;
}

[hidden] {
  display: none !important;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .assistant-card {
    position: static;
    min-height: 680px;
    max-height: 760px;
  }
}

@media (max-width: 700px) {
  .page-shell {
    width: min(100% - 24px, 1480px);
  }

  .topbar {
    min-height: 76px;
  }

  .brand small {
    display: none;
  }

  .privacy-badge {
    padding: 8px 10px;
    font-size: 11px;
  }

  .workspace {
    gap: 20px;
    padding-top: 30px;
  }

  .intro-row {
    display: block;
  }

  h1 {
    font-size: 38px;
  }

  .month-control {
    display: block;
    margin-top: 22px;
  }

  .month-control input {
    width: 100%;
  }

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

  .summary-card {
    min-height: 118px;
  }

  .summary-card strong {
    margin: 12px 0 8px;
  }

  .card {
    padding: 20px;
    border-radius: 19px;
  }

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

  .note-field {
    grid-column: auto;
  }

  .form-actions {
    display: block;
  }

  .primary-button {
    width: 100%;
    justify-content: center;
    margin-top: 10px;
  }

  .category-row {
    grid-template-columns: minmax(60px, 0.8fr) minmax(90px, 1.6fr) auto;
    gap: 8px;
  }

  .transaction-item {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
  }

  .delete-button {
    grid-column: 3;
  }

  .transaction-amount {
    grid-row: 1;
    grid-column: 3;
  }

  .delete-button {
    grid-row: 2;
    align-self: start;
  }

  .assistant-card {
    min-height: 640px;
    border-radius: 19px;
  }

  .assistant-header {
    padding: 18px;
  }
}

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