/* ---------------------------------------------------------------------------
   デザイントークン（ライト/ダーク）
   --------------------------------------------------------------------------- */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e8ebef;
  --line: #dfe3e8;
  --line-strong: #c9d0d8;
  --text: #171b21;
  --text-muted: #5d6772;
  --text-faint: #8b95a1;
  --accent: #2f6feb;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;
  --ok: #1f8a5c;
  --ok-soft: #e6f4ec;
  --warn: #8a6100;
  --warn-soft: #fdf3dd;
  --danger: #b4341f;
  --danger-soft: #fdeceb;
  --user-bubble: #eef1f5;
  --code-bg: #f7f8fa;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 10px;
  --radius-sm: 7px;
  --rail-width: 264px;
  --inspector-width: 400px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1014;
  --surface: #14181e;
  --surface-2: #1a1f26;
  --surface-3: #222831;
  --line: #262c35;
  --line-strong: #333a45;
  --text: #e7ebf0;
  --text-muted: #9aa4b1;
  --text-faint: #6d7885;
  --accent: #6f9cff;
  --accent-soft: #1b2534;
  --accent-text: #0b0f14;
  --ok: #56c596;
  --ok-soft: #14251d;
  --warn: #e0b558;
  --warn-soft: #241f13;
  --danger: #f08a7a;
  --danger-soft: #2a1917;
  --user-bubble: #1d232c;
  --code-bg: #10141a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button, textarea, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: not-allowed; opacity: .45; }
code { font-family: var(--mono); font-size: .92em; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
   アプリ全体の骨格
   --------------------------------------------------------------------------- */

.app {
  display: grid;
  /* 行を minmax(0,1fr) にしないと、内容の多いペインに引っ張られて
     コンポーザが画面外へ押し出される。 */
  grid-template-columns: var(--rail-width) minmax(0, 1fr) var(--inspector-width);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
.app.rail-closed { grid-template-columns: 0 minmax(0, 1fr) var(--inspector-width); }
.app.inspector-closed { grid-template-columns: var(--rail-width) minmax(0, 1fr) 0; }
.app.rail-closed.inspector-closed { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app.rail-closed .rail { transform: translateX(-100%); }
.app.inspector-closed .inspector { transform: translateX(100%); }

/* ---------------------------------------------------------------------------
   左レール
   --------------------------------------------------------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: transform .18s ease;
}
.rail-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.brand-mark {
  width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 8px; background: var(--text); color: var(--bg);
  font-size: 10px; font-weight: 800; letter-spacing: .04em;
}
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 13px; }
.brand-text span { display: block; font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.new-session {
  margin: 6px 12px 14px; padding: 9px 12px; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 12.5px; font-weight: 600;
}
.new-session:hover { border-color: var(--accent); color: var(--accent); }
.new-session .plus { font-size: 14px; line-height: 1; }

.rail-section { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px; }
.rail-label, .panel-label {
  margin: 12px 8px 6px; color: var(--text-faint);
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
}
.recent-list { display: grid; gap: 1px; }
.recent-row { display: flex; align-items: center; gap: 2px; border-radius: var(--radius-sm); }
.recent-row:hover { background: var(--surface-2); }
.recent-row.active { background: var(--accent-soft); }
.recent-project {
  flex: 1; min-width: 0; padding: 8px 9px; text-align: left; font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recent-row.active .recent-project { color: var(--accent); font-weight: 600; }
.row-delete {
  flex: 0 0 auto; padding: 4px 7px; border-radius: 6px; color: var(--text-faint);
  font-size: 14px; line-height: 1; visibility: hidden;
}
.recent-row:hover .row-delete { visibility: visible; }
.row-delete:hover { color: var(--danger); background: var(--danger-soft); }

.rail-foot { padding: 10px 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }

/* ---------------------------------------------------------------------------
   フィールド共通
   --------------------------------------------------------------------------- */

.field { display: grid; gap: 4px; font-size: 11px; color: var(--text-muted); }
.field select, .field input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 12.5px;
}
.field select:focus, .field input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.ghost-button {
  padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-muted); font-size: 11.5px; font-weight: 600;
}
.ghost-button:hover { color: var(--text); border-color: var(--accent); }
.icon-button {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 15px;
}
.icon-button:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.primary-button {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-text); font-size: 12.5px; font-weight: 700;
}
.primary-button:hover:not(:disabled) { filter: brightness(1.06); }

