/* =========================================================
   app.css — レイアウトとUI部品
   モバイルファースト（iPhone基準）／PCでも中央寄せで動作
   ========================================================= */

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;            /* 16px未満だとiOSが入力時に自動ズームするため厳守 */
  line-height: 1.55;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ===== メイン表示領域 ===== */
#view {
  max-width: 640px;            /* PCで開いたときはスマホ幅で中央寄せ */
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 88px);
  min-height: 100dvh;
}

/* ===== 画面ヘッダー ===== */
.screen-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px 14px;
}
.screen-title { font-size: 22px; font-weight: 700; letter-spacing: .01em; }
.head-back {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--accent); font-weight: 600; font-size: 16px; padding: 6px 8px 6px 0;
}
.head-back svg { width: 20px; height: 20px; }

/* ===== 月ナビゲーション ===== */
.month-nav {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 12px;
}
.month-nav .m-label { font-weight: 700; font-size: 17px; min-width: 128px; text-align: center; }
.month-nav button {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--sub);
}
.month-nav button:active { background: var(--surface-2); }
.month-nav svg { width: 20px; height: 20px; }

/* ===== クイック入力（1行解析） ===== */
.quick-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.quick-input {
  flex: 1; padding: 13px 16px;
  background: var(--surface); border: none; border-radius: 99px;
  box-shadow: var(--shadow); outline: none; font-size: 16px;
}
.quick-input:focus { box-shadow: var(--shadow), 0 0 0 2px var(--accent); }
.quick-input::placeholder { color: var(--sub); opacity: .7; }
.quick-go {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.quick-go svg { width: 22px; height: 22px; }
.quick-go:active { opacity: .85; }

.quick-error { color: var(--expense); font-size: 13.5px; font-weight: 600; padding: 0 8px 10px; }

/* 解析結果プレビュー */
.quick-preview { border: 2px solid var(--accent); }
.qp-row { display: flex; align-items: center; gap: 12px; }
.qp-main { flex: 1; min-width: 0; }
.qp-cat { font-weight: 700; font-size: 15px; }
.qp-warn { font-size: 12px; color: var(--expense); font-weight: 600; }
.qp-sub { font-size: 12.5px; color: var(--sub); }
.qp-amount {
  font-family: var(--font-number); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 20px; flex: none;
}
.qp-amount.income { color: var(--accent); }
.qp-actions { display: flex; gap: 8px; margin-top: 14px; }
.qp-actions .btn { padding: 12px; }
.qp-actions .btn-ghost { flex: 0 0 32%; }

/* ===== カード ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--sub);
  letter-spacing: .04em; margin-bottom: 10px;
}

/* ===== ホーム：収支サマリーカード ===== */
.balance-label { font-size: 13px; color: var(--sub); font-weight: 600; }
.balance-value {
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
  font-size: 40px; font-weight: 700; letter-spacing: -.01em;
  margin: 2px 0 14px;
}
.balance-value.minus { color: var(--expense); }

.io-row { display: flex; gap: 10px; }
.io-box {
  flex: 1; border-radius: var(--radius-s);
  padding: 10px 12px; background: var(--surface-2);
}
.io-box .io-name { font-size: 12px; color: var(--sub); font-weight: 600; }
.io-box .io-amount {
  font-family: var(--font-number); font-variant-numeric: tabular-nums;
  font-size: 19px; font-weight: 700; margin-top: 2px;
}
.io-amount.income  { color: var(--accent); }
.io-amount.expense { color: var(--expense); }

/* 収入と支出の比率バー（サマリーカードの署名的要素） */
.io-meter {
  display: flex; height: 8px; border-radius: 99px; overflow: hidden;
  margin-top: 14px; background: var(--surface-2);
}
.io-meter .seg-in  { background: var(--accent); }
.io-meter .seg-out { background: var(--expense); }

/* ===== 取引リスト ===== */
.tx-day {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--sub); font-weight: 600;
  padding: 14px 4px 6px;
}
.tx-day .day-sum { font-family: var(--font-number); font-variant-numeric: tabular-nums; }

.tx-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
  min-height: 56px;                          /* タップ領域を十分に確保 */
}
.tx-row:last-child { border-bottom: none; }
.tx-row:active { background: var(--surface-2); }

