:root {
  --bg: #0f1419;
  --panel: #161b22;
  --panel2: #1c2330;
  --border: #2a3444;
  --text: #e7ecf3;
  --muted: #9aa7b8;
  --accent: #3d9a78;
  --accent2: #5b8def;
  --warn: #d4a017;
  --danger: #d35f5f;
  --font: "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Source Han Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.05rem;
}
.meta { color: var(--muted); font-size: 0.85rem; flex: 1; }
.actions { display: flex; gap: 6px; }

button, .primary {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
}
button:hover { border-color: #456; }
button.primary, .primary {
  background: #1e3d32;
  border-color: #2f6b55;
  color: #d7ffe9;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(420px, 46%) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  height: auto;
}
.pane { border-right: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; }
.pane:last-child { border-right: none; }
.pane-title {
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.ws-root {
  padding: 6px 10px;
  font-size: 0.75rem;
  color: var(--accent2);
  word-break: break-all;
  border-bottom: 1px solid var(--border);
}
.tree {
  overflow: auto;
  padding: 6px;
  font-size: 0.82rem;
}
.tree button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
}
.tree button:hover, .tree button.active { background: #243044; }

.tabs {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.85rem;
}
.CodeMirror {
  flex: 1;
  height: auto !important;
  font-family: "Source Han Mono", "Noto Sans JP", var(--mono);
  font-size: 13px;
  background: #0d1117 !important;
}
.editor-pane { min-width: 0; min-height: 0; background: #0d1117; }
.editor-pane .CodeMirror { height: auto !important; min-height: 0; }
.status {
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-pane { background: #1b1d21; min-width: 0; }
.chat-log {
  flex: 1;
  overflow: auto;
  padding: 14px 8px 8px;
  font-size: 14px;
  line-height: 1.65;
}
.ns-user-msg {
  margin: 4px 10px 12px;
  padding: 10px 12px;
  border: 1px solid #3c4048;
  border-radius: 12px;
  background: #2a2d33;
  white-space: pre-wrap;
  word-break: break-word;
}
.ns-agent-msg {
  margin: 2px 16px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e6e6e6;
}
.ns-agent-msg .who {
  display: block;
  font-size: 12px;
  color: #8b919a;
  margin-bottom: 4px;
}
.ns-activity {
  margin: 2px 16px 8px;
  color: #8b919a;
  font-size: 13px;
}
.ns-diffcard {
  margin: 8px 16px 14px;
  border: 1px solid #34383f;
  border-radius: 10px;
  overflow: hidden;
  background: #16181c;
}
.ns-diffcard-h {
  padding: 8px 10px;
  font-size: 13px;
  color: #c9cdd3;
  background: #22252b;
}
.ns-diffrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid #2c3036;
  font-family: var(--mono);
  font-size: 12px;
}
.ns-diffrow .ns-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ns-add { color: #3fb950; }
.ns-del { color: #f85149; margin-right: 8px; }
.ns-diffacts { display: flex; gap: 6px; }
.ns-diffacts button { padding: 2px 8px; font-size: 12px; }
.ns-pastes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.ns-pastes:empty { display: none; }
.ns-paste {
  position: relative;
  border: 1px solid #3c4048;
  border-radius: 8px;
  overflow: hidden;
  background: #111316;
}
.ns-paste img { display: block; height: 72px; width: auto; max-width: 160px; object-fit: cover; }
.ns-paste button {
  position: absolute;
  top: 2px;
  right: 2px;
  padding: 0 6px;
  line-height: 18px;
  border-radius: 6px;
  background: #1b1d21;
}
.ns-paste button:focus,
.ns-paste button:focus-visible {
  outline: none;
  box-shadow: none;
}
.ns-user-msg .ns-paste-img {
  display: block;
  margin-top: 8px;
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  border: 1px solid #3c4048;
}
.chat-compose {
  border-top: 1px solid #2c3036;
  padding: 10px;
  background: #1b1d21;
}
.chat-compose textarea {
  width: 100%;
  resize: vertical;
  min-height: 64px;
  background: #111316;
  color: var(--text);
  border: 1px solid #3c4048;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}
.chat-compose textarea:focus,
.chat-compose textarea:focus-visible {
  outline: none;
  box-shadow: none;
  border-color: #5a616b;
}
.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.who { font-size: 0.78rem; color: var(--muted); }
.proposals {
  max-height: 220px;
  overflow: auto;
  border-top: 1px solid var(--border);
  padding: 8px;
  background: #121820;
  font-size: 0.8rem;
}
.proposal {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}
.proposal .path { color: var(--accent2); font-family: var(--mono); }
.proposal .issues { color: var(--warn); margin: 4px 0; }
.proposal .issues.err { color: var(--danger); }

.terminal-pane {
  flex: 0 0 auto;
  max-height: 32%;
  overflow: auto;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #0a0e13;
}
.term-out {
  flex: 0 0 auto;
  min-height: 96px;
  max-height: 180px;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: #c8d2de;
  white-space: pre-wrap;
}
.term-row {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}
.term-row input {
  flex: 1;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: var(--mono);
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}
.dlg { padding: 16px; display: grid; gap: 10px; min-width: min(480px, 90vw); }
.dlg input {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
}
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

input:focus, textarea:focus, button:focus, select:focus {
  outline: none;
  box-shadow: none;
}
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 1px solid #4a5a6e;
  outline-offset: 1px;
}

.tree-filter {
  margin: 6px;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 0.8rem;
}
.tree { flex: 1; }
.tree-note { padding: 4px 10px; font-size: 0.72rem; color: var(--warn); }
.tree-note:empty { display: none; }

.plain-editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  padding: 8px 10px;
  background: #0d1117;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  tab-size: 4;
}
.tab.dirty::after { content: " ●"; color: var(--warn); }

.proposal .role { color: var(--muted); font-size: 0.74rem; }
.proposal .label { margin: 2px 0; }
.proposal .diff {
  max-height: 160px;
  overflow: auto;
  margin: 6px 0;
  padding: 6px;
  background: #0a0e13;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre;
}
.proposal .diff .add { color: #7ed69f; }
.proposal .diff .del { color: #e88b8b; }
.proposal .diff .hunk { color: var(--accent2); }
.proposal button { margin-right: 6px; }
.issues.info { color: var(--muted); }

@media (max-width: 1100px) {
  html, body { height: auto; overflow: auto; }
  .layout { grid-template-columns: 180px 1fr; height: auto; }
  .tree-pane { height: 40vh; }
  .chat-pane { height: 70vh; }
  .editor-pane { grid-column: 1 / -1; height: 70vh; border-top: 1px solid var(--border); }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .tree-pane { height: 30vh; }
}

/* 迷ったら選択肢で聞く（1〜3択＋その他） */
.ns-ask {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-left: 3px solid #6366f1;
  border-radius: 10px;
  background: #f8f9ff;
}
.ns-ask.ns-ask-used {
  opacity: 0.6;
}
.ns-ask-q {
  font-size: 13px;
  color: #374151;
  margin-bottom: 8px;
  line-height: 1.6;
}
.ns-ask-opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ns-ask-opt {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
  transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.ns-ask-opt:hover {
  background: #eef2ff;
  color: #4338ca;
  border-color: rgba(99, 102, 241, 0.35);
}
.ns-ask-opt:focus,
.ns-ask-opt:focus-visible {
  outline: none;
  box-shadow: none;
  border-color: #cbd5e1;
}
.ns-ask-opt.rec {
  border-color: rgba(99, 102, 241, 0.4);
  font-weight: 600;
}
.ns-ask-opt.other {
  color: #6b7280;
  font-style: italic;
}
.ns-ask-opt:disabled {
  cursor: default;
  opacity: 0.6;
}
