/* 月次試算表・資金繰りシミュレーター
   色の約束: 利益＝青 / 現金＝緑 / 不足・マイナス＝赤 */
:root {
  --ink: #1c2530;
  --ink-2: #4a5665;
  --ink-3: #6f7b8a;
  --line: #d9dee5;
  --line-2: #eceff3;
  --bg: #f4f6f8;
  --card: #ffffff;
  --profit: #1f5fbf;
  --profit-bg: #e8f0fb;
  --cash: #0e8a5f;
  --cash-bg: #e3f4ec;
  --bad: #d23b3b;
  --bad-bg: #fdeaea;
  --cost: #aab3bf;
  --verdict-h: 96px;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 16px; line-height: 1.6;
  font-feature-settings: "palt";
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.nowrap { white-space: nowrap; }

/* ---------- 上部 ---------- */
.top {
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px; background: var(--card); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 19px; line-height: 1.35; }
.top-sub { font-size: 13.5px; color: var(--ink-2); }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ex-label { font-size: 13px; color: var(--ink-2); }
select, input[type="number"], input[type="text"] {
  border: 1px solid #b9c1cc; border-radius: 7px; background: #fff; padding: 7px 9px; min-height: 40px;
}
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid #8ab4f8; outline-offset: 1px;
}
.btn {
  border: 1px solid var(--profit); background: var(--profit); color: #fff; border-radius: 7px;
  padding: 7px 13px; min-height: 40px; cursor: pointer; font-weight: 600; font-size: 14.5px;
}
.btn:hover { filter: brightness(1.08); }
.btn-quiet { background: #fff; color: var(--ink-2); border-color: #b9c1cc; font-weight: 500; }
.btn-small { min-height: 34px; padding: 4px 10px; font-size: 13.5px; }

/* ---------- 結論バー（いつも見える） ---------- */
.verdict {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; gap: 6px 24px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--cash-bg); border-bottom: 2px solid var(--cash);
  box-shadow: 0 2px 8px rgba(20, 30, 45, .08);
}
.verdict.is-bad { background: var(--bad-bg); border-bottom-color: var(--bad); }
.verdict-main { display: flex; gap: 10px; align-items: center; min-width: 0; flex: 1 1 380px; }
.verdict-badge {
  flex: none; font-size: 13px; font-weight: 700; color: #fff; background: var(--cash);
  border-radius: 999px; padding: 3px 11px; white-space: nowrap;
}
.is-bad .verdict-badge { background: var(--bad); }
.verdict-text { font-size: 21px; font-weight: 700; line-height: 1.35; min-width: 0; }
.verdict-text .part { display: inline-block; }
.verdict-text .num { white-space: nowrap; }
.is-bad .verdict-text .num { color: #b42323; }
.verdict-side { flex: 1 1 300px; min-width: 0; display: flex; gap: 12px; align-items: center; }
.verdict-sub { font-size: 14px; color: var(--ink-2); line-height: 1.5; flex: 1 1 auto; min-width: 0; }
.verdict-sub b { color: var(--ink); }
.spark { display: none; flex: none; }

/* ---------- 配置 ---------- */
.layout { padding: 14px 16px 40px; max-width: 1560px; margin: 0 auto; }
.results { min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px;
}
.card-kicker { font-size: 13.5px; color: var(--ink-3); font-weight: 600; }
.headline { font-size: 20px; line-height: 1.4; margin: 2px 0 10px; }
.headline .c-profit { color: var(--profit); }
.headline .c-cash { color: var(--cash); }
.headline .c-bad { color: var(--bad); }
.headline .hl-sub { font-size: .78em; font-weight: 600; color: var(--ink-2); display: inline-block; }
.chart { position: relative; width: 100%; }
.chart > svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.line-key svg { flex: none; }
.line-key { display: grid; gap: 2px; margin-top: 6px; font-size: 13px; }
.line-key div { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.line-key span { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart-note { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.chart-key { font-size: 13.5px; color: var(--ink-2); margin: -4px 0 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; margin: 0 3px 0 8px; }
.sw:first-child { margin-left: 0; }
.sw-cost { background: var(--cost); } .sw-profit { background: var(--profit); } .sw-loss { background: var(--bad); }

/* グラフの吹き出し */
.tip {
  position: absolute; z-index: 5; pointer-events: none; width: 270px; max-width: calc(100% - 8px);
  background: #fff; border: 1px solid #b9c1cc; border-radius: 8px; padding: 9px 11px;
  box-shadow: 0 6px 18px rgba(20, 30, 45, .16); font-size: 13.5px; line-height: 1.5;
}
.tip-title { font-weight: 700; margin-bottom: 3px; }
.tip-row { display: flex; justify-content: space-between; gap: 10px; }
.tip-row span:last-child { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tip-why { margin-top: 5px; padding-top: 5px; border-top: 1px dashed var(--line); color: var(--ink-2); }
.t-profit { color: var(--profit); } .t-cash { color: var(--cash); } .t-bad { color: var(--bad); }

/* ---------- 入力 ---------- */
.inputs { min-width: 0; margin-bottom: 14px; }
.plans { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.plan-tab {
  border: 1px solid #b9c1cc; background: #fff; border-radius: 8px; padding: 7px 12px; min-height: 42px;
  cursor: pointer; font-weight: 600; font-size: 14.5px; color: var(--ink-2); text-align: left; line-height: 1.3;
}
.plan-tab small { display: block; font-weight: 500; font-size: 12px; color: var(--ink-3); }
.plan-tab[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.plan-tab[aria-pressed="true"] small { color: #cfd6df; }
.plan-add { border-style: dashed; color: var(--profit); border-color: var(--profit); }
.plan-tools { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.plan-hint { width: 100%; font-size: 13px; color: var(--ink-2); background: #fff8e1; border: 1px solid #f0dca0; border-radius: 7px; padding: 6px 10px; }
.ex-note { font-size: 13px; color: var(--ink-2); margin: 0 2px 8px; }
.ex-note:empty { display: none; }

.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.group > summary {
  list-style: none; cursor: pointer; padding: 11px 14px; display: flex; align-items: baseline; gap: 10px;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--ink-3); flex: none; width: 1em; }
.group[open] > summary::before { content: "▾"; }
.group-title { font-weight: 700; font-size: 16.5px; flex: none; }
.group-sum { font-size: 13px; color: var(--ink-3); margin-left: auto; text-align: right; min-width: 0; }
.group-body { padding: 0 14px 12px; }
.solo { padding: 11px 14px; }

.field { padding: 5px 0; }
.field + .field { border-top: 1px solid var(--line-2); }
.field-label { font-size: 14.5px; font-weight: 600; display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.field-label .sub { font-weight: 500; font-size: 12.5px; color: var(--ink-3); }
.slider-row { display: flex; gap: 10px; align-items: center; margin-top: 2px; }
.slider-row input[type="range"] { flex: 1 1 auto; min-width: 0; height: 30px; accent-color: var(--profit); cursor: pointer; }
.numbox { display: inline-flex; align-items: center; gap: 5px; flex: none; white-space: nowrap; position: relative; }
.months-grid > div { position: relative; }
.limit-msg {
  position: absolute; right: 0; top: calc(100% + 3px); z-index: 6; background: #b42323; color: #fff; font-size: 12.5px;
  font-weight: 600; padding: 3px 9px; border-radius: 6px; white-space: nowrap; box-shadow: 0 3px 10px rgba(0, 0, 0, .2);
}
.numbox input { width: 108px; text-align: right; font-variant-numeric: tabular-nums; font-size: 16px; }
.numbox.narrow input { width: 62px; }
.unit { font-size: 13px; color: var(--ink-2); }
.hint { font-size: 13px; color: var(--profit); margin-top: 1px; font-weight: 600; }
.row-inline { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.term {
  border: 0; background: none; padding: 0; cursor: help; color: inherit; font: inherit;
  border-bottom: 1.5px dotted var(--ink-3);
}
.term-q {
  border: 1px solid #9aa5b2; background: #fff; color: var(--ink-2); border-radius: 999px; cursor: help;
  width: 20px; height: 20px; padding: 0; font-size: 12px; line-height: 1; font-weight: 700; flex: none;
}
.termtip {
  position: fixed; z-index: 60; max-width: 300px; background: var(--ink); color: #fff; border-radius: 8px;
  padding: 8px 11px; font-size: 13.5px; line-height: 1.55; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
.termtip b { display: block; font-size: 13px; color: #bcd3ff; }

.more { margin-top: 4px; }
.more > summary { cursor: pointer; font-size: 13.5px; color: var(--profit); font-weight: 600; padding: 4px 0; }
.months-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 8px; margin-top: 6px; }
.months-grid label { font-size: 12.5px; color: var(--ink-2); display: block; }
.months-grid input { width: 100%; text-align: right; font-size: 16px; }

.item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; background: #fbfcfd; }
.item-main { display: flex; gap: 6px; align-items: center; }
.item-main input[type="text"] { flex: 1 1 auto; min-width: 0; width: 100%; font-size: 16px; }
.del {
  flex: none; width: 36px; height: 36px; border: 1px solid #c9d0d9; background: #fff; border-radius: 7px;
  cursor: pointer; color: var(--ink-3); font-size: 18px; line-height: 1;
}
.del:hover { color: var(--bad); border-color: var(--bad); }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; margin-top: 6px; font-size: 14px; }
.kv > label, .kv > span.k { color: var(--ink-2); }
.kv select { max-width: 100%; font-size: 15px; }
.kv .numbox input { width: 108px; }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.add-row .lbl { font-size: 12.5px; color: var(--ink-3); }
.chip {
  border: 1px dashed var(--profit); background: #fff; color: var(--profit); border-radius: 999px;
  padding: 4px 11px; min-height: 34px; cursor: pointer; font-size: 13.5px; font-weight: 600;
}
.empty { font-size: 13.5px; color: var(--ink-3); padding: 4px 0; }

/* ---------- 滝グラフ ---------- */
.wf-months { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.wf-months button {
  border: 1px solid #b9c1cc; background: #fff; border-radius: 6px; min-width: 38px; min-height: 36px; padding: 2px 8px;
  cursor: pointer; font-size: 13.5px; color: var(--ink-2);
}
.wf-months button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }
.wf-months button.neg { border-bottom: 3px solid var(--bad); }
.wf-labels { display: grid; margin-top: 4px; }
.wf-labels div { text-align: center; padding: 0 3px; min-width: 0; }
.wf-labels b { display: block; font-size: 13.5px; line-height: 1.3; }
.wf-labels span { display: block; font-size: 12px; color: var(--ink-2); line-height: 1.35; margin-top: 2px; text-wrap: balance; }
.wf-rows { display: grid; gap: 9px; }
.wf-row-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.wf-row-head b { font-size: 14px; }
.wf-row-desc { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.wf-row-head .amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 14.5px; }
.wf-track { position: relative; height: 18px; background: var(--line-2); border-radius: 3px; margin-top: 2px; }
.wf-track i { position: absolute; top: 0; bottom: 0; border-radius: 2px; min-width: 2px; }
.wf-track .zero { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); margin-left: -1px; }
.wf-step-arrow { text-align: center; color: var(--ink-3); font-size: 12px; line-height: 1; }

/* ---------- 表 ---------- */
.tables > summary, .about > summary { cursor: pointer; font-weight: 700; font-size: 16.5px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.tables-title::before { content: "▸ "; color: var(--ink-3); }
.tables[open] .tables-title::before { content: "▾ "; }
.tables > summary { list-style: none; }
.tables > summary::-webkit-details-marker { display: none; }
.checks { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12.5px; font-weight: 700; border-radius: 999px; padding: 2px 10px; background: var(--cash-bg); color: #0a6b49; border: 1px solid #a9dcc6; }
.badge.ng { background: var(--bad-bg); color: #b42323; border-color: #efb1b1; }
.unit-toggle { display: flex; align-items: center; gap: 6px; margin: 12px 0 4px; font-size: 13.5px; color: var(--ink-2); }
.unit-toggle button { border: 1px solid #b9c1cc; background: #fff; border-radius: 6px; min-width: 54px; min-height: 36px; padding: 2px 10px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.unit-toggle button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }
.tbl-note { margin-top: 10px; }
table.fin.fin-yen { min-width: 1560px; }
.tbl-title { font-size: 16px; margin: 16px 0 6px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.tbl-title small { font-weight: 500; color: var(--ink-3); font-size: 13px; }
.tbl-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; }
table.fin { border-collapse: separate; border-spacing: 0; font-size: 13.5px; width: 100%; min-width: 1040px; font-variant-numeric: tabular-nums; }
table.fin th, table.fin td { padding: 4px 8px; border-bottom: 1px solid var(--line-2); text-align: right; white-space: nowrap; }
table.fin thead th { background: #eef1f5; font-weight: 700; position: sticky; top: 0; }
table.fin th.lab { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; font-weight: 500; border-right: 1px solid var(--line); min-width: 150px; max-width: 210px; white-space: normal; }
table.fin thead th.lab { background: #eef1f5; z-index: 2; }
table.fin tr.k-head th.lab { font-weight: 700; background: #f6f7f9; }
table.fin tr.k-head td { background: #f6f7f9; }
table.fin tr.k-sub th.lab, table.fin tr.k-sub td { font-weight: 700; }
table.fin tr.k-total th.lab, table.fin tr.k-total td { font-weight: 700; background: #f1f6ff; border-top: 1px solid #c8d6ee; }
table.fin tr.k-memo td, table.fin tr.k-memo th.lab { color: var(--profit); font-weight: 700; }
table.fin tr.k-check td, table.fin tr.k-check th.lab { color: var(--ink-3); font-size: 12.5px; }
table.fin th.ind1 { padding-left: 22px; }
table.fin td.neg { color: var(--bad); }
table.fin td.tot { border-left: 1px solid var(--line); background: #fafbfc; }
table.fin tr.k-cash td, table.fin tr.k-cash th.lab { background: #f0faf5; }

.about > summary { font-size: 15px; color: var(--ink-2); font-weight: 600; }
.about-body { font-size: 13.5px; color: var(--ink-2); }
.about-body h3 { font-size: 14px; color: var(--ink); margin: 12px 0 2px; }
.about-body ul { margin: 2px 0 0; padding-left: 1.3em; }
.foot { font-size: 12.5px; color: var(--ink-3); padding: 4px 2px 0; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 70; max-width: calc(100vw - 24px);
  background: var(--ink); color: #fff; border-radius: 8px; padding: 10px 16px; font-size: 14.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast input { width: min(72vw, 420px); margin-top: 6px; color: var(--ink); font-size: 13px; min-height: 34px; display: block; }
[hidden] { display: none !important; }

/* ---------- PC: 左に入力・右に結果 ---------- */
@media (min-width: 1000px) {
  .layout { display: grid; grid-template-columns: 410px minmax(0, 1fr); gap: 18px; align-items: start; }
  .inputs {
    position: sticky; top: calc(var(--verdict-h) + 10px);
    max-height: calc(100vh - var(--verdict-h) - 20px); overflow-y: auto; overscroll-behavior: contain;
    padding-right: 4px; margin-bottom: 0;
  }
  .verdict { padding: 12px 22px; }
  .verdict-text { font-size: 25px; }
  .top { padding: 12px 22px 10px; }
  .layout { padding: 16px 22px 48px; }
  .headline { font-size: 22px; }
}

/* ---------- スマホ ---------- */
@media (max-width: 999px) {
  .spark { display: block; width: 132px; }
  .verdict-side { flex-basis: 100%; }
}
@media (max-width: 560px) {
  .top h1 { font-size: 17px; }
  .top-sub { font-size: 12.5px; }
  .top-actions { width: 100%; }
  .top-actions select { flex: 1 1 120px; min-width: 0; }
  .verdict { padding: 8px 12px; gap: 4px 12px; }
  .verdict-main { flex-basis: 100%; align-items: flex-start; flex-wrap: wrap; gap: 2px 10px; }
  .verdict-badge { margin-top: 3px; font-size: 12px; padding: 2px 9px; }
  .verdict-text { font-size: 17.5px; }
  .verdict-sub { font-size: 12.5px; }
  .layout { padding: 10px 10px 36px; }
  .card { padding: 13px 12px; }
  .headline { font-size: 17.5px; }
  .group > summary { padding: 10px 11px; }
  .group-body { padding: 0 11px 10px; }
}
/* スマホ・タッチ端末では、吹き出しをグラフの下に置く（グラフを隠さない） */
@media (max-width: 700px), (hover: none) {
  .tip { position: static; width: auto; max-width: none; margin-top: 8px; box-shadow: none; background: #f8fafc; }
}
@media (prefers-reduced-motion: no-preference) {
  .verdict { transition: background-color .25s, border-color .25s; }
}
@media print {
  .verdict, .inputs { position: static; max-height: none; }
  .top-actions, .chart-note { display: none; }
}