/* ---------------------------------------------------------------------------
   中央（チャット）
   --------------------------------------------------------------------------- */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.topbar h1 {
  margin: 0; font-size: 13.5px; font-weight: 650; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.pill {
  padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 700;
}
/* ★ MOCK バッジ: 誤って本番と勘違いしないよう、警告色で大きく出す。 */
.pill.mock {
  background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn);
  letter-spacing: 0.08em;
}
.connection-info { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.connection-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.connection-row code { font-size: 11px; word-break: break-all; }
.mock-note { color: var(--warn); font-weight: 700; }
.raw-actions { display: flex; gap: 6px; margin: 6px 0; }
.raw-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.raw-entry { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 11px; }
.raw-entry > summary { cursor: pointer; word-break: break-all; }
.raw-label { margin: 6px 0 2px; font-size: 10px; color: var(--text-muted); }
.raw-pre {
  margin: 0; padding: 6px; border-radius: 6px; background: var(--code-bg, rgba(127, 127, 127, 0.12));
  font-size: 10px; line-height: 1.45; white-space: pre-wrap; word-break: break-all;
  max-height: 240px; overflow: auto;
}

.transcript { flex: 1; min-height: 0; overflow-y: auto; }
.thread { max-width: 780px; margin: 0 auto; padding: 26px 24px 12px; }

/* 「最新へ ↓」— 追従が止まっている間だけ、スクロール領域の右下に貼り付く。
   sticky なのでコンポーザの高さが変わっても位置がずれない。 */
.scroll-latest-wrap {
  position: sticky; bottom: 10px; z-index: 3;
  display: flex; justify-content: flex-end;
  padding: 0 18px; pointer-events: none;
}
.scroll-latest {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  font-size: 11.5px; font-weight: 650;
}
.scroll-latest:hover { border-color: var(--accent); color: var(--accent); }
.scroll-latest-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent); animation: pulse 1.2s infinite;
}

.hero { text-align: center; padding: 12vh 8px 0; }
.hero h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; }
.hero p { margin: 0 auto; max-width: 560px; color: var(--text-muted); font-size: 13px; }
.examples { margin: 22px auto 0; display: grid; gap: 8px; max-width: 560px; }
.example {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text-muted); text-align: left; font-size: 12.5px;
}
.example:hover { border-color: var(--accent); color: var(--accent); }

.message { display: flex; gap: 12px; margin-bottom: 22px; }
.message .avatar {
  flex: 0 0 auto; width: 26px; height: 26px; margin-top: 2px; border-radius: 8px;
  display: grid; place-items: center; font-size: 10px; font-weight: 800;
  background: var(--surface-3); color: var(--text-muted);
}
.message.user .avatar { background: var(--text); color: var(--bg); }
.message.assistant .avatar { background: var(--accent-soft); color: var(--accent); }
.message-body { min-width: 0; flex: 1; }
.message-role { margin: 0 0 4px; font-size: 11px; font-weight: 700; color: var(--text-faint); }
.message-text { white-space: pre-wrap; word-break: break-word; }
.message.user .message-text {
  display: inline-block; padding: 9px 13px; border-radius: var(--radius);
  background: var(--user-bubble);
}
.message.error .message-text { color: var(--danger); }
/* タイムアウト・通信断は「失敗」ではなく「まだ終わっていない」。
   赤（--danger）ではなく warn 色で出し、進行中の見た目にする。 */
.message.waiting .message-text { color: var(--warn); }
.waiting-note {
  color: var(--warn); background: var(--warn-soft); border-radius: 6px;
  padding: 6px 9px; margin: 6px 0 0;
}
.pill.waiting { background: var(--warn-soft); color: var(--warn); }

