:root {
  /* High-Contrast Minimalism Refined (Brighter HUD) */
  --bg-main: #0a0a0c;
  --bg-surface: #121214;
  --bg-panel: #18181b;
  --border-subtle: #202023;
  --border-base: #2e2e32;
  --border-strong: #3f3f46;

  --accent-blue: #60a5fa;
  --accent-purple: #a5b4fc;
  --accent-success: #4ade80;
  --accent-warning: #fbbf24;
  --accent-error: #f87171;

  --text-primary: #ffffff;
  --text-secondary: #d4d4d8;
  --text-dim: #71717a;

  --sidebar-width: 240px;
  --header-height: 56px;
  --footer-height: 40px;
}

/* Reset & base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
}

h1,
h2,
h3,
.logo-mark {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
}

/* Container & Layout */
.container {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: var(--footer-height);
  overflow: hidden;
}

.layout {
  display: flex;
  height: 100%;
  width: 100%;
}

/* Header (HUD) */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-base);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-mark {
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-shadow: 0 0 12px rgba(165, 180, 252, 0.3);
}

.edition-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}
.edition-badge--community {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.edition-badge--pro {
  background: rgba(99, 102, 241, 0.2);
  color: var(--accent-purple);
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.header-info {
  display: flex;
  gap: 16px;
  align-items: center;
}

.model-name-top {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: monospace;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-dot.idle {
  background: var(--text-dim);
}

.status-dot.running {
  background: var(--accent-success);
  box-shadow: 0 0 4px var(--accent-success);
}

.status-dot.stopped {
  background: var(--accent-error);
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: var(--header-height);
  bottom: var(--footer-height);
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-base);
  display: flex;
  flex-direction: column;
  z-index: 90;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover {
  background: var(--bg-panel);
  color: var(--text-primary);
}

.nav-item.active {
  color: var(--accent-purple);
  background: var(--bg-panel);
  border-right: 2px solid var(--accent-purple);
  text-shadow: 0 0 8px rgba(165, 180, 252, 0.4);
}

.sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  padding-top: 8px;
}

.sidebar-resizer {
  position: absolute;
  right: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 100;
}

/* Main Panel */
.main-content {
  flex: 1;
  min-height: 0;
  height: 100%;
  background: var(--bg-main);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* カスタム要素は既定で inline のため、確実にブロックで高さを確保 */
main-panel,
.main-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  width: 100%;
  background: var(--bg-main, #0a0a0c);
}

/* JS で innerHTML が差し替わるまでのフォールバック表示 */
.main-panel-loading {
  padding: 24px;
  color: var(--text-primary, #ffffff);
  font-size: 0.95rem;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  min-height: 0;
  /* CRITICAL: allows flex child to shrink and scroll */
  background: var(--bg-main, #0a0a0c);
  color: var(--text-primary, #ffffff);
}

/* パネル内のテキスト・フォームが必ず見えるように */
.panel h2,
.panel label,
.panel legend,
.panel .empty-state,
.panel .settings-form,
.panel .setting-row {
  color: var(--text-primary, #ffffff);
}

/* Toast UI ツールバーアイコン用ボタンは除外（.panel button を当てると background ショートハンドで background-image が消える） */
.panel input,
.panel button:not(.toastui-editor-toolbar-icons):not([class*="toolbar-icons"]) {
  color: var(--text-primary, #ffffff);
  background: var(--bg-surface, #121214);
}

/* 検索・文書パネルも確実に表示されるように */
.panel-search,
.panel-docs {
  background: var(--bg-main, #0a0a0c);
  color: var(--text-primary, #ffffff);
}

.panel.hidden {
  display: none;
}

.panel-settings {
  background: var(--bg-main, #0a0a0c);
  color: var(--text-primary, #ffffff);
  overflow-y: auto;
}

.panel-settings h2,
.panel-settings .settings-form,
.panel-settings .setting-row label,
.panel-settings legend,
.panel-settings input,
.panel-settings button {
  color: var(--text-primary, #ffffff);
}

.settings-form {
  margin-top: 8px;
}
.settings-fieldset {
  border: 1px solid var(--border-base);
  border-radius: 6px;
  padding: 16px;
  color: var(--text-primary);
}
.settings-fieldset legend {
  padding: 0 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.setting-row label {
  min-width: 140px;
  font-size: 0.9rem;
}
.setting-row .setting-checkbox-label {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.setting-row input[type="number"] {
  width: 80px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.setting-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.settings-feedback {
  font-size: 0.85rem;
  color: var(--accent-green);
}
.settings-feedback.error {
  color: var(--accent-red, #ef4444);
}
.setting-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.setting-monitor-paths-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.setting-monitor-path-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.setting-monitor-path-row .setting-monitor-path {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.setting-monitor-path-row .setting-monitor-category {
  width: 120px;
  flex-shrink: 0;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.setting-monitor-path-row .setting-monitor-path-remove {
  flex-shrink: 0;
}
.setting-row-watch-extensions {
  align-items: flex-start;
}
.setting-row-watch-extensions .setting-watch-extensions-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}
.setting-watch-extensions {
  width: 100%;
  min-width: 24em;
  max-width: 100%;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
  box-sizing: border-box;
}
.setting-hint-block {
  display: block;
  margin-top: 0;
}

/* 文書管理パネル */
.docs-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.docs-toolbar .secondary-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 8px 14px;
  font-weight: 600;
}
.docs-toolbar .secondary-btn:hover {
  background: var(--border-base);
  border-color: var(--accent-blue);
  color: var(--text-primary);
}
.docs-list {
  overflow: auto;
  margin-bottom: 16px;
}
.docs-pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.docs-pager-btn {
  padding: 6px 14px;
  font-size: 0.9rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
}
.docs-pager-btn:hover:not(:disabled) {
  background: var(--border-base);
  border-color: var(--accent-blue);
  color: var(--text-primary);
}
.docs-pager-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.docs-pager-info {
  color: var(--text-dim);
  font-size: 0.9rem;
}
.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.docs-table th,
.docs-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}
.docs-table th {
  color: var(--text-dim);
  font-weight: 600;
}
.docs-cell-path {
  font-family: ui-monospace, monospace;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.docs-cell-preview {
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
  font-size: 0.85em;
}
.docs-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.docs-btn {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
}
.docs-btn:hover {
  border-color: var(--accent-purple);
  color: var(--text-primary);
}
.docs-btn-delete:hover {
  border-color: var(--accent-error);
  color: var(--accent-error);
}
.docs-form-area {
  margin-top: 16px;
}
.docs-form-area .docs-input,
.docs-form-area .docs-textarea {
  width: 100%;
  max-width: 400px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.docs-textarea {
  min-height: 120px;
  resize: vertical;
}
.docs-import-row .docs-import-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.docs-import-row #docs-file-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.docs-import-feedback {
  font-size: 0.85rem;
  color: var(--text-dim);
}
.docs-import-feedback.error {
  color: var(--accent-error);
}
.docs-editor-container {
  min-height: 320px;
  width: 100%;
  max-width: 640px;
}
.docs-editor-container .toastui-editor-defaultUI {
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}
/* Toast UI ツールバー: 当てない（アイコンはバンドル CSS の background-image スプライトで描画） */
.docs-editor-fallback {
  padding: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* 編集モーダル */
.docs-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.docs-edit-modal.hidden {
  display: none !important;
}
.docs-edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.docs-edit-modal-box {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 90%;
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
}

/* 編集モーダル内の保存・キャンセルボタン */
.docs-edit-modal .setting-actions {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}
.docs-edit-modal .setting-actions .secondary-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  color: var(--text-primary);
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
}
.docs-edit-modal .setting-actions .secondary-btn:hover {
  background: var(--border-base);
  border-color: var(--accent-blue);
  color: var(--text-primary);
}
#docs-save-btn {
  background: rgba(96, 165, 250, 0.15);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
#docs-save-btn:hover {
  background: rgba(96, 165, 250, 0.25);
  border-color: var(--accent-blue);
  color: #93c5fd;
}

/* Search Area */
.search-container {
  flex-shrink: 0;
  /* Don't shrink the search bar */
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.search-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent-purple);
}

.search-category-filter {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 0.85rem;
  max-width: 140px;
}
.search-category-filter:focus {
  border-color: var(--accent-purple);
}
.result-category-badge {
  display: inline-block;
  background: var(--accent-purple);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.search-btn {
  background: var(--accent-purple);
  color: #000;
  font-weight: 700;
  padding: 0 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(165, 180, 252, 0.2);
  transition: transform 0.1s, box-shadow 0.2s;
}

.search-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 20px rgba(165, 180, 252, 0.4);
}

.search-btn:active {
  transform: translateY(0);
}

/* Results */
.results-panel {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 24px;
  padding-right: 8px;
}

.search-hint {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 500;
}
.search-hint-ok {
  background: rgba(76, 175, 80, 0.15);
  border: 1px solid rgba(76, 175, 80, 0.4);
  color: var(--text-primary);
}
.search-hint-warn {
  background: rgba(255, 152, 0, 0.15);
  border: 1px solid rgba(255, 152, 0, 0.4);
  color: var(--text-primary);
}

.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.result-card:hover {
  border-color: var(--border-strong);
}

.result-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: monospace;
}

.result-content {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Activity Log */
.activity-log {
  flex-shrink: 0;
  /* Keep fixed height log at bottom */
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 4px;
  padding: 12px;
  height: 140px;
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.activity-log-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

#activity-items {
  flex: 1;
  overflow-y: auto;
}

.log-item {
  font-size: 0.75rem;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  font-family: monospace;
}

.log-method {
  color: var(--accent-purple);
}

.log-time {
  color: var(--text-dim);
}

/* Footer */
.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-height);
  background: var(--bg-main);
  border-top: 1px solid var(--border-base);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
}

.footer-inner {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.footer-ingestion-status {
  flex: 1;
  text-align: center;
  min-height: 1em;
  color: var(--text-secondary, var(--text-dim));
}

/* Buttons and UI */
.actions {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}

.secondary-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

.secondary-btn:hover {
  background: var(--bg-panel);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.warning-btn:hover {
  border-color: var(--accent-warning);
  color: var(--accent-warning);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
}

/* Accordion */
.accordion-header {
  width: 100%;
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: bold;
  text-align: left;
  cursor: pointer;
}

.accordion-content {
  padding: 0 16px 8px 16px;
  font-size: 0.75rem;
}

/* Modal */
#mcp-json-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 640px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 24px;
  z-index: 200;
  display: none;
}

#mcp-json-modal.open {
  display: block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 190;
  display: none;
}

.modal-overlay.open {
  display: block;
}

pre {
  background: var(--bg-main);
  border: 1px solid var(--border-base);
  padding: 12px;
  border-radius: 4px;
  color: var(--text-secondary);
  font-family: monospace;
  font-size: 0.8rem;
  max-height: 480px;
  overflow: auto;
}

/* Utils */
.hidden {
  display: none !important;
}
/* 設定パネル内の非表示フィールドセット（起動・フォルダモニタ） */
.panel-settings .settings-fieldset.hidden {
  display: none !important;
}

.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.empty-state.error-state {
  color: var(--accent-error);
}