:root {
  color-scheme: dark;
  /* Neural Cockpit と同じダークモダン配色（ディープネイビー背景＋
     シアン→インディゴ→バイオレットのアクセント）を踏襲する */
  --bg: #0b1020;
  --card: rgba(255, 255, 255, 0.045);
  --card-2: rgba(255, 255, 255, 0.075);
  --surface-solid: #141a2e;
  --border: rgba(255, 255, 255, 0.09);
  --fg: #e8edf9;
  --muted: #aab4cc;
  --cyan: #22d3ee;
  --accent: #818cf8;
  --accent-strong: #6366f1;
  --violet: #a78bfa;
  --active: rgba(129, 140, 248, 0.14);
  --user: rgba(99, 102, 241, 0.22);
  --ok: #34d399;
  --err: #f87171;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--fg);
  background:
    radial-gradient(1150px 650px at 100% -8%, rgba(168, 85, 247, 0.22), transparent 60%),
    radial-gradient(1000px 560px at -10% 0%, rgba(34, 211, 238, 0.16), transparent 56%),
    radial-gradient(900px 900px at 50% 122%, rgba(99, 102, 241, 0.12), transparent 60%),
    linear-gradient(180deg, #0e1530 0%, #0b1020 46%, #070a16 100%);
  background-attachment: fixed;
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 14px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.topbar {
  display: flex; align-items: baseline; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--card);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar .sub { color: var(--muted); font-size: 12px; }

.layout {
  display: grid; grid-template-columns: 340px 1fr 320px; gap: 16px;
  padding: 16px; max-width: none; margin: 0; align-items: start;
}
/* 中間幅：横断一覧を下段（全幅）に回す */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 320px 1fr; }
  .history-col { grid-column: 1 / -1; }
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .history-col { grid-column: auto; } }