/* 会話内カード */
.card {
  margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 650;
}
.card-head .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto;
}
.card-head .dot.ok { background: var(--ok); }
.card-head .dot.warn { background: var(--warn); }
.card-head .dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.card-head .spacer { flex: 1; }
.card-body { padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); }
.card-actions { display: flex; gap: 6px; padding: 0 12px 10px; }
.mini-button {
  padding: 4px 9px; border: 1px solid var(--line-strong); border-radius: 999px;
  color: var(--text-muted); font-size: 11px; font-weight: 600;
}
.mini-button:hover { color: var(--accent); border-color: var(--accent); }
.change-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.change-list li { font-size: 11.5px; color: var(--text-muted); word-break: break-word; }
.change-list code { color: var(--accent); }
.change-list .arrow { color: var(--text-faint); }

/* ---------------------------------------------------------------------------
   コンポーザ
   --------------------------------------------------------------------------- */

.composer-wrap { padding: 8px 24px 20px; }
.composer {
  max-width: 780px; margin: 0 auto; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  width: 100%; min-height: 46px; max-height: 220px; resize: none; border: 0; background: transparent;
  padding: 13px 14px 4px; font-size: 13.5px; line-height: 1.6;
}
.composer textarea:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 10px; padding: 6px 8px 8px 12px; }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.inline-field select { border: 0; background: transparent; font-size: 11.5px; color: var(--text); }
.hint { flex: 1; text-align: right; color: var(--text-faint); font-size: 10.5px; }
.send-button {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text);
  font-size: 15px; font-weight: 700; display: grid; place-items: center;
}
.send-button:hover:not(:disabled) { filter: brightness(1.08); }
/* 実行中の停止ボタン（送信の隣に出る） */
.stop-button { background: var(--danger, #c0392b); font-size: 12px; }
.stop-button[hidden] { display: none; }

/* ---------------------------------------------------------------------------
   右パネル（詳細）
   --------------------------------------------------------------------------- */

.inspector {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line);
  transition: transform .18s ease;
}
.inspector-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px;
  border-bottom: 1px solid var(--line);
}
.tabs { flex: 1; display: flex; gap: 2px; }
.tab {
  padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 11.5px; font-weight: 600;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.inspector-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-block {
  padding: 12px; margin-bottom: 14px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface-2); display: grid; gap: 9px;
}
.panel-block .panel-label { margin: 0; }
.panel-block.generation { background: var(--surface); }
.empty-note { color: var(--text-faint); font-size: 12px; line-height: 1.6; }
.empty-note.small { font-size: 11.5px; }

.meta-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.meta-pill {
  padding: 3px 7px; border-radius: 999px; background: var(--surface-2);
  color: var(--text-muted); font-size: 10px; font-weight: 600;
}
.lint-box { display: grid; gap: 6px; margin-bottom: 10px; }
.lint-warning {
  padding: 7px 9px; border-left: 3px solid var(--warn); border-radius: 4px;
  background: var(--warn-soft); color: var(--warn); font-size: 11px; line-height: 1.5;
}
.lint-note {
  padding: 7px 9px; border-left: 3px solid var(--line-strong); border-radius: 4px;
  background: var(--surface-2); color: var(--text-muted); font-size: 11px; line-height: 1.5;
}

.code-block { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.code-block.negative { border-color: var(--line-strong); }
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  font-size: 10.5px; font-weight: 700; color: var(--text-muted);
}
.code-block pre {
  margin: 0; padding: 11px; background: var(--code-bg);
  font: 11.5px/1.65 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--text);
}
.copy { color: var(--accent); font-size: 10.5px; font-weight: 700; }
.copy:hover { text-decoration: underline; }

