:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1f2328; --muted: #6a737d; --line: #d8dbdf;
  --head: #2b3a4a; --headtext: #ffffff; --link: #0b5cad; --warn: #c0392b;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; padding: 12px 16px; background: var(--bg); color: var(--text); display: flex; flex-direction: column;
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif; font-size: 14px; line-height: 1.45; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 13px; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.note, .hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 12px; margin: 6px 0 4px; }
code { font-family: Consolas, monospace; font-size: 12px; }
a { color: var(--link); }
select, input, button { font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { color: var(--muted); cursor: default; opacity: .6; }
button.primary { background: var(--head); color: var(--headtext); border-color: var(--head); }
.right { margin-left: auto; }

.top { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-start; justify-content: space-between; }
.heading { flex: 1 1 420px; }
.filebar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.fname { font-weight: 600; max-width: 22em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 状態の文言が変わっても周りが動かないよう、最長の文言が入る幅を確保する */
.savestate { display: inline-block; min-width: 19em; font-size: 12px; color: var(--muted); }
.savestate.bad { color: var(--warn); }

.start { max-width: 760px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.start .target { font-weight: 700; }
.startbtns { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.format { overflow-x: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 12px; }
.formatnotes { font-size: 12px; color: var(--muted); padding-left: 18px; }

/* 作業画面: 上にツールバー、左に図面、右に一覧 */
main#app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.toolbar label { display: flex; gap: 4px; align-items: center; white-space: nowrap; }
#planSel { width: 16em; }
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.modes button { border: 0; border-radius: 0; }
.modes button + button { border-left: 1px solid var(--line); }
.modes button.on { background: var(--link); color: #fff; }
.autobtn { min-width: 11em; }
.histbtns { display: inline-flex; gap: 4px; }
/* 保存した版の一覧（増えても下の欄を押し下げすぎないよう、高さに上限を付けて中で送る） */
.verlist { max-height: 168px; overflow-y: auto; }
.vrow { display: flex; gap: 6px; align-items: center; margin: 3px 0; padding: 1px 2px; border-radius: 6px; transition: background-color .6s; }
.vrow.new { background: #e8f0fe; }
.vrow input { flex: 1; min-width: 0; }
.vmeta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.vauto { font-size: 10px; padding: 0 4px; margin-right: 4px; border-radius: 4px; background: #eceeef; color: var(--muted); }
.modehint { margin: 6px 2px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 1.5em; }
.work { flex: 1; min-height: 360px; display: grid; grid-template-columns: 1fr 400px; gap: 10px; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #eceeef;
  border: 1px solid var(--line); border-radius: 8px; user-select: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.side section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.frm { display: grid; gap: 4px; }
.frm label { display: grid; grid-template-columns: 3em 1fr; align-items: center; gap: 4px; font-size: 12px; }
.meta { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.frow { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.frow label { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; }
input.num { width: 6em; }
.px { display: inline-block; min-width: 9em; font-size: 12px; color: var(--muted); }
.scalenow { margin: 0; font-weight: 600; }
.scalenow.bad { color: var(--warn); }
.lrow { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.lrow input { flex: 1; min-width: 0; }
.lrow .area { font-size: 12px; color: var(--muted); min-width: 8em; text-align: right; }
.stats { display: grid; grid-template-columns: 6em 1fr; gap: 2px 8px; margin: 0; font-size: 13px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; }
.stats.muted dd { font-weight: 400; color: var(--muted); }

/* 家具のカード（図面へドラッグして置く）。一覧の高さは固定し、家具が増えても図面や下の欄を動かさない */
.furnsec { position: relative; }
.fcards { height: 212px; overflow-y: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 64px;
  gap: 6px; align-content: start; }
.fcard { display: grid; grid-template-columns: 26px minmax(0, 1fr); grid-template-rows: repeat(3, auto); column-gap: 4px; align-content: center;
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; background: var(--panel); cursor: grab; font-size: 12px; line-height: 1.35; }
.fcard:hover { border-color: var(--muted); }
.fcard.open { border-color: var(--link); box-shadow: inset 0 0 0 1px var(--link); }
/* 数量の分を置き終えたカード（ドラッグできない） */
.fcard.done { opacity: .5; cursor: pointer; }
.ficonbox { grid-row: 1 / span 3; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; }
.ficon { border: 1.5px solid var(--head); background: #e8f0fe; }
.fcname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fsize { color: var(--muted); white-space: nowrap; }
.fcfoot { display: flex; gap: 4px; align-items: center; }
.fwall { font-size: 10px; padding: 0 4px; border-radius: 4px; background: #e8f0fe; color: #1558b0; }
.fwall.off { visibility: hidden; }
/* 置いた数/数量（桁が変わっても周りが動かないよう幅を取る） */
.fcount { display: inline-block; min-width: 3.5em; font-size: 12px; color: var(--muted); }
.fcount.full { color: #2e8b45; font-weight: 700; }
/* 家具の編集欄（開いたカードのすぐ下に重ねる。top は JS で設定） */
.fedit { position: absolute; left: 6px; right: 6px; z-index: 5; display: grid; gap: 4px; background: var(--panel);
  border: 1px solid var(--link); border-radius: 8px; padding: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.fedit .fename { flex: 1; min-width: 0; font-weight: 600; }
.fedit .sub { margin: 0; }
.fedit .small input[type="number"] { width: 5em; padding: 2px 4px; }
.fedit .small input.cnt { width: 3.5em; }
.fedit .fnote { width: 100%; font-size: 12px; }

/* 図面が無いときの案内（図面の上に重ねる） */
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; text-align: center; color: var(--muted); background: rgba(236,238,239,.92); }
a.btnlink { display: inline-block; padding: 8px 14px; border-radius: 6px; background: var(--head); color: var(--headtext); text-decoration: none; }
/* 選択中の家具の操作（図面の下に重ねる。文言が変わっても位置は変わらない） */
.selbar { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 6px; align-items: center;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.selname { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinbtn { min-width: 6.5em; }
.rotlbl { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; white-space: nowrap; }
.rotlbl input { width: 5em; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: 80vw;
  background: var(--head); color: #fff; padding: 8px 14px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.25); font-size: 13px; }

/* 図面（SVG）。線の太さは拡大率に関係なく一定 */
svg.m-select { cursor: grab; }
svg.m-room, svg.m-scale, svg.m-keepout { cursor: crosshair; }
#bg.off { display: none; }
.room { fill: rgba(26,115,232,.06); stroke: #1a73e8; stroke-width: 2; vector-effect: non-scaling-stroke; }
.rname, .koname { text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: #fff; font-weight: 700; }
.rname { fill: #1558b0; }
.koname { fill: #a33f06; font-weight: 400; }
.vert { fill: #fff; stroke: #1a73e8; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: move; }
.vert.sel { fill: #1a73e8; }
.ko { stroke: #e8590c; stroke-width: 1.5; stroke-dasharray: 5 3; vector-effect: non-scaling-stroke; }
.ko.sel { stroke-width: 3; stroke-dasharray: none; }
svg.m-select .ko { cursor: pointer; }
.item { cursor: move; }
.item rect { fill: rgba(255,255,255,.85); stroke: #2b3a4a; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.item.wall rect { fill: rgba(232,240,254,.9); }
.item .back { stroke: #2b3a4a; stroke-width: 4; vector-effect: non-scaling-stroke; }
.item.pinned rect { stroke-dasharray: 6 3; }
.item.sel rect { stroke: #0b5cad; stroke-width: 3; }
/* 重なり・部屋からのはみ出し */
.item.bad rect { fill: rgba(253,226,225,.9); stroke: #d93025; stroke-width: 3; }
.item text { text-anchor: middle; dominant-baseline: middle; fill: #1f2328; pointer-events: none; paint-order: stroke; stroke: rgba(255,255,255,.8); }
.item text.dim { fill: #4a535c; }
svg:not(.m-select) .item, svg:not(.m-select) .ko { pointer-events: none; }
.draft { fill: none; stroke: #1a73e8; stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.draftpt { fill: #1a73e8; }
.draftpt.first { fill: #fff; stroke: #1a73e8; stroke-width: 2; vector-effect: non-scaling-stroke; }
.scl { stroke: #b3261e; stroke-width: 2; vector-effect: non-scaling-stroke; }
.sclpt { fill: #b3261e; }

@media (max-width: 900px) {
  .work { grid-template-columns: 1fr; grid-template-rows: minmax(360px, 60vh) auto; }
  .side { overflow: visible; }
}
