:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-muted: #f1efe8;
  --ink: #202124;
  --muted: #696b70;
  --line: #d9d5ca;
  --teal: #087f73;
  --teal-soft: #dcefeb;
  --rose: #b4455a;
  --rose-soft: #f5e1e5;
  --amber: #a66a00;
  --amber-soft: #f5ead4;
  --indigo: #4656a5;
  --green: #2f7d4f;
  --shadow: 0 14px 40px rgba(32, 33, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

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

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.text-button,
.primary-button,
.segment {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 42px;
  font-size: 20px;
}

.text-button {
  padding: 0 12px;
  color: var(--teal);
  font-weight: 700;
}

.primary-button {
  width: 100%;
  border-color: var(--teal);
  background: var(--teal);
  color: white;
  font-weight: 800;
}

.secondary-button {
  min-height: 42px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 800;
}

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

.import-form {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.workspace {
  display: grid;
  gap: 18px;
}

.workspace > * {
  min-width: 0;
}

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

.metric,
.panel {
  min-width: 0;
  border: 1px solid rgba(217, 213, 202, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 112px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-label,
.soft-label {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.metric.income {
  border-top: 4px solid var(--green);
}

.metric.expense {
  border-top: 4px solid var(--rose);
}

.metric.net {
  border-top: 4px solid var(--indigo);
}

.metric.reimburse {
  border-top: 4px solid var(--amber);
}

.primary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.primary-grid > *,
.tools-grid > *,
.detail-grid > *,
.side-stack > * {
  min-width: 0;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-head {
  min-height: 32px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.entry-form,
.command-form,
.tool-form,
.import-form {
  display: grid;
  gap: 14px;
}

.tool-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.tool-form label {
  align-self: stretch;
}

.tool-form .secondary-button {
  align-self: end;
}

.span-2 {
  grid-column: span 2;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segment {
  min-width: 0;
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: 0 6px 18px rgba(8, 127, 115, 0.12);
}

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  min-height: 108px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 115, 0.12);
}

.wide-label {
  display: grid;
}

.checkbox-row {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-action {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
}

.reply-box {
  min-height: 118px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202124;
  color: #f6f4ef;
  white-space: pre-wrap;
  line-height: 1.55;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-muted);
}

tbody tr:last-child td {
  border-bottom: none;
}

.number-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.expense {
  background: var(--rose-soft);
  color: var(--rose);
}

.badge.income {
  background: #ddf0e3;
  color: var(--green);
}

.badge.transfer {
  background: #e5e7f8;
  color: var(--indigo);
}

.progress-list,
.category-bars,
.compact-list {
  display: grid;
  gap: 12px;
}

.progress-item,
.compact-item,
.category-item {
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.progress-item:last-child,
.compact-item:last-child,
.category-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.row-between {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.row-between strong,
.row-between span {
  overflow-wrap: anywhere;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--teal);
}

.bar-fill.warn {
  background: var(--amber);
}

.bar-fill.danger {
  background: var(--rose);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 5;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 33, 36, 0.42);
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card h2 {
  font-size: 20px;
}

.auth-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-grid,
  .tools-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .summary-grid,
  .form-grid,
  .tool-form,
  .side-stack {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

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

  .panel,
  .metric {
    padding: 14px;
  }
}
