/* CFO Cockpit — 手書きCSS（外部CDN依存なし） */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: "Meiryo UI", Meiryo, "メイリオ", sans-serif;
  background: #e8ecf1;
  color: #1e293b;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

input, select, textarea, button {
  font-family: "Meiryo UI", Meiryo, "メイリオ", sans-serif;
  font-size: 16px; /* iOS自動ズーム防止 */
}

/* PC表示時は中央寄せモバイルフレーム */
.phone-frame {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  background: #f6f8fb;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 32px rgba(15, 23, 42, 0.12);
}

/* ---------- ヘッダー ---------- */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  color: #fff;
  padding: 14px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title { display: flex; align-items: center; gap: 10px; }
.app-logo {
  background: #f59e0b;
  color: #0f172a;
  font-weight: bold;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  letter-spacing: 1px;
}
.app-title h1 { font-size: 18px; }
.app-title .sub { font-size: 11px; opacity: 0.75; }
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 10px;
}
.month-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.month-btn:active { background: rgba(255,255,255,0.3); }
.current-month { font-size: 17px; font-weight: bold; letter-spacing: 1px; }

/* ---------- ボディ ---------- */
.app-body {
  flex: 1;
  padding: 12px 12px 88px; /* タブバー分の余白 */
  overflow-y: auto;
}
.tab-page { display: none; }
.tab-page.active { display: block; animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.07);
}
.card-label { font-size: 13px; font-weight: bold; color: #475569; margin-bottom: 8px; }
.hero-card { background: linear-gradient(135deg, #0f172a 0%, #27446b 100%); color: #fff; }
.hero-card .card-label { color: #cbd5e1; }
.big-number { font-size: 32px; font-weight: bold; margin: 4px 0 10px; }
.big-number.sm { font-size: 26px; }
.big-number .unit { font-size: 14px; font-weight: normal; margin-left: 4px; opacity: 0.8; }

.pl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pl-item {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}
.pl-cap { font-size: 11px; opacity: 0.8; }
.pl-val { font-size: 14px; font-weight: bold; }

/* カテゴリ別バーグラフ */
.cat-bars { display: flex; flex-direction: column; gap: 8px; }
.cat-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.cat-name { width: 64px; flex-shrink: 0; color: #475569; }
.cat-bar-wrap { flex: 1; background: #eef2f7; border-radius: 6px; height: 18px; overflow: hidden; }
.cat-bar { height: 100%; background: linear-gradient(90deg, #2563eb, #3b82f6); border-radius: 6px; min-width: 2px; transition: width 0.3s; }
.cat-amt { width: 76px; text-align: right; flex-shrink: 0; font-weight: bold; color: #0f172a; }

/* ---------- AI CFO ---------- */
.ai-card { border: 1.5px solid #c7d6ee; }
.tone-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.tone-btn {
  flex: 1;
  border: 1.5px solid #94a3b8;
  background: #fff;
  color: #475569;
  border-radius: 999px;
  padding: 7px 4px;
  cursor: pointer;
}
.tone-btn.selected { background: #0f172a; border-color: #0f172a; color: #fff; }
.cfo-result { margin-top: 12px; border-top: 1px dashed #cbd5e1; padding-top: 10px; }
.cfo-headline { font-weight: bold; font-size: 16px; color: #0f172a; margin-bottom: 6px; }
.cfo-summary { font-size: 13.5px; line-height: 1.7; color: #334155; white-space: pre-wrap; }
.cfo-advice { margin: 10px 0 0 18px; font-size: 13px; color: #334155; }
.cfo-advice li { margin-bottom: 4px; line-height: 1.6; }
.action-item { margin-top: 10px; background: #fef7e6; border-radius: 8px; padding: 8px 10px; }
.action-cap { font-size: 11px; color: #b45309; font-weight: bold; display: block; }
.action-item p { font-size: 13.5px; color: #92400e; font-weight: bold; }

/* ---------- フォーム ---------- */
.stack-form label {
  display: block;
  font-size: 12px;
  color: #475569;
  margin-bottom: 10px;
  font-weight: bold;
}
.stack-form input, .stack-form select, .stack-form textarea,
#ai-text {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  color: #1e293b;
}
.stack-form input:focus, .stack-form select:focus, .stack-form textarea:focus, #ai-text:focus {
  outline: none;
  border-color: #2563eb;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row3 input { padding: 10px 6px; }
#ai-text { margin: 0 0 4px; resize: vertical; }
.file-label { display: block; font-size: 12px; color: #475569; font-weight: bold; }
.file-label input { margin-top: 4px; width: 100%; font-size: 13px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: bold;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.75; }
.btn.primary { background: #2563eb; color: #fff; }
.btn.danger { background: #fee2e2; color: #b91c1c; padding: 6px 10px; font-size: 12px; }
.btn.ghost { background: #eef2f7; color: #334155; padding: 6px 10px; font-size: 12px; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.full { width: 100%; }

/* ---------- 明細リスト ---------- */
.tx-list { list-style: none; }
.tx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid #eef2f7;
}
.tx-item:last-child { border-bottom: none; }
.tx-date { font-size: 11px; color: #64748b; width: 56px; flex-shrink: 0; }
.tx-merchant { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-merchant .tx-cat { font-size: 10px; background: #eef2f7; color: #475569; border-radius: 4px; padding: 2px 5px; margin-right: 5px; }
.tx-amount { font-weight: bold; font-size: 14px; flex-shrink: 0; }
.tx-item .btn { flex-shrink: 0; }

.status-text { font-size: 12px; color: #64748b; margin-top: 8px; min-height: 1em; }
.hidden { display: none !important; }

/* ---------- ローンカード ---------- */
.loan-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.07);
  border-left: 5px solid #2563eb;
}
.loan-card.rate-high { border-left-color: #dc2626; }
.loan-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.loan-title { font-weight: bold; font-size: 15px; }
.loan-lender { font-size: 11px; color: #64748b; }
.loan-balance { font-size: 24px; font-weight: bold; color: #0f172a; }
.loan-rate-chip { font-size: 12px; color: #dc2626; font-weight: bold; }
.loan-rate-chip.low { color: #059669; }
.gauge { background: #eef2f7; border-radius: 8px; height: 20px; overflow: hidden; display: flex; margin: 8px 0 4px; }
.gauge .g-interest { background: #fbbf24; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #7c3f00; }
.gauge .g-principal { background: #3b82f6; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; }
.gauge-cap { font-size: 10.5px; color: #64748b; margin-bottom: 8px; }
.loan-meta { font-size: 12px; color: #475569; margin-bottom: 8px; }
.loan-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.warn-chip { font-size: 11px; background: #fef2f2; color: #b91c1c; border-radius: 6px; padding: 3px 8px; margin-top: 6px; display: inline-block; }

/* ---------- 繰上返済スライダー ---------- */
.slider-card { border: 1.5px solid #c7d6ee; }
.slider-value { font-size: 14px; font-weight: bold; color: #0f172a; margin-bottom: 8px; }
#prepay-slider { width: 100%; accent-color: #2563eb; height: 28px; }
.prepay-result { margin-top: 10px; font-size: 13px; }
.prepay-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #f6f8fb;
  flex-wrap: wrap;
}
.prepay-row.best { background: #e6f6ec; border: 1.5px solid #34d399; }
.prepay-name { font-weight: bold; font-size: 13px; width: 100%; }
.prepay-detail { font-size: 12px; color: #334155; }
.prepay-best-chip { font-size: 10px; background: #10b981; color: #fff; border-radius: 4px; padding: 2px 6px; }

/* ---------- 固定費リスト ---------- */
.fixed-list { list-style: none; margin-bottom: 10px; }
.fixed-item { display: flex; align-items: center; gap: 8px; padding: 8px 2px; border-bottom: 1px solid #eef2f7; font-size: 13.5px; }
.fixed-item:last-child { border-bottom: none; }
.fixed-name { flex: 1; }
.fixed-name .fixed-cat { font-size: 10px; background: #eef2f7; border-radius: 4px; padding: 2px 5px; margin-right: 4px; color: #475569; }
.fixed-amt { font-weight: bold; flex-shrink: 0; }
.toggle-btn { border: none; border-radius: 999px; padding: 4px 10px; font-size: 11px; cursor: pointer; flex-shrink: 0; }
.toggle-btn.on { background: #d1fae5; color: #065f46; }
.toggle-btn.off { background: #e2e8f0; color: #64748b; }
.form-card summary { cursor: pointer; list-style: none; color: #2563eb; }
.form-card summary::-webkit-details-marker { display: none; }
.form-card summary::before { content: ''; }
.form-card.inner { margin-top: 8px; border-top: 1px dashed #e2e8f0; padding-top: 10px; }

/* ---------- 資産・連携 ---------- */
.asset-val-src { font-size: 10px; color: #64748b; }
.endpoint-box {
  background: #0f172a;
  color: #7dd3fc;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 12px;
  word-break: break-all;
}
.endpoint-box code { font-family: inherit; display: block; margin-bottom: 8px; }
.guide-list { margin: 8px 0 8px 18px; font-size: 13px; line-height: 1.8; color: #334155; }
.guide-list code { background: #eef2f7; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.guide-text { font-size: 13px; color: #475569; line-height: 1.7; margin-bottom: 6px; }

/* ---------- 下部タブバー ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid #e2e8f0;
  display: flex;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10.5px;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 0;
}
.tab-btn .tab-ico { font-size: 20px; }
.tab-btn.active { color: #2563eb; font-weight: bold; }

/* AI解析プレビュー */
.ai-preview { margin-top: 10px; }
.ai-preview .tx-item { border-bottom: 1px dashed #e2e8f0; }
