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

:root {
  --accent: #e8927a;
  --accent-dark: #d4735a;
  --bg: #f6f2f0;
  --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: #eae2de;
  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 var(--accent);
}

/* ===== メイン ===== */
.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; }

/* ===== サマリー ===== */
.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); }

.summary-now {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #eee;
  font-size: 13px;
  color: var(--accent-dark);
  font-weight: 600;
}

/* ===== おでかけ一覧 ===== */
.event-list { display: flex; flex-direction: column; gap: 10px; }

.event-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.ev-card-top { display: flex; align-items: center; gap: 8px; }
.ev-name { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ev-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.ev-badge.now { background: #ffe8df; color: var(--accent-dark); }
.ev-badge.future { background: #e8ecf7; color: #4a5fa8; }

.ev-range { font-size: 12px; color: var(--muted); }

.ev-bar {
  height: 8px;
  background: #f0eae7;
  border-radius: 4px;
  overflow: hidden;
}
.ev-bar-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .3s;
}
.ev-bar-fill.over { background: var(--red); }

.ev-amts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
}
.ev-amts b { font-size: 14px; }
.ev-remain { font-size: 13px; font-weight: 700; color: var(--text); }
.ev-remain.minus { color: var(--red); }

/* ===== 横棒グラフ ===== */
.chart-card {
  background: var(--accent);
  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: #5c332a;
  font-weight: 600;
  margin-bottom: 2px;
}

.hbar-label .amt { font-size: 10px; font-weight: 600; opacity: .85; }
.hbar-label .amt.over { color: #8f1f1c; 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(--accent-dark);
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}

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

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

/* ===== 下部バー ===== */
/* 背後にbg色の帯を敷き、スクロールしたカードが透けて重ならないようにする */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom)) 62px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(246,242,240,0) 0%, var(--bg) 22%, var(--bg) 100%);
}

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

/* オーバーレイ内の下部バーは左タブが無いので左paddingを揃える */
.bottom-bar.overlay-bar { padding-left: 16px; z-index: 25; }

.bottom-spacer { height: calc(110px + env(safe-area-inset-bottom)); }

/* ===== ボタン ===== */
.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(--accent); 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(--accent-dark);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 8px 6px 0;
}

.overlay-title {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.overlay-header-spacer { width: 60px; flex-shrink: 0; }

.header-edit-btn {
  border: none;
  background: var(--card);
  color: var(--accent-dark);
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  flex-shrink: 0;
}

/* ===== 記録リスト ===== */
.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; }

/* ===== 日ごとの記録 ===== */
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 14px 4px 6px;
  font-size: 14px;
  font-weight: 700;
}
.day-head:first-child { margin-top: 0; }
.day-total { color: var(--red); }

.day-tag {
  font-size: 11px;
  font-weight: 700;
  color: #4a5fa8;
  background: #e8ecf7;
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* カテゴリ詳細: サマリーカード */
.detail-card {
  background: var(--accent);
  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); }

.detail-subrow-r { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.override-tag {
  font-size: 11px;
  font-weight: 700;
  color: #b26a00;
  background: #fff3e0;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
}

.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;
}

/* 記録ボタンだけの下部バー(右寄せ) */
.bottom-bar.detail-bar { justify-content: flex-end; }

/* ===== メモカード ===== */
.memo-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border-radius: 12px;
  padding: 11px 14px;
  margin: 12px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.memo-card .memo-head { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.memo-card .memo-body { display: block; font-size: 13px; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.memo-card .memo-empty { display: block; font-size: 13px; color: #bbb; }

.field textarea {
  width: 100%;
  border: 1.5px solid #ddd;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: #fafafa;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--accent); background: #fff; }

/* ===== モーダル ===== */
.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(--accent); 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(--accent-dark); background: #fdeee8; 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; }
