/* 配色方針: 白／オフホワイト基調、文字はダークグレー、
   アクセントは落ち着いたディープグリーン（+補助のくすんだインディゴ）。
   原色の青ベタ塗りは使わない。カテゴリ色も彩度を抑えて統一する。 */
:root {
  --bg: #f7f5f0;
  --surface: #fffdf9;
  --border: #e6e1d6;
  --text: #2f3336;
  --muted: #7d8288;
  --accent: #2f6f5e;
  --accent-soft: #e3ede8;
  --accent-warm: #c98a4e;
  --sun: #c08552;   /* 日曜: くすんだテラコッタ寄り */
  --sat: #7d84b8;   /* 土曜: くすんだインディゴ */
  --danger: #b0563f;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; background: var(--bg); color: var(--text); }
.app-header { padding: 14px 16px 6px; max-width: 960px; margin: 0 auto; }
.app-header h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: .04em; }
main { max-width: 960px; margin: 0 auto; padding: 10px 16px 110px; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.card.warn { border-color: #d9a441; background: #fdf6e3; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.subhead { font-size: 14px; margin: 16px 0 6px; color: var(--text); }
button { font: inherit; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.error { color: var(--danger); white-space: pre-wrap; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 118px; gap: 8px; align-items: center; margin: 6px 0; font-size: 14px; }
.bar { height: 10px; background: #eee9dd; border-radius: 6px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.bar-row .amount, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 8px; border-bottom: 1px solid #efece3; text-align: left; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #f5ecd7; border: 1px solid #d9a441; color: #7a5b14; font-size: 11px; }
.badge-income { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.badge-fixed { background: #e8eaf3; border-color: #9aa1c4; color: #4c5480; }
.amount-income { color: var(--accent); font-weight: 600; }
.empty { color: var(--muted); }

/* ---------- 月ナビ（ホーム上部バー） ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 0; }
.month-nav h2 { font-size: 20px; margin: 0; font-weight: 700; }
.month-nav button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--accent); font-size: 15px; line-height: 1; }

/* ---------- 月次サマリー行（収入／支出／合計） ---------- */
.summary-row { display: flex; justify-content: space-between; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 16px; }
.summary-item { flex: 1; }
.summary-item:last-child { text-align: right; }
.summary-item:nth-child(2) { text-align: center; }
.summary-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.summary-item strong { font-size: 19px; font-variant-numeric: tabular-nums; }
#sum-income { color: var(--accent); }

/* ---------- カードフィルター（チップ型） ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filter-label { font-size: 12px; color: var(--muted); }
.chip { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 下部タブバー（固定・ピル型） ---------- */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 20; display: flex; gap: 4px; background: rgba(255, 253, 249, .96); border: 1px solid var(--border); border-radius: 999px; padding: 5px; box-shadow: 0 6px 24px rgba(47, 51, 54, .14); max-width: calc(100vw - 20px); }
.tab-btn { flex: 1; padding: 9px 16px; font-weight: 600; font-size: 14px; border: none; background: transparent; color: var(--muted); white-space: nowrap; }
.tab-btn.is-active { background: var(--accent); color: #fff; }

/* ---------- ホーム画面レイアウト（上: カレンダー＋サマリー / 下: 選択日の明細） ---------- */
.home-layout { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - 190px); min-height: 480px; }
.home-layout .card { margin: 0; }
.home-layout .calendar-card { flex: 2 1 0; display: flex; flex-direction: column; overflow: hidden; }
.home-layout .day-card { flex: 1 1 0; display: flex; flex-direction: column; overflow: hidden; }
.home-layout .day-card .table-wrap { overflow-y: auto; flex: 1; min-height: 0; }
.day-total { font-weight: 600; margin-bottom: 8px; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.settings-row { margin: 0 0 14px; line-height: 1.7; }

/* ---------- カレンダー ---------- */
.calendar-week, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.calendar-week span { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.calendar-week .dow-sun { color: var(--sun); }
.calendar-week .dow-sat { color: var(--sat); }
.calendar-grid { flex: 1; grid-template-rows: repeat(6, 1fr); min-height: 0; }
.cal-cell { border: 1px solid #efece3; border-radius: 10px; background: var(--surface); padding: 3px 4px; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-height: 0; overflow: hidden; text-align: left; }
.cal-cell.cal-blank { border-color: transparent; background: transparent; }
.cal-cell.dow-sun .cal-day { color: var(--sun); }
.cal-cell.dow-sat .cal-day { color: var(--sat); }
.cal-cell.is-selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day { font-size: 12px; font-weight: 600; line-height: 1; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.cal-cell.is-today .cal-day { background: var(--accent); color: #fff; }
.cal-amount { font-size: 10px; color: #4a4f54; line-height: 1.1; font-variant-numeric: tabular-nums; }
.cal-dots { display: flex; gap: 2px; align-items: center; margin-top: auto; }
.cal-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cal-more { font-size: 9px; color: var(--muted); }

/* ---------- カテゴリ色・凡例 ---------- */
.cat-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: baseline; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; }
.legend-col { flex-direction: column; gap: 6px; margin-top: 0; }
.legend-item { display: inline-flex; align-items: center; }
.legend-item .cat-dot { margin-right: 6px; }
.legend-amount { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- グラフ ---------- */
.donut-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.donut { width: 180px; height: 180px; }
.donut-label { font-size: 13px; fill: var(--muted); }
.donut-value { font-size: 17px; font-weight: 700; fill: var(--text); }
.chart { width: 100%; height: auto; }
.chart-value { font-size: 13px; fill: #4a4f54; }
.chart-label { font-size: 12px; fill: var(--muted); }

@media (max-width: 480px) {
  main { padding: 8px 10px 104px; gap: 10px; }
  .card { padding: 12px; }
  .home-layout { height: calc(100dvh - 178px); min-height: 440px; gap: 8px; }
  .tab-btn { padding: 9px 12px; font-size: 13px; }
  .summary-item strong { font-size: 17px; }
  th, td { padding: 5px 6px; }
}