/* ---- カラム開閉（広い画面のみ） ---- */
.collapse-btn { line-height: 1; padding: 2px 8px; }
.rail-btn {
  display: none; width: 100%; cursor: pointer;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 0; font-size: 18px; line-height: 1;
  writing-mode: vertical-rl; text-orientation: upright;
  min-height: 120px; letter-spacing: 2px;
}
.rail-btn:hover { color: var(--fg); border-color: var(--accent, #888); }

@media (min-width: 1201px) {
  .layout.left-collapsed  { grid-template-columns: 40px 1fr 320px; }
  .layout.right-collapsed { grid-template-columns: 340px 1fr 40px; }
  .layout.left-collapsed.right-collapsed { grid-template-columns: 40px 1fr 40px; }

  .side.collapsed > .card,
  .history-col.collapsed > .card { display: none; }
  .side.collapsed > .rail-btn,
  .history-col.collapsed > .rail-btn { display: block; }
}

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 14px;
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 14px; }
.lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

select, textarea {
  width: 100%; background: var(--card-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px;
  font-family: inherit; font-size: 14px;
}
select:focus, textarea:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(99,102,241,.28); }

.info-row { display: flex; gap: 10px; padding: 4px 0; align-items: baseline; }
.info-k { color: var(--muted); font-size: 12px; min-width: 64px; }
.info-v { font-size: 13px; word-break: break-all; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.path { background: var(--card-2); padding: 2px 6px; border-radius: 6px; font-size: 12px; }

/* アプリ／ホームページ 選択リスト */
.app-list { display: flex; flex-direction: column; gap: 4px; }
.app-group-label { font-size: 11px; color: var(--muted); font-weight: 700; margin: 8px 0 2px; letter-spacing: .04em; }
.app-group-label:first-child { margin-top: 0; }
.app-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; color: var(--fg); font-size: 14px;
}
.app-item:hover { border-color: var(--accent-strong); }
.app-item.active { border-color: var(--accent); background: var(--active); }
.app-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-count { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
/* 状態アイコン（進行中 ⏳ / 反応待ち 🔔） */
.app-status { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px; font-size: 13px; line-height: 1; }
.app-status[hidden] { display: none; }
/* 編集／削除（UI 追加分のみ） */
.app-acts { flex: 0 0 auto; display: inline-flex; gap: 2px; opacity: .5; }
.app-item:hover .app-acts { opacity: 1; }
.app-act {
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  font-size: 12px; line-height: 1; padding: 3px 4px; border-radius: 6px;
}
.app-act:hover { background: var(--card); color: var(--fg); }
/* ドラッグ並び替え */
.app-item { cursor: grab; }
.app-item.dragging { opacity: .45; border-style: dashed; }

/* アイコン選択 */
.icon-pick { display: flex; align-items: center; gap: 10px; }
.icon-preview {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--border); background: var(--card-2);
}
.icon-pick input[type="file"] { flex: 1 1 auto; min-width: 0; color: var(--muted); font-size: 12px; }
.app-item.is-running { border-color: var(--accent-strong); }
.app-item.is-waiting { border-color: var(--ok); }
.app-status .spinner {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 2px solid rgba(129,140,248,.28); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.favicon { width: 18px; height: 18px; border-radius: 4px; flex: 0 0 auto; object-fit: contain; vertical-align: middle; background: rgba(255,255,255,.04); }
.fav-emoji { display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
#chatTitle .favicon { width: 18px; height: 18px; }

.session-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.session-item {
  display: flex; align-items: center; gap: 9px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  cursor: pointer;
}
.session-item:hover { border-color: var(--accent-strong); }
.session-item.active { border-color: var(--accent); background: var(--active); }
.session-item .sess-fav { flex: 0 0 auto; }
.session-main { min-width: 0; flex: 1 1 auto; }
.session-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11px; color: var(--muted); }

/* 横断 過去セッション一覧（最右カラム） */
.history-card { position: sticky; top: 16px; }
.history-list { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 150px); overflow-y: auto; }
.history-item {
  display: flex; align-items: flex-start; gap: 9px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  cursor: pointer;
}
.history-item:hover { border-color: var(--accent-strong); }
.history-item.active { border-color: var(--accent); background: var(--active); }
.history-item .hist-fav { margin-top: 2px; }
.history-item.is-running { border-color: var(--accent-strong); }
.history-item.is-waiting { border-color: var(--ok); }
.history-main { min-width: 0; flex: 1 1 auto; }
.history-app { font-size: 11px; color: var(--accent); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 11px; color: var(--muted); }
.hist-status { margin-top: 2px; }
@media (max-width: 1200px) { .history-card { position: static; } .history-list { max-height: 360px; } }

.btn { border: 1px solid var(--border); background: var(--card-2); color: var(--fg); border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--accent-strong); }
.btn.primary { background: linear-gradient(120deg, #22d3ee 0%, #6366f1 52%, #a855f7 100%); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 8px 28px rgba(99, 102, 241, 0.4); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; }
.btn.danger { background: var(--err); border-color: transparent; color: #fff; font-weight: 600; }
.btn.danger:hover { filter: brightness(1.1); border-color: transparent; }
.foot-btns { display: flex; align-items: center; gap: 8px; }
.model-pick { display: inline-flex; align-items: center; gap: 4px; }
.model-pick .model-ic { font-size: 13px; opacity: .8; }
.model-pick select { padding: 5px 8px; font-size: 12px; border-radius: 8px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chip { font-size: 11px; color: var(--muted); background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.head-actions { display: flex; align-items: center; gap: 8px; }
/* アプリ操作ツールバー（追加・編集・削除） */
.app-toolbar { display: flex; gap: 6px; margin-bottom: 10px; }
.app-toolbar .btn { flex: 1 1 0; white-space: nowrap; text-align: center; padding: 6px 6px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* チャット */
/* grid の 1fr トラックは既定 min-width:auto のため、長いパス/URL/表があると
   中央列が min-content 幅まで膨張してレイアウトが崩れる。min-width:0 で縮小を許可。 */
.chat-col { min-width: 0; }
.chat-card { display: flex; flex-direction: column; min-height: 70vh; min-width: 0; }
.chat-list-wrap { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.chat-list { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; margin-bottom: 10px; min-height: 240px; min-width: 0; }
.msg { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); max-width: 88%; min-width: 0; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg.user { background: var(--user); align-self: flex-end; }
.msg.assistant { background: var(--card-2); align-self: flex-start; }
.msg .role { display: block; font-size: 10px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.msg.typing { color: var(--muted); font-style: italic; }
.msg.typing .progress-line { display: block; margin-top: 4px; font-style: normal; font-size: 12px; color: var(--text); opacity: .85; white-space: pre-wrap; word-break: break-word; border-left: 2px solid var(--border); padding-left: 8px; }
.msg.typing .progress-log { margin-top: 6px; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; border-left: 2px solid var(--border); padding-left: 8px; }
.msg.typing .progress-log .progress-line { margin-top: 0; border-left: none; padding-left: 0; opacity: .8; }
.msg.typing .progress-log .progress-line:last-child { opacity: 1; font-weight: 500; }
.chat-error { color: var(--err); background: rgba(248,113,113,.1); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; }
.chat-input { display: flex; flex-direction: column; gap: 8px; }
.input-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.small { font-size: 11px; }
/* 順番待ちキュー（送信したが実行待ちのプロンプト） */
.queue-strip { display: flex; flex-direction: column; gap: 4px; background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.queue-head { font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.queue-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.queue-num { flex: 0 0 auto; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; background: rgba(127,127,127,.22); color: var(--muted); font-size: 11px; }
.queue-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-x { flex: 0 0 auto; width: 18px; height: 18px; line-height: 16px; text-align: center; border-radius: 50%; border: none; background: rgba(0,0,0,.45); color: #fff; cursor: pointer; font-size: 13px; padding: 0; }
.queue-x:hover { background: var(--err); }
/* 添付画像（送信前のサムネ） */
.img-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.img-thumb { position: relative; width: 72px; height: 72px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card-2); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; text-align: center; border-radius: 50%; border: none; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; font-size: 13px; padding: 0; }
.img-x:hover { background: var(--err); }
/* メッセージ内の画像 */
.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-imgs img { max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); }
/* Markdown 整形（Claude の返答） */
.msg.assistant { max-width: 92%; }
.md { white-space: normal; font-size: 13px; line-height: 1.7; min-width: 0; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.3; font-weight: 700; }
.md h1 { font-size: 18px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14.5px; } .md h4 { font-size: 13.5px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md strong { font-weight: 700; }
.md code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 5px; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.md pre { background: #070a16; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.md pre code { background: none; padding: 0; font-size: 12px; line-height: 1.55; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; font-size: 12px; text-align: left; }
.md th { background: var(--card-2); font-weight: 700; }
.md img { max-width: 100%; border-radius: 6px; }
.chat-input .btn { align-self: flex-end; }

/* 最大化 */
.chat-card.maxed {
  position: fixed; inset: 0; z-index: 1000; margin: 0; border-radius: 0;
  min-height: 0; padding: 14px 18px;
}
/* 最大化時は読みやすいよう本文フォントを拡大（本文 18pt） */
.chat-card.maxed .md { font-size: 18pt; line-height: 1.8; }
.chat-card.maxed .md h1 { font-size: 26pt; }
.chat-card.maxed .md h2 { font-size: 22pt; }
.chat-card.maxed .md h3 { font-size: 20pt; }
.chat-card.maxed .md h4 { font-size: 18pt; }
.chat-card.maxed .md code { font-size: 16pt; }
.chat-card.maxed .md pre code { font-size: 15pt; }
.chat-card.maxed .md th, .chat-card.maxed .md td { font-size: 15pt; }
.chat-card.maxed .msg .role { font-size: 11px; }

/* 返信文エリアの右下に浮かせる「戻す」×ボタン（最大化中のみ表示） */
.max-close { display: none; }
.chat-card.maxed .max-close {
  display: flex; align-items: center; justify-content: center;
  position: absolute; right: 18px; bottom: 16px; z-index: 1001;
  width: 46px; height: 46px; border-radius: 50%; padding: 0;
  background: var(--card-2); border: 1px solid var(--border); color: var(--fg);
  font-size: 26px; line-height: 1; cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,.45);
}
.chat-card.maxed .max-close:hover { border-color: var(--accent-strong); background: var(--active); }

/* ---- アプリ／ホームページ 追加モーダル ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(520px, 94vw); background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; padding: 14px 18px;
}
.modal-head { justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-foot { justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; color: var(--muted); }
.field input, .field select {
  width: 100%; background: var(--card-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
  font-family: inherit; font-size: 14px;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(77, 139, 255, .2);
}
