/* TSUMERU の見た目。
   左: 手順の欄(白)。右: ダッシュボード(灰色の作業面に白いカード)。上の帯に道しるべと状況、下の縁が進み具合。
   文字と大事なボタンは黒。差し色の薄い緑は「終わった・選んでいる」所(完了の札・進み具合の帯・選んだ案)だけ。
   書体は LINE Seed JP ひとつ、数字は桁をそろえる。
   左の欄の入力: 1つなら「名前 | 欄」(.row)、2つ並べるときは名前を上に置いた .field を .pair で横に */

:root {
  --canvas: #f1f1ef;
  --panel: #ffffff;
  --field: #f7f7f5;
  --line: #e6e5e1;
  --line-strong: #d4d3ce;
  --ink: #3e3a39; /* 黒は CMYK の K90 相当(真っ黒より少し落ち着いた黒) */
  --muted: #85857f;
  --sage: #d3f9e0;
  --sage-ink: #12863f;
  --brand-green: #8ce99a; /* ロゴの差し色(favicon.svg と同じ) */
  --warn: #e8590c;
  --warn-bg: #fff4e6;
  --caution: #f59f00; /* 取込プレビューの重なり(注意)の線。赤(NG)と見分けやすい黄みのオレンジ */
  --err: #e03131;
  --err-bg: #fff0f0;
  --sheet: #fbfbfa;
  --part: #4a78c8;
  --preview-part: #c3c7cd;
  --label-w: 6.2em;
  /* ★書体と太さはここで変える。LINE Seed JP の太さは 100 / 400 / 700 / 800 の4つ
     (読み込む太さは index.html の Google Fonts の行 wght@400;700;800。100 を使うなら足す) */
  --sans: "LINE Seed JP", "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  --w-heading: 400;   /* 大見出し(取込プレビュー・割付結果)・手順とカードの見出し・ファイル名 */
  --w-strong: 700;    /* 数字のカードの値・メディア名など、強めたい文字 */
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #141414;
    --panel: #1d1d1c;
    --field: #252524;
    --line: #2f2f2d;
    --line-strong: #3d3d3a;
    --ink: #ecece8;
    --muted: #9a9a93;
    --sage: #173d26;
    --sage-ink: #69db8f;
    --warn: #ffa94d;
    --warn-bg: #3a2614;
    --err: #ff6b6b;
    --err-bg: #3b1d1d;
    --sheet: #262624;
    --preview-part: #5d636b;
  }
}

* { box-sizing: border-box; }
/* display を指定した要素でも hidden 属性で隠れるように */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--canvas);
}
.muted { color: var(--muted); }
.strong { font-weight: var(--w-strong); }

