/* マルチエージェントチャット スタイル(ダークテーマ + ワイド対応・リサイズ追従) */
:root {
  color-scheme: dark;               /* ネイティブの select/input 等もダークに */
  --bg: #0d1117;                    /* 全体背景(ほぼ黒) */
  --panel: #12161d;                 /* アプリ面 */
  --panel2: #1a2029;               /* 上部バー等の面 */
  --panel3: #232b36;               /* 入力・ボタンの面 */
  --border: #2a3340;
  --border2: #3a4553;
  --text: #e6edf3;                 /* 主要文字 */
  --dim: #9aa7b4;                  /* 副次文字 */
  --accent: #2f81f7;               /* 青アクセント */
  --accent-d: #245bb5;
  --green: #2f8a4e;
  --red: #d0453b;
  --purple: #8a63d2;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  background: var(--bg); color: var(--text);
}
/* ワイド画面でも快適に。左サイドバー(ルーム一覧)+右メイン。リサイズに自動追従 */
#app {
  display: flex; flex-direction: row; height: 100vh;
  width: 100%; max-width: min(96vw, 1600px); margin: 0 auto;
  background: var(--panel); overflow: hidden;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.main {
  display: flex; flex-direction: column; height: 100vh; flex: 1; min-width: 0;
}

/* ルーム一覧サイドバー */
.sidebar {
  width: 250px; flex-shrink: 0; height: 100vh;
  background: #0f141b; border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 12px; border-bottom: 1px solid var(--border); background: var(--panel2);
}
.sidebar-title { font-weight: 600; font-size: 14px; }
.sidebar-new {
  font-size: 12px; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--border2);
  background: var(--panel3); color: var(--text); cursor: pointer; white-space: nowrap;
}
.sidebar-new:hover { background: #2c3644; }
.thread-list { flex: 1; overflow-y: auto; padding: 6px; }
.thread-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 9px; margin-bottom: 3px;
  border-radius: 9px; cursor: pointer; border: 1px solid transparent;
}
.thread-item:hover { background: #161d27; }
.thread-item.active { background: #1b2635; border-color: var(--accent-d); }
.thread-item .th-main { flex: 1; min-width: 0; }
.thread-item .th-title { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-item .th-sub { font-size: 10px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.thread-item .th-acts { display: flex; gap: 2px; opacity: 0; flex-shrink: 0; }
.thread-item:hover .th-acts, .thread-item.active .th-acts { opacity: 1; }
.th-act {
  background: none; border: none; color: var(--dim); cursor: pointer; font-size: 12px;
  padding: 2px 4px; border-radius: 6px; line-height: 1;
}
.th-act:hover { background: #2c3644; color: var(--text); }
.active-room { font-weight: 600; font-size: 15px; }
.sidebar-toggle { display: none; }         /* デスクトップでは非表示(スマホ幅で出す) */
/* 既定は非表示。スマホ幅でサイドバーを開いたときだけ表示する(下のメディアクエリ) */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }

/* 上部バー */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 14px; background: var(--panel2); color: var(--text);
  flex-wrap: wrap; border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 600; font-size: 15px; }
.topbar .stage { font-size: 11px; background: #2c3542; padding: 2px 6px; border-radius: 8px; margin-left: 4px; color: var(--dim); }
.server-stamp { color: var(--dim); font-size: 10px; line-height: 1.35; max-width: min(52vw, 470px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; max-width: 100%; }

.mobile-access {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 8px 14px;
  background: #111b27; border-bottom: 1px solid var(--border); color: var(--dim);
  font-size: 12px;
}
.mobile-access-toggle {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 8px; border: 1px solid var(--border2); border-radius: 7px;
  background: var(--panel3); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.mobile-access-toggle:hover { background: #2c3644; }
.mobile-access-chevron { font-size: 10px; transition: transform .15s ease; }
.mobile-access-toggle[aria-expanded="true"] .mobile-access-chevron { transform: rotate(180deg); }
.mobile-access-details { display: flex; flex: 1; min-width: 0; align-items: center; gap: 12px; }
.mobile-access-details[hidden] { display: none; }
.mobile-access-main { display: flex; flex: 1; min-width: 0; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.mobile-access strong { color: var(--text); }
.mobile-url { color: #79b8ff; font-family: Consolas, monospace; text-decoration: none; overflow-wrap: anywhere; }
.mobile-url:hover { text-decoration: underline; }
.mobile-url.secondary { color: var(--dim); }
.mobile-qr { width: 92px; height: 92px; padding: 3px; background: #fff; border-radius: 4px; image-rendering: pixelated; }
.mobile-firewall { width: 100%; color: #ffd38a; line-height: 1.55; }
.mobile-firewall code { display: block; margin-top: 3px; padding: 3px 5px; color: #e6edf3; background: #0d1117; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Codex / Claude の利用量。バーは使用率、表示値は残り率を示す。 */
.usage-bars { display: flex; align-items: stretch; gap: 6px; flex: 0 1 390px; min-width: 260px; }
.usage-bar { flex: 1 1 150px; min-width: 0; padding: 4px 6px; border: 1px solid var(--border); border-radius: 7px; background: #111820; }
.usage-bar.usage-measured { border-color: #346c84; background: #101c24; }
.usage-bar.usage-estimated { border-style: dashed; }
.usage-head { display: flex; justify-content: space-between; gap: 5px; font-size: 10px; line-height: 1.25; color: var(--text); }
.usage-head-right { display: inline-flex; align-items: center; gap: 3px; min-width: 0; }
.usage-refresh { width: 16px; height: 16px; padding: 0; border: 0; border-radius: 3px; color: var(--dim); background: transparent; font: inherit; line-height: 16px; cursor: pointer; }
.usage-refresh:hover { color: var(--text); background: var(--panel3); }
.usage-refresh:disabled { opacity: .45; cursor: wait; }
.usage-value { color: var(--dim); white-space: nowrap; }
.usage-track { height: 5px; margin-top: 3px; overflow: hidden; border-radius: 999px; background: #2b3440; }
.usage-fill { width: 0; height: 100%; border-radius: inherit; background: #3aa55d; transition: width .2s ease, background-color .2s ease; }
.usage-bar.usage-yellow .usage-fill { background: #d5a52d; }
.usage-bar.usage-red { border-color: #8d3e3a; }
.usage-bar.usage-red .usage-fill { background: var(--red); }
.usage-bar.usage-red .usage-value { color: #ff938d; font-weight: 600; }
.usage-detail { margin-top: 3px; min-height: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; line-height: 1.25; color: var(--dim); }

@media (max-width: 880px) {
  .usage-bars { order: 4; flex-basis: 100%; }
}
@media (max-width: 480px) {
  .usage-bars { min-width: 0; }
}

/* 小画面ではチャットを優先し、PC 用の接続案内は警告以外を隠す。 */
@media (max-width: 700px) {
  .mobile-access { display: none; padding: 6px 10px; }
  .mobile-access.has-firewall-warning { display: block; }
  .mobile-access-toggle, .mobile-access-details { display: none !important; }
  .mobile-firewall { font-size: 11px; line-height: 1.45; }
  .mobile-firewall code { margin-top: 2px; padding: 2px 4px; font-size: 10px; }

  .topbar { gap: 5px; padding: 5px 8px; flex-wrap: nowrap; overflow-x: auto; }
  .topbar .title { font-size: 13px; white-space: nowrap; }
  .server-stamp, .proj-label { display: none; }
  .topbar-right { gap: 3px; flex-wrap: nowrap; }
  .topbtn { padding: 3px 6px; font-size: 11px; }
  #project-select { max-width: 28vw; padding: 3px 4px; font-size: 11px; }
  .model-ctl, .qwen-ctl { display: none; }
  .usage-bars { order: initial; flex: 0 0 auto; min-width: 0; gap: 3px; }
  .usage-bar { display: none; padding: 2px 4px; }
  .usage-bar:first-child { display: block; flex: 0 0 86px; }
  .usage-head { font-size: 9px; }
  .usage-track { height: 3px; margin-top: 1px; }
  .usage-detail { display: none; }
}

/* セレクト/インプットの共通ダーク見た目 */
select, input, textarea { color: var(--text); background: var(--panel3); border: 1px solid var(--border2); }
.model-ctl { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.model-ctl select { font-size: 12px; padding: 3px 5px; border-radius: 6px; max-width: 150px; }
.proj-label { font-size: 12px; color: var(--dim); }
#project-select { font-size: 13px; padding: 4px 6px; border-radius: 6px; max-width: 30vw; }
.network-switch { font-size: 11px; color: var(--dim); display: inline-flex; align-items: center; gap: 3px; cursor: pointer; white-space: nowrap; }
.network-switch.enabled { color: #ffcc66; font-weight: 600; }

/* 上部バーのボタン */
.topbtn {
  font-size: 12px; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--border2);
  background: var(--panel3); color: var(--text); cursor: pointer; white-space: nowrap;
}
.topbtn:hover { background: #2c3644; }
/* 読み上げなど、ON/OFF を持つ上部バーのボタン */
.topbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.topbtn.on:hover { background: var(--accent-d); }
.stopbtn { background: #7a2620; border-color: #a13b30; }
.stopbtn:hover { background: #9a3128; }
.hidden { display: none !important; }

/* 思考の深さセレクタ(トークン節約) */
.effort-sel { font-size: 11px; padding: 3px 4px; border-radius: 6px; margin-left: 2px; max-width: 130px; }

/* Qwen コントロール */
.qwen-ctl { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#qwen-model { font-size: 12px; padding: 3px 5px; border-radius: 6px; max-width: 150px; }
.ka-switch { font-size: 11px; color: var(--dim); display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }

/* モーダル(ゴミ箱・復旧 共通) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel2); width: 100%; max-width: 620px; max-height: 82vh; border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: #10151c; color: var(--text); font-weight: 600; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: none; color: var(--dim); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-note { font-size: 12px; color: var(--dim); padding: 8px 14px; border-bottom: 1px solid var(--border); }
.trash-list { overflow-y: auto; padding: 8px 14px 14px; }
.trash-empty { color: var(--dim); font-size: 13px; text-align: center; padding: 20px; }
.trash-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.trash-rel { font-size: 14px; font-weight: 600; color: var(--text); word-break: break-all; }
.trash-meta { font-size: 11px; color: var(--dim); margin-top: 2px; }
.trash-acts { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.trash-btn2 { font-size: 12px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--border2); background: var(--panel3); color: var(--text); cursor: pointer; }
.trash-btn2:hover { background: #2c3644; }
.trash-btn2:disabled { opacity: .5; cursor: default; }
.trash-explain { margin-top: 8px; background: #12283f; border: 1px solid #2b4a6b; border-radius: 8px; padding: 8px 10px; font-size: 13px; color: #cfe0f5; white-space: pre-wrap; }

/* ➕ 新しいルーム作成モーダル */
.newroom-box { max-width: 460px; }
.newroom-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.newroom-label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
.newroom-label input, .newroom-label select {
  font-size: 14px; padding: 8px 10px; border-radius: 8px; font-family: inherit;
}
.newroom-hint { font-size: 12px; color: var(--dim); line-height: 1.5; }
.newroom-actions { display: flex; justify-content: flex-end; }
#newroom-create {
  font-size: 14px; padding: 8px 20px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; cursor: pointer;
}
#newroom-create:hover { background: var(--accent-d); }

/* 📁 追加許可フォルダ */
.extra-folders-box { max-width: 650px; }
.extra-folders-list { overflow-y: auto; padding: 8px 14px; min-height: 90px; }
.extra-folder-row { display: flex; align-items: flex-start; gap: 9px; padding: 9px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.extra-folder-row:last-child { border-bottom: none; }
.extra-folder-row input { margin-top: 3px; flex-shrink: 0; }
.extra-folder-name { font-size: 13px; color: var(--text); }
.extra-folder-path { margin-top: 2px; font-size: 11px; color: var(--dim); word-break: break-all; }
.extra-folders-actions { display: flex; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--border); }
#extra-folders-save { font-size: 13px; padding: 7px 18px; border: none; border-radius: 9px; background: var(--accent); color: #fff; cursor: pointer; }
#extra-folders-save:hover { background: var(--accent-d); }

/* 📂 Web フォルダブラウザ(スマホからサーバーPCのフォルダを辿る) */
.folder-browser-box { max-width: 680px; }
.folder-browser-controls { display: flex; gap: 7px; padding: 10px 14px 0; }
.folder-browser-btn, .folder-browser-row {
  border: 1px solid var(--border2); background: var(--panel3); color: var(--text); cursor: pointer;
}
.folder-browser-btn { font-size: 13px; padding: 6px 11px; border-radius: 8px; }
.folder-browser-btn:hover, .folder-browser-row:hover { background: #2c3644; }
.folder-browser-btn:disabled { opacity: .45; cursor: default; }
.folder-browser-path { padding: 9px 14px; font-size: 12px; color: var(--text); word-break: break-all; }
.folder-browser-list { overflow-y: auto; min-height: 120px; padding: 0 14px 8px; }
.folder-browser-row {
  display: flex; width: 100%; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 7px; border-width: 0 0 1px; border-radius: 0; text-align: left;
}
.folder-browser-name { font-size: 14px; }
.folder-browser-row-path { font-size: 11px; color: var(--dim); word-break: break-all; }
.folder-browser-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); }
.folder-browser-status { font-size: 12px; color: var(--dim); }
#folder-browser-select { font-size: 13px; padding: 7px 14px; border: none; border-radius: 9px; background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap; }
#folder-browser-select:hover { background: var(--accent-d); }
#folder-browser-select:disabled { background: #2b3a4f; color: #7f93a8; cursor: default; }

/* 普通チャットで無効化される作業系ボタン */
.topbtn:disabled { opacity: .4; cursor: default; }
.topbtn:disabled:hover { background: var(--panel3); }

/* 🧠 記憶モーダル */
.memory-addrow { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.memory-addrow #memory-add-title { flex: 0 0 130px; font-size: 13px; padding: 6px 8px; border-radius: 7px; }
.memory-addrow #memory-add-body { flex: 1; min-width: 140px; font-size: 13px; padding: 6px 8px; border-radius: 7px; }
.memory-addrow #memory-add-btn { font-size: 12px; padding: 6px 12px; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap; }
.memory-addrow #memory-add-btn:hover { background: var(--accent-d); }
.memory-item.memory-off { opacity: .5; }
.memory-item.memory-off .trash-rel { text-decoration: line-through; }

/* 各発言の 🧠 追加ボタン */
.msg .meta { display: inline-flex; align-items: center; gap: 6px; }
.msg-mem-btn { background: none; border: none; cursor: pointer; font-size: 12px; opacity: 0; padding: 0 2px; line-height: 1; transition: opacity .15s; }
.msg:hover .msg-mem-btn { opacity: .6; }
.msg-mem-btn:hover { opacity: 1; }

/* 🧠 記憶の提案カード(承認制) */
.memory-suggest-card { align-self: center; max-width: min(92%, 640px); background: #13202b; border: 1px solid #2b466b; border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 6px rgba(0,0,0,.4); }
.memory-suggest-msg { font-size: 13px; color: #cfe0f5; white-space: pre-wrap; margin-bottom: 10px; }

/* 🔁 自動モードパネル */
.auto-panel { background: #10151c; border-bottom: 1px solid var(--border); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.auto-row { display: flex; gap: 12px; flex-wrap: wrap; }
.auto-row label { font-size: 12px; color: var(--dim); display: flex; flex-direction: column; gap: 3px; }
.auto-row select { font-size: 13px; padding: 4px 6px; border-radius: 6px; }
#auto-task { resize: vertical; font-size: 13px; padding: 8px; border-radius: 8px; font-family: inherit; min-height: 42px; }
.auto-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.auto-hint { font-size: 11px; color: var(--dim); }
#auto-start { font-size: 13px; padding: 7px 16px; border: none; border-radius: 10px; background: var(--green); color: #fff; cursor: pointer; }
#auto-start:disabled { background: #2c4a37; color: #9ab0a2; cursor: default; }

/* 状態バナー・接続状態 */
.loop-status { text-align: center; font-size: 12px; padding: 5px; color: #86e0a5; background: #16301f; border-bottom: 1px solid #274a35; }
.conn-status { text-align: center; font-size: 12px; padding: 4px; color: var(--dim); background: #10151c; border-bottom: 1px solid var(--border); }
.conn-status.ok { color: #58c479; }
.conn-status.ng { color: #e5766b; }

/* チャット。ワイドでも中央寄りで読みやすく */
.chat { flex: 1; overflow-y: auto; padding: 16px clamp(12px, 4vw, 40px); display: flex; flex-direction: column; gap: 10px; }
/* 吹き出しは%と絶対上限の併用で、超ワイドでも1行が長すぎない */
.msg { display: flex; flex-direction: column; max-width: min(74%, 800px); }
.msg .meta { font-size: 11px; color: var(--dim); margin: 0 4px 2px; }
.msg .bubble {
  padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 2px rgba(0,0,0,.3);
  border: 1px solid var(--border2);
}
.bubble.with-images { min-width: 150px; }
.message-images { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.message-image-link { display: block; line-height: 0; border-radius: 9px; overflow: hidden; border: 1px solid rgba(255,255,255,.18); background: #111; }
.message-image { display: block; width: min(280px, 100%); max-height: 280px; object-fit: contain; }

/* 人間=右・グレー */
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: #222c39; border-color: #33404f; border-bottom-right-radius: 4px; }

/* AI=左。色分け維持(ダーク調・左ボーダーで識別) */
.msg.claude, .msg.codex, .msg.gemini, .msg.qwen { align-self: flex-start; align-items: flex-start; }
.msg.claude .bubble { background: #2e2113; border-color: #5c421f; border-left: 3px solid #e08a3c; border-bottom-left-radius: 4px; }
.msg.codex  .bubble { background: #12271a; border-color: #2c5238; border-left: 3px solid #4bbd6b; border-bottom-left-radius: 4px; }
.msg.gemini .bubble { background: #251b3a; border-color: #4b356e; border-left: 3px solid #a478e3; border-bottom-left-radius: 4px; }
.msg.qwen   .bubble { background: #142438; border-color: #2b466b; border-left: 3px solid #4b90e0; border-bottom-left-radius: 4px; }
.msg.claude .meta { color: #e0a06a; }
.msg.codex  .meta { color: #6fc98a; }
.msg.gemini .meta { color: #bb94eb; }
.msg.qwen   .meta { color: #7ab0ea; }

/* system=中央 */
.msg.system { align-self: center; align-items: center; max-width: min(92%, 900px); }
.msg.system .bubble { background: #191f28; border-color: var(--border); color: var(--dim); font-size: 13px; text-align: center; }

/* 「入力中」インジケータ */
.thinking { align-self: flex-start; font-size: 12px; color: var(--dim); padding: 4px 10px; font-style: italic; }

/* 🎙 音声モードの再生中バブル: 一文ずつ再生開始に合わせてフェード表示する */
.msg.voice-live .bubble { min-height: 1.55em; }
.voice-sent { opacity: 0; transition: opacity .45s ease; }
.voice-sent.show { opacity: 1; }

/* 許可要求カード */
.approval-card { align-self: center; max-width: min(92%, 640px); background: #2a2413; border: 1px solid #5c5220; border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 6px rgba(0,0,0,.4); }
.approval-msg { font-size: 13px; color: #e8d79a; white-space: pre-wrap; margin-bottom: 10px; }
.approval-btns { display: flex; gap: 10px; justify-content: center; }
.approval-btns button { font-size: 14px; padding: 7px 18px; border: none; border-radius: 10px; cursor: pointer; color: #fff; }
.approve-ok { background: var(--green); }
.approve-ng { background: var(--red); }
.approval-btns button:disabled { opacity: .5; cursor: default; }
.approval-done { text-align: center; font-size: 13px; color: var(--dim); }

/* 一時的なお知らせ */
.notice-toast { align-self: center; background: #2a2413; border: 1px solid #5c5220; color: #e8d79a; font-size: 13px; padding: 8px 12px; border-radius: 10px; max-width: min(92%, 640px); text-align: center; }

/* 入力エリア */
.composer { border-top: 1px solid var(--border); background: var(--panel2); padding: 8px clamp(10px, 3vw, 30px) 12px; }
.composer.drag-over { background: #172a3a; box-shadow: inset 0 0 0 2px var(--accent); }
.mention-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.mention-label { font-size: 12px; color: var(--dim); }
.chip { font-size: 13px; padding: 4px 11px; border-radius: 14px; border: 1px solid var(--border2); background: var(--panel3); color: var(--text); cursor: pointer; user-select: none; }
.chip:hover { background: #2c3644; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.chip-all.active { background: var(--purple); border-color: var(--purple); }
.image-previews { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 7px; }
.image-previews:empty { display: none; }
.image-preview { position: relative; width: 62px; height: 62px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border2); background: #111; }
.image-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.image-preview-remove { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: rgba(0,0,0,.75); color: #fff; cursor: pointer; font-size: 17px; line-height: 18px; }
.file-preview { width: 220px; max-width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 30px 7px 8px; background: var(--panel2); }
.file-preview-icon { flex: 0 0 auto; min-width: 36px; height: 24px; padding: 0 5px; border-radius: 5px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; }
.file-preview-meta { min-width: 0; }
.file-preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--fg); }
.file-preview-size { font-size: 11px; color: var(--muted); }
.message-file-link { display: inline-flex; align-items: center; gap: 8px; max-width: min(360px, 100%); padding: 7px 9px; border: 1px solid var(--border2); border-radius: 8px; color: var(--fg); text-decoration: none; background: rgba(255,255,255,.04); }
.message-file-link:hover { border-color: var(--accent); }
.message-file-icon { flex: 0 0 auto; padding: 3px 5px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; }
.message-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#image-attach { flex: 0 0 auto; font-size: 18px; width: 42px; height: 42px; padding: 0; border: 1px solid var(--border2); border-radius: 12px; background: var(--panel3); color: var(--text); cursor: pointer; }
#image-attach:hover { background: #2c3644; }
#image-attach:disabled, #send:disabled { opacity: .6; cursor: wait; }
#input { flex: 1; resize: none; font-size: 14px; padding: 10px 12px; border-radius: 12px; font-family: inherit; max-height: 160px; line-height: 1.45; }
#input::placeholder { color: #6b7684; }
#send { font-size: 14px; padding: 10px 18px; border: none; border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap; }
#send:hover { background: var(--accent-d); }
#send:disabled { background: #2b3a4f; color: #7f93a8; cursor: default; }

/* 🔄 再起動オーバーレイ */
.restart-overlay { position: fixed; inset: 0; background: rgba(5,8,12,.88); display: flex; align-items: center; justify-content: center; z-index: 100; }
.restart-box { text-align: center; color: var(--text); font-size: 15px; line-height: 1.7; }
.restart-spinner { width: 46px; height: 46px; margin: 0 auto 16px; border: 4px solid #2a3340; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
.restart-overlay.failed .restart-spinner { display: none; }
.restart-overlay.failed .restart-box { max-width: min(92vw, 620px); color: #ffb4ad; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ログイン画面 */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-box { background: var(--panel2); padding: 28px 26px; border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); width: 300px; text-align: center; border: 1px solid var(--border2); }
.login-box h1 { font-size: 18px; margin: 0 0 6px; }
.login-box p { font-size: 13px; color: var(--dim); margin: 4px 0 14px; }
.login-box input { width: 100%; padding: 9px; font-size: 14px; border-radius: 8px; margin-bottom: 10px; }
.login-box button { width: 100%; padding: 9px; font-size: 14px; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
.login-error { color: #e5766b; }

/* スクロールバーもダークに */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #2f3a48; border-radius: 6px; border: 2px solid var(--panel); }
::-webkit-scrollbar-thumb:hover { background: #3d4a5a; }

/* ==== レスポンシブ(メディアクエリのみ=リサイズに自動追従) ==== */
/* 中間幅: 全幅寄りに */
@media (max-width: 1100px) {
  #app { max-width: 100%; border-left: none; border-right: none; }
  .sidebar { width: 220px; }
  .msg { max-width: min(80%, 720px); }
}
/* 狭い幅: サイドバーはオフキャンバス(☰で開閉するオーバーレイ)。
   transform ではなく left オフセットで出し入れする(描画が確実) */
@media (max-width: 680px) {
  .sidebar-toggle { display: inline-block; }
  .sidebar {
    position: fixed; top: 0; left: -250px; z-index: 40; width: 250px;
    transition: left .2s ease; box-shadow: 2px 0 14px rgba(0,0,0,.5);
  }
  #app.sidebar-open .sidebar { left: 0; }
  #app.sidebar-open .sidebar-backdrop { display: block; }
}
/* スマホ幅: 既存の縦長レイアウトを維持 */
@media (max-width: 480px) {
  .topbar .title { font-size: 14px; }
  #project-select { max-width: 45vw; }
  .msg { max-width: 88%; }
  .chat { padding: 14px 12px; }
  .composer { padding: 8px 10px 10px; }
}
