/* 検索トップページのみ margin: 1px を維持（他ページは base.css の 0px リセットのまま） */
*, *::before, *::after { margin: 1px;}

/* ── Schema radio buttons ── */
#schema {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  margin: 4px 0 2px;
}
/* グループ（親+その子孫を囲む） */
.schema-group {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--bg-subtle);
  border: 1px solid var(--border)3ec;
  border-radius: 6px;
  padding: 4px 8px;
  gap: 1px;
}
/* 関係なしのフラット表示でもラベルを整える */
.schema-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 13px;
  cursor: pointer;
  padding: 1px 2px;
  border-radius: 3px;
}
.schema-item:hover { background: #e8eef6; }
.schema-item input[type="radio"] { margin: 0; cursor: pointer; }
/* 子スキーマの字下げ */
.schema-child { color: var(--text-muted); }
.schema-chain-prefix { color: #aaa; font-size: 11px; letter-spacing: -1px; }
.schema-depth-1 { padding-left: 4px; }
.schema-depth-2 { padding-left: 8px; }
.schema-depth-3 { padding-left: 12px; }
.schema-depth-4 { padding-left: 16px; }

/* ── Search textarea ── */
textarea#query {
  width: 480px; min-height: 26px; resize: vertical; overflow-y: auto;
  padding: 4px 8px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 4px; box-sizing: border-box;
  line-height: 1.5; vertical-align: middle; transition: border-color .2s;
}
textarea#query:focus { border-color: #4a90e2; outline: none; }
/* ── Search button RAG mode ── */
#searchBtn {
  transition: background .25s, color .25s;
  padding: 4px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 6px; box-sizing: border-box;
  vertical-align: middle; cursor: pointer;
}
#searchBtn.rag-mode {
  background: #2e7d32 !important; color: #fff !important;
  border-color: #2e7d32 !important;
}
/* ── Main layout ── */
#main-layout { display: flex; width: 100%; box-sizing: border-box; }
#result { flex: 1; min-width: 0; transition: flex .3s; }
/* ── 拡張子サマリ（左パネル）幅固定 ── */
#summary { width: 250px; flex: 0 0 auto; box-sizing: border-box; }
/* ── Chat resize handle ── */
#chat-resize-handle {
  display: none; flex-shrink: 0; width: 6px; cursor: col-resize;
  background: #e0e8f0; border-left: 1px solid #c8d8e8; border-right: 1px solid #c8d8e8;
  transition: background .15s; position: relative; z-index: 10;
}
#main-layout.rag-active #chat-resize-handle { display: block; }
#chat-resize-handle:hover, #chat-resize-handle.resizing { background: #4a7fc1; }
/* ── Chat panel ── */
#chat-panel {
  flex: 0 0 0; width: 0; overflow: hidden;
  transition: flex .3s, opacity .3s;
  opacity: 0; display: flex; flex-direction: column;
  background: var(--bg-subtle);
  box-sizing: border-box; height: calc(100vh - 100px); position: sticky; top: 0;
  align-self: flex-start;
}
#main-layout.rag-active #chat-panel {
  flex: 0 0 33%; width: 33%; opacity: 1; overflow: hidden;
}
#main-layout.rag-active #result { flex: 0 0 67%; }
#chat-panel-header {
  background: #1a5276; color: #fff; padding: 8px 14px;
  font-size: 13px; font-weight: bold; flex-shrink: 0;
  display: flex; justify-content: space-between; align-items: center;
}
#chat-close-btn {
  background: none; border: none; color: #adf; cursor: pointer;
  font-size: 16px; padding: 0 4px; line-height: 1;
}
#chat-history {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-msg { padding: 8px 11px; border-radius: 8px; max-width: 94%; font-size: 12px; line-height: 1.55; }
.chat-msg.user { background: #e3f2fd; align-self: flex-end; position: relative; padding-right: 26px; }
.chat-rewind-btn {
  position: absolute; top: 4px; right: 4px;
  background: none; border: none; color: #90bcd8; cursor: pointer;
  font-size: 13px; padding: 1px 3px; border-radius: 3px; line-height: 1;
  opacity: 0; transition: opacity 0.15s;
}
.chat-msg.user:hover .chat-rewind-btn { opacity: 1; }
.chat-rewind-btn:hover { background: rgba(26,82,118,0.15); color: #1a5276; }
.chat-msg.assistant { background: var(--bg); border: 1px solid var(--border); align-self: flex-start; font-family: inherit; }
.chat-msg.assistant p { margin: 0 0 6px; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant pre { background: #f5f5f5; border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; overflow-x: auto; font-size: 11px; width: fit-content; max-width: 100%; }
.chat-msg.assistant code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 11px; }
.chat-msg.assistant pre code { background: none; padding: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 4px 0 6px 16px; padding: 0; }
.chat-msg.assistant li { margin-bottom: 2px; display: list-item; }
.chat-msg.assistant li > p { display: inline; margin: 0; padding: 0; }
.chat-msg.assistant li > p + p { display: block; margin-top: 2px; }
.chat-msg.assistant h1, .chat-msg.assistant h2, .chat-msg.assistant h3 { font-size: 13px; margin: 6px 0 4px; }
.chat-msg.assistant table { border-collapse: collapse; font-size: 11px; margin: 4px 0; }
.chat-msg.assistant th, .chat-msg.assistant td { border: 1px solid var(--border); padding: 3px 6px; }
.chat-msg.assistant blockquote { border-left: 3px solid #ccc; margin: 4px 0; padding: 2px 8px; color: var(--text-muted); }
.chat-typing { color: var(--text-muted); font-size: 11px; padding: 4px 12px; }
/* チャット履歴モーダル */
#chat-log-modal {
  display:none; position:fixed; inset:0; background:rgba(0,0,0,.45);
  z-index:10000; align-items:center; justify-content:center;
}
#chat-log-modal.open { display:flex; }
#chat-log-inner {
  background:#fff; border-radius:8px; width:min(700px,92vw);
  max-height:80vh; display:flex; flex-direction:column;
  box-shadow:0 4px 24px rgba(0,0,0,.25); overflow:hidden;
}
#chat-log-header {
  background:#1a5276; color:#fff; padding:10px 16px;
  display:flex; justify-content:space-between; align-items:center; flex-shrink:0;
}
#chat-log-list {
  overflow-y:auto; flex:1; padding:8px 12px;
}
.chat-log-item {
  border:1px solid #dde; border-radius:6px; padding:8px 12px;
  margin-bottom:6px; cursor:pointer; font-size:12px;
}
.chat-log-item:hover { background:#f0f6ff; }
.chat-log-item .cli-time { color:#888; font-size:11px; }
.chat-log-item .cli-query { font-weight:bold; margin:2px 0; }
.chat-log-item .cli-meta { color:#666; font-size:11px; }
#agentic-footer-opts {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px; border-top: 1px solid #e4e8ee;
  background: var(--bg-subtle); flex-shrink: 0; font-size: 11px; color: var(--text-muted);
}
#agentic-auto-label {
  display: flex; align-items: center; gap: 5px;
  cursor: pointer; user-select: none; font-weight: 500; color: #1a5276;
}
#agentic-auto-label input[type="checkbox"] { cursor: pointer; accent-color: #1a5276; }
#agentic-auto-hint { color: var(--text-muted); font-size: 10px; }
#chat-input-area {
  padding: 8px 10px; border-top: 1px solid #dde;
  display: flex; gap: 6px; align-items: flex-end; flex-shrink: 0;
}
#chat-input {
  flex: 1; resize: none; padding: 5px 8px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 4px; font-family: inherit;
  max-height: 80px; overflow-y: auto;
}
#chat-send-btn {
  padding: 5px 12px; font-size: 12px; background: #1a5276;
  color: #fff; border: none; border-radius: 4px; cursor: pointer; flex-shrink: 0;
  align-self: stretch;
}
#chat-send-btn:hover { background: #154360; }
.chunk-card {
  border: 1px solid var(--border); border-radius: 5px; margin-bottom: 6px;
  overflow: hidden; font-size: 12px;
}
.chunk-card-hdr {
  background: rgba(37, 99, 235, 0.05); padding: 4px 10px; display: flex;
  justify-content: space-between; align-items: center;
}
.chunk-card-hdr a { color: #1a5276; font-weight: bold; text-decoration: none; }
.chunk-card-hdr a:hover { text-decoration: underline; }
.chunk-meta { font-size: 10px; color: var(--text-muted); }
.chunk-role { display:inline-block; font-size:9px; padding:1px 5px; border-radius:8px; margin-left:5px; }
.role-common_subroutine { background:#d5f5e3; color:#1e8449; }
.role-root_module { background:#fef9e7; color:#9a7d0a; }
.role-intermediate { background:#eaf4fb; color:#1a5276; }
.role-leaf { background:#f5f5f5; color:#888; }
/* ─── フォルダー階層パネル（左側・レイアウト内蔵） ───
   #chat-panel と同じ「flex幅トランジションで押し出す」方式。
   fixed オーバーレイにしないため、開いても検索結果や右上のプロファイルメニューと重ならない。
   ボタン自体は画面下部に固定表示（fixed）。left は拡張子サマリの右端に合わせて
   JS（folder_tree_panel.js の _positionFab）が動的に計算する。 */
#folder-tree-fab {
  position: fixed; bottom: 20px; left: 16px; z-index: 9400;
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: #1a5276; color: #fff; font-size: 20px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .2s, left .2s;
}
#folder-tree-fab:hover { background: #21618c; transform: scale(1.05); }
#folder-tree-fab.open { background: #21618c; }
#folder-tree-panel {
  flex: 0 0 0; width: 0; overflow: hidden;
  transition: flex .28s, opacity .28s;
  opacity: 0; display: flex; flex-direction: column;
  background: var(--bg); border-right: 1px solid #dde3ec;
  box-sizing: border-box; height: calc(100vh - 100px); position: sticky; top: 0;
  align-self: flex-start;
}
#main-layout.folder-tree-active #folder-tree-panel {
  flex: 0 0 320px; width: 320px; opacity: 1; overflow: hidden;
}
/* ── Folder tree resize handle ── */
#folder-tree-resize-handle {
  display: none; flex-shrink: 0; width: 6px; cursor: col-resize;
  background: #e0e8f0; border-left: 1px solid #c8d8e8; border-right: 1px solid #c8d8e8;
  transition: background .15s; position: relative; z-index: 10;
}
#main-layout.folder-tree-active #folder-tree-resize-handle { display: block; }
#folder-tree-resize-handle:hover, #folder-tree-resize-handle.resizing { background: #4a7fc1; }
#folder-tree-panel-header {
  background: #1a5276; color: #fff; padding: 10px 14px; font-size: 13px; font-weight: bold;
  display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
#folder-tree-panel-close {
  background: none; border: none; color: #adf; cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1;
}
#folder-tree-toolbar {
  display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid #e5e7eb; flex-shrink: 0;
}
.ftp-toolbar-btn {
  flex: 1; padding: 4px 6px; font-size: 11px; border: 1px solid #cbd5e1; border-radius: 4px;
  background: var(--bg-subtle); color: #334155; cursor: pointer; white-space: nowrap;
}
.ftp-toolbar-btn:hover { background: #eef2f7; }
#folder-tree-content { flex: 1; overflow: auto; padding: 8px 6px; font-size: 13px; }
.ftp-node { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border-radius: 4px; }
.ftp-node:hover { background: rgba(37, 99, 235, 0.06); }
.ftp-node.active { background: rgba(37, 99, 235, 0.08); color: #0f3f71; }
.ftp-toggle { width: 14px; text-align: center; color: #6b7280; font-size: 11px; cursor: pointer; user-select: none; }
.ftp-indent { display: inline-block; width: 14px; }
.ftp-name { flex: 1; min-width: 0; word-break: break-all; cursor: pointer; }
.ftp-count { font-size: 11px; color: #6b7280; white-space: nowrap; }

/* ─── 検索スピナー ─── */
#search-spinner-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.55);
    backdrop-filter: blur(2px);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}
#search-spinner-overlay.active { display: flex; }
.search-spinner {
    width: 48px; height: 48px;
    border: 5px solid #ccc;
    border-top-color: #2471a3;
    border-radius: 50%;
    animation: search-spin 0.7s linear infinite;
}
.search-spinner-label {
    font-size: 13px; color: var(--text-muted); font-weight: 500;
}
@keyframes search-spin {
    to { transform: rotate(360deg); }
}
/* ── Asset category dropdown ── */
#assetCategory {
  height: 28px; padding: 3px 6px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 4px; box-sizing: border-box;
  vertical-align: middle; cursor: pointer; background: var(--bg);
  color: var(--text); transition: border-color .2s, height .15s;
}
#assetCategory:focus { border-color: #4a90e2; outline: none; }
/* マルチセレクト（テキストボックス拡大時）モード */
#assetCategory[multiple] {
  cursor: default; padding: 2px 4px; overflow-y: auto;
}
#assetCategory[multiple] option { padding: 3px 6px; border-radius: 2px; }
/* ── ユーザーメニュー（Phase 6） ── */
.user-menu { position: relative; display: inline-block; }
.user-menu-btn {
  background: none; border: none; cursor: pointer; font-size: 13px;
  color: #1a3a6a; font-weight: 600; padding: 0;
  display: flex; align-items: center; gap: 4px;
}
.user-menu-btn:hover { color: var(--accent); }
.user-menu-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--bg); border: 1px solid var(--border)3ea; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 180px; z-index: 10001;
  overflow: hidden;
}
.user-menu-dropdown.open { display: block; }
.dropdown-header {
  padding: 10px 14px 8px; border-bottom: 1px solid var(--border-light);
}
.dropdown-header .d-username { font-weight: 700; font-size: 13px; color: var(--text); }
.dropdown-header .d-org { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.dropdown-item {
  display: block; width: 100%; padding: 9px 14px; text-align: left;
  background: none; border: none; cursor: pointer; font-size: 13px;
  color: var(--text); text-decoration: none; transition: background .15s;
}
.dropdown-item:hover { background: rgba(37, 99, 235, 0.04); color: #1a3a6a; }
.dropdown-divider { border: none; border-top: 1px solid #eee; margin: 4px 0; }
.dropdown-section-label {
  padding: 6px 14px 2px; font-size: 10px; color: #aaa;
  text-transform: uppercase; letter-spacing: .05em;
}
#sr-toast.error{background:#e74c3c}#sr-toast.ok{background:#27ae60}
/* ── Schema loading badges (N-T9) ── */
.schema-loading-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  color: #7a5c00;
  background: var(--bg)8e1;
  border: 1px solid #f9c74f;
  border-radius: 10px;
  padding: 0 5px;
  line-height: 1.6;
  vertical-align: middle;
  animation: schema-badge-pulse 1.4s ease-in-out infinite;
}
@keyframes schema-badge-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
.schema-item.schema-pending { opacity: 0.6; cursor: default; }
.schema-item.schema-pending:hover { background: none; }
.schema-item.schema-pending input[type="radio"] { cursor: default; }
.schema-loaded-badge {
  font-size: 11px; color: #1e8449; margin-left: 2px;
}

/* ── Dir Graph toggle button (right spacer top) ── */
#dg-toggle-wrap {
  display: none;
  padding: 6px 8px 4px;
  text-align: center;
}
#arch-graph-toggle-btn {
  width: 100%; padding: 5px 10px;
  background: #1a56db; color: #fff;
  border: none; border-radius: 4px;
  font-size: 12px; font-weight: bold; cursor: pointer;
}
#arch-graph-toggle-btn:hover { background: #1344b0; }
#edgenum-wrap {
  display: none;
  padding: 6px 8px 4px;
  flex-direction: column; gap: 2px;
}
#edgenum-wrap input[type=range] { width: 100%; accent-color: #1a56db; }
#edgenum-wrap label { font-size: 11px; color: var(--text-muted); text-align: center; }
/* ── Dir-graph embedded panel ── */
@keyframes dg-spin { to { transform: rotate(360deg); } }
#cy {
  width: 100%; height: calc(100vh - 100px);
  position: relative; display: none; background: var(--bg);
}
#three-graph {
  width: 100%; height: calc(100vh - 100px);
  position: relative; display: none; overflow: hidden;
  background: #06090f;
}
#three-graph canvas { display: block; }
#tg-loading {
  display: none; position: absolute; inset: 0;
  background: rgba(6,9,15,.72); z-index: 10;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; color: #d8f3ff; font-size: 13px;
}
#tg-empty {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  color: #9db7c8; font-size: 13px;
}
#dg-loading {
  display: none; position: absolute; inset: 0;
  background: rgba(255,255,255,.8); z-index: 10;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; color: var(--text); font-size: 13px;
}
.dg-spinner {
  width: 36px; height: 36px; border: 4px solid #ccc;
  border-top-color: #e94560; border-radius: 50%;
  animation: dg-spin .8s linear infinite;
}
#dir-graph-panel {
  display: none; overflow-y: auto; height: calc(100vh - 100px);
  padding: 8px 10px; background: var(--bg-subtle);
  border-left: 1px solid #d0d5dd; box-sizing: border-box;
}
#three-graph-panel {
  display: none; overflow-y: auto; height: calc(100vh - 100px);
  padding: 8px 10px; background: var(--bg-subtle);
  border-left: 1px solid #d0d5dd; box-sizing: border-box;
}
.dgp-row {
  display: flex; align-items: center; gap: 4px; margin-bottom: 6px; flex-wrap: wrap;
}
.dgp-row label { font-size: 11px; color: var(--text-muted); min-width: 52px; }
.dgp-row input[type=text], .dgp-row select {
  flex: 1; font-size: 12px; padding: 3px 5px;
  border: 1px solid #b0b8c4; border-radius: 4px; background: var(--bg);
  box-sizing: border-box; min-width: 0;
}
.dgp-row input[type=number] {
  width: 48px; font-size: 12px; padding: 3px 4px;
  border: 1px solid #b0b8c4; border-radius: 4px; background: var(--bg);
}
.dgp-row input.tg-limit-input {
  width: 78px; flex: 0 0 78px;
}
.dgp-row input[type=range] { flex: 1; accent-color: #e94560; min-width: 0; }
.dg-btn-primary {
  background: #e94560; color: #fff; border: none;
  border-radius: 4px; padding: 4px 10px; cursor: pointer;
  font-size: 12px; font-weight: bold;
}
.dg-btn-primary:hover { background: #c73652; }
.dg-btn-sec {
  background: #f0f0f0; color: var(--text); border: 1px solid #b0b8c4;
  border-radius: 4px; padding: 4px 7px; cursor: pointer; font-size: 11px;
}
.dg-btn-sec:hover { background: #dde3ea; }
.tg-depth-btn.tg-depth-active { background: #1a56db; color: #fff; border-color: #1a56db; }
#dgp-detail { border-top: 1px solid #d0d5dd; padding-top: 8px; margin-top: 8px; }
#dgp-detail-content { font-size: 12px; }
#dgp-detail-content p { margin: 4px 0; color: var(--text); word-break: break-all; }
#dgp-detail-content h4 { font-size: 12px; color: var(--text-muted); margin-top: 8px; margin-bottom: 2px; }
#dgp-detail-content strong { color: var(--primary); }
#tgp-legend { border-top: 1px solid #d0d5dd; padding-top: 8px; margin-top: 8px; }
.tg-legend-row {
  display: grid; grid-template-columns: 16px 12px minmax(0,1fr) auto;
  align-items: center; gap: 6px; padding: 4px 0; font-size: 11px;
}
.tg-legend-row input { margin: 0; }
.tg-legend-swatch { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.18); }
.tg-legend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-legend-count { color: #667085; font-variant-numeric: tabular-nums; }
#tgp-detail { border-top: 1px solid #d0d5dd; padding-top: 8px; margin-top: 8px; }
#tgp-detail-content { font-size: 12px; }
#tgp-detail-content p { margin: 4px 0; color: var(--text); word-break: break-all; }
#tgp-detail-content code { background:#eef0f4; padding:1px 4px; border-radius:3px; }
#tgp-cluster-summary { border-top: 1px solid #d0d5dd; padding-top: 8px; margin-top: 8px; }
#tgp-cluster-summary-content { font-size: 12px; }
#tgp-cluster-summary-content p { margin: 4px 0; color: var(--text); word-break: break-word; }
#tgp-cluster-summary-content .tg-summary-title { font-weight: 700; color: var(--primary); }
#tgp-cluster-summary-content .tg-summary-muted { color: #667085; font-size: 11px; }
#tgp-cluster-summary-content .tg-summary-list { margin: 2px 0 6px; padding-left: 14px; color: var(--text); }
#tgp-cluster-summary-content .tg-summary-list li { margin: 2px 0; word-break: break-word; }
#tgp-cluster-summary-content .tg-folder-chip {
  margin-left: 4px;
  padding: 1px 6px;
  border: 1px solid #b8c0cc;
  border-radius: 4px;
  background: var(--bg);
  color: #344054;
  font-size: 11px;
  line-height: 1.4;
  cursor: pointer;
}
#tgp-cluster-summary-content .tg-folder-chip:hover { background: #f2f4f7; }
