* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --teal: #82cabc;
  --teal-dark: #5fb3a3;
  --bg: #f2f2f6;
  --card: #ffffff;
  --text: #333;
  --muted: #999;
  --blue: #3b4bd8;
  --red: #e0484f;
  --radius: 14px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

.app {
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
}

/* ===== 左タブ ===== */
.rail {
  width: 46px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  padding-top: max(10px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-tab {
  writing-mode: vertical-rl;
  letter-spacing: 4px;
  padding: 18px 0;
  min-height: 100px;
  border: none;
  background: #e3e3ea;
  color: #666;
  font-size: 14px;
  font-weight: 600;
  border-radius: 0 10px 10px 0;
  cursor: pointer;
  border-top: 4px solid transparent;
}

.rail-tab.active {
  background: var(--card);
  color: var(--text);
  border-top: 4px solid #e08a8a;
}

/* ===== メイン ===== */
.content {
  flex: 1;
  min-width: 0;
  padding: max(10px, env(safe-area-inset-top)) 12px 12px 8px;
}

.view.hidden, .overlay.hidden, .modal-wrap.hidden, .hidden { display: none !important; }

/* ===== 月ナビ ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.month-label { font-size: 16px; font-weight: 700; }

.month-arrow {
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  color: var(--teal-dark);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ===== サマリー ===== */
.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

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

.range-label { font-size: 13px; font-weight: 600; }
.summary-item { font-size: 13px; }
.summary-item b { font-size: 15px; margin-left: 2px; }
.blue { color: var(--blue); }
.red { color: var(--red); }

/* ===== 横棒グラフ ===== */
.chart-card {
  background: var(--teal);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  margin-bottom: 12px;
}

.chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hbar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  color: #2f4f48;
  font-weight: 600;
  margin-bottom: 2px;
}

.hbar-label .amt { font-size: 10px; font-weight: 600; opacity: .85; }
.hbar-label .amt.over { color: #b5322f; opacity: 1; font-weight: 700; }

.hbar-track {
  height: 9px;
  background: #fff;
  border-radius: 5px;
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  border-radius: 5px;
  min-width: 0;
  transition: width .3s;
}

/* ===== カテゴリ行 ===== */
.cat-rows { display: flex; flex-direction: column; gap: 8px; }

.cat-row {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px 10px 0;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  cursor: pointer;
  border: none;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}

.cat-stripe {
  width: 5px;
  align-self: stretch;
  border-radius: 3px;
  margin: 2px 10px 2px 6px;
  flex-shrink: 0;
}

.cat-main { flex: 1; min-width: 0; }

.cat-name { font-size: 14px; font-weight: 700; }

.cat-sub { font-size: 12px; color: var(--muted); }

.cat-right {
  text-align: right;
  margin-right: 4px;
  flex-shrink: 0;
}

.cat-pct { font-size: 12px; color: #bbb; }

.cat-remain { font-size: 14px; font-weight: 700; }
.cat-remain .label { font-size: 11px; font-weight: 400; color: var(--muted); margin-right: 2px; }
.cat-remain.minus { color: var(--red); }

.chev { color: #ccc; font-size: 18px; margin-left: 6px; }

/* ===== カテゴリ管理: 並び替え ===== */
.cat-row.manage { padding: 0; }

.cat-main-btn {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 10px 0;
}

.reorder {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px 8px 6px;
  flex-shrink: 0;
}

.reorder-btn {
  width: 40px;
  height: 30px;
  border: 1px solid #e0e0e6;
  background: #fafafa;
  border-radius: 8px;
  color: var(--teal-dark);
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}

.reorder-btn:disabled {
  color: #d8d8d8;
  background: #f5f5f7;
  cursor: default;
}

.reorder-btn:active:not(:disabled) { background: #eafaf6; }

/* ===== 下部バー ===== */
.bottom-bar {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 0; right: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  padding: 0 16px 0 62px;
  pointer-events: none;
}

.bottom-bar .pill-btn { pointer-events: auto; }

.bottom-spacer { height: 90px; }

/* ===== ボタン ===== */
.pill-btn {
  border: none;
  border-radius: 28px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}

.pill-btn.white { background: var(--card); color: var(--text); }
.pill-btn.teal { background: var(--teal); color: #fff; }
.pill-btn.danger { background: #fff0f0; color: var(--red); box-shadow: none; border: 1px solid #f3c9c9; }
.pill-btn.wide { width: 100%; margin-top: 10px; }

/* ===== カテゴリ・予算 / 設定ページ ===== */
.page-title { font-size: 20px; margin: 6px 0 8px; }
.page-note { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.total-budget-card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.total-budget-card b { color: var(--blue); font-size: 18px; margin-left: 4px; }

.cat-manage-list { display: flex; flex-direction: column; gap: 8px; }

.settings-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.settings-card h2 { font-size: 16px; margin-bottom: 6px; }

.app-version { text-align: center; color: #bbb; font-size: 12px; margin-top: 20px; }

/* ===== オーバーレイ ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
  overflow-y: auto;
  padding: max(10px, env(safe-area-inset-top)) 14px 30px;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.back-btn {
  border: none;
  background: none;
  color: var(--teal-dark);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 8px 6px 0;
}

.overlay-title { font-size: 18px; font-weight: 700; }
.overlay-header-spacer { width: 60px; }

/* ===== カレンダー ===== */
.cal-grid-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.cal-grid-head span:first-child { color: #d66; }
.cal-grid-head .sat { color: #48a; }

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

.cal-cell {
  background: var(--card);
  border-radius: 8px;
  min-height: 54px;
  padding: 4px;
  font-size: 13px;
  border: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}

.cal-cell.empty { background: transparent; cursor: default; }
.cal-cell.static { cursor: default; }
.cal-cell.today { border-color: var(--teal); }
.cal-cell.selected { border-color: var(--teal-dark); background: #eafaf6; }

.cal-day-num { font-weight: 600; }
.cal-day-amt { font-size: 10px; letter-spacing: -0.5px; color: var(--red); display: block; margin-top: 2px; white-space: nowrap; }

.cal-cell.holiday .cal-day-num { color: #d9534f; }
.cal-holiday {
  display: inline-block;
  font-size: 9px;
  line-height: 1.2;
  color: #d9534f;
  border: 1px solid #eab6b6;
  border-radius: 4px;
  padding: 0 3px;
  margin-top: 1px;
}

.day-detail h3 { font-size: 15px; margin-bottom: 8px; }

/* ===== 記録リスト ===== */
.entry-list { display: flex; flex-direction: column; gap: 6px; }

.entry-item {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.entry-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.entry-info { flex: 1; min-width: 0; }
.entry-date { font-size: 12px; color: var(--muted); }
.entry-memo { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-amt { font-weight: 700; flex-shrink: 0; }

.entry-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 16px 0; }

/* カテゴリ詳細: tealサマリーカード */
.detail-card {
  background: var(--teal);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.detail-range { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.detail-remain { font-size: 14px; }
.detail-remain b { font-size: 20px; font-weight: 700; }

.detail-card-r { text-align: right; }
.detail-head {
  font-size: 12px;
  opacity: .92;
  display: flex;
  gap: 14px;
  justify-content: flex-end;
  margin-bottom: 4px;
}
.detail-amt { font-size: 14px; }
.detail-amt b { font-size: 18px; font-weight: 700; }

.detail-subrow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 4px;
}
.detail-perday { font-size: 13px; color: var(--muted); }

.budget-edit-btn {
  border: none;
  background: #b9b9ee;
  color: #2e2e5a;
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.detail-fab {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 25;
}

/* ===== モーダル ===== */
.modal-wrap {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--card);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh;
  overflow-y: auto;
}

.modal h2 { font-size: 18px; margin-bottom: 14px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.field input[type="date"],
.field input[type="text"] {
  width: 100%;
  border: 1.5px solid #ddd;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: #fafafa;
  font-family: inherit;
}

/* iOS Safari: date入力が幅100%にならず崩れるのを防ぐ */
.field input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  display: block;
  text-align: left;
}
.field input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}
.field input[type="date"]::-webkit-datetime-edit { padding: 0; }

.field input:focus { outline: none; border-color: var(--teal); background: #fff; }

.yen-input { display: flex; align-items: center; gap: 6px; }
.yen-input input { flex: 1; text-align: right; font-size: 20px; font-weight: 700; }

.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.cat-chip {
  border: 2px solid #eee;
  background: #fafafa;
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  color: inherit;
}

.cat-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.cat-chip.selected { border-color: var(--teal-dark); background: #eafaf6; font-weight: 700; }

.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; }

.swatch {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.selected { border-color: #333; box-shadow: 0 0 0 2px #fff inset; }

.modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.modal-btns .danger { margin-right: auto; }