.shot-list { display: grid; gap: 6px; margin-bottom: 12px; }
.shot { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.shot summary { padding: 8px 10px; font-size: 11px; font-weight: 650; cursor: pointer; }
.shot pre {
  margin: 0; padding: 0 10px 10px; font: 11px/1.6 var(--mono); color: var(--text-muted);
  white-space: pre-wrap; word-break: break-word;
}

/* IR表示 */
.ir-section { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.ir-section:last-child { border-bottom: 0; }
.ir-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.ir-section h3 { margin: 0; font-size: 11.5px; font-weight: 700; }
.lock-toggle { padding: 2px 4px; color: var(--text-faint); font-size: 13px; }
.lock-toggle.locked { color: var(--accent); }
.ir-row { display: grid; grid-template-columns: 74px 1fr; gap: 8px; margin: 6px 0; font-size: 11.5px; }
.ir-key { color: var(--text-faint); }
.source {
  display: inline-block; margin-left: 6px; padding: 1px 5px; border-radius: 4px;
  background: var(--surface-3); color: var(--text-muted); font-size: 9px; font-style: normal;
}
.source.explicit { background: var(--accent-soft); color: var(--accent); }
.source.inferred { background: var(--warn-soft); color: var(--warn); }
.source.creative { background: var(--ok-soft); color: var(--ok); }
.constraint {
  padding: 6px 8px; margin-top: 5px; border-left: 3px solid var(--warn); border-radius: 4px;
  background: var(--warn-soft); color: var(--warn); font-size: 10.5px;
}
.segment { padding: 2px 0 10px 10px; margin-bottom: 10px; border-left: 2px solid var(--line-strong); }
.segment-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 5px; }
.seg-badge {
  padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 700;
}
.seg-time { color: var(--text-faint); font-size: 10px; }
.seg-group-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 7px 0 3px; color: var(--text-faint); font-size: 10.5px; font-weight: 700;
}
.seg-note { margin: 5px 0 0; color: var(--text-faint); font-size: 10.5px; }

/* 履歴と差分 */
.version-list { display: grid; gap: 6px; }
.version-item {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 11.5px;
}
.version-item.current { border-color: var(--accent); background: var(--accent-soft); }
.version-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.version-item span { color: var(--text-muted); }
.version-actions { display: flex; gap: 5px; }
.branch-note { display: block; margin-top: 4px; color: var(--warn); font-size: 10.5px; font-style: normal; }
.diff-panel { margin-top: 12px; }
.diff-head { margin-bottom: 7px; color: var(--accent); font-size: 11.5px; font-weight: 700; }
.diff-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.diff-list li { font-size: 11px; color: var(--text-muted); word-break: break-word; }
.diff-list code { color: var(--accent); }

