:root {
  color-scheme: light;
  --bg: #ffffff;
  --paper: #ffffff;
  --paper-tint: #fff8fb;
  --ink: #2b2730;
  --muted: #7f7888;
  --line: #ece7f0;
  --green: #a77c14;
  --green-soft: #fff0b8;
  --red: #bf6376;
  --red-soft: #ffe0ea;
  --blue: #6b6bb8;
  --blue-soft: #e4e0ff;
  --gold: #b68a1f;
  --gold-soft: #fff0b8;
  --pink-soft: #ffddea;
  --purple-soft: #ebe2ff;
  --yellow-soft: #fff4c7;
  --shadow: 0 16px 38px rgba(143, 117, 154, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

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

body {
  min-height: 100%;
  margin: 0;
  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;
}

body.app-locked .app-shell {
  filter: blur(10px);
  pointer-events: none;
  user-select: none;
}

button,
input,
select {
  max-width: 100%;
  min-width: 0;
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px max(10px, env(safe-area-inset-left)) 34px max(10px, env(safe-area-inset-right));
  overflow-x: hidden;
}

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 22% 16%, rgba(255, 221, 234, 0.82), transparent 30%),
    radial-gradient(circle at 78% 20%, rgba(235, 226, 255, 0.9), transparent 28%),
    linear-gradient(180deg, #fff 0%, #fff8fb 100%);
}

body.app-locked .lock-screen {
  display: flex;
}

.lock-card {
  display: grid;
  width: min(100%, 390px);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.lock-card h1 {
  font-size: 26px;
  line-height: 1.12;
}

.lock-copy,
.lock-error {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.lock-card input {
  width: 100%;
}

.lock-card button {
  min-height: 46px;
  border: 1px solid #eec7d7;
  border-radius: 8px;
  background: var(--pink-soft);
  color: var(--ink);
  font-weight: 800;
}

.lock-error {
  min-height: 20px;
  color: var(--red);
}

.topbar,
.summary-head,
.section-title,
.ledger-strip,
.quick-row,
.budget-actions,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar,
.summary-head,
.section-title {
  justify-content: space-between;
  gap: 12px;
}

.summary-head > *,
.section-title > * {
  min-width: 0;
}

.topbar {
  padding: 6px 2px 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.icon-button,
.add-ledger,
.section-title button,
.budget-actions button,
.quick-row button,
.primary-button,
.dialog-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 650;
}

.icon-button {
  width: 46px;
  padding: 0;
  font-size: 12px;
}

.ledger-strip {
  gap: 8px;
  margin-bottom: 12px;
}

.ledger-tabs {
  display: flex;
  flex: 1;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.ledger-tabs::-webkit-scrollbar {
  display: none;
}

.ledger-tab {
  min-width: max-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff8fb;
  color: var(--muted);
  font-weight: 700;
}

.ledger-tab.active {
  border-color: #e6c8ff;
  background: var(--purple-soft);
  color: var(--ink);
}

.add-ledger {
  padding: 0 12px;
}

.summary-panel,
.quick-card,
.form-card,
.stats-section,
.trip-section,
.entries-section,
.fixed-section {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.summary-panel {
  padding: 16px;
}

.month-picker {
  display: grid;
  gap: 5px;
  flex: 0 1 132px;
  min-width: 112px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.month-picker input,
input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffafb;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input[type="date"],
input[type="month"] {
  min-width: 0;
  padding-inline: 8px;
}

input:focus,
select:focus {
  border-color: #d7b8ff;
  box-shadow: 0 0 0 3px rgba(215, 184, 255, 0.28);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.metric {
  min-width: 0;
  border-radius: 8px;
  padding: 11px 9px;
}

.metric span,
.budget-copy span,
.trip-grid span,
.entry-meta,
.stat-row span,
.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: clamp(16px, 5vw, 22px);
}

.metric.income {
  background: #fff0b8;
}

.metric.expense {
  background: #ffe0ea;
}

.metric.balance {
  background: #e4e0ff;
}

.budget-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.budget-copy {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.budget-copy strong {
  text-align: right;
}

.budget-actions {
  gap: 8px;
  margin-top: 10px;
}

.budget-actions input {
  min-width: 0;
  width: 100%;
}

.budget-actions button {
  padding: 0 14px;
}

.budget-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #f4eef6;
}

.budget-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease, background-color 180ms ease;
}

.quick-card,
.form-card,
.stats-section,
.trip-section,
.entries-section,
.fixed-section {
  padding: 14px;
}

.quick-card label,
.entry-form label,
.dialog-card label,
.rent-rule label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quick-row {
  gap: 8px;
  margin-top: 8px;
}

.quick-row input {
  min-width: 0;
  flex: 1;
}

.quick-row button {
  width: 50px;
}

.parse-preview {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.entry-form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #fbf6ff;
}

.segment {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.segment.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(143, 117, 154, 0.14);
}

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

.entry-form input,
.entry-form select,
.dialog-card input,
.dialog-card select {
  min-width: 0;
  width: 100%;
}

.trip-fields {
  display: grid;
  gap: 8px;
}

.trip-fields > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.trip-fields.hidden,
.trip-section.hidden,
.reimbursement-segments.hidden {
  display: none;
}

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

.fixed-section {
  display: grid;
  gap: 12px;
}

.rent-rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px minmax(0, 1fr);
  gap: 10px;
}

.rent-actions {
  display: grid;
  gap: 10px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toggle-line span {
  min-width: 0;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.rent-actions button {
  min-height: 42px;
  border: 1px solid #ead58b;
  border-radius: 8px;
  background: var(--yellow-soft);
  color: var(--ink);
  font-weight: 750;
}

.primary-button {
  width: 100%;
  min-height: 46px;
  border-color: #eec7d7;
  background: var(--pink-soft);
  color: var(--ink);
}

.section-title {
  min-height: 32px;
}

.section-title button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.category-stats {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(96px, 128px) 1fr minmax(70px, auto);
  gap: 9px;
  align-items: center;
}

.category-label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

.category-icon,
.entry-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  font-style: normal;
  line-height: 1;
}

.stat-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #f4eef6;
}

.stat-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--gold-soft);
}

.trip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.trip-grid article {
  border-radius: 8px;
  padding: 12px;
  background: var(--yellow-soft);
}

.trip-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 21px;
}

.trip-substats {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.trip-substats h3 {
  margin: 0 0 9px;
  font-size: 14px;
}

.mini-stats {
  display: grid;
  gap: 8px;
}

.mini-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  padding: 9px 10px;
  background: #fffafb;
}

.mini-stat span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-stat strong {
  flex: 0 0 auto;
  font-size: 14px;
}

.empty-state {
  display: none;
  margin-top: 12px;
  border: 1px dashed #dbcdea;
  border-radius: 8px;
  padding: 18px 12px;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

.entry-list {
  display: grid;
  gap: 9px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.entry-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fffafb;
}

.entry-title {
  min-width: 0;
  font-weight: 760;
}

.entry-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-meta {
  margin-top: 4px;
}

.entry-currency {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.entry-amount {
  text-align: right;
  font-weight: 800;
}

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

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

.entry-delete {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
}

.status-button {
  min-height: 28px;
  margin-top: 5px;
  border: 1px solid #ead58b;
  border-radius: 8px;
  background: var(--yellow-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

dialog {
  width: min(calc(100vw - 28px), 420px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(35, 33, 29, 0.34);
}

.dialog-card {
  display: grid;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.dialog-actions {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.dialog-actions button {
  padding: 0 14px;
}

.dialog-actions button[type="submit"] {
  border-color: #eec7d7;
  background: var(--pink-soft);
  color: var(--ink);
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 28px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }

  .summary-panel,
  .quick-card,
  .form-card,
  .stats-section,
  .trip-section,
  .entries-section,
  .fixed-section {
    padding: 12px;
  }

  .summary-head {
    align-items: start;
  }

  .month-picker {
    flex-basis: 122px;
    min-width: 104px;
  }

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

  .rent-rule {
    grid-template-columns: minmax(0, 1fr) 74px;
  }

  .rent-rule label:last-child {
    grid-column: 1 / -1;
  }

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

  .quick-row button {
    width: 44px;
  }

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

  .entry-item > div:last-child {
    grid-column: 2;
    justify-self: start;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
  }

  .entry-delete,
  .status-button {
    margin-top: 0;
  }
}

@media (max-width: 360px) {
  .metric-grid,
  .field-grid,
  .trip-grid,
  .rent-rule {
    grid-template-columns: 1fr;
  }

  .stat-row {
    grid-template-columns: 1fr;
  }

  .reimbursement-segments {
    grid-template-columns: repeat(2, 1fr);
  }
}
