:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-soft: #f0f3ef;
  --ink: #151815;
  --muted: #697069;
  --line: #dde2dc;
  --green: #187546;
  --green-soft: #e4f1e8;
  --blue: #2473b9;
  --blue-soft: #e6f0fa;
  --coral: #dc4d43;
  --coral-soft: #fdeae7;
  --amber: #a36208;
  --amber-soft: #f8eed9;
  --shadow: 0 16px 40px rgba(26, 45, 32, 0.1);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(36, 115, 185, 0.2);
  outline-offset: 2px;
}
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 32px 20px;
  text-align: center;
}
.auth-gate h1 { margin: 0 0 10px; }
.auth-gate > p:not(.eyebrow) {
  max-width: 320px;
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.65;
}
.auth-mark {
  display: grid;
  width: 62px;
  height: 62px;
  margin-bottom: 20px;
  place-items: center;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
}
.auth-mark svg { width: 30px; height: 30px; }
.google-sign-in { min-height: 44px; }
.auth-status { margin-top: 14px; color: var(--muted); font-size: 0.78rem; }
.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 150px;
}
.app-header, .header-actions, .month-navigation, .section-heading, .budget-foot, .composer-row, .dialog-header, .dialog-actions, .settings-actions {
  display: flex;
  align-items: center;
}
.app-header { justify-content: space-between; gap: 16px; }
.eyebrow, .section-kicker {
  display: block;
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 2rem; line-height: 1.1; }
h2 { margin: 0; font-size: 1.1rem; }
.header-actions { gap: 10px; }
.sync-state { color: var(--muted); font-size: 0.8rem; }
.sync-state.is-error { color: var(--coral); }
.icon-button, .round-button {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
}
.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: transparent;
  color: var(--green);
}
.icon-button:hover { background: var(--surface-soft); }
.icon-button svg { width: 22px; height: 22px; }
.month-navigation {
  justify-content: center;
  gap: 10px;
  margin: 24px 0;
}
.month-control {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 210px;
  height: 44px;
  font-size: 1.18rem;
  font-weight: 800;
}
.month-control input {
  position: absolute;
  inset: 0;
  cursor: pointer;
  opacity: 0;
}
.month-control svg { width: 20px; color: var(--green); }
.content-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.overview-column { display: grid; gap: 14px; position: sticky; top: 20px; }
.budget-panel, .insights-panel, .category-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.budget-panel { padding: 20px; }
.budget-copy { display: grid; gap: 5px; }
.budget-copy span, .insight span { color: var(--muted); font-size: 0.82rem; }
.budget-copy strong { font-size: 2rem; }
.budget-progress {
  overflow: hidden;
  height: 8px;
  margin: 18px 0 10px;
  border-radius: 4px;
  background: #e5e9e4;
}
.budget-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 180ms ease;
}
.budget-foot { justify-content: space-between; color: var(--muted); font-size: 0.85rem; }
.budget-foot strong { color: var(--green); }
.text-button {
  margin-top: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 800;
}
.insights-panel, .category-panel { padding: 18px; }
.section-heading { justify-content: space-between; gap: 12px; }
.section-heading > svg { color: var(--green); }
.section-heading.compact { margin-bottom: 14px; }
.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0;
  background: var(--line);
}
.insight { display: grid; gap: 7px; padding: 10px 8px; background: var(--surface); }
.insight strong { font-size: 1rem; }
.ai-insight {
  margin: 0;
  padding: 11px 12px;
  border-radius: 6px;
  background: var(--green-soft);
  color: #245e3e;
  font-size: 0.82rem;
  line-height: 1.55;
}
select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
select, input { height: 44px; padding: 0 12px; }
textarea { min-height: 90px; padding: 11px 12px; resize: vertical; }
.section-heading select { width: 96px; height: 34px; font-size: 0.82rem; }
.category-breakdown { display: grid; gap: 11px; }
.category-row { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; align-items: center; font-size: 0.84rem; }
.category-bar { overflow: hidden; height: 6px; border-radius: 3px; background: var(--surface-soft); }
.category-bar span { display: block; height: 100%; background: var(--green); }
.category-row strong { font-size: 0.82rem; }
.timeline-panel { min-width: 0; }
.timeline-heading {
  padding: 0 4px 16px;
  border-bottom: 1px solid var(--line);
}
.add-top { background: var(--green); color: white; }
.add-top:hover { background: #105d36; }
.timeline { position: relative; }
.date-group {
  position: relative;
  padding: 24px 0 2px 54px;
}
.date-group::before {
  content: "";
  position: absolute;
  top: 36px;
  bottom: -28px;
  left: 17px;
  width: 1px;
  background: var(--line);
}
.date-group:last-child::before { bottom: 28px; }
.date-dot {
  position: absolute;
  top: 28px;
  left: 9px;
  width: 17px;
  height: 17px;
  border: 3px solid var(--green);
  border-radius: 50%;
  background: var(--bg);
}
.date-title { display: flex; align-items: baseline; gap: 9px; margin-bottom: 13px; }
.date-title strong { font-size: 1.18rem; }
.date-title span { color: var(--muted); font-size: 0.82rem; }
.record-list { border-top: 1px solid var(--line); }
.record-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  width: 100%;
  padding: 18px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}
