/* ============================================================
   coffee ファイル閲覧

   PC: レイアウトの一部として右に並べる（ターミナルを押しのける）。
       閉じているときは display:none で場所も取らない。
   モバイル: 右から出るドロワー（下のメディアクエリで上書き）。
   中身はどちらも縦積み（上: プレビュー / 下: ツリー）。
   ============================================================ */
.coffee-files-overlay {
  display: none;   /* PC では背景を敷かない（ペインなので裏側も操作できる） */
}

.coffee-files-drawer {
  display: none;
  flex: 0 0 auto;
  width: var(--coffee-files-width, 40%);
  min-width: 300px;
  max-width: 80%;
  min-height: 0;
  flex-direction: column;
  background: #1e1e2e;
  border-left: 1px solid #45475a;
  overflow: hidden;
}
.coffee-files-drawer.open {
  display: flex;
}

/* ターミナルとファイルペインの境界（PC・表示中のみ）。
   .coffee-sidebar-resizer と同じ作りにしてある。 */
.coffee-files-resizer {
  display: none;
  flex: 0 0 4px;
  cursor: col-resize;
  background: #313244;
}
.coffee-layout.files-open .coffee-files-resizer {
  display: block;
}
.coffee-files-resizer:hover,
.coffee-files-resizer.dragging { background: #585b70; }

.coffee-files-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}
/* ルート（＝画面のカレントディレクトリ）。末尾のフォルダ名だけ出す */
.coffee-files-title {
  font-size: 0.9rem;
  color: #cdd6f4;
  font-weight: 600;
  flex-shrink: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ルートを1つ上へ（ホームでは押せない） */
.coffee-files-up {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #a6adc8;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-up:hover:not(:disabled) { color: #89b4fa; background: #313244; }
.coffee-files-up:disabled { opacity: 0.3; cursor: default; }
/* ホーム ⇄ /private の切替。文字で出すので ↑ より小さく */
.coffee-files-jump { font-size: 0.75rem; font-family: ui-monospace, monospace; }
.coffee-files-path {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  color: #7f849c;
  font-family: 'Consolas', 'Monaco', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* HTML のソース/描画 切り替え（HTML を開いているときのみ表示） */
.coffee-files-source {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #a6adc8;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-source:hover { color: #89b4fa; background: #313244; }

/* 印刷（HTML を開いているときのみ表示） */
.coffee-files-print {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #a6adc8;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-print .material-symbols-outlined { font-size: 1.1rem; }
.coffee-files-print:hover { color: #89b4fa; background: #313244; }
.coffee-files-print:disabled { opacity: 0.4; cursor: default; }
.coffee-files-print.failed { color: #f38ba8; }

/* 印刷用の隠し iframe。画面外に置くだけで、描画自体はさせる
   （display:none や visibility:hidden にすると中で print() が動かない）。
   大きさを与えるのは、幅を見て描くスクリプトのため。 */
.cf-print-frame {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1024px;
  height: 768px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* HTML ビューア: サンドボックス iframe をペインいっぱいに置く */
.cf-html {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* ダウンロード（ファイル選択中のみ表示） */
.coffee-files-download {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #a6adc8;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-download .material-symbols-outlined { font-size: 1.1rem; }
.coffee-files-download:hover { color: #89b4fa; background: #313244; }
.coffee-files-download:disabled { opacity: 0.4; cursor: default; }

.coffee-files-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #6c7086;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-close:hover { color: #ff5555; background: #313244; }

/* 上: プレビュー / 下: ツリー。DOM 順（ツリー→内容）は変えずに入れ替える */
.coffee-files-body {
  display: flex;
  flex-direction: column-reverse;
  flex: 1;
  min-height: 0;
}

.coffee-files-tree {
  flex: 0 0 38%;
  overflow: auto;
  background: #11111b;
  padding: 6px 0;
  font-size: 0.82rem;
  -webkit-overflow-scrolling: touch;
}

/* ツリーと内容の境界。仕切り線を兼ねる（ドラッグで高さの比率を変えられる）。
   細いと指で掴めないので高さを確保する。 */
.coffee-files-split {
  flex: 0 0 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #181825;
  border-top: 1px solid #313244;
  border-bottom: 1px solid #313244;
  cursor: row-resize;
  touch-action: none;   /* ドラッグ中にブラウザのスクロールを走らせない */
  -webkit-tap-highlight-color: transparent;
}
.coffee-files-split::after {
  content: '';
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: #45475a;
}
.coffee-files-split:hover::after { background: #585b70; }
.coffee-files-split.dragging { background: #1e1e2e; }
.coffee-files-split.dragging::after { background: #89b4fa; }

.coffee-files-content {
  flex: 1;
  min-width: 0;
  min-height: 0;   /* 縦積み（モバイル）で縮めるために必要 */
  overflow: auto;
  background: #1e1e2e;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.cf-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  color: #cdd6f4;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cf-row:hover { background: #1e1e2e; }
.cf-row.active { background: #313244; }
.cf-row.cf-dir { color: #89b4fa; }
.cf-icon {
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  color: #7f849c;
  font-size: 0.7rem;
}
.cf-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.cf-children { }

.cf-text {
  margin: 0;
  padding: 14px 16px;
  color: #cdd6f4;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre;
  tab-size: 4;
}
.cf-image {
  display: block;
  max-width: 100%;
  margin: 16px auto;
  background: repeating-conic-gradient(#2a2a3a 0% 25%, #22222e 0% 50%) 50% / 20px 20px;
}
/* PC のプレビューペインで再生する動画（モバイルは上部のプレイヤーを使う） */
.cf-video {
  display: block;
  width: 100%;
  max-height: 100%;
  background: #000;
}
/* PC のプレビューペインで鳴らす音声。映像が無いので標準コントローラーを出す */
.cf-audio {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
}

/* 図はペインいっぱいに固定し、拡大縮小と移動はホイール／ドラッグで行う。
   スクロールさせないため overflow:hidden にする。 */
.cf-drawio {
  position: absolute;
  inset: 0;
  background: #ffffff;
  overflow: hidden;
}
/* container 側でスクロールさせないこと（!important は mxGraph が
   インラインで overflow:auto を書き戻すため）。スクロールできる状態だと、
   CSS transform で動かした分をブラウザがスクロールで打ち消してしまい、
   拡大するほど図がずれていく。はみ出しは .cf-drawio 側で切る。 */
.cf-drawio .mxgraph {
  width: 100%;
  height: 100%;
  background: #ffffff;
  overflow: visible !important;
}
.cf-drawio .mxgraph > div { height: 100%; }
/* PDF: ページ canvas をグレー地に並べる（一般的な PDF ビューアに合わせた見た目） */
.cf-pdf {
  padding: 16px;
  background: #525659;
  min-height: 100%;
}
.cf-pdf-page {
  max-width: 900px;
  margin: 0 auto 16px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.cf-pdf-page:last-child { margin-bottom: 0; }
.cf-pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
}
.cf-pdf-page.cf-pdf-failed {
  background: #3a3a42;
  box-shadow: none;
}

.cf-message {
  padding: 20px;
  color: #7f849c;
  font-size: 0.85rem;
}
.cf-message.cf-error { color: #f38ba8; }
/* 復元で選ばれた動画を、押したときだけプレイヤーへ載せるボタン */
.cf-play {
  margin-top: 12px;
  padding: 10px 16px;
  border: 1px solid #45475a;
  border-radius: 6px;
  background: #313244;
  color: #cdd6f4;
  font-size: 0.85rem;
  cursor: pointer;
}
.cf-play:active { background: #45475a; }

/* ------------------------------------------------------------
   Markdown プレビューはライトテーマ（白地・黒文字）で表示する。
   .files-markdown はファイルビューと共有しているため、変数の再定義と
   ハードコード色の上書きをこのモーダル内だけにスコープする。
   ------------------------------------------------------------ */
.coffee-files-content .files-markdown {
  --text: #1f2328;
  --text-light: #57606a;
  --heading: #0d1117;
  --border: #d0d7de;
  --border-light: #e4e8ed;
  --primary: #0969da;
  --primary-alpha-10: #f2f4f7;
  min-height: 100%;
  background: #ffffff;
  color: var(--text);
}

.coffee-files-content .files-markdown a { color: #0969da; }
.coffee-files-content .files-markdown a:hover { color: #0550ae; }

.coffee-files-content .files-markdown pre { background: #f6f8fa; border: 1px solid #d0d7de; }
.coffee-files-content .files-markdown pre code { color: #1f2328; }

.coffee-files-content .files-markdown .mermaid {
  background: #ffffff;
  border: 1px solid #d0d7de;
}

/* モバイルは右から出るドロワー。
   閉状態は translateX(100%) で画面外にあるが、そのままだと右端が
   ヒットテストに残るため visibility: hidden で外す
   （画面リストのドロワーと同じ方針。visibility はスライド完了後に遅延）。 */
@media (max-width: 768px) {
  .coffee-files-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .coffee-files-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .coffee-layout.files-open .coffee-files-resizer { display: none; }

  /* 左レールぶんだけ空けて、そこをタップでも閉じられるようにする */
  .coffee-files-drawer {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: calc(100% - var(--mobile-rail-width, 0px));
    min-width: 0;
    max-width: none;
    z-index: 2010;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    /* ヘッダーは最下部（操作するものほど親指の届く側に置く） */
    flex-direction: column-reverse;
  }
  .coffee-files-drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.2s ease;
  }
  .coffee-files-header {
    border-bottom: none;
    border-top: 1px solid #313244;
  }
  /* 指で掴めるようつまみを少し厚く */
  .coffee-files-split {
    flex: 0 0 16px;
    height: 16px;
  }
}
.memo-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.memo-sidebar {
  width: 260px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  overflow: hidden;
}

.memo-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.memo-editor-area {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.memo-editor {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 16px;
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}

.memo-editor::placeholder {
  color: var(--text-light);
}

.memo-save-status {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-light);
  min-width: 40px;
  text-align: right;
}

/* ロックボタン */
.memo-lock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-light);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  margin-left: 8px;
}

.memo-lock-btn:hover {
  background: var(--hover-bg);
  color: var(--text-color);
}

.memo-lock-btn.locked {
  border-color: #e8934a;
  color: #e8934a;
  background: rgba(232, 147, 74, 0.08);
}

.memo-lock-btn.locked:hover {
  background: rgba(232, 147, 74, 0.18);
}

.memo-lock-btn .material-symbols-outlined {
  font-size: 18px;
}

/* サイドバーのロックアイコン */
.memo-list-lock {
  font-size: 16px;
  color: #e8934a;
  flex-shrink: 0;
  padding: 4px;
  opacity: 0.85;
}

/* メモ帳 モバイル対応 */
@media (max-width: 768px) {
  /* 一覧はオフキャンバスのドロワー（左レールの右から出現）。
     coffee の画面リストと同じ作りで、右スワイプ／ハンバーガーで開き、
     左スワイプ・オーバーレイのタップ・メモの選択で閉じる。
     閉状態は translateX(-100%) でちょうど左レールの真上に重なるため、
     visibility: hidden でヒットテストから外す（外さないとレールがタップ不能になる）。
     高さは 100vh ではなく top/bottom で取る — 100vh はレイアウトビューポート
     基準で OSK が出ても縮まず、下端がキーボードの裏へ回り込む */
  .memo-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--mobile-rail-width, 0);
    width: calc(75% - var(--mobile-rail-width, 0px));
    min-width: 0;
    max-width: 300px;
    z-index: 610;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    box-shadow: 2px 0 8px var(--black-alpha-10);
  }

  .memo-sidebar.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.2s ease;
  }
}

