/* ===========================================================
   かんたん家計簿 — スタイルシート
   キーカラー：暖色系（コーラル / オレンジ）
   =========================================================== */

:root {
  /* 暖色系パレット */
  --c-primary: #ff7043;        /* コーラルオレンジ */
  --c-primary-dark: #f4511e;
  --c-primary-light: #ffab91;
  --c-accent: #ffb300;         /* アンバー */
  --c-income: #1e88e5;         /* 収入：明るめの青 */
  --c-expense: #e53935;        /* 支出：レッド */
  --c-balance: #fb8c00;

  --c-bg: #fff8f3;
  --c-surface: #ffffff;
  --c-text: #4e342e;           /* ブラウン系の文字 */
  --c-text-muted: #a1887f;
  --c-border: #f0e2d8;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 20px rgba(229, 115, 60, .12);
  --shadow-lg: 0 12px 32px rgba(229, 115, 60, .22);

  /* グラフ用：暖色グラデーション（支出） */
  --chart-1: #ff7043;
  --chart-2: #ffa726;
  --chart-3: #ffca28;
  --chart-4: #ff8a65;
  --chart-5: #f4511e;
  --chart-6: #ffb74d;
  --chart-7: #e57373;
  --chart-8: #d4a373;

  /* グラフ用：ブルー系（収入） */
  --chart-i1: #1e88e5;
  --chart-i2: #42a5f5;
  --chart-i3: #26c6da;
  --chart-i4: #5c6bc0;
  --chart-i5: #29b6f6;
  --chart-i6: #7986cb;
  --chart-i7: #4dd0e1;
  --chart-i8: #64b5f6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 96px;
}

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  box-shadow: var(--shadow);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-title { color: #fff; font-size: 1.25rem; font-weight: 700; letter-spacing: .02em; }
.header-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background .2s;
}
.icon-btn:hover { background: rgba(255,255,255,.35); }

