/* ============================================================
 * style.css ― 見た目だけ。色・フォントを変えたいときはここを触る。
 * テイスト: 清潔・落ち着き・信頼感（FP資料のような誠実さ）
 * ============================================================ */

:root {
  /* 配色（ダークネイビー基調＋暖色アクセント） */
  --bg:        #0f1b2d;   /* 画面の背景：深いネイビー */
  --panel:     #16263d;   /* パネル背景 */
  --panel-2:   #1d3150;   /* パネル内の一段明るい面 */
  --border:    #2a3f5f;   /* 枠線 */
  --text:      #e8eef6;   /* 文字 */
  --text-dim:  #9fb2c9;   /* 補助文字 */
  --accent-warm: #f0a868; /* 暖色アクセント */
  --ok:        #4ec98f;   /* 安心＝緑 */
  --ok-soft:   rgba(78, 201, 143, .15);
  --danger:    #ef6b6b;   /* 危険＝赤 */
  --danger-soft: rgba(239, 107, 107, .14);
  --invest:    #7bb6ff;   /* 投資ライン＝青 */
  --bucket:    #c9a0ff;   /* バケット＝紫 */

  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ---- ヘッダー ---- */
header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  letter-spacing: .02em;
}
.app-header .subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 8px;
  font-weight: 400;
}
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- ボタン ---- */
button {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover { background: #25406a; }
button.primary { background: var(--accent-warm); color: #2a1c0a; border-color: var(--accent-warm); font-weight: 700; }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.small { padding: 3px 9px; font-size: 12px; }

/* ---- レイアウト（左：入力 / 右：グラフ） ---- */
.layout {
  display: grid;
  grid-template-columns: 500px 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---- 入力パネル ---- */
.input-col { display: flex; flex-direction: column; gap: 12px; }

.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.section.bucket-section { border-color: var(--bucket); }

/* ---- セクション左ラインの色分け（全部開いても一目でわかるように） ---- */
.section.section-type-family   { border-left: 4px solid #4ec9b0; }
.section.section-type-income   { border-left: 4px solid #4ec98f; }
.section.section-type-invest   { border-left: 4px solid #7bb6ff; }
.section.section-type-teki1    { border-left: 4px solid #f0a868; }
.section.section-type-teki2    { border-left: 4px solid #e8c56a; }
.section.section-type-teki3    { border-left: 4px solid #e89a6a; }
.section.section-type-teki4    { border-left: 4px solid #ef8b6b; }
.section.section-type-life     { border-left: 4px solid #f0a868; }
.section.section-type-bucket   { border-left: 4px solid #c9a0ff; }
.section.section-type-settings { border-left: 4px solid #9fb2c9; }

/* ---- 並び替えボタン ---- */
.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.reorder-btn {
  padding: 1px 5px;
  height: 15px;
  font-size: 9px;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 3px;
  cursor: pointer;
}
.reorder-btn:disabled { opacity: 0.2; cursor: default; }
.reorder-btn:not(:disabled):hover { color: var(--text); border-color: var(--accent-warm); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  cursor: pointer;
  user-select: none;
  background: var(--panel);
}
.section-head:hover { background: var(--panel-2); }
.section-head .title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.section-head .title .tag {
  font-size: 11px; color: var(--text-dim); font-weight: 400;
}
.section-head .chevron { color: var(--text-dim); transition: transform .15s; }
.section.collapsed .chevron { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }

.section-body { padding: 6px 14px 14px; }

/* ヘルプ（?）ボタン */
.help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; cursor: pointer; padding: 0;
  line-height: 1;
}
.help-btn:hover { color: var(--text); border-color: var(--accent-warm); }

/* ---- 項目リスト（行） ---- */
.item-row {
  display: grid;
  gap: 6px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
}
.item-row:last-child { border-bottom: none; }
.item-row .row-main {
  display: flex; gap: 6px; align-items: center;
  overflow: hidden;   /* はみ出しを防ぐ */
}
.item-row input[type="text"],
.item-row input[type="number"],
.item-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  min-width: 0;
}
.item-row input[type="text"] { flex: 1 1 auto; }
.item-row input[type="number"] { width: 96px; text-align: right; }
/* セレクトボックスは長いラベルでも縮められるようにする */
.item-row select {
  flex-shrink: 1;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
 * 支出（敵1〜4）コンパクト1行テーブルレイアウト
 * 列: [▲▼] [費目] [詳細] [金額] [周期] [から] [まで] [×]
 * ============================================================ */
.cost-table-body { padding: 4px 10px 10px; }

.cost-row {
  display: grid;
  grid-template-columns: 26px 82px minmax(80px, 1fr) 66px 50px 42px;
  gap: 4px;
  align-items: center;
  padding: 3px 0;
  min-width: 0;
}

/* 期間展開行 */
.cost-period-row {
  display: flex; gap: 6px; align-items: center;
  padding: 4px 0 4px 30px;
  font-size: 12px; color: var(--text-dim);
}
.cost-period-row input { width: 62px; }

/* 期間トグルボタン（未設定=薄色、設定済=白文字） */
.cost-period-btn {
  padding: 3px 5px; font-size: 11px; border-radius: 4px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; line-height: 1; width: 100%;
}
.cost-period-btn:hover { border-color: var(--text-dim); color: var(--text); }

/* バケット行（▲▼+cb|実行年|カテゴリ|内容|状況|費用） */
.bucket-row {
  grid-template-columns: 26px 56px 66px 1fr 62px 50px;
  align-items: start;  /* textareaに合わせて上揃え */
}
.bucket-cost-row {
  display: flex; gap: 8px; align-items: center;
  padding: 4px 0 4px 30px;
  font-size: 12px; color: var(--text-dim);
}

/* バケットの内容欄（2行textarea） */
.bucket-label-input {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 4px 6px;
  font-family: inherit; font-size: 12px; width: 100%; min-width: 0;
  resize: none; line-height: 1.4; box-sizing: border-box;
}

/* 収入コンパクト行 */
.income-row {
  display: grid;
  grid-template-columns: 26px 1fr 150px 78px 26px;
  gap: 4px; align-items: center; padding: 3px 0; min-width: 0;
}

/* 家族構成コンパクト行 */
.family-row {
  display: grid;
  grid-template-columns: 18px 26px 1fr 68px 56px;
  gap: 4px; align-items: center; padding: 3px 0; min-width: 0;
}
.family-row input, .family-row select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 4px 5px;
  font-family: inherit; font-size: 12px; width: 100%; min-width: 0;
}
.family-radio { cursor: pointer; width: 14px; height: 14px; accent-color: var(--ok); }
.section.delete-active .family-radio { opacity: 0.25; pointer-events: none; }
.income-row input, .income-row select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 4px 5px;
  font-family: inherit; font-size: 12px; width: 100%; min-width: 0; box-sizing: border-box;
}
.income-row .money-input { font-size: 12px; width: 100%; min-width: 0; text-align: right; }

/* 西暦プルダウン共通 */
.year-select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 4px 3px;
  font-family: inherit; font-size: 12px; min-width: 0; width: 100%;
}
.bucket-cost-btn {
  padding: 3px 5px; font-size: 11px; border-radius: 4px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; line-height: 1; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bucket-cost-btn.has-cost { color: var(--bucket); border-color: var(--bucket); }
.bucket-cost-btn:hover { border-color: var(--bucket); color: var(--text); }
.bucket-cost-row .money-input { width: 110px; }

/* ライフイベント行 */
.life-row {
  display: grid;
  grid-template-columns: 26px minmax(92px, 1.1fr) 56px 62px minmax(92px, 1.2fr) 66px 34px;
  gap: 4px;
  align-items: center;
  padding: 3px 0;
  min-width: 0;
}
.life-row input,
.life-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 5px;
  font-family: inherit;
  font-size: 12px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.life-row .money-input { text-align: right; }
.life-target-cell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  min-width: 0;
}
.life-include-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}
.life-include-check {
  width: 15px !important;
  height: 15px;
  accent-color: var(--accent-warm);
  cursor: pointer;
}
.life-expense-note {
  margin: 1px 0 4px 30px;
  color: var(--text-dim);
  font-size: 11px;
}

/* ヘッダー行 */
.cost-row-header {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0 0 5px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.cost-row-header > div { text-align: center; overflow: hidden; }

/* セル内の input / select 共通 */
.cost-row input,
.cost-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 5px;
  font-family: inherit;
  font-size: 12px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.cost-row input[type="number"] { text-align: right; }
.cost-row .money-input { font-size: 12px; width: 100%; min-width: 0; text-align: right; }

/* 周期セル（select＋N年入力を横並びに） */
.cycle-cell { display: flex; gap: 2px; align-items: center; min-width: 0; }
.cycle-cell select { flex: 1 1 0; min-width: 0; }
.cycle-n-input { flex: 0 0 30px; width: 30px !important; text-align: center !important; padding: 4px 2px !important; }

/* 年割り計算の表示（行の直下に小さく） */
.cost-ann { font-size: 11px; color: var(--accent-warm);
  background: rgba(240,168,104,.08); border-left: 3px solid var(--accent-warm);
  padding: 2px 6px; border-radius: 3px; margin: 1px 0 3px 30px; }
.cost-ann[style*="none"] { margin: 0; }

/* ---- 削除モード ---- */
/* 各行の先頭セル：通常はreorder-btns、削除モード時はチェックボックス */
.row-first-cell { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.delete-checkbox { display: none; width: 16px; height: 16px; cursor: pointer; margin: 0; accent-color: var(--danger); }
.section.delete-active .delete-checkbox { display: block; }
.section.delete-active .reorder-btns { display: none; }

/* 削除モード中：追加ボタンと削除トリガーを隠す */
.section.delete-active .add-btn { display: none; }
.section.delete-active .delete-trigger-btn { display: none; }

/* セクション下部ボタン行 */
.section-btn-row { display: flex; gap: 8px; margin-top: 6px; }
.section-btn-row .add-btn { flex: 1; margin-top: 0; }
.delete-trigger-btn { color: var(--danger); background: transparent; border-color: transparent; font-size: 12px; padding: 7px 10px; flex-shrink: 0; }
.delete-trigger-btn:hover { border-color: var(--danger); }

/* 削除フッター（チェック後に表示） */
.section-delete-footer { display: none; flex-direction: column; gap: 6px; margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border); }
.section.delete-active .section-delete-footer { display: flex; }
.delete-footer-hint { font-size: 12px; color: var(--text-dim); }
.delete-action-row { display: flex; gap: 8px; }
.item-row .money-input,
.field .money-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  width: 140px;
  min-width: 0;
  text-align: right;
}
.item-row select { flex: 0 0 auto; }
.item-row .row-sub {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  font-size: 12px; color: var(--text-dim);
}
.item-row .row-sub input[type="number"] { width: 72px; }
.item-row .del-btn {
  color: var(--text-dim); border-color: transparent; background: transparent;
  padding: 4px 8px;
}
.item-row .del-btn:hover { color: var(--danger); }

/* 年割りの計算過程表示（透明化のキモ） */
.annualized {
  font-size: 12px;
  color: var(--accent-warm);
  background: rgba(240,168,104,.08);
  border-left: 3px solid var(--accent-warm);
  padding: 4px 8px;
  border-radius: 4px;
}

.add-btn {
  margin-top: 8px;
  width: 100%;
  border-style: dashed;
  color: var(--text-dim);
}
.add-btn:hover { color: var(--text); }

/* バケットのステータス色分け */
.status-候補   { color: var(--text-dim); }
.status-計画中 { color: var(--accent-warm); }
.status-完了   { color: var(--ok); }

/* 設定セクションの入力 */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 12px; color: var(--text-dim); }
.field input {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 6px 8px; font-family: inherit;
}

/* ---- グラフ側 ---- */
.chart-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
}
.card .label { font-size: 12px; color: var(--text-dim); }
.card .value { font-size: 21px; font-weight: 700; margin-top: 3px; }
.card .sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.card.ok    .value { color: var(--ok); }
.card.warn  .value { color: var(--accent-warm); }
.card.alert .value { color: var(--danger); }

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-wrap h2 { font-size: 14px; margin: 0 0 10px; font-weight: 700; }
.chart-box { position: relative; height: 420px; }

/* ライフイベント年表 */
.timeline-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.timeline-scroll {
  overflow: auto;
  max-height: 300px;
}
.timeline-scroll.hidden-table { display: none; }
.timeline-wrap .chevron.rot { transform: rotate(-90deg); }
.timeline-table {
  border-collapse: collapse;
  min-width: 1200px;
  width: max-content;
  font-size: 12px;
}
.timeline-table th,
.timeline-table td {
  min-width: 86px;
  max-width: 120px;
  height: 34px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}
.timeline-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--text);
  z-index: 2;
}
.timeline-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 110px;
  max-width: 110px;
  background: var(--panel-2);
  text-align: left;
}
.timeline-table tbody .sticky-col {
  color: var(--text);
  font-weight: 600;
}
.timeline-table .age-row td {
  color: var(--text-dim);
  background: rgba(255,255,255,.025);
}
.timeline-table .event-row td {
  background: rgba(240,168,104,.055);
}
.timeline-event {
  display: inline-block;
  max-width: 100%;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(240,168,104,.18);
  color: var(--text);
  line-height: 1.35;
  white-space: normal;
}
.timeline-event.with-expense {
  border: 1px solid rgba(240,168,104,.55);
}

/* 安心ライン割れの警告バナー */
.alert-banner {
  display: none;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: #ffd9d9;
  border-radius: var(--radius);
  padding: 11px 15px;
  font-size: 13px;
}
.alert-banner.show { display: block; }
.alert-banner.safe {
  display: block;
  background: var(--ok-soft);
  border-color: var(--ok);
  color: #c8f4dd;
}

/* 年テーブル（折りたたみ） */
.year-table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.year-table-scroll { max-height: 360px; overflow: auto; }
.year-table-scroll.hidden-table { display: none; }
.year-table-wrap .chevron.rot { transform: rotate(-90deg); }
table.year-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
table.year-table th, table.year-table td {
  padding: 6px 9px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.year-table th {
  position: sticky; top: 0; background: var(--panel-2);
  color: var(--text-dim); font-weight: 600; z-index: 1;
}
table.year-table td:first-child, table.year-table th:first-child { text-align: left; }
table.year-table tr.under td { background: var(--danger-soft); }
table.year-table tr.status-かかりどき td { background: rgba(240,168,104,.08); }
table.year-table tr.status-見直し候補 td { background: rgba(232,197,106,.08); }
table.year-table .status-cell { font-weight: 700; }
table.year-table tr.status-良好 .status-cell { color: var(--ok); }
table.year-table tr.status-かかりどき .status-cell { color: var(--accent-warm); }
table.year-table tr.status-見直し候補 .status-cell,
table.year-table tr.status-要注意 .status-cell { color: var(--danger); }
table.year-table tr.has-event td:first-child::after {
  content: " *"; color: var(--accent-warm); font-weight: 700;
}

/* ---- モーダル ---- */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 100;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 480px; width: 100%;
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal p { color: var(--text-dim); font-size: 13px; }
.modal .modal-close { margin-top: 16px; width: 100%; }
.modal ul { padding-left: 18px; color: var(--text-dim); font-size: 13px; }

/* マーカー凡例 */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }
.dot.liquid { background: var(--ok); }
.dot.invest { background: var(--invest); }
.dot.total { background: #f3f6fb; height: 0; border-top: 2px dotted #f3f6fb; }
.dot.defense { background: var(--danger); height: 0; border-top: 2px dashed var(--danger); }
.dot.event  { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 8px solid var(--accent-warm); }
.dot.bucket { width: 9px; height: 9px; background: var(--bucket); transform: rotate(45deg); }