/* ---------- ボタン・入力 ---------- */
button {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:not(:disabled):hover { border-color: var(--ink); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--sage-ink); outline-offset: 1px; }
/* 主ボタン(開始・書き出し)は黒 */
button.primary, button.dark { background: var(--ink); border-color: var(--ink); color: var(--panel); font-weight: 700; }
button.primary:not(:disabled):hover, button.dark:not(:disabled):hover { opacity: 0.86; }
button.dark.out::before { content: "⬇ "; }
button.ghost { background: var(--panel); }
button.link { padding: 0; border: none; background: none; color: var(--muted); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
button.link:not(:disabled):hover { color: var(--ink); }

select, input[type="number"] {
  font: inherit;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  min-width: 0;
}
select {
  width: 100%;
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2385857f' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
input[type="number"] { text-align: right; }
/* 単位を欄の中の右端に入れた入力(.inp = 枠、中の input は枠なし) */
.inp {
  display: flex; align-items: center; min-width: 0;
  height: 32px; padding-right: 9px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--field);
}
.inp:focus-within { border-color: var(--ink); }
.inp input[type="number"] { flex: 1; width: 100%; height: 30px; border: none; background: none; padding: 0 6px 0 10px; outline: none; }
.inp i { font-style: normal; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
/* 決まった板の大きさは変えられない */
.inp:has(input[readonly]) { background: transparent; border-style: dashed; }
input[readonly] { color: var(--muted); cursor: not-allowed; }
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.hint.err { color: var(--err); font-weight: var(--w-strong); }
/* 入力欄の範囲チェック(app.js renderInputChecks)。赤 = エラー、オレンジ = 注意。理由は欄のまとまりの下に */
.side .inp.is-err, .side input.is-err { border-color: var(--err); background-color: var(--err-bg); }
.side .inp.is-warn { border-color: var(--warn); background-color: var(--warn-bg); }
.vmsg { list-style: none; margin: 6px 0 0; padding: 0; font-size: 11.5px; line-height: 1.5; }
.vmsg li.err { color: var(--err); font-weight: var(--w-strong); }
.vmsg li.warn { color: var(--warn); }
.files li .vmsg { order: 3; flex-basis: 100%; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--ink); width: 15px; height: 15px; margin: 0; }

/* ---------- 全体の配置 ---------- */
.app { display: flex; height: 100vh; }

/* ---------- 左: 手順の欄 ---------- */
.side {
  width: 384px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 26px; border-bottom: 1px solid var(--line); }
.brand-mark { flex: none; width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; font-weight: 800; letter-spacing: 0.08em; }
.brand-text small { font-size: 11px; color: var(--muted); }
/* デモの読み込み: ロゴの右端に小さく */
.brand .demo { margin-left: auto; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--sage); color: var(--sage-ink); font-size: 12px; font-weight: var(--w-strong); white-space: nowrap; cursor: pointer; }
.brand .demo:hover { border-color: var(--sage-ink); }
.brand .demo:disabled { opacity: 0.5; cursor: default; }
.side-body { flex: 1; overflow-y: auto; padding: 0 26px 18px; }
fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled { opacity: 0.45; }
fieldset:disabled .drop { cursor: not-allowed; }
.side section, .side details.sec { padding: 21px 0; border-bottom: 1px solid var(--line); }
.side details.sec:last-of-type { border-bottom: none; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.side h2 { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 15px; font-weight: var(--w-strong); }
/* 小さいラベル(複数可)は真ん中に並べると字の下が見出しより上に来るので、1px 下げて見出しの字の下にそろえる(5倍で確認) */
.side h2 small { margin-left: 2px; font-size: 11px; font-weight: 400; color: var(--muted); position: relative; top: 1px; }
/* 手順の番号(1→5 の順に進むので番号を付ける)。数字の字面は丸の中心より 0.2px 下にあり、下がって見えるので 0.2px 上げる(padding-bottom 0.4px) */
.step { display: inline-grid; place-items: center; width: 20px; height: 20px; padding-bottom: 0.4px; border-radius: 50%; background: var(--ink); color: var(--panel); font-size: 11px; font-weight: 800; }
/* 畳める手順(加工時間)。見出しの右に今の値 */
details.sec > summary { display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .sum { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.sec > summary::after { content: ""; width: 7px; height: 7px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); margin: -3px 2px 0 4px; transition: transform 0.15s; }
details.sec[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
details.sec[open] > summary { margin-bottom: 10px; }

/* 左の欄の型は1つ: 名前は欄の上、欄は全幅(左端が1本にそろう)。
   文字は3段: 手順の見出し 15px 太字 / 項目の名前(メイン・追加・割付方法など)12.5px 太字 /
   項目の中の小さい名前(幅・長さ・縮尺など)と補足 12px 灰色 */
.row { margin-top: 14px; }
.row > label:first-child { display: block; margin-bottom: 6px; color: var(--ink); font-size: 12.5px; font-weight: var(--w-strong); line-height: 1.3; }
.row > label small { font-size: 10.5px; font-weight: 400; color: var(--muted); }
/* 2つを横に並べる欄(名前はそれぞれの上) */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 12.5px; font-weight: var(--w-strong); color: var(--ink); }
/* 割付方法: セレクトの右に「穴の中にも入れる」 */
.with-check { display: flex; align-items: center; gap: 12px; }
.with-check select { flex: 1; min-width: 0; }
.with-check .check { flex: none; }
/* メインのメディアの幅・長さ(サイズを指定・ロール材)は名前を欄の左に */
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline > span:first-child { flex: none; font-size: 12px; font-weight: 400; color: var(--muted); }
.field.inline .inp { flex: 1; min-width: 0; }
/* 説明は名前の横の ? に(乗せると出る。title より早く出て、見落とさない) */
/* 吹き出しは ? ではなく名前の行(全幅)に合わせて出す(? の位置から出すと右にはみ出す) */
.row > label:first-child, .sec-head, .kpi { position: relative; }
.q { display: inline-grid; place-items: center; width: 15px; height: 15px; margin-left: 5px; border: 1px solid var(--line-strong); border-radius: 50%; font-size: 10px; font-style: normal; font-weight: 700; color: var(--muted); cursor: help; vertical-align: 1px; }
.q:hover::after { content: attr(data-tip); position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 5; padding: 8px 10px; border-radius: 8px; background: var(--ink); color: var(--panel); font-size: 11.5px; font-weight: 400; line-height: 1.6; white-space: normal; }
/* 左の欄の入力は枠を出さず塗りだけ(線を減らす)。触っている欄だけ枠 */
.side select, .side input[type="number"], .side .inp { border-color: transparent; }
.side select:focus, .side .inp:focus-within, .side input[type="number"]:focus { border-color: var(--ink); outline: none; }
.side .inp input[type="number"] { border: none; }
.side .inp:has(input[readonly]) { border-color: var(--line-strong); }
.side-foot { padding: 18px 26px 22px; border-top: 1px solid var(--line); }
.side-foot > button { width: 100%; padding: 12px; font-size: 15px; }

/* 取込 */
.intake { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 70px; padding: 10px 8px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--field);
  cursor: pointer; text-align: center;
  font: inherit; color: var(--ink);
}
.drop strong { font-size: 12.5px; }
.drop span { color: var(--muted); font-size: 11px; line-height: 1.45; }
.drop:hover, .drop.over { border-color: var(--ink); background: var(--panel); }

/* ファイル一覧 */
.files { list-style: none; margin: 10px 0 0; padding: 0; }
/* 1件ずつ薄い台に載せる(線で挟まない)。台の上の入力は台と同じ塗りだと消えるので白に */
.files li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 8px; padding: 10px 12px 12px; border-radius: 10px; background: var(--field); }
.files li select, .files li input[type="number"] { background-color: var(--panel); }
.files .no { min-width: 1.3em; margin-right: 2px; font-size: 13px; font-weight: 800; text-align: right; }
.files .name { flex: 1; min-width: 0; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; line-height: 1.6; }
/* 数は名前の下の行に(名前の幅を取らない)。回転の段より上 */
.files .count { order: 1; flex-basis: 100%; margin: 2px 0 0 calc(1.3em + 2px); color: var(--muted); font-size: 11.5px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.files button { padding: 2px 8px; border-radius: 6px; }
.files button.move { padding: 1px 5px; font-size: 9px; color: var(--muted); }
/* 数量「× [1]」: × の左右の空きをそろえる */
.files label { display: flex; align-items: center; gap: 4px; margin-left: 2px; color: var(--muted); }
.files input[type="number"] { width: 48px; height: 26px; padding: 0 6px; }
/* ファイルごとの回転は2段目に(番号の幅だけ下げる) */
.files .rotrow { order: 2; flex-basis: 100%; display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 11.5px; }
.files .rotrow select { flex: 1; min-width: 0; height: 26px; font-size: 12px; }
/* 縮尺と回転を横に並べる。縮尺は 1/200 まで見切れない幅、回転は残りを使って右端を上の × にそろえる */
.files .rotrow > label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.files .rotrow > label:first-child { flex: 0 0 auto; }
.files .rotrow > label:last-child { flex: 1; }
.files .rotrow .fscale { width: 86px; flex: none; }
.warnings { list-style: none; margin: 6px 0 0; padding: 0; color: var(--warn); font-size: 11.5px; line-height: 1.5; }
.warnings li { margin-top: 3px; }
.warnings li.load-err { color: var(--err); font-weight: 700; }

/* 追加メディア */
.extra { list-style: none; margin: 0; padding: 0; font-size: 12.5px; max-height: 470px; overflow-y: auto; }
.extra li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.extra .thumb { width: 44px; height: 30px; flex-shrink: 0; background: var(--field); border: 1px solid var(--line); border-radius: 6px; }
.extra .thumb path { fill: var(--preview-part); stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.extra .what { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.extra .tag { font-weight: 700; white-space: nowrap; }
.extra .src { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.extra .size { white-space: nowrap; font-size: 11.5px; }
.extra button { padding: 1px 7px; border-radius: 6px; }
.extra:not(:empty) + .extra-add { margin-top: 8px; }
/* 幅 [1000 mm] × 長さ [1000 mm] [足す] を1行で。1回で1枚(何枚も要るときは足すを繰り返す)。
   名前は欄の外の左に(左の欄にスクロールバーが出て約 15px 狭くなっても 4 桁が収まる) */
.extra-add { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto minmax(0, 1fr) auto; align-items: center; gap: 5px; }
.extra-add label { font-size: 12px; color: var(--muted); }
.extra-add .times { margin: 0 1px; color: var(--muted); font-size: 12px; }
.extra-add .inp { padding: 0 6px 0 4px; }
.extra-add .inp i { font-size: 11px; }
.extra-add .inp input[type="number"] { padding: 0 3px; }
.extra-add button { padding: 0 10px; height: 32px; }

/* ---------- 右: ダッシュボード ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  min-height: 60px; padding: 0 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.crumb { font-size: 13px; color: var(--muted); }
.crumb .sep { margin: 0 8px; color: var(--line-strong); }
.crumb #crumb { color: var(--ink); font-weight: 700; }
.topstate { margin-left: auto; display: flex; align-items: center; gap: 12px; }
#elapsed { font-size: 12px; color: var(--muted); }
/* 状況の札。計算中は点が明滅、終わったら薄い緑、できなかったら赤 */
.state {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0; padding: 5px 12px 5px 10px;
  border-radius: 999px; background: var(--canvas);
  font-size: 12.5px; font-weight: 700;
}
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.state[data-state="run"] { background: var(--sage); color: var(--sage-ink); }
.state[data-state="run"]::before { background: var(--sage-ink); animation: blink 1.2s ease-in-out infinite; }
.state[data-state="done"] { background: var(--sage); color: var(--sage-ink); }
.state[data-state="done"]::before { background: var(--sage-ink); }
.state[data-state="error"] { background: var(--err-bg); color: var(--err); }
.state[data-state="error"]::before { background: var(--err); }
@keyframes blink { 50% { opacity: 0.25; } }
/* 進み具合の帯 */
.progress { height: 4px; margin-top: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress-bar {
  height: 100%; width: 0; transition: width 0.5s linear;
  background: linear-gradient(90deg, var(--sage-ink), #51cf66, #b2f2bb, #51cf66, var(--sage-ink));
  background-size: 200% 100%;
  animation: flow 1.6s linear infinite;
}
@keyframes flow { from { background-position: 200% 0; } to { background-position: 0 0; } }
.progress.done .progress-bar { background: var(--sage-ink); animation: none; }
/* 最長時間を過ぎても最初の案を探しているとき: 帯と札をオレンジに */
.progress.overtime .progress-bar { background: linear-gradient(90deg, var(--warn), #ffa94d, #ffd8a8, #ffa94d, var(--warn)); background-size: 200% 100%; }
.state.overtime { background: var(--warn-bg) !important; color: var(--warn) !important; }
.state.overtime::before { background: var(--warn) !important; }
.progress.endless .progress-bar { width: 30%; transition: none; animation: endless 1.4s ease-in-out infinite, flow 1.6s linear infinite; }
@keyframes endless { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) {
  .progress-bar, .progress.endless .progress-bar, .state[data-state="run"]::before { animation: none; }
}

.main-scroll { flex: 1; overflow: auto; padding: 32px 38px 52px; }
.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: var(--w-heading); letter-spacing: 0.01em; }
.page-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions .check { margin-right: 6px; font-size: 12.5px; color: var(--muted); }
.page-actions button { height: 36px; padding: 0 14px; }

/* ---------- 右の欄: 状況と結果・書き出し ---------- */
.side-right { width: 400px; border-right: none; border-left: 1px solid var(--line); }
.side-right .side-body { padding-top: 4px; }
/* 状況は右の欄の上に貼り付く(下の罫線が区切り)。下の内容が透けないよう白で塗る */
.side-right .status-sec { position: sticky; top: 0; z-index: 2; background: var(--panel); }
.side-right .sec-head .state { margin-left: auto; }
.side-right #elapsed { display: block; margin-top: 6px; }
.side-right .side-foot { padding-bottom: 22px; }
.side-right .side-foot .sec-head .check { font-size: 12px; color: var(--muted); }
/* 2×2: SVG 書き出し・DXF 書き出し / SVG コピー・作業を保存 */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions button { height: 40px; padding: 0 8px; white-space: nowrap; }

/* 数字のカード4枚(右の欄で 2×2) */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
/* 枠と中の線はやめて塗りだけ(左の欄の入力と同じ)。説明は名前の横の ? に */
/* 左右 12px: 「最後のメディアの使用幅 ?」が1行に収まる幅(13px だと 2px はみ出す) */
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 12px; background: var(--field); border-radius: 12px; }
/* ? のある名前とない名前で高さがずれて、横の値の位置が 2px ずれないよう、行の高さを ? にそろえる */
.kpi-label { display: flex; align-items: center; height: 15px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.kpi-label .q { flex: none; margin-left: 4px; }
.kpi-value { font-size: 23px; font-weight: var(--w-strong); letter-spacing: -0.01em; line-height: 1.25; }
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi-sub { font-size: 11px; color: var(--muted); }
.kpi.warn .kpi-value { color: var(--warn); }
.warn-box { margin: 10px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); font-size: 12.5px; line-height: 1.6; }

/* カード */
.card { padding: 20px 24px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card h2 { margin: 0; font-size: 14px; font-weight: var(--w-heading); }
.card-head .muted { font-size: 12px; }

/* 結果の表と案の履歴 */
.result-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.result-grid .card + .card { margin-top: 0; }
.table-wrap { overflow-x: auto; }
.breakdown { width: 100%; border-collapse: collapse; font-size: 13px; }
.breakdown th { text-align: left; font-size: 11.5px; font-weight: 400; color: var(--muted); padding: 0 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.breakdown td { padding: 10px 10px; line-height: 1.45; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
/* 2行目にメディアの大きさと使用を横並びで(数字の列を詰めて、メディアの列を広くとる) */
.breakdown td small { display: block; margin-top: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
/* 右の欄の幅に収める: 1列目(メディアと大きさ)は折り返してよい、数字の列は詰める */
.breakdown td:first-child { white-space: normal; }
.breakdown th.num, .breakdown td.num { padding-left: 6px; padding-right: 0; }
/* 使用率と加工時間の列は中身の幅だけ(width: 1% で縮める)。2つの間は 18px */
.breakdown thead th.num, .breakdown tbody td.num { width: 1%; }
.breakdown th.num + th.num, .breakdown td.num + td.num { padding-left: 18px; }
.breakdown th:first-child, .breakdown td:first-child { padding-left: 0; }
.breakdown .num { text-align: right; }
.breakdown td.warn { color: var(--warn); font-weight: 700; }
.breakdown tfoot td { border-bottom: none; color: var(--muted); font-size: 12px; padding-top: 12px; }
.breakdown tfoot tr.foot-sum td { color: var(--ink); font-weight: var(--w-strong); font-size: 13px; white-space: nowrap; padding-bottom: 2px; }
.breakdown tfoot .foot-detail td { padding: 0; font-size: 11.5px; white-space: normal; }
.history { margin: 0; padding: 0; list-style: none; counter-reset: plan; }
.history li { counter-increment: plan; display: flex; gap: 10px; padding: 8px 10px; margin-bottom: 4px; cursor: pointer; border-radius: 8px; font-size: 12.5px; }
.history li::before { content: counter(plan); color: var(--muted); min-width: 1.2em; text-align: right; }
.history li:hover { background: var(--canvas); }
.history li.on { background: var(--sage); color: var(--sage-ink); font-weight: 700; }
/* NG: 赤は見出しの横の札だけ。中の一覧は普通の色(赤が二重・三重にならないように) */
.ng-count { padding: 1px 9px; border-radius: 999px; background: var(--err-bg); color: var(--err); font-size: 12px; font-weight: var(--w-strong); }
.summary { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.summary li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); line-height: 1.8; }
.summary li span:last-child { text-align: right; }
/* NG の一覧は 5 行ほどを超えたら、その中でスクロール。高さは中身に合わせる(下を空けない) */
.summary li.ng { display: block; padding: 0; border-top: none; }
.summary li.ng + li.ng { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.summary li.ng span:first-child { display: block; margin-bottom: 4px; font-size: 12.5px; font-weight: var(--w-strong); }
.summary li.ng span:last-child { display: block; max-height: 115px; overflow-y: auto; padding-right: 4px; text-align: left; white-space: nowrap; }

/* お知らせ(右下) */
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 420px; margin: 0; padding: 11px 16px; border-radius: 10px; background: var(--ink); color: var(--panel); font-size: 13px; line-height: 1.5; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); }

/* ---------- 図(取込プレビュー・割付結果) ---------- */
.view svg { display: block; max-width: 100%; height: auto; }
.empty { color: var(--muted); }
.err { color: var(--err); }
/* 計算できなかった理由(部品が多すぎる・どれも入らない など)。見落とさないよう、赤い太枠の箱で大きく */
.view .err { display: flex; gap: 12px; align-items: flex-start; margin: 0 0 18px; padding: 16px 20px; max-width: 1100px;
  border: 2px solid var(--err); border-radius: 12px; background: var(--err-bg); font-size: 16px; font-weight: 700; line-height: 1.6; }
.view .err::before { content: "!"; flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--err); color: #fff; font-size: 17px; }
/* 左の欄の数の式は札に(取込プレビューの見出しと同じ形)。その下に大きさ・注意を小さく */
#partsInfo:empty { display: none; }
#partsInfo { margin-top: 12px; }
#partsInfo .chips { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
#partsInfo .chips b { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: var(--w-strong); background: var(--sage); color: var(--sage-ink); }
#partsInfo .chips b.ng { background: var(--err-bg); color: var(--err); }
#partsInfo .chips b.calc { background: var(--ink); color: var(--panel); }
#partsInfo .chips i { font-style: normal; font-size: 13px; color: var(--muted); }
#partsInfo .chips span { font-size: 11.5px; color: var(--muted); }
#partsInfo p { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
/* 計算するものが上限を超えたら、開始を押す前から赤く */
#partsInfo.over .chips b.calc { background: var(--err); color: #fff; }
#partsInfo.over p.over-msg { color: var(--err); font-weight: var(--w-strong); }
/* 最初の案までの見込みが最長時間より長いときの知らせ(オレンジの箱、下に延ばすボタン) */
.time-fix { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); font-size: 12px; line-height: 1.6; }
.time-fix button { display: block; margin-top: 8px; padding: 5px 12px; font-size: 12px; }
.view .save-pasted { margin: 0 0 16px; }
.view .sheet { fill: var(--sheet); stroke: var(--muted); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.view .part { fill: var(--part); stroke: none; }
.view .pick .part { cursor: pointer; }
.view .pick .part:hover { opacity: 0.75; }
.view .part.remnant { fill: var(--sheet); stroke: var(--muted); stroke-width: 2; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; }
.view .remlabel { fill: var(--muted); font-size: 28px; pointer-events: none; }
.view figcaption { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.view .dim path { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.view .dim text { fill: var(--muted); }

/* 取込プレビュー: ファイルごとの白い台紙(app.js の CARD_PAD と合わせる)。この時点では色分けせず薄い灰色 */
.preview {
  position: relative; margin: 0;
  width: fit-content; max-width: 100%;
  padding: 20px 28px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.preview + .preview { margin-top: 16px; }
.preview figcaption { font-size: 17px; font-weight: var(--w-heading); color: var(--ink); margin: 0 0 12px; padding-right: 40px; }
.preview .remove-file { position: absolute; top: 16px; right: 16px; padding: 3px 9px; background: var(--ink); border-color: var(--ink); color: var(--panel); border-radius: 8px; }
.preview .remove-file:hover { background: var(--err); border-color: var(--err); }
/* 重なっていても見えるよう、塗りは少し透かして黒い線を足す */
.view .preview .part:not(.remnant) { fill: var(--preview-part); fill-opacity: 0.3; stroke: var(--ink); stroke-width: 1; vector-effect: non-scaling-stroke; }
/* ほかの部品と重なったままの形(注意文に番号) */
.view .preview .part.overlap { stroke: var(--caution); stroke-width: 2.5; }
/* メディアに入らないパーツ(NG): 赤い線と薄い赤の塗り */
.view .preview .part.ngpart { stroke: var(--err); stroke-width: 2; fill: var(--err-bg); fill-opacity: 1; }
/* 使わなかった線・文字(閉じていない線、text、画像など)は赤で重ねる */
.view .preview .ignored { pointer-events: none; }
.view .preview .ignored path { fill: none; stroke: var(--err); stroke-width: 2; vector-effect: non-scaling-stroke; }
.view .preview .ignored text, .view .preview .ignored tspan { fill: var(--err); stroke: none; }

/* 割付結果: メディアを左から右へ並べ、詰まったら下の段へ */
.sheets { display: flex; flex-wrap: wrap; gap: 18px 22px; align-items: flex-start; }
.sheetfig { margin: 0; }
.sheetfig figcaption { color: var(--ink); font-weight: 700; }
.sheetfig svg { display: block; max-width: none; border-radius: 2px; }
.view .caption { fill: var(--muted); font-size: 40px; }
.sheetfig.unused { opacity: 0.55; }
.sheetfig.unused .sheet { stroke-dasharray: 8 6; }
.sheetfig.ng .part { stroke: var(--err); stroke-width: 2; vector-effect: non-scaling-stroke; }
/* NG(入らなかった部品・使えなかった追加メディア) */
.view .ng-area { margin-top: 20px; padding: 16px 24px 20px; background: transparent; border: 1px dashed color-mix(in srgb, var(--err) 45%, var(--line)); }
.view .ng-area h2 { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--err); }
.view .ngtitle { margin: 12px 0 8px; font-size: 12px; font-weight: 400; color: var(--muted); }
.view .ng-area .sheets + .ngtitle { margin-top: 28px; padding-top: 16px; border-top: 1px dashed var(--line); }
/* NG の形は小さめ・灰色の塗り・赤い線で(OK より目立たないように) */
.sheetfig.ng { opacity: 0.85; }
.sheetfig.ng .part { fill: var(--preview-part) !important; fill-opacity: 0.45; }
.sheetfig.ng figcaption { color: var(--muted); font-weight: 400; }
/* OK: 割り付けたメディアのカード。見出しに緑の札、上の縁に緑の帯 */
.ok-card { border-top: 3px solid var(--sage-ink); }
.ok-badge, .ng-badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.ok-badge { background: var(--sage); color: var(--sage-ink); }
.ng-badge { background: var(--err-bg); color: var(--err); }

@media (max-width: 720px) {
  .app { flex-direction: column; height: auto; }
  .side { width: 100%; border-right: none; border-bottom: 1px solid var(--line); }
  .main-scroll { padding: 16px; }
}

/* 取込の NG と注意: ファイルごとに台紙の見出しの下(読めなかったファイルは図の上に)。
   NG = 使えないので計算に入れないもの(赤)、注意 = 計算はするが確かめてほしいこと(オレンジ)。幅があれば横に並べる */
.file-notes { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; margin: -4px 0 14px; max-width: 1100px; }
.file-notes section { flex: 1 1 340px; padding: 10px 14px; border-radius: 10px; font-size: 12.5px; line-height: 1.6; }
.file-notes h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 12px; font-weight: var(--w-heading); }
.file-notes h4 b { padding: 1px 9px; border-radius: 999px; color: #fff; font-size: 11.5px; font-weight: var(--w-strong); letter-spacing: 0.04em; }
.file-notes ul { list-style: none; margin: 0; padding: 0; }
.file-notes li + li { margin-top: 3px; }
.note-ng { background: var(--err-bg); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); color: var(--ink); }
.note-ng h4 { color: var(--err); }
.note-ng h4 b { background: var(--err); }
/* NG の1行: 種類・個数・番号(・直し方) */
.note-ng li { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 10px; }
.note-ng .what { font-weight: var(--w-strong); }
.note-ng .cnt { color: var(--muted); }
.note-ng .nos { color: var(--err); font-weight: var(--w-strong); }
.note-ng small { flex-basis: 100%; color: var(--muted); font-size: 11.5px; }
.note-warn { background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); }
.note-warn h4 { color: var(--warn); }
.note-warn h4 b { background: var(--warn); }
.preview.load-errors { margin-bottom: 16px; }
.preview.load-errors figcaption { color: var(--err); }
.preview.load-errors ul { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.8; }
.preview.load-errors li::before { content: "⚠ "; color: var(--err); }

/* メディアごとの内訳は 10 行ほどで、それ以上は表の中でスクロール(見出しは上に残す) */
.breakdown-wrap { max-height: 560px; overflow-y: auto; }
.breakdown-wrap thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.breakdown td.num small { display: inline; margin: 0 4px 0 0; font-weight: 400; }
.breakdown tfoot td.num { white-space: nowrap; }

/* 取込プレビューの番号(まとめ A3 と同じ文字の番号)と、使えなかったものの ×1 …(注意文の番号と同じ) */
.view .pnums text, .view .xnums text { stroke: #fff; paint-order: stroke; stroke-linejoin: round; font-weight: 700; pointer-events: none; }
.view .pnums text { fill: var(--ink); }
.view .xnums text { fill: var(--err); }

/* 最初の案を待っているあいだ(部品が多いと数分) */
.first-wait { max-width: 560px; }
.first-wait h2 { font-size: 15px; }
.first-step { margin: 14px 0 8px; font-size: 14px; font-weight: var(--w-strong); }
.first-bar { margin-top: 0; }

/* 内訳の合計行は、表をスクロールしても下に残す */
.breakdown-wrap tfoot { position: sticky; bottom: 0; background: var(--panel); }
.breakdown-wrap tfoot tr.foot-detail td { padding-bottom: 6px; }

/* 取込プレビューの見出しの右: 番号の範囲 */
.preview figcaption .num-range { display: inline-flex; gap: 6px; margin-left: 14px; vertical-align: 2px; }
.preview figcaption .num-range b { padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: var(--w-strong); background: var(--sage); color: var(--sage-ink); }
.preview figcaption .num-range b.ng { background: var(--err-bg); color: var(--err); }
/* 「パーツ − NG = 計算」: 記号は札の間に。計算する数は黒の札 */
.preview figcaption .num-range { align-items: center; }
.preview figcaption .num-range i { font-style: normal; font-size: 14px; color: var(--muted); }
.preview figcaption .num-range b.calc { background: var(--ink); color: #fff; }
/* 計算中の説明 */

/* ---------- クイック取説(js/guide.js) ---------- */
/* ロゴの右端: もう一度開く「?」 */
.brand .guide-open { flex: none; width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 13px; font-weight: 700; color: var(--muted); }
.guide { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(20, 20, 20, 0.45); }
.guide[hidden] { display: none; }
.guide-card { position: relative; display: flex; flex-direction: column; width: min(880px, 100%); max-height: calc(100vh - 32px); overflow: auto; border-radius: 16px; background: var(--panel); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
/* 上の帯: 「クイック説明」と、何枚目か */
.guide-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 24px; background: var(--ink); color: var(--panel); border-radius: 16px 16px 0 0; }
.guide-head strong { font-size: 14px; font-weight: var(--w-strong); letter-spacing: 0.04em; }
.guide-count { padding: 2px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); font-size: 12px; font-weight: var(--w-strong); font-variant-numeric: tabular-nums; }
.guide-close { margin-left: auto; width: 32px; height: 32px; padding: 0; border: none; border-radius: 50%; background: transparent; color: inherit; font-size: 15px; }
.guide-close:not(:disabled):hover { background: rgba(255, 255, 255, 0.16); }
/* 1枚 = 左に絵、右に説明。高さは固定(1枚ごとにカードの高さが変わってボタンが動かないように) */
.guide-body { position: relative; }
.guide-slide { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: 470px; }
.guide-slide[hidden] { display: none; }
.guide-shot { position: relative; display: grid; place-items: center; margin: 0; padding: 24px 24px 24px 56px; background: var(--canvas); box-sizing: border-box; overflow: hidden; }
.guide-shot > span { position: relative; display: inline-block; line-height: 0; }
.guide-shot img { display: block; max-width: 100%; max-height: 422px; width: auto; height: auto; border-radius: 8px; box-shadow: 0 1px 0 var(--line), 0 4px 16px rgba(0, 0, 0, 0.08); background: var(--panel); }
/* 枠は要素より 5px 外に描く(要素の端の文字に線がかからないように) */
.guide-shot .mark { position: absolute; font-style: normal; }
.guide-shot .mark::before { content: ""; position: absolute; inset: -5px; border: 2.5px solid var(--sage-ink); border-radius: 9px; }
.guide-shot .mark b, .guide-text li b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--sage-ink); color: #fff; font-size: 12px; font-weight: 800; line-height: 1; }
.guide-shot .mark b { position: absolute; top: -15px; left: -15px; }
/* カード全体の左右の端に ‹ ›。最初の枚の ‹ と最後の枚の › は出さない */
.guide-arrow { position: absolute; top: 50%; z-index: 2; width: 40px; height: 40px; margin-top: -20px; padding: 0 0 3px; border-radius: 50%; background: var(--panel); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15); font-size: 26px; line-height: 1; }
.guide-arrow.prev { left: 10px; }
.guide-arrow.next { right: 10px; }
.guide-arrow:disabled { visibility: hidden; }
/* スマホ: 絵の左半分 = 前へ、右半分 = 次へ(見えない押し場所。js/guide.js が足す)。マウスの PC では使わない */
.guide-tap { position: absolute; top: 0; bottom: 0; z-index: 1; width: 50%; padding: 0; border: none; border-radius: 0; background: none; opacity: 0; }
.guide-tap.prev { left: 0; }
.guide-tap.next { right: 0; }
.guide-tap:disabled { display: none; }
@media (hover: hover) { .guide-tap { display: none; } }
.guide-text { overflow: auto; padding: 28px 64px 16px 28px; box-sizing: border-box; }
.guide-intro { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--sage); color: var(--sage-ink); font-size: 13px; line-height: 1.6; }
.guide-intro b { display: inline-grid; place-items: center; width: 18px; height: 18px; border: 1px solid currentColor; border-radius: 50%; font-size: 11px; }
.guide-text h2 { margin: 0 0 10px; font-size: 18px; font-weight: var(--w-strong); }
.guide-text ol { margin: 0; padding: 0; list-style: none; }
.guide-text li { display: flex; gap: 10px; align-items: flex-start; margin-top: 9px; font-size: 13.5px; line-height: 1.6; }
.guide-text li b { flex: none; margin-top: 2px; }
.guide-text li.note { display: block; padding-left: 30px; font-size: 12.5px; color: var(--muted); }
.guide-text li.note::before { content: "※ "; }
.guide-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 28px 20px; border-top: 1px solid var(--line); }
.guide-never { font-size: 12px; color: var(--muted); cursor: default; }
.guide-never small { margin-left: 2px; font-size: 11px; }
.guide-dots { display: flex; gap: 6px; margin: 0 auto; }
.guide-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.guide-dots i.on { background: var(--ink); }
.guide-nav { display: flex; gap: 8px; }
.guide-nav button { min-width: 88px; height: 38px; }
/* スマホ: 絵を上、説明を下に。説明の欄の高さも固定して、長いときは欄の中でスクロール。‹ › は絵の高さの真ん中 */
@media (max-width: 720px) {
  .guide-head { padding-left: 18px; }
  .guide-slide { grid-template-columns: 1fr; grid-template-rows: 250px 300px; height: auto; }
  .guide-shot { padding: 16px 48px; }
  .guide-shot img { max-height: 218px; }
  .guide-arrow { top: 125px; width: 34px; height: 34px; margin-top: -17px; font-size: 22px; }
  .guide-arrow.prev { left: 6px; }
  .guide-arrow.next { right: 6px; }
  .guide-text { padding: 16px 18px 8px; }
  .guide-foot { padding: 12px 18px 16px; }
  .guide-dots { order: -1; width: 100%; justify-content: center; }
  .guide-nav { width: 100%; justify-content: flex-end; }
  .guide-nav button { min-width: 0; flex: 1; }
}
