/* ============================================================
   ファイルビュー
   ============================================================ */
.files-view {
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

/* ツールバー */
.files-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.files-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.files-nav-btn:hover:not(:disabled) {
  background: var(--primary-alpha-10);
}
.files-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.files-nav-btn .material-symbols-outlined {
  font-size: 18px;
}

.files-host-switcher {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.files-host-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.files-host-btn:hover {
  background: var(--primary-alpha-10);
  color: var(--text);
}
.files-host-btn.active {
  background: var(--primary-alpha-10);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
#files-root-private { margin-left: 4px; font-family: ui-monospace, monospace; }

.files-breadcrumb-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.files-breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}

.files-crumb {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  color: var(--secondary);
  cursor: pointer;
  transition: background 0.15s;
  font-weight: 500;
}
.files-crumb:hover {
  background: var(--primary-alpha-10);
  color: var(--heading);
}
.files-crumb .material-symbols-outlined {
  font-size: 14px;
}
.files-crumb-sep {
  color: var(--text-light);
  font-size: 12px;
}

.files-search-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}
.files-search-icon {
  font-size: 16px;
  color: var(--text-light);
}
.files-search-input {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  width: 140px;
  outline: none;
}
.files-search-input::placeholder {
  color: var(--text-light);
}

/* メインエリア（左リスト + 右コンテンツ） */
.files-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* 左ペイン（ファイル一覧） */
.files-list-pane {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-bg);
}

.files-sort-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2, #1e1e2e);
  flex-shrink: 0;
}
.files-sort-icon {
  font-size: 15px;
  color: var(--text-muted, #6c7086);
  flex-shrink: 0;
}
.files-sort-select {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  min-width: 0;
}
.files-sort-select option { background: var(--surface, #313244); }

.files-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}

.files-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 0;
  min-width: 0;
}
.files-item:hover {
  background: var(--primary-alpha-10);
}
.files-item.active {
  background: var(--primary-alpha-15);
}
.files-item-icon {
  font-size: 18px;
  flex-shrink: 0;
  color: var(--secondary);
}
.files-item-dir .files-item-icon {
  color: #c9a227;
}
.files-item-binary {
  opacity: 0.5;
  cursor: default;
}
.files-item-image .files-item-icon {
  color: #7aa2d4;
}
.files-item-media .files-item-icon {
  color: #b48ead;
}
.files-item-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.files-item-dir .files-item-name {
  font-weight: 500;
}
.files-item-meta {
  font-size: 11px;
  color: var(--text-light);
  flex-shrink: 0;
  white-space: nowrap;
}

.files-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  color: var(--text-light);
}
.files-spin {
  animation: files-spin 1s linear infinite;
}
@keyframes files-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.files-empty,
.files-error {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  font-size: 13px;
  color: var(--text-light);
}

/* 記憶していたフォルダが無くなり別の場所を開いたときの案内 */
.files-notice {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-light);
  background: var(--black-alpha-05, rgba(0, 0, 0, 0.04));
  border-bottom: 1px solid var(--border);
}

.files-notice .material-symbols-outlined {
  font-size: 16px;
  flex-shrink: 0;
}

/* 右ペイン（ファイル内容） */
.files-content-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.files-content {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.files-content-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-light);
  gap: 10px;
}
.files-content-placeholder .material-symbols-outlined {
  font-size: 48px;
  opacity: 0.3;
}
.files-content-placeholder p {
  font-size: 14px;
  opacity: 0.6;
}

.files-content-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
  flex-shrink: 0;
}
.files-content-header .material-symbols-outlined {
  font-size: 18px;
  color: var(--secondary);
  flex-shrink: 0;
}
.files-content-filename {
  font-size: 14px;
  font-weight: 600;
  color: var(--heading);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.files-content-meta {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}
.files-copy-wrap {
  position: relative;
  flex-shrink: 0;
}

.files-content-copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.files-content-copy-btn:hover {
  background: var(--primary-alpha-10);
  color: var(--text);
}
.files-content-copy-btn .material-symbols-outlined {
  font-size: 16px;
}

.files-copy-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  flex-direction: column;
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.files-copy-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
  font-family: inherit;
}
.files-copy-menu-item:hover {
  background: var(--primary-alpha-10);
}
.files-copy-menu-item .material-symbols-outlined {
  font-size: 16px;
  color: var(--secondary);
}

.files-content-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  color: var(--text-light);
  font-size: 14px;
}
.files-content-error .material-symbols-outlined {
  font-size: 20px;
  color: #c0392b;
}

