:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-soft: #efede5;
  --text: #202124;
  --muted: #6d7278;
  --line: #dfdacf;
  --income: #176b57;
  --expense: #ad4139;
  --accent: #2f5d8c;
  --shadow: 0 18px 44px rgba(32, 33, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.35rem);
  font-weight: 760;
}

h2 {
  font-size: 1.02rem;
}

.month-filter {
  display: grid;
  gap: 7px;
  min-width: 180px;
  color: var(--muted);
  font-size: 0.9rem;
}

.month-filter input,
form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 93, 140, 0.14);
}

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

.metric,
.panel {
  background: var(--surface);
  border: 1px solid rgba(223, 218, 207, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.metric span {
  color: var(--muted);
  font-size: 0.92rem;
}

.metric strong {
  font-size: clamp(1.65rem, 3vw, 2.45rem);
}

.balance {
  background: #edf3f4;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(260px, 0.8fr) minmax(360px, 1.2fr);
  gap: 14px;
  align-items: start;
}

.panel {
  padding: 18px;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.form-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented label {
  display: block;
}

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

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}

.segmented input:checked + span {
  background: #fff;
  color: var(--text);
  box-shadow: 0 7px 18px rgba(32, 33, 36, 0.08);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: #111;
}

.form-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.86rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title span {
  color: var(--muted);
  font-size: 0.86rem;
}

.category-list,
.transaction-list {
  display: grid;
  gap: 10px;
}

.category-item,
.transaction-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.category-row,
.transaction-main,
.transaction-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.category-name,
.transaction-name {
  font-weight: 700;
}

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

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

.bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.bar-income {
  background: var(--income);
}

.bar-expense {
  background: var(--expense);
}

.transaction-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

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

.delete-button {
  width: 30px;
  min-height: 30px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.delete-button:hover {
  background: #f7eeee;
  color: var(--expense);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

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

  .form-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 22px, 560px);
    padding: 18px 0;
  }

  .topbar,
  .category-row,
  .transaction-main {
    align-items: stretch;
    flex-direction: column;
  }

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

  .month-filter {
    width: 100%;
  }
}