.record-row:hover { background: rgba(255,255,255,0.65); }
.record-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
}
.record-icon svg { width: 21px; height: 21px; }
.record-icon.medical { background: var(--blue-soft); color: var(--blue); }
.record-icon.pending { background: var(--coral-soft); color: var(--coral); }
.record-icon.planned { background: var(--amber-soft); color: var(--amber); }
.record-main { min-width: 0; }
.record-main strong { display: block; margin-bottom: 5px; font-size: 1rem; }
.record-main p {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.record-meta { display: flex; align-items: center; gap: 7px; margin-top: 8px; color: var(--muted); font-size: 0.76rem; }
.record-meta svg { width: 14px; }
.record-side { display: grid; justify-items: end; gap: 7px; }
.record-side strong { font-size: 1rem; white-space: nowrap; }
.record-side strong.pending-text { color: var(--coral); }
.status-badge {
  padding: 4px 7px;
  border: 1px solid currentColor;
  border-radius: 5px;
  color: var(--green);
  font-size: 0.7rem;
  font-weight: 800;
}
.status-badge.reimbursable { color: var(--blue); }
.status-badge.pending { color: var(--coral); }
.status-badge.planned { color: var(--amber); }
.empty-state {
  display: none;
  justify-items: center;
  gap: 8px;
  padding: 70px 20px;
  color: var(--muted);
  text-align: center;
}
.empty-state svg { width: 30px; height: 30px; color: var(--green); }
.smart-composer {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid rgba(221, 226, 220, 0.88);
  background: rgba(247, 248, 245, 0.94);
  backdrop-filter: blur(18px);
}
.composer-row { width: min(720px, 100%); margin: 0 auto; gap: 10px; }
.round-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}
.round-button.primary { background: var(--green); color: #fff; box-shadow: 0 8px 20px rgba(24, 117, 70, 0.25); }
.round-button.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--green); }
.round-button.is-listening { background: var(--coral); }
.composer-input {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
}
.composer-input input { min-width: 0; height: 100%; border: 0; border-radius: inherit; background: transparent; }
.composer-input button { display: grid; width: 44px; height: 44px; flex: 0 0 auto; place-items: center; border: 0; background: transparent; color: var(--green); }
.composer-input svg, .round-button svg { width: 21px; height: 21px; }
.composer-hint { width: min(620px, calc(100% - 110px)); margin: 7px auto 0; color: var(--muted); font-size: 0.73rem; }
.parse-preview {
  width: min(620px, calc(100% - 110px));
  margin: 0 auto 8px;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 7px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 0.8rem;
}
.parse-preview:not([hidden]) { display: flex; }
.parse-preview svg { width: 16px; }
.parse-preview span { flex: 1; }
.parse-preview button { border: 0; background: transparent; color: inherit; font-weight: 800; }
.sheet-dialog {
  width: min(640px, calc(100% - 24px));
  max-height: calc(100vh - 40px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet-dialog::backdrop { background: rgba(18, 24, 20, 0.36); backdrop-filter: blur(3px); }
.dialog-header { justify-content: space-between; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.span-2 { grid-column: span 2; }
.money-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; }
.money-input span { display: grid; width: 36px; place-items: center; color: var(--muted); }
.money-input input { border: 0; }
.dialog-actions { justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog-actions > span { flex: 1; }
.primary-button, .ghost-button, .danger-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-radius: 6px;
  font-weight: 800;
}
.primary-button { border: 1px solid var(--green); background: var(--green); color: #fff; }
.ghost-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.danger-button { border: 1px solid var(--coral); background: transparent; color: var(--coral); }
.compact-dialog { max-width: 460px; }
.settings-copy { color: var(--muted); line-height: 1.7; }
.account-row {
  display: grid;
  gap: 5px;
  margin: 18px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}
.account-row span { color: var(--muted); font-size: 0.76rem; }
.account-row strong { overflow-wrap: anywhere; font-size: 0.88rem; }
.settings-actions { gap: 10px; }
.settings-actions button { flex: 1; }
.sign-out-button {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--coral);
  font-weight: 800;
}

@media (max-width: 800px) {
  .app-shell { width: min(100% - 28px, 720px); padding-top: 20px; }
  .content-grid { grid-template-columns: 1fr; gap: 22px; }
  .overview-column { position: static; grid-template-columns: 1fr 1fr; }
  .category-panel { grid-column: span 2; }
}
@media (max-width: 560px) {
  .app-shell { width: calc(100% - 24px); padding: 16px 0 150px; }
  h1 { font-size: 1.65rem; }
  .sync-state { display: none; }
  .month-navigation { justify-content: space-between; margin: 15px 0 18px; }
  .month-control { min-width: 170px; font-size: 1.04rem; }
  .overview-column { grid-template-columns: 1fr; gap: 10px; }
  .category-panel { grid-column: auto; }
  .budget-panel { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 16px; }
  .budget-progress, .budget-foot { grid-column: span 2; }
  .budget-copy strong { font-size: 1.55rem; }
  .text-button { margin: 0; align-self: end; }
  .category-panel { display: none; }
  .timeline-heading { padding-top: 4px; }
  .date-group { padding-left: 38px; }
  .date-group::before { left: 11px; }
  .date-dot { left: 3px; }
  .record-row { grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; padding: 16px 0; }
  .record-icon { width: 38px; height: 38px; }
  .record-main p { max-width: 42vw; }
  .record-meta { display: none; }
  .record-side strong { font-size: 0.94rem; }
  .sheet-dialog {
    width: 100%;
    max-width: none;
    max-height: 88vh;
    margin: auto 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 8px 8px 0 0;
  }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .span-2 { grid-column: span 2; }
  .dialog-actions { position: sticky; bottom: 0; padding-top: 12px; background: var(--surface); }
  .composer-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