/* 生成ジョブ（右パネル） */
.gen-jobs { display: grid; gap: 7px; margin-top: 4px; }
.gen-job {
  padding: 8px 10px; border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.gen-job.queued, .gen-job.starting, .gen-job.generating { border-left-color: var(--accent); }
.gen-job.completed { border-left-color: var(--ok); }
.gen-job.failed, .gen-job.cancelled { border-left-color: var(--danger); }
.gen-job-head { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.gen-badge {
  padding: 2px 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-muted);
  font-size: 9.5px; font-weight: 700;
}
.gen-badge.queued, .gen-badge.starting, .gen-badge.generating { background: var(--accent-soft); color: var(--accent); }
.gen-badge.completed { background: var(--ok-soft); color: var(--ok); }
.gen-badge.failed, .gen-badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.gen-id { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; color: var(--text-faint); }
.gen-meta { margin-top: 5px; font-size: 10.5px; color: var(--text-muted); }
.gen-output { margin-top: 4px; font-size: 10.5px; color: var(--ok); word-break: break-all; }
.gen-error {
  margin-top: 5px; padding: 5px 7px; border-radius: 4px; background: var(--danger-soft);
  color: var(--danger); font-size: 10.5px; word-break: break-word;
}

/* ---------------------------------------------------------------------------
   トースト / スクリム
   --------------------------------------------------------------------------- */

.toast {
  position: fixed; right: 18px; bottom: 18px; max-width: 360px; padding: 10px 13px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-size: 12px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 5; }

.loading { pointer-events: none; }
.loading .send-button { opacity: .5; }

/* ---------------------------------------------------------------------------
   レスポンシブ
   --------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .app { grid-template-columns: var(--rail-width) minmax(0, 1fr); }
  .inspector {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
    z-index: 10; box-shadow: var(--shadow);
  }
  .app.inspector-closed .inspector { transform: translateX(100%); }
  .app:not(.inspector-closed) .inspector { transform: none; }
  .rail { position: fixed; top: 0; left: 0; bottom: 0; width: min(var(--rail-width), 86vw); z-index: 10; }
  .app:not(.rail-closed) .rail { box-shadow: var(--shadow); }
}

@media (max-width: 720px) {
  .thread { padding: 18px 14px 8px; }
  .composer-wrap { padding: 8px 12px 14px; }
  .hero { padding-top: 6vh; }
  .topbar { padding: 8px 10px; }
  .scroll-latest-wrap { bottom: 8px; padding: 0 12px; }
  .scroll-latest { padding: 6px 10px; font-size: 11px; }
}

/* ---------------------------------------------------------------------------
   進捗の段階表示とタイピング
   --------------------------------------------------------------------------- */

.steps { display: grid; gap: 4px; margin: 4px 0 8px; }
.step {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--text-muted); line-height: 1.5;
}
.step.done { color: var(--text-faint); }
.step.error { color: var(--danger); }
/* 実行中だった段階を、タイムアウト時に赤い「!」へ変えない（進行中のまま見せる）。 */
.step.waiting { color: var(--warn); }
.step-icon {
  flex: 0 0 auto; width: 14px; height: 14px; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--ok);
}
.step.error .step-icon { color: var(--danger); }
.step.waiting .step-icon { color: var(--warn); }
.spinner {
  display: block; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.typing-cursor {
  display: inline-block; width: 6px; height: 13px; margin-left: 2px;
  background: var(--accent); vertical-align: -2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.message.streaming .message-role { color: var(--accent); }

/* ---------------------------------------------------------------------------
   画像（SDXL）→ I2V
   --------------------------------------------------------------------------- */

.image-box {
  margin-top: 8px; padding: 9px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; line-height: 1.6; color: var(--text-muted);
}
.image-box .image-title { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.image-box pre {
  margin: 4px 0 0; padding: 6px 8px; border-radius: 6px;
  background: var(--surface-1); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; font-size: 11.5px;
}
.image-box .warn-list { margin: 4px 0 0; padding-left: 16px; color: var(--warn); }
.image-box .image-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.image-thumb { max-width: 100%; border-radius: 6px; margin-top: 6px; }

.field.checkbox {
  flex-direction: row; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.field.checkbox input { width: auto; margin: 0; }

.image-box textarea {
  width: 100%; margin-top: 6px; padding: 6px 8px; resize: vertical;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text);
  font-family: inherit; font-size: 11.5px; line-height: 1.5;
}

/* チャット内のSD1.5プレビュー（承認/却下つき） */
.preview-card { display: flex; flex-direction: column; gap: 8px; }
.preview-card .card-head { display: flex; align-items: center; gap: 8px; }
.preview-image {
  width: 100%;
  max-width: 340px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}
.preview-image.rejected { opacity: 0.45; filter: grayscale(0.6); }
.preview-actions { display: flex; gap: 8px; }
.preview-prompt { font-size: 11px; color: var(--text-muted); }
.preview-prompt summary { cursor: pointer; }
.preview-prompt .prompt-text {
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-muted);
}
.preview-prompt .prompt-text.negative { opacity: 0.75; }
.inline-field.check { gap: 4px; cursor: pointer; }
.inline-field.check input { width: auto; margin: 0; }

/* ---------------------------------------------------------------------------
   Vast の LLM（vastai/bonsai27b）を1クリックで起動
   --------------------------------------------------------------------------- */

.vast-llm-box {
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: grid;
  gap: 7px;
}
.vast-llm-note { margin: 0; font-size: 11px; line-height: 1.5; color: var(--text-muted); }
.vast-llm-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.vast-llm-box .mini-button[hidden],
.vast-llm-box .ghost-button[hidden] { display: none; }