.tx-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 19px;
}
.tx-main { flex: 1; min-width: 0; }
.tx-cat  { font-weight: 600; font-size: 15px; }
.tx-memo { font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount {
  font-family: var(--font-number); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 16px; flex: none;
}
.tx-amount.income { color: var(--accent); }

/* ===== 空状態 ===== */
.empty {
  text-align: center; padding: 46px 20px; color: var(--sub);
}
.empty .e-icon { font-size: 40px; margin-bottom: 10px; }
.empty .e-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty .e-text { font-size: 14px; }

/* ===== 汎用ボタン ===== */
.btn {
  display: block; width: 100%; text-align: center;
  padding: 14px; border-radius: var(--radius-s);
  font-weight: 700; font-size: 16px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { opacity: .85; }
.btn-ghost { color: var(--accent); background: var(--accent-soft); }
.btn-ghost:active { opacity: .8; }
.btn-danger-text { color: var(--danger); font-weight: 600; padding: 12px; width: 100%; text-align: center; }
.btn:disabled { opacity: .45; }

.link-row {
  display: flex; justify-content: center; padding: 4px 0 0;
}
.link-row button { color: var(--accent); font-weight: 600; padding: 10px 16px; font-size: 15px; }

/* ===== 下部タブバー ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; align-items: stretch; justify-content: space-around;
  max-width: 640px; margin: 0 auto;
}
@media (min-width: 641px) {
  .tabbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--sub); font-size: 10.5px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: currentColor; }
.tab.active { color: var(--accent); }

/* 中央の追加ボタン */
.fab {
  flex: none; align-self: center;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
  margin: 0 4px; transform: translateY(-8px);
}
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: translateY(-8px) scale(.94); }

/* ===== 入力シート（下からせり上がるモーダル） ===== */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 15, 13, .45);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 640px; margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-close { color: var(--sub); font-size: 15px; font-weight: 600; padding: 6px 4px; }

/* 支出／収入 切替 */
.segmented {
  display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; margin-bottom: 16px;
}
.segmented button {
  flex: 1; padding: 9px; border-radius: 8px; font-weight: 700; font-size: 15px; color: var(--sub);
}
.segmented button.on-expense { background: var(--surface); color: var(--expense); box-shadow: var(--shadow); }
.segmented button.on-income  { background: var(--surface); color: var(--accent);  box-shadow: var(--shadow); }

/* 金額入力 */
.amount-wrap {
  display: flex; align-items: baseline; justify-content: center; gap: 6px; margin-bottom: 16px;
}
.amount-wrap .yen-mark { font-size: 22px; font-weight: 700; color: var(--sub); }
.amount-input {
  font-family: var(--font-number); font-variant-numeric: tabular-nums;
  font-size: 42px; font-weight: 700;
  border: none; outline: none; background: transparent;
  width: 60%; min-width: 120px; text-align: center;
  border-bottom: 2px solid var(--line); padding: 0 4px 2px;
  caret-color: var(--accent);
}
.amount-input:focus { border-bottom-color: var(--accent); }

/* カテゴリ選択チップ */
.field-label { font-size: 12.5px; font-weight: 700; color: var(--sub); margin: 14px 0 8px; letter-spacing: .03em; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 7px; border-radius: var(--radius-s);
  background: var(--surface-2); border: 2px solid transparent;
  font-size: 11.5px; font-weight: 600; color: var(--sub);
}
.cat-chip .c-icon { font-size: 20px; line-height: 1; }
.cat-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

/* 日付・メモ入力 */
.input-line {
  width: 100%; padding: 12px 14px;
  background: var(--surface-2); border: none; border-radius: var(--radius-s);
  outline: none; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.input-line:focus { box-shadow: 0 0 0 2px var(--accent); }
input[type="date"].input-line { min-height: 48px; color-scheme: light dark; }

.sheet .btn-primary { margin-top: 20px; }

/* ===== 設定画面 ===== */
.settings-group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.settings-row {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; min-height: 52px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--surface-2); }
.settings-row .s-main { flex: 1; }
.settings-row .s-title { font-weight: 600; font-size: 15px; }
.settings-row .s-desc { font-size: 12.5px; color: var(--sub); }
.settings-row .s-value { color: var(--sub); font-size: 14px; }

.cat-legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2);
}

/* ===== トースト ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 20px; border-radius: 99px;
  font-size: 14px; font-weight: 600; z-index: 60;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
