:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --ink: #26231d;
  --muted: #776f63;
  --line: #ded6c9;
  --panel: #fffdf8;
  --panel-soft: #f0ebe1;
  --accent: #2f5d62;
  --shadow: 0 18px 44px rgba(66, 52, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.86), rgba(247, 244, 238, 0.92)),
    radial-gradient(circle at top left, rgba(47, 93, 98, 0.12), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    sans-serif;
  letter-spacing: 0;
}

button,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0 20px;
}

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

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

h1 {
  font-size: clamp(1.65rem, 2.6vw, 2.4rem);
  line-height: 1.12;
}

h2 {
  font-size: 1rem;
}

.month-controls {
  display: grid;
  grid-template-columns: 42px minmax(132px, 180px) 42px;
  gap: 8px;
  align-items: center;
}

.icon-button,
select {
  height: 42px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 18px rgba(76, 62, 39, 0.08);
}

.icon-button {
  border-radius: 50%;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
}

select {
  width: 100%;
  border-radius: 8px;
  padding: 0 12px;
}

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

.summary-strip > div,
.panel {
  border: 1px solid rgba(222, 214, 201, 0.92);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.summary-strip > div {
  min-height: 96px;
  padding: 18px 20px;
  border-radius: 8px;
}

.summary-strip span,
.footer,
.section-title span,
.calendar-head span {
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-strip strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.35rem, 2.2vw, 2rem);
  line-height: 1.1;
}

.dashboard-grid,
.detail-grid {
  display: grid;
  gap: 16px;
}

.dashboard-grid {
  grid-template-columns: minmax(320px, 0.86fr) minmax(420px, 1.14fr);
}

.detail-grid {
  grid-template-columns: minmax(480px, 1.1fr) minmax(320px, 0.9fr);
  margin-top: 16px;
}

.panel {
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
}

.chart-panel {
  display: grid;
  grid-template-columns: minmax(190px, 230px) 1fr;
  gap: 20px;
  align-items: center;
}

.pie-chart {
  width: min(230px, 54vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--panel-soft);
  border: 10px solid #fffaf0;
  box-shadow: inset 0 0 0 1px rgba(38, 35, 29, 0.06), 0 12px 32px rgba(38, 35, 29, 0.12);
}

.legend {
  display: grid;
  gap: 7px;
}

.legend-row {
  display: grid;
  grid-template-columns: 14px minmax(56px, 0.78fr) minmax(118px, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.legend-row:hover {
  border-color: rgba(222, 214, 201, 0.9);
  background: rgba(255, 250, 240, 0.72);
}

.legend-row.is-zero {
  opacity: 0.62;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 4px 10px rgba(38, 35, 29, 0.12);
}

.legend-name {
  color: var(--ink);
  font-weight: 650;
  white-space: nowrap;
}

.legend-metric {
  display: grid;
  grid-template-columns: minmax(68px, 1fr) minmax(54px, auto);
  gap: 8px;
  align-items: center;
  justify-self: end;
  width: 100%;
}

.legend-amount {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.legend-percent {
  min-width: 54px;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(38, 35, 29, 0.07);
  color: #4f4940;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.legend-row.is-zero .legend-amount,
.legend-row.is-zero .legend-percent {
  color: var(--muted);
  font-weight: 650;
}

.calendar-head,
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  min-height: 30px;
  margin-bottom: 12px;
}

.weekday-grid,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekday-grid span {
  height: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.day-button {
  position: relative;
  display: grid;
  align-content: start;
  gap: 4px;
  width: 100%;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.day-button.is-empty {
  visibility: hidden;
}

.day-button.is-selected {
  border-color: var(--accent);
  outline: 2px solid rgba(47, 93, 98, 0.18);
}

.day-number {
  font-weight: 800;
  font-size: 0.86rem;
}

.day-total {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

td {
  font-size: 0.92rem;
}

.amount-cell {
  text-align: right;
  white-space: nowrap;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 0.82rem;
  white-space: nowrap;
}

.day-list {
  display: grid;
  gap: 10px;
}

.day-entry {
  border-left: 4px solid var(--accent);
  background: #fffaf0;
  border-radius: 0 8px 8px 0;
  padding: 12px;
}

.day-entry strong {
  display: block;
  margin-bottom: 4px;
}

.day-entry span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.day-entry small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.empty-state {
  min-height: 96px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.5);
}

.footer {
  padding: 16px 2px 0;
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-strip,
  .dashboard-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    grid-template-columns: 1fr;
    justify-items: center;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 14px;
  }

  .summary-strip {
    gap: 8px;
  }

  .summary-strip > div {
    min-height: 82px;
    padding: 14px;
  }

  .panel {
    padding: 12px;
  }

  .day-button {
    min-height: 60px;
    padding: 6px;
  }

  .day-total {
    font-size: 0.68rem;
  }

  .legend-row {
    grid-template-columns: 14px minmax(48px, 0.7fr) minmax(112px, 1fr);
    gap: 7px;
    padding-inline: 5px;
  }

  .legend-metric {
    grid-template-columns: minmax(62px, 1fr) minmax(48px, auto);
    gap: 6px;
  }

  .legend-percent {
    min-width: 48px;
    padding-inline: 6px;
  }
}