/* 同期ステータス */
.sync {
  font-size: .72rem;
  color: #fff;
  background: rgba(255,255,255,.18);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .3s;
}
.sync::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
}
.sync.is-synced::before { background: #b9f6ca; }
.sync.is-saving::before { background: #fff59d; animation: pulse 1s infinite; }
.sync.is-local::before  { background: #ffab91; }
.sync.is-error::before  { background: #ff8a80; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ===== レイアウト ===== */
.container { max-width: 640px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card__head h3 { font-size: 1.05rem; }

.muted { color: var(--c-text-muted); font-size: .85rem; }
.text-btn {
  background: none; border: none; color: var(--c-primary-dark);
  font-weight: 600; font-size: .9rem; cursor: pointer;
}
.text-btn:hover { text-decoration: underline; }

/* ===== 月ナビ ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
}
.month-nav__label { font-size: 1.25rem; font-weight: 700; }
.month-nav__btn {
  background: var(--c-bg);
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  color: var(--c-primary-dark);
  cursor: pointer;
  line-height: 1;
  transition: background .2s;
}
.month-nav__btn:hover { background: var(--c-primary-light); color: #fff; }

/* ===== サマリー ===== */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--c-border);
}
.stat--balance { grid-column: 1 / -1; border-left-color: var(--c-balance); }
.stat--income { border-left-color: var(--c-income); }
.stat--expense { border-left-color: var(--c-expense); }
.stat__label { display: block; font-size: .8rem; color: var(--c-text-muted); }
.stat__value { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.stat--income .stat__value { color: var(--c-income); }
.stat--expense .stat__value { color: var(--c-expense); }
.stat--balance .stat__value { color: var(--c-balance); font-size: 1.8rem; }

/* ===== 予算 ===== */
.budget__track {
  height: 14px;
  background: var(--c-bg);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.budget__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c-accent), var(--c-primary));
  transition: width .4s ease, background .3s;
}
.budget__fill.is-over { background: linear-gradient(90deg, #e53935, #b71c1c); }
.budget__text { font-size: .9rem; color: var(--c-text-muted); }
.budget__text strong { color: var(--c-text); }

/* ===== 円グラフ ===== */
.toggle { display: inline-flex; background: var(--c-bg); border-radius: 999px; padding: 3px; }
.toggle__btn {
  border: none; background: none;
  padding: 5px 16px;
  border-radius: 999px;
  font-size: .85rem; font-weight: 600;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: all .2s;
}
.toggle__btn.is-active { background: var(--c-primary); color: #fff; box-shadow: var(--shadow); }
.toggle__btn.is-active[data-type="income"] { background: var(--c-income); }

.chart { position: relative; width: 200px; height: 200px; margin: 8px auto 4px; }
.chart__svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.chart__svg circle { transition: stroke-dasharray .5s ease; }
.chart__center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  pointer-events: none;
}
.chart__total-label { font-size: .8rem; color: var(--c-text-muted); }
.chart__total { font-size: 1.3rem; font-weight: 700; }

.legend { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.legend__item { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.legend__dot { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.legend__name { flex: 1; }
.legend__pct { color: var(--c-text-muted); font-size: .82rem; min-width: 42px; text-align: right; }
.legend__val { font-weight: 600; min-width: 80px; text-align: right; }

/* ===== 取引リスト ===== */
.tx-list { list-style: none; }
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--c-border);
}
.tx-item:last-child { border-bottom: none; }
.tx-item__icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.2rem;
  background: var(--c-bg);
  flex-shrink: 0;
}
.tx-item__body { flex: 1; min-width: 0; }
.tx-item__cat { font-weight: 600; }
.tx-item__meta { font-size: .78rem; color: var(--c-text-muted); }
.tx-item__amount { font-weight: 700; white-space: nowrap; }
.tx-item__amount.is-income { color: var(--c-income); }
.tx-item__amount.is-expense { color: var(--c-expense); }
.tx-item__del {
  background: none; border: none; cursor: pointer;
  color: var(--c-text-muted); font-size: 1.1rem; padding: 4px;
  opacity: .5; transition: opacity .2s;
}
.tx-item__del:hover { opacity: 1; color: var(--c-expense); }

.empty { text-align: center; color: var(--c-text-muted); padding: 24px 0; font-size: .9rem; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
  color: #fff;
  font-size: 2rem; line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  transition: transform .15s;
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(.96); }

/* ===== モーダル ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(78,52,46,.45); animation: fade .2s; }
.modal__sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: var(--c-surface);
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: slideup .28s cubic-bezier(.2,.9,.3,1);
  max-height: 92vh;
  overflow-y: auto;
}
.modal__grip { width: 44px; height: 5px; border-radius: 999px; background: var(--c-border); margin: 4px auto 14px; }
.modal__title { font-size: 1.2rem; margin-bottom: 4px; }
.modal__sub { margin-bottom: 14px; }
.modal__actions { display: flex; gap: 12px; margin-top: 20px; }

@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* タイプ切替 / 収支スイッチ */
.type-switch { display: flex; gap: 0; background: var(--c-bg); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.type-switch__btn {
  flex: 1; border: none; background: none;
  padding: 10px; border-radius: 9px;
  font-weight: 700; font-size: .95rem;
  color: var(--c-text-muted); cursor: pointer;
  transition: all .2s;
}
.type-switch__btn.is-active[data-kind="expense"] { background: var(--c-expense); color: #fff; }
.type-switch__btn.is-active[data-kind="income"] { background: var(--c-income); color: #fff; }

/* ===== スマホでリセットボタン非表示 ===== */
@media (max-width: 479px) {
  #resetBtn { display: none; }
}

/* フォーム */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-size: .85rem; font-weight: 600; color: var(--c-text-muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color .2s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--c-primary); }

.amount-input { display: flex; align-items: center; border: 2px solid var(--c-border); border-radius: var(--radius-sm); padding-left: 14px; transition: border-color .2s; }
.amount-input:focus-within { border-color: var(--c-primary); }
.amount-input__yen { font-size: 1.3rem; font-weight: 700; color: var(--c-text-muted); }
.amount-input input { border: none; font-size: 1.5rem; font-weight: 700; padding: 12px 14px; }
.amount-input input:focus { border: none; }

/* ボタン */
.btn {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1rem; font-weight: 700;
  cursor: pointer;
  transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark)); color: #fff; }
.btn--ghost { background: var(--c-bg); color: var(--c-text-muted); }

/* ===== ロック画面 ===== */
.lock {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
}
.lock[hidden] { display: none; }
.lock__card {
  width: 100%; max-width: 360px;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 24px;
  text-align: center;
  animation: slideup .3s cubic-bezier(.2,.9,.3,1);
}
.lock__icon { font-size: 2.6rem; }
.lock__title { font-size: 1.3rem; margin: 8px 0 4px; }
.lock__input {
  width: 100%;
  margin-top: 18px;
  padding: 13px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 1.1rem; text-align: center;
  font-family: inherit; color: var(--c-text);
  transition: border-color .2s;
}
.lock__input:focus { outline: none; border-color: var(--c-primary); }
.lock__error { color: var(--c-expense); font-size: .85rem; margin-top: 10px; font-weight: 600; }
.lock__btn { width: 100%; margin-top: 16px; }

/* ===== レスポンシブ ===== */
@media (min-width: 480px) {
  .summary-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stat--balance { grid-column: auto; }
}