.files-image-wrap {
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.files-image-preview {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}

/* 動画・音声はペインの高さに収める（縦長の動画でコントローラーが画面外へ出ないように）。
   ヘッダーを除いた残りを wrap に渡すため、中身が媒体のときだけ縦 flex にする */
.files-content:has(> .files-media-wrap) {
  display: flex;
  flex-direction: column;
}
.files-media-wrap {
  flex: 1;
  min-height: 0;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}
.files-media-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: #000;
  display: block;
}
.files-media-audio {
  width: 100%;
  display: block;
}

.files-pre {
  margin: 0;
  padding: 16px;
  font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: break-word;
  tab-size: 2;
}

/* JSONシンタックスハイライト（フォールバック用） */
.files-pre-json { padding: 20px; }
.json-key     { color: #9cdcfe; }
.json-string  { color: #ce9178; }
.json-number  { color: #b5cea8; }
.json-boolean { color: #569cd6; }
.json-null    { color: #569cd6; }
.files-json-warning {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(249, 168, 37, 0.12);
  color: #f9a825;
  font-size: 12px;
  border-bottom: 1px solid rgba(249, 168, 37, 0.25);
}
.files-json-warning .material-symbols-outlined { font-size: 16px; }

/* JSON ツリービュー */
.json-tree {
  padding: 12px 16px;
  font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  overflow-y: auto;
  overflow-x: hidden;
}
.json-row,
.json-coll-header,
.json-coll-footer {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  min-height: 1.7em;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: break-word;
}
.json-coll-body { padding-left: 20px; }
.json-collapsible.collapsed .json-coll-body,
.json-collapsible.collapsed .json-coll-footer { display: none; }
.json-collapsible:not(.collapsed) .json-hint { display: none; }
.json-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  margin-right: 3px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted, #6c7086);
  border-radius: 3px;
  line-height: 1;
  vertical-align: middle;
}
.json-toggle-btn:hover { background: var(--primary-alpha-10, rgba(137,180,250,0.1)); }
.json-toggle-btn::before {
  content: '▼';
  font-size: 8px;
  display: inline-block;
  transition: transform 0.12s;
}
.json-collapsible.collapsed .json-toggle-btn::before { transform: rotate(-90deg); }
.json-collapsible.collapsed > .json-coll-header > .json-toggle-btn {
  color: #ff2020;
}
.json-collapsible.collapsed > .json-coll-header > .json-toggle-btn:hover {
  background: rgba(255,32,32,0.15);
}
.json-bracket { color: var(--text, #cdd6f4); }
.json-punct   { color: var(--text-muted, #6c7086); }
.json-hint    { color: var(--text-muted, #6c7086); font-style: italic; white-space: pre; }
.json-truncated { color: var(--text-muted, #6c7086); }
.json-more    { color: var(--text-muted, #6c7086); font-style: italic; padding-left: 4px; }

/* JSONキーフィルター */
.json-fkey {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s;
}
.json-fkey:hover { background: var(--primary-alpha-10, rgba(137,180,250,0.12)); }
.json-fkey.active-fkey {
  background: rgba(137,180,250,0.22);
  outline: 1px solid rgba(137,180,250,0.5);
}
.json-filter-panel {
  padding: 10px 16px;
  font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  overflow-y: auto;
  overflow-x: hidden;
}
.json-filter-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.json-filter-count {
  color: var(--text-muted, #6c7086);
  font-style: italic;
  font-size: 12px;
}
.json-filter-close-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted, #6c7086);
  border-radius: 4px;
  padding: 2px;
}
.json-filter-close-btn:hover { background: var(--hover); color: var(--text); }
.json-filter-close-btn .material-symbols-outlined { font-size: 18px; }
.json-filter-list { display: flex; flex-direction: column; gap: 2px; }
.json-filter-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 2px 4px;
  border-radius: 3px;
}
.json-filter-item:hover { background: var(--hover); }
.json-filter-idx {
  color: var(--text-muted, #6c7086);
  font-size: 11px;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}
.json-filter-objkey {
  color: var(--primary, #89b4fa);
  font-size: 11px;
  min-width: 60px;
  max-width: 160px;
  text-align: right;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.json-filter-missing { color: var(--text-muted, #6c7086); font-style: italic; }

/* JSON 検索バー */
.files-json-search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2, #1e1e2e);
  position: sticky;
  top: 0;
  z-index: 2;
}
.files-json-search-icon {
  font-size: 17px;
  color: var(--text-muted, #6c7086);
  flex-shrink: 0;
}
.files-json-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
  min-width: 0;
}
.files-json-search-input::placeholder { color: var(--text-muted, #6c7086); }
.files-json-search-count {
  color: var(--text-muted, #6c7086);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.files-json-search-clear {
  display: inline-flex;
  align-items: center;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted, #6c7086);
  border-radius: 4px;
  padding: 2px;
  flex-shrink: 0;
}
.files-json-search-clear:hover { background: var(--hover); color: var(--text); }
.files-json-search-clear .material-symbols-outlined { font-size: 16px; }
mark.json-search-mark {
  background: rgba(255, 214, 0, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.json-search-empty {
  padding: 20px 16px;
  color: var(--text-muted, #6c7086);
  font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  font-style: italic;
}

/* Markdownレンダリング */
.files-markdown {
  padding: 20px 24px;
  color: var(--text);
  line-height: 1.75;
  font-size: 15px;
}

.files-markdown h1,
.files-markdown h2,
.files-markdown h3,
.files-markdown h4 {
  color: var(--heading);
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
}

.files-markdown h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.files-markdown h2 { font-size: 1.35em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.2em; }
.files-markdown h3 { font-size: 1.15em; }
.files-markdown h4 { font-size: 1em; }

.files-markdown p { margin: 0.6em 0; }
.files-markdown p:first-child { margin-top: 0; }
.files-markdown p:last-child { margin-bottom: 0; }

.files-markdown a { color: #8be9fd; text-decoration: underline; }
.files-markdown a:hover { color: #cdfff4; }

.files-markdown ul,
.files-markdown ol {
  margin: 0.5em 0;
  padding-left: 1.8em;
}

.files-markdown li { margin: 0.2em 0; }

.files-markdown blockquote {
  border-left: 3px solid var(--primary);
  margin: 0.8em 0;
  padding: 4px 12px;
  color: var(--text-light);
  background: var(--primary-alpha-10);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.files-markdown code {
  background: var(--primary-alpha-10);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.85em;
  font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
}

.files-markdown pre {
  background: #1e1e2e;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0.8em 0;
}

.files-markdown pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: #cdd6f4;
}

.files-markdown-table-wrap {
  overflow-x: auto;
  margin: 0.8em 0;
  -webkit-overflow-scrolling: touch;
}

.files-markdown table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 0.9em;
}

.files-markdown th,
.files-markdown td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}

.files-markdown th {
  background: var(--primary-alpha-10);
  color: var(--heading);
}

.files-markdown tr:nth-child(even) td { background: var(--primary-alpha-10); }

.files-markdown img {
  max-width: 100%;
  border-radius: var(--radius-md);
}

.files-markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

/* Mermaid ダイアグラム */
.files-markdown .mermaid {
  display: flex;
  justify-content: center;
  margin: 1em 0;
  background: #1e1e2e;
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
}

/* リサイズハンドル（モバイル専用） */
.files-resize-handle {
  display: none;
}
@media (max-width: 768px) {
  .files-resize-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 12px;
    flex-shrink: 0;
    background: var(--bg-sub, #1a1a2e);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: row-resize;
    touch-action: none;
    z-index: 5;
  }
  .files-resize-handle:active,
  .files-resize-handle.dragging {
    background: var(--primary-alpha-10);
  }
  .files-resize-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
  }
  .files-resize-handle:active .files-resize-handle-bar,
  .files-resize-handle.dragging .files-resize-handle-bar {
    background: var(--primary, #6272a4);
  }
}

/* モバイル対応 */
@media (max-width: 768px) {
  .files-main {
    flex-direction: column;
    overflow: hidden;
  }
  .files-list-pane {
    width: 100%;
    border-right: none;
    border-bottom: none;
    height: 40vh;
    min-height: 60px;
    flex-shrink: 0;
    display: block;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }
  .files-list {
    height: auto;
    overflow: visible;
  }
  .files-content-pane {
    flex: 1;
    min-height: 40vh;
    display: block;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }
  .files-content {
    height: auto;
    overflow: visible;
  }
  /* モバイルはペインごとスクロールさせるため高さが auto。媒体のときだけペインに合わせる */
  .files-content:has(> .files-media-wrap) {
    height: 100%;
  }
  .files-search-input {
    width: 80px;
  }
  .files-content-meta {
    display: none;
  }
}
