:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #1d1d1f;
  --sub: #6b6b70;
  --line: #e2e0da;
  --accent: #00adbb; /* 見積もりアプリの看板と同じ水色 */
  --ai: #f1f0ec;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Hiragino Sans", "Noto Sans JP", sans-serif; }
button, input, textarea { font: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--ink); color: #fff; }
.logo { font-weight: 800; letter-spacing: .05em; }
.logo span { font-weight: 500; font-size: 14px; margin-left: 8px; opacity: .8; }
.mode { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: #444; }
.mode.ai { background: #2e7d4f; }

.layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; padding: 16px; max-width: 1200px; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.preview, .side { background: var(--card); border-radius: 14px; padding: 16px; }
.stage { position: relative; background: #e9e7e1; border-radius: 10px; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; }
#mockup { width: 92%; height: 92%; touch-action: none; user-select: none; }
#mockup .obj { cursor: move; }
#mockup .handle { fill: #fff; stroke: #2b8cff; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
#mockup .handle.rot { cursor: grab; fill: #2b8cff; }
.pair { width: 96%; }
.pair svg { width: 100%; height: auto; display: block; }
.check { display: block; font-size: 13px; color: var(--sub); margin: 8px 0 4px; }

.group { margin-top: 12px; }
.label { font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 14px; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.chip:disabled { opacity: .35; cursor: default; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #0003; }

.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .4; cursor: default; }

.side { display: flex; flex-direction: column; height: calc(100vh - 90px); min-height: 560px; position: sticky; top: 16px; }
@media (max-width: 860px) { .side { height: 78vh; position: static; } }
.pane { flex: 1; overflow-y: auto; min-height: 0; }
.pane.chat { display: flex; flex-direction: column; overflow: hidden; }
.ai-main { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 10px; }
.ai-main .log { display: none; } /* やりとりの履歴は出さない（いちばん新しい返事だけ上に出す） */
.ai-main .label { margin-top: 12px; }
/* よく頼まれることのボタン（スマホでも押しやすい大きさで、3列） */
.ai-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ai-presets button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 4px; font-size: 13px; font-weight: 700; color: var(--ink); cursor: pointer; }
.ai-presets button:active { background: #e8f7f8; border-color: var(--accent); }
.ai-presets button:disabled { opacity: .5; }
.ai-main[hidden], .ai-empty[hidden] { display: none; }
.ai-empty { margin: auto 0; padding: 12px 4px; color: var(--sub); font-size: 14px; line-height: 1.7; }
.ai-goto { display: flex; gap: 8px; margin-top: 10px; }
.ai-goto .btn { flex: 1; }
.ai-target { flex: none; margin-top: 8px; font-size: 12px; color: var(--accent); font-weight: 700; }
.ai-latest { margin-top: 8px; background: #f3f2ee; border-radius: 12px; padding: 8px 12px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
.pane[hidden] { display: none; }
.log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.6; font-size: 15px; white-space: pre-wrap; }
.msg.ai { background: var(--ai); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--ink); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.err { background: #fde8e5; color: #a02a1a; align-self: flex-start; }
.msg.wait { color: var(--sub); }
.msg img { display: block; max-width: 160px; margin-top: 8px; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 6px; cursor: pointer; }
.hints { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.hints button { border: 1px dashed var(--line); background: none; border-radius: 99px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--sub); }
.input { display: flex; gap: 8px; }
.input textarea { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: none; }

dialog { border: none; border-radius: 14px; padding: 20px; width: min(420px, 92vw); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog label { display: block; font-size: 13px; margin-top: 12px; }
dialog input, dialog textarea { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.small { font-size: 13px; color: var(--sub); margin: 0; }

.tools { display: flex; gap: 6px; margin-bottom: 8px; }
.tool { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 14px; cursor: pointer; font-size: 13px; font-weight: 600; }
.font-panel { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; max-height: 46vh; overflow-y: auto; background: #fafaf8; }
.font-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--sub); margin-bottom: 8px; }
.font-head button { border: none; background: none; color: var(--sub); cursor: pointer; font-size: 12px; }
.font-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.font-item { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px; cursor: pointer; text-align: left; }
.font-item:hover { border-color: var(--ink); }
.font-item .sample { height: 34px; display: flex; align-items: center; overflow: hidden; }
.font-item .sample svg { height: 30px; width: auto; max-width: 100%; }
.font-item .name { font-size: 12px; font-weight: 700; margin-top: 4px; }
.font-item .desc { font-size: 11px; color: var(--sub); line-height: 1.4; }
.font-group { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--sub); margin-top: 4px; }

.bar { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--ink); color: #fff; }
.seg button:disabled { opacity: .35; cursor: default; }

.selbar { margin-top: 10px; border: 1px solid #cfe2ff; background: #f3f8ff; border-radius: 10px; padding: 8px 10px; }
.selsize { flex: none; font-size: 12px; line-height: 1.25; color: var(--sub); }
.selsize b { color: var(--ink); }
.selbtns { display: flex; flex-wrap: wrap; gap: 5px; }
.selbtns button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.selbtns button.danger { color: #c0392b; }
.selbtns button[hidden] { display: none; }
.warnings { margin-top: 8px; display: grid; gap: 4px; }
.warn { background: #fff4e0; color: #8a5300; border-radius: 8px; padding: 6px 10px; font-size: 13px; line-height: 1.5; }
.summary { margin-top: 8px; font-size: 13px; }
.sumtitle { font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.sumrow { display: grid; grid-template-columns: 4em 1fr auto; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 10px; background: var(--bg); padding: 4px; border-radius: 12px; }
.tabs button { border: none; background: none; padding: 8px 4px; border-radius: 9px; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--sub); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px #0001; }
.ptitle { font-weight: 800; font-size: 15px; margin: 4px 0 6px; }
.pane .label { margin-top: 12px; }
.pane textarea, .ai-text input[type=text] { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 15px; resize: vertical; }
.wide { display: block; width: 100%; margin-top: 12px; text-align: center; }
.upload { cursor: pointer; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.row input[type=range] { flex: 1; }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; position: relative; overflow: hidden; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
.sw.none { width: auto; border-radius: 99px; padding: 0 10px; font-size: 11px; background: #fff; }
.sw.pick { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.sw.pick input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.font-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 4px; max-height: 190px; overflow-y: auto; padding: 2px; }
.fm { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 3px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; gap: 0; min-width: 0; }
.fm svg { height: 13px; width: auto; max-width: 100%; }
.fm span { font-size: 9px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.fm.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }


.pending { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 10px; padding: 6px 8px; margin-bottom: 8px; font-size: 12px; }
.pending img { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 6px; }
.pending button { margin-left: auto; border: none; background: none; color: var(--sub); cursor: pointer; font-size: 12px; }
.pending[hidden] { display: none; }
.ai-text { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.ai-text select { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.ai-text input[type=color] { width: 40px; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
dialog .summary { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }

/* ---- 拡大ボタン・お知らせ ---- */
.sp { display: none !important; }
.tabs svg { display: none; }
/* 範囲の点線を出すかどうか（服の画面の左下） */
.box-check { position: absolute; left: 8px; bottom: 8px; z-index: 2; display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink); background: #fffe; border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px 4px 7px; cursor: pointer; }
.box-check input { margin: 0; accent-color: var(--accent); }
.zoom { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #fffe; font-size: 18px; line-height: 1; cursor: pointer; color: var(--ink); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; border-radius: 99px; padding: 10px 10px 10px 18px; display: flex; gap: 12px; align-items: center; font-size: 14px; z-index: 50; box-shadow: 0 6px 20px #0003; }
.toast[hidden] { display: none; }
.toast button { border: none; background: #fff; color: var(--ink); border-radius: 99px; padding: 6px 14px; font-weight: 700; cursor: pointer; }
#micBtn.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- スマホ：服を上に固定、下にメニュー ---- */
@media (max-width: 860px) {
  .pc { display: none; }
  .tabs .sp { display: flex !important; }
  .sheet-close.sp { display: block !important; }
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); display: flex; flex-direction: column; }
  input, textarea, select { font-size: 16px !important; } /* iPhone で入力時に画面が拡大されないように */
  .top { padding: 8px 12px; flex: none; }
  .logo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .logo span { font-size: 12px; }
  .top { gap: 8px; }
  .mode { white-space: nowrap; flex: none; }
  .mode { font-size: 10px; padding: 3px 8px; }
  body.kb .top, body.kb .undo-seg, body.kb .nav, body.kb .pager, body.kb .selbar, body.kb .warnings, body.kb .zoom, body.kb .box-check { display: none !important; }

  .layout { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; gap: 0; max-width: none; }
  /* 服の画面は、下のパネルを開いても高さ60%を保つ（パネルのほうを小さくしてスクロールさせる） */
  /* 服は横幅いっぱいに大きく。高さは服がちょうど収まる分だけ（余った分は下の欄に回す） */
  .preview { flex: none; min-height: 0; display: flex; flex-direction: column; border-radius: 0; padding: 4px; }
  .bar { flex: none; margin-bottom: 6px; flex-wrap: nowrap; }
  .seg button { padding: 7px 11px; }
  .stage { flex: none; height: calc(min(var(--app-h, 100dvh) * 0.6, 100vw) - 8px); min-height: 0; aspect-ratio: auto; }
  body.kb .stage { height: calc(var(--app-h, 100dvh) * 0.42 - 8px); }
  #mockup { width: 100%; height: 100%; }
  .pair { width: 100%; }
  /* 選んだ部品の欄は、服の画面のすぐ下に出す（プリント範囲に重ならないように。服の大きさは変わらない） */
  /* 2行だけ（大きさ＋スライダー／ボタン）で、縦を小さく */
  .selbar { margin: 4px 0 0; padding: 3px 6px 4px; }
  .selsize { font-size: 11px; white-space: nowrap; }
  .selbtns { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .selbtns { gap: 4px; }
  .selbtns button { flex: 1 1 0; min-width: 38px; padding: 5px 0; font-size: 12px; } /* 8つが1行に収まるように、横幅を等分 */
  /* 注意は1行だけ見せて、押すと全部ひらく */
  /* 注意は服の上に重ねて出す（服の大きさを変えないため） */
  .preview { position: relative; }
  .warnings { position: absolute; left: 18px; right: 18px; top: 46px; z-index: 3; margin: 0; max-height: 27px; overflow: hidden; cursor: pointer; box-shadow: 0 2px 8px #0002; border-radius: 8px; }
  .warnings.open { max-height: 30vh; overflow-y: auto; }
  .warnings[data-more]:not(.open)::after { content: attr(data-more); position: absolute; right: 4px; top: 3px; background: #8a5300; color: #fff; font-size: 10px; border-radius: 99px; padding: 1px 7px; }
  .warn { padding: 4px 8px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .warnings.open .warn { white-space: normal; }

  .side { flex: 1; height: auto; min-height: 0; position: static; border-radius: 18px 18px 0 0; padding: 0; box-shadow: 0 -6px 18px #0000001a; display: flex; flex-direction: column; }
  .sheet-close { order: 1; border: none; background: none; padding: 8px 0 6px; cursor: pointer; }
  .sheet-close span { display: block; width: 44px; height: 5px; border-radius: 3px; background: #d0cec8; margin: 0 auto; }
  .pane { order: 2; flex: 1; height: auto; min-height: 0; padding: 0 14px calc(10px + env(safe-area-inset-bottom)); }
  body.sheet-closed .side { flex: none; }
  body.sheet-closed .pane, body.sheet-closed .sheet-close { display: none !important; }
  .tabs { flex: none; grid-template-columns: repeat(4, 1fr); margin: 0; border-radius: 0; padding: 2px 4px; background: #fff; border-bottom: 1px solid var(--line); }
  body.kb .tabs { display: none; }
  /* メニューは細長く（アイコンと文字を横に並べる） */
  .tabs button { display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 3px; font-size: 11px; padding: 4px 2px; white-space: nowrap; }
  .tabs svg { display: block; width: 16px; height: 16px; flex: none; fill: currentColor; }
  .tabs button.on { box-shadow: none; color: var(--accent); background: none; }
  body.sheet-closed .tabs button.on { color: var(--sub); }

  .msg { font-size: 14px; }
  .hints { margin: 6px 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .hints button { flex: none; }
  .tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tool { flex: none; }
  .font-panel { max-height: none; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---- 前・後ろの切りかえ（左右にスワイプ） ---- */
.bar { align-items: center; }
.page-name { position: absolute; top: 10px; left: 10px; z-index: 2; font-weight: 800; font-size: 14px; background: #ffffffd9; border-radius: 8px; padding: 4px 10px; pointer-events: none; }
.undo-seg { position: absolute; left: 8px; bottom: 44px; z-index: 2; background: #fff; }
.undo-seg button { display: inline-flex; align-items: center; gap: 4px; }
.undo-seg .tri { width: 9px; height: 9px; fill: currentColor; flex: none; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); width: 34px; height: 54px; border: none; background: #ffffffb0; border-radius: 10px; font-size: 26px; line-height: 1; color: var(--ink); cursor: pointer; z-index: 2; }
.nav.prev { left: 6px; }
.nav.next { right: 6px; }
.nav:disabled { visibility: hidden; }
.pager { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; z-index: 2; }
.pager button { width: 9px; height: 9px; border-radius: 50%; border: none; padding: 0; background: #0003; cursor: pointer; }
.pager button.on { background: var(--ink); width: 22px; border-radius: 99px; }
#mockup.slide-l, #pair.slide-l { animation: slideL .22s ease-out; }
#mockup.slide-r, #pair.slide-r { animation: slideR .22s ease-out; }
@keyframes slideL { from { transform: translateX(14%); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes slideR { from { transform: translateX(-14%); opacity: .3; } to { transform: none; opacity: 1; } }
#pair { touch-action: pan-y; }
@media (max-width: 860px) {
  .nav { width: 28px; height: 46px; font-size: 22px; }
}

.chat-guide { margin: auto 0; text-align: left; color: #9a9890; font-size: 14px; line-height: 1.7; padding: 12px 4px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.presets button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.val { font-size: 12px; color: var(--sub); width: 2.5em; text-align: right; }

/* ---- 右上の「保存・相談」 ---- */
.top-right { display: flex; align-items: center; gap: 10px; flex: none; }
.save-wrap { position: relative; }
.save-btn { display: flex; align-items: center; gap: 6px; border: none; background: var(--accent); color: #fff; border-radius: 99px; padding: 7px 14px; font-weight: 700; font-size: 13px; cursor: pointer; }
.save-btn svg { width: 16px; height: 16px; }
.save-btn:disabled { opacity: .45; cursor: default; }
.save-menu { position: absolute; right: 0; top: calc(100% + 8px); background: #fff; border-radius: 12px; box-shadow: 0 10px 30px #0003; padding: 6px; display: grid; gap: 4px; min-width: 230px; z-index: 60; }
.save-menu[hidden] { display: none; }
.save-menu button { border: none; background: none; text-align: left; padding: 11px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.save-menu button:hover { background: var(--bg); }
.save-menu button.primary { background: var(--accent); color: #fff; }
.save-menu button:disabled { opacity: .4; cursor: default; }
.save-menu button[hidden] { display: none; }
@media (max-width: 860px) {
  .save-btn { padding: 6px 10px; font-size: 12px; }
  .top-right { gap: 6px; }
}

/* ---- ロゴ（手書き風。文字は図形にしてあるので、書体を読みこまなくてよい） ---- */
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark { height: 22px; width: auto; display: block; color: #fff; }
.logo .logo-item { margin: 0; opacity: 1; font-size: 13px; font-weight: 700; color: #fff; background: #ffffff22; border-radius: 99px; padding: 3px 10px; white-space: nowrap; letter-spacing: 0; }
@media (max-width: 860px) { .logo-mark { height: 18px; flex: none; } .logo { gap: 6px; } .logo .logo-item { font-size: 12px; padding: 2px 8px; } }

.q-good { color: #1f8a4c; }
.q-mid { color: #a35d00; }
.q-low { color: #c0362c; }
.img-info { margin-bottom: 10px; }
.q-box-mid, .q-box-low { border-radius: 10px; padding: 8px 10px; }
.q-box-mid { background: #fff6e8; }
.q-box-low { background: #fdeceb; }
.img-info .btn { margin-top: 8px; background: #fff; }
.toast { width: max-content; max-width: min(440px, calc(100vw - 32px)); border-radius: 14px; }
.toast span { flex: 1; min-width: 0; }
.toast span { line-height: 1.5; }
.toast button { flex: none; }

/* ---- 大きさのスライダー ---- */
.size-row { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; }
.size-row input { flex: 1; accent-color: var(--accent); height: 28px; }
@media (max-width: 860px) {
  .size-row { margin-bottom: 2px; }
  .size-row input { height: 24px; } /* 指で動かしやすく */
}

