:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d212c;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b92a3;
  --accent: #6aa3ff;
  --accent-2: #3b6fd4;
  --danger: #e06a6a;
  --user: #243047;
  --radius: 10px;
  --sidebar-w: 280px;
}

:root { color-scheme: dark; } /* ネイティブ要素(select候補/スクロールバー)もダークに */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
#app { height: 100%; }

/* ---------- レイアウト ---------- */
.layout { display: flex; height: 100%; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.scrim { display: none; }

/* ---------- サイドバー ---------- */
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 8px;
}
.project-select { width: 100%; }
.project-actions { display: flex; gap: 12px; margin-top: 8px; }

.chat-list { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text);
}
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: var(--bg-3); outline: 1px solid var(--border); }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-item .icon-btn { opacity: 0; }
.chat-item:hover .icon-btn, .chat-item.active .icon-btn { opacity: .7; }

.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- トップバー ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.crumb { color: var(--muted); font-weight: 400; }
.topbar-chip { flex-shrink: 0; }
.head-actions { display: inline-flex; gap: 2px; }

/* ---------- 空状態 ---------- */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 0; }

/* ---------- チャット ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-area { flex: 1; display: flex; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px clamp(12px, 6vw, 80px); }
.chat-area.with-panel .messages { padding: 20px clamp(12px, 3vw, 32px); }
.msg { max-width: 820px; margin: 0 auto 22px; }
.msg-role { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg-body {
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: var(--radius); overflow-wrap: anywhere;
}
.msg.user .msg-body { background: var(--user); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body pre {
  background: #0b0d12; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto;
}
.msg-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.msg-body :not(pre) > code { background: #0b0d12; padding: 2px 5px; border-radius: 4px; }
.msg-body table { border-collapse: collapse; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 6px 10px; }

.reasoning { margin-bottom: 8px; border: 1px dashed var(--border); border-radius: 8px; padding: 6px 12px; background: var(--bg-2); }
.reasoning summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.reasoning-body { margin-top: 8px; color: var(--muted); font-size: 14px; }

.verify { margin-top: 10px; border: 1px solid #6a5acd; border-radius: 8px; padding: 8px 14px; background: rgba(106,90,205,.08); }
.verify summary { cursor: pointer; color: #b3a8ff; font-size: 13px; font-weight: 600; }
.verify-body { margin-top: 8px; font-size: 14px; }
.verify-body > :first-child { margin-top: 0; }

.refine-draft { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 160px; overflow-y: auto; }
.refine-edit { width: 100%; resize: vertical; }
.refine-critique { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; max-height: 220px; overflow-y: auto; }
.refine-critique > :first-child { margin-top: 0; }
.refine-rewrite { background: rgba(59,111,212,.12); border: 1px solid var(--accent-2); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* 選択時に浮かぶ「＋コンテキスト」ボタン */
.sel-float {
  position: fixed; z-index: 60; transform: translateY(-100%);
  background: var(--accent-2); color: #fff; border-radius: 8px; padding: 5px 10px;
  font-size: 12px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.4); white-space: nowrap;
}
.sel-float:hover { background: var(--accent); }

.cursor { animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.msg-role { display: flex; align-items: center; gap: 8px; }
.msg-action { color: var(--muted); font-size: 11px; border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; opacity: 0; }
.msg:hover .msg-action { opacity: .8; }
.msg-action:hover { color: var(--accent); border-color: var(--accent-2); }

.usage { margin-top: 6px; font-size: 11px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.usage.search-usage { margin-top: 2px; opacity: .85; }
.stage-foot .usage, .verify .usage { display: inline-block; margin-top: 0; margin-left: 8px; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.sources-label { font-size: 11px; color: var(--muted); }
.source {
  font-size: 12px; color: var(--accent); text-decoration: none;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source:hover { border-color: var(--accent-2); }

.status-pill {
  max-width: 820px; margin: 0 auto 16px; color: var(--muted); font-size: 13px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; width: fit-content; display: block;
}

/* リモート生成(☁)の進行表示 */
.remote-note {
  color: var(--muted); font-size: 12px; margin: 2px 0 6px;
  border: 1px dashed var(--border); border-radius: 8px; padding: 5px 10px;
  width: fit-content;
}

/* 逆質問カード(検索前の確認) */
.clarify-card {
  max-width: 820px; margin: 0 auto 16px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.clarify-head { font-size: 13px; margin-bottom: 8px; }
.clarify-q { margin: 10px 0; }
.clarify-question { font-size: 13px; margin-bottom: 6px; }
.clarify-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.clarify-free {
  width: 100%; background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px;
}
.clarify-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* 💡 カード候補バナー(会話から抽出した前提をカード化するか選ぶ) */
.suggest-banner {
  border-top: 1px solid var(--border); background: var(--bg-2);
  padding: 10px clamp(12px, 6vw, 80px); max-height: 40vh; overflow-y: auto;
}
.suggest-head { font-size: 13px; color: var(--accent); margin-bottom: 6px; }
.suggest-item { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.suggest-item input { margin-top: 3px; flex-shrink: 0; }
.suggest-text { overflow-wrap: anywhere; }
.suggest-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 8px; }
.ctx-suggest { margin-top: 6px; width: 100%; }

/* ---------- コンテキストパネル ---------- */
.context-panel {
  width: 320px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 0;
}
.context-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.context-add { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.context-add textarea { width: 100%; resize: vertical; }
.ctx-add-row { display: flex; gap: 8px; align-items: center; }
.ctx-add-row select { flex: 1; padding: 6px 8px; font-size: 13px; }
.ctx-scope { margin-bottom: 14px; }
.ctx-scope-title { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 6px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.ctx-scope-title .muted { font-weight: 400; }
.small-btn { padding: 6px 14px; align-self: flex-end; }
.context-list { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.pad-sm { padding: 16px 0; }

.ctx-card { background: var(--bg-3); border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: 8px; padding: 10px 12px; }
.ctx-card-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 8px; }
.ctx-note { width: 100%; resize: vertical; min-height: 32px; font-size: 13px; margin-bottom: 8px; background: var(--bg-2) !important; }
.ctx-card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctx-card-foot select { padding: 3px 8px; font-size: 13px; }
.ctx-send { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-left: auto; cursor: pointer; }
.ctx-send.dim { opacity: .5; }
.ctx-send input { width: auto; }

.context-legend { border-top: 1px solid var(--border); padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.legend { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }

/* ---------- ブランチ可視化 ---------- */
.branch-summary { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.branch-list { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.branch-item { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: flex; gap: 8px; align-items: flex-start; }
.branch-main { flex: 1; min-width: 0; }
.branch-label { font-size: 13px; font-weight: 600; }
.branch-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.branch-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; align-items: flex-end; }
.msg.flash { animation: flash 1.3s ease; }
@keyframes flash { 0%, 30% { background: rgba(106,163,255,.18); border-radius: 8px; } 100% { background: transparent; } }

/* ---------- 相談サブスレッド ---------- */
.scratch-panel { display: flex; flex-direction: column; }
.scratch-bar { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.scratch-bar select { flex: 1; padding: 4px 8px; font-size: 13px; }
.scratch-ref { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 4px 14px 0; cursor: pointer; }
.scratch-ref input { width: auto; }
.scratch-note { padding: 8px 14px 0; }
.scratch-list { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.scratch-msg { font-size: 14px; }
.scratch-role { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.scratch-msg.user .scratch-body { background: var(--user); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.scratch-msg.assistant .scratch-body { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; overflow-wrap: anywhere; }
.scratch-body > :first-child { margin-top: 0; }
.scratch-body > :last-child { margin-bottom: 0; }
.scratch-actions { display: flex; gap: 4px; margin-top: 4px; }
.scratch-input { border-top: 1px solid var(--border); padding: 8px 14px; display: flex; flex-direction: column; gap: 6px; }
.scratch-input-row { display: flex; gap: 8px; align-items: flex-end; }
.scratch-input-row textarea { flex: 1; resize: vertical; min-height: 44px; }

.chip { color: var(--text); background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.chip:hover { border-color: var(--accent-2); }
.chip.on { border-color: var(--accent-2); color: var(--accent); }
.chip em { font-style: normal; background: var(--accent-2); color: #fff; border-radius: 999px; padding: 0 7px; margin-left: 4px; font-size: 12px; }

/* ---------- 同時発言(比較) ---------- */
.compare-wrap { position: relative; display: inline-block; }
.compare-pop {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 30;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px;
  width: 240px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.compare-pop-head { font-size: 12px; color: var(--muted); padding: 4px 6px 8px; }
.compare-opt { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.compare-opt:hover { background: var(--bg-3); }
.compare-opt input { width: auto; }
.compare-pop-foot { display: flex; justify-content: space-between; padding: 6px 6px 2px; border-top: 1px solid var(--border); margin-top: 4px; }

/* 生成パラメータ */
.gen-pop { width: 260px; }
.gen-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 4px 6px 8px; font-size: 12px; }
.gen-row { display: flex; flex-direction: column; gap: 4px; padding: 6px; font-size: 12px; color: var(--muted); }
.gen-row input[type=range] { width: 100%; }
.gen-row input[type=number] { width: 100%; }
.gen-foot { display: flex; justify-content: space-between; padding: 6px; border-top: 1px solid var(--border); margin-top: 4px; }

/* モデル既定パラメータ編集 */
.mm-rowwrap { display: flex; flex-direction: column; gap: 4px; }
.mm-params { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mm-params label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.mm-params input { width: 90px; }
.mm-params .muted.small { flex-basis: 100%; }

.msg.multi { max-width: 1100px; }
.variants { display: grid; gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.variant { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.variant.chosen { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.variant-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.variant-model { font-size: 12px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.variant-actions { display: flex; gap: 4px; flex-shrink: 0; }
.variant .msg-body { background: transparent; border: none; padding: 0; }
.variant .msg-action.active { color: var(--accent); border-color: var(--accent-2); opacity: 1; }
.variant .msg-action { opacity: .85; }
.variant.focused { width: 100%; }
.variant-focus { display: flex; flex-direction: column; gap: 8px; }
.vbadge { font-style: normal; font-size: 10px; border-radius: 999px; padding: 0 6px; margin-left: 6px; vertical-align: middle; }
.chosen-badge { background: var(--accent-2); color: #fff; }
.default-badge { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.multi-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; }

.report { margin-top: 10px; border: 1px solid #d9a441; border-radius: 8px; padding: 8px 14px; background: rgba(217,164,65,.08); }
.report summary { cursor: pointer; color: #e6c07b; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.report-body { margin-top: 8px; font-size: 14px; }
.report-body > :first-child { margin-top: 0; }

/* ---------- サブエージェント ---------- */
.wf-pop { width: 260px; }
.wf-agents { max-height: 160px; overflow-y: auto; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.msg.agentic { max-width: 900px; }
.agentic-plan { margin: 4px 0 8px; }
.agentic-steps { border: 1px solid #6a5acd; border-radius: 8px; padding: 6px 12px; background: rgba(106,90,205,.07); margin-bottom: 10px; }
.agentic-steps summary { cursor: pointer; color: #b3a8ff; font-size: 13px; font-weight: 600; }
.agentic-step { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.agentic-step:first-of-type { border-top: none; }
.agentic-step-head { font-size: 12px; font-weight: 600; }
.agentic-task { margin: 2px 0 4px; }
.agentic-step .msg-body { background: transparent; border: none; padding: 4px 0 0; }
.agentic-final .msg-body { border-color: var(--accent-2); }
.agent-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.agent-card { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.agent-row { display: flex; gap: 8px; align-items: center; }
.agent-name { flex: 1; }
.agent-desc { width: 100%; }
.agent-card textarea { width: 100%; resize: vertical; }

/* ---------- 役割分担パイプライン ---------- */
.msg.pipeline { max-width: 860px; }
.stage { margin-top: 10px; border: 1px solid var(--border); border-left: 3px solid #7aa2f7; border-radius: 8px; padding: 8px 14px; background: var(--bg-2); }
.stage summary { cursor: pointer; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stage-model { font-weight: 400; font-size: 12px; color: var(--muted); }
.stage .msg-body { background: transparent; border: none; padding: 8px 0 0; }
.stage-foot { margin-top: 6px; }
.pipe-stage { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.pipe-stage:last-of-type { border-bottom: none; }
.pipe-stage-head { display: flex; align-items: center; gap: 8px; flex: 1; cursor: pointer; }
.pipe-stage-head input { width: auto; }
.pipe-stage select { min-width: 150px; }

/* ---------- モデル管理 ---------- */
.mm-section { margin-bottom: 18px; }
.mm-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.mm-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.mm-row, .mm-cat-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; }
.mm-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mm-row-main strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-id { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-meta { font-size: 11px; color: var(--muted); }
.mm-reason { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.mm-reason input { width: auto; }
.mm-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.mm-filters input[type=text] { flex: 1; min-width: 160px; }
.mm-results { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.mm-cat-row .small-btn { flex-shrink: 0; }
.mm-matrix-wrap { overflow-x: auto; }
.mm-matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
.mm-matrix th, .mm-matrix td { border: 1px solid var(--border); padding: 6px 8px; text-align: center; }
.mm-matrix th:first-child, .mm-matrix td.mm-matrix-name { text-align: left; }
.mm-matrix-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-matrix thead th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg-2); }
.mm-matrix input { width: auto; }

/* ---------- 代重ね ---------- */
.handoff { max-width: 820px; margin: 0 auto 22px; }
.handoff details {
  background: var(--bg-2); border: 1px solid var(--accent-2); border-radius: var(--radius); padding: 10px 16px;
}
.handoff summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.handoff .lineage { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }
.handoff-body { margin-top: 8px; }
.handoff-body > :first-child { margin-top: 0; }
.handoff-edit { margin-top: 8px; }
.handoff-edit textarea { width: 100%; resize: vertical; }
.handoff-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.succ-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.succ-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.succ-item:hover { background: var(--bg-3); }
.succ-list input[type=checkbox] { width: auto; flex: 0 0 auto; margin: 0; }
.succ-item span { flex: 1; }
.succ-builder { display: flex; gap: 12px; }
.succ-src, .succ-basket { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.succ-src select { margin-bottom: 8px; }
.succ-pieces { border: 1px solid var(--border); border-radius: 8px; padding: 6px; height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.succ-basket { border: 1px dashed var(--accent-2); border-radius: 8px; padding: 6px; height: 332px; overflow-y: auto; gap: 6px; }
.succ-basket-head { font-size: 12px; color: var(--muted); padding: 4px 6px; position: sticky; top: 0; background: var(--bg-2); }
.succ-piece, .succ-bitem { display: flex; align-items: center; gap: 6px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.succ-piece { cursor: grab; }
.succ-piece:active { cursor: grabbing; }
.succ-piece-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.succ-piece-main strong { font-size: 12px; }
.succ-piece-text { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.succ-opts { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin: 12px 0 4px; }
.succ-progress {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  max-height: 200px; overflow-y: auto; white-space: pre-wrap; font-size: 13px; color: var(--muted);
}

.error-banner {
  max-width: 820px; margin: 0 auto 16px; background: rgba(224,106,106,.12);
  border: 1px solid var(--danger); color: #f3b6b6; padding: 10px 14px; border-radius: 8px;
}

/* ---------- 入力欄 ---------- */
.composer { position: relative; border-top: 1px solid var(--border); background: var(--bg-2); padding: 12px clamp(12px, 6vw, 80px); }
/* 折りたたみ: .min=機能ボタン行を隠す / .gone=入力エリア全体を隠す(下書きは保持) */
.composer.min .composer-controls { display: none; }
.composer.gone { display: none; }
.composer-toggles { position: absolute; top: -13px; right: 12px; display: flex; gap: 6px; z-index: 5; }
.composer-toggle {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 999px;
  font-size: 11px; color: var(--muted); padding: 2px 10px; line-height: 1.5;
}
.composer-toggle:hover { color: var(--text); border-color: var(--accent-2); }
.composer-restore {
  position: fixed; right: 14px; bottom: 14px; z-index: 30;
  background: var(--accent-2); color: #fff; border-radius: 999px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.composer-restore:hover { background: var(--accent); }
.composer-controls { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; max-width: 820px; margin-left: auto; margin-right: auto; }
.ctrl { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ctrl.disabled { opacity: .45; }
.ctrl.toggle { gap: 6px; }
.soon { font-style: normal; color: var(--accent); font-size: 11px; }

.composer-input { display: flex; gap: 10px; align-items: flex-end; max-width: 820px; margin: 0 auto; }
.composer-input textarea {
  flex: 1; resize: vertical; min-height: 52px; max-height: 240px;
}
.composer-input.tall textarea { min-height: 45vh; max-height: 70vh; }
.composer-expand { align-self: flex-start; flex-shrink: 0; }

/* ---------- フォーム要素 ---------- */
input, textarea, select, button { font: inherit; color: var(--text); }
/* type属性の有無に関わらず暗背景を当てる(checkbox/radioは除外) */
input:not([type=checkbox]):not([type=radio]), textarea, select {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-2); }
/* ブラウザの自動補完で白背景になるのを防ぐ */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-3) inset;
  caret-color: var(--text);
}
select { cursor: pointer; }

button { cursor: pointer; border: none; background: none; }
.primary { background: var(--accent-2); color: #fff; border-radius: 8px; padding: 9px 18px; font-weight: 600; }
.primary:hover { background: var(--accent); }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.primary.stop { background: var(--danger); }
.ghost { border: 1px solid var(--border); border-radius: 8px; padding: 9px 18px; }
.ghost:hover { background: var(--bg-3); }
.link-btn { color: var(--accent); font-size: 13px; padding: 0; }
.link-btn.danger { color: var(--danger); }
.icon-btn { color: var(--muted); font-size: 16px; padding: 4px 6px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.tiny { font-size: 12px; padding: 2px 4px; }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 40px 0; }

/* ---------- モーダル ---------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal.modal-wide { width: min(840px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea { width: 100%; }
.field small { display: block; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.exp-row { display: flex; gap: 10px; flex-wrap: wrap; }
.sync-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }

/* APIキー保管庫(設定→クラウド同期) */
.vault { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); }
.vault-title { font-size: 12px; color: var(--accent); margin-bottom: 6px; }
.vault-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 1px 0; }
.vault-on { color: var(--accent); }
.vault-info { display: block; margin-top: 4px; color: var(--accent); }

/* ---------- モバイル ---------- */
.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.5);
  }
  .layout.sidebar-open .sidebar { transform: translateX(0); }
  .layout.sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }

  .context-panel {
    position: fixed; inset: 0 0 0 auto; width: min(340px, 88vw); z-index: 38;
    box-shadow: 0 0 40px rgba(0,0,0,.5);
  }
  .composer-controls { gap: 10px; }
  .composer { padding: 10px 12px; }
  /* タッチ操作向け: 選択フロートと折りたたみトグルを押しやすく */
  .sel-float { padding: 9px 14px; font-size: 13px; }
  .composer-toggle { padding: 4px 12px; font-size: 12px; }
  .composer-restore { bottom: 16px; right: 12px; }
}
