/* styles.css */
/* ============================= */
/* ======== ベーススタイル ======== */
/* ============================= */

body {
  font-family: sans-serif;
  background: #f0f0f5;
  color: #000000;
  padding: 20px;
  margin: 0;
  transition: background 0.3s, color 0.3s;
}

h1 {
  font-size: 1.5em;
  margin-bottom: 1em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* テーマ切替ボタン */
.theme-toggle {
  background: transparent;
  border: none;
  font-size: 1em;
  cursor: pointer;
  padding: 0.3em;
}

/* ── 全体レイアウト: Flexboxで左右2カラム ───────────────────────── */
.layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

/* 左カラム（メインコンテンツ） */
.main-content {
  flex: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: auto;
  gap: 16px;
}

/* 左カラム 内部で 2列に跨る要素 */
.main-content .span-two-columns {
  grid-column: 1 / span 2;
}

/* 右カラム（サイドバー） */
.sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

/* ── 各セクション共通スタイル ───────────────────────────────────────── */
.section {
  background: #ffffff;
  border-radius: 8px;
  padding: 1em;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: background 0.3s, box-shadow 0.3s;
  height: auto;
  max-height: none;
}

/* details をセクションとして使う場合 */
details.section {
  padding: 1em;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* summary 部分 */
details > summary {
  font-weight: bold;
  cursor: pointer;
  margin-bottom: 0.5em;
}

/* 見出し右のボタン群をまとめる */
.header-buttons > button {
  margin-left: 0.5em;
}

/* ── テンプレート管理用コントロール ───────────────────────────────────── */
.template-controls {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
  margin-bottom: 0.5em;
}

#template-name-input,
#new-category-input {
  padding: 0.5em;
  border-radius: 5px;
  border: 1px solid #ccc;
}

/* ── タグ検索入力欄 ───────────────────────────────────────── */
#tag-search-input {
  padding: 0.5em;
  border-radius: 5px;
  border: 1px solid #ccc;
  background: #f9f9ff;
  color: #000;
}

/* ── カテゴリ管理エリア（縦並び） ───────────────────────────────────────── */
#category-management {
  margin-top: 1em;
  padding: 1em;
  background: #f9f9f9;
  border: 1px solid #ccc;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

#category-management input,
#category-management select,
#category-management button {
  width: 100%;
  font-size: 1em;
  padding: 0.4em;
  border: 1px solid #ccc;
  background: #ffffff;
  color: #000000;
  border-radius: 5px;
}

#category-management button:hover {
  background-color: #286090;
}

/* ── タグ読み込みセクション ─────────────────────────────────────────── */
.tag-loading {
  display: flex;
  flex-direction: column;
}

.tag-loading input,
.tag-loading select,
.tag-loading button {
  flex: 1;
}

.tag-loading input,
.tag-loading select {
  margin-bottom: 0.5em;
  padding: 0.5em;
  border-radius: 5px;
  border: 1px solid #ccc;
}

/* ── 補完スペース用スタイル ───────────────────────────────────────── */
.extra-section {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.extra-controls {
  flex: 0 0 auto;
  margin-bottom: 0.5em;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.extra-select {
  padding: 0.4em;
  border-radius: 5px;
  border: 1px solid #ccc;
  background: #ffffff;
  color: #000000;
}

.load-extra-button,
.delete-extra-button {
  background-color: #2563eb;
  color: white;
  border: none;
  padding: 0.4em;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
}

.delete-extra-button {
  background-color: #ef4444;
}

.load-extra-button:hover {
  background-color: #1d4ed8;
}

.delete-extra-button:hover {
  background-color: #c53030;
}

/* ── 一括カテゴリ設定 UI ───────────────────────────────────────── */
.extra-bulk-category {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 0.5em;
}

#bulk-category-select {
  padding: 0.4em;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: #ffffff;
  color: #000000;
  font-size: 0.95em;
  width: auto;
}

.extra-bulk-category button {
  font-size: 0.95em;
  padding: 0.4em 0.8em;
  border: none;
  border-radius: 6px;
  background-color: #337ab7;
  color: white;
  cursor: pointer;
}

.extra-bulk-category button:hover {
  background-color: #286090;
}

.extra-bulk-category label {
  font-size: 0.9em;
  white-space: nowrap;
}

.extra-list {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0; /* Firefox対応 */
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

/* ── タグ表示領域（ベース／キャラ／ネガティブ） ─────────────────────────── */
.tag-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  max-height: 120px;
  overflow-y: auto;
  padding: 0.5em;
  background: #f9f9ff;
  border: 1px solid #ddd;
  border-radius: 8px;
  transition: background 0.3s, border-color 0.3s;
}

/* 個々のタグ */
.tag {
  display: flex;
  align-items: center;
  background: #e0e7ff;
  padding: 0.3em 0.6em;
  border-radius: 9999px;
  border: 1px solid transparent;
  position: relative;
  transition: background 0.3s, border-color 0.3s;
}

/* 括弧強調（positive） */
.tag.positive {
  background: #c7eaff;
  border-color: #3b82f6;
}

/* 括弧抑制（negative） */
.tag.negative {
  background: #ffe0e0;
  border-color: #dc2626;
}

/* コロン形式 */
.tag.colon {
  background: #e6ffcc;
  border-color: #84cc16;
  color: #000000;
}

/* plain（通常タグ）はデフォルトの青系背景 */
.tag.plain {
  background: #e0e7ff;
  border-color: transparent;
}

/* タグ内の入力フィールド */
.tag input {
  border: none;
  background: transparent;
  font-size: 1em;
  max-width: 150px;
  color: inherit;
}

/* weight 数値表示（表示モードと編集モード） */
.tag .weight {
  font-size: 0.8em;
  margin-left: 0.5em;
  color: #444;
  cursor: pointer;
}

.tag .weight.editing {
  display: none;
}

.tag .weight-input {
  width: 3em;
  font-size: 0.8em;
  margin-left: 0.5em;
  display: none;
}

/* タグ内のボタン（+ - ×） */
.tag button {
  margin-left: 0.3em;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 1.5em;
  height: 1.5em;
  font-size: 0.9em;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s;
}

.tag button:hover {
  background: #c53030;
}

/* ── ドラッグハンドル用スタイル ───────────────────────────────────────── */
.drag-handle {
  cursor: grab;
  margin-right: 0.4em;
  font-size: 1em;
  color: #666;
}

body.dark-mode .drag-handle {
  color: #aaa;
}

/* コロン形式タグ：ダークモードでも濃い緑背景＋明るい文字色 */
body.dark-mode .tag.colon {
  background: #335533 !important;
  border-color: #84cc16 !important;
  color: #eaffea !important;
}

/* ── 共通ボタン／入力欄スタイル ───────────────────────────────────────── */
button,
select,
input[type="text"],
input[type="file"] {
  padding: 0.5em;
  border-radius: 5px;
  border: 1px solid #ccc;
  background: #ffffff;
  color: #000000;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

button:hover {
  background: #e2e8f0;
}

/* キャラクタープロンプト追加ボタン */
.add-button {
  background-color: #22c55e;
  color: white;
  border: none;
  margin-top: 0.5em;
}

.add-button:hover {
  background-color: #16a34a;
}

/* キャラクタープロンプト削除ボタン */
.remove-button {
  background-color: #ef4444;
  color: white;
  border: none;
  margin-left: 1em;
}

.remove-button:hover {
  background-color: #c53030;
}

/* ── 各プロンプト欄内の「最終プロンプト」表示ボックス ───────────────────────── */
.prompt-output-box {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.5em;
  margin-top: 0.5em;
  max-height: 100px;
  overflow-y: auto;
  font-size: 0.85em;
}

body.dark-mode .prompt-output-box {
  background: #2a2a3a;
  border-color: #555;
}

/* ============================= */
/* ======== ダークモード ========= */
/* ============================= */
body.dark-mode {
  background: #1e1e2e;
  color: #e5e5e5;
}

body.dark-mode h1,
body.dark-mode button,
body.dark-mode select,
body.dark-mode input[type="text"],
body.dark-mode input[type="file"] {
  color: #e5e5e5;
}

body.dark-mode .section {
  background: #2a2a3a;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

body.dark-mode .tag-container {
  background: #2b2b3b;
  border-color: #444;
}

body.dark-mode .tag {
  background: #3a3f5f;
  border-color: transparent;
}

body.dark-mode .tag.positive {
  background: #2b6cb0;
  border-color: #90cdf4;
}

body.dark-mode .tag.negative {
  background: #a94442;
  border-color: #fc8181;
}

body.dark-mode .tag input {
  color: #e5e5e5;
}

body.dark-mode .tag .weight {
  color: #ddd;
}

body.dark-mode .tag button {
  background: #9b2c2c;
}

body.dark-mode .tag button:hover {
  background: #822727;
}

body.dark-mode button,
body.dark-mode select,
body.dark-mode input[type="text"],
body.dark-mode input[type="file"] {
  background: #3a3a4a;
  border-color: #555;
  color: #e5e5e5;
}

body.dark-mode button:hover {
  background: #4b4b5b;
}

body.dark-mode .add-button {
  background-color: #2f855a;
}

body.dark-mode .add-button:hover {
  background-color: #276846;
}

body.dark-mode .remove-button {
  background-color: #9b2c2c;
}

body.dark-mode .remove-button:hover {
  background: #822727;
}

body.dark-mode .extra-section {
  background: #2a2a3a;
  color: #e5e5e5;
}

/* プレースホルダーの色調整 */
body.dark-mode input::placeholder,
body.dark-mode input[type="file"]::placeholder {
  color: #aaa;
}

/* チェックボックスのアクセントカラー */
body.dark-mode input[type="checkbox"] {
  accent-color: #90cdf4;
}

/* スクロールバー（Chrome系） */
body.dark-mode ::-webkit-scrollbar {
  background: #444;
}
body.dark-mode ::-webkit-scrollbar-thumb {
  background: #888;
}

/* ─── ダークテーマ対応追加 ───────────────────────────────────────── */

/* タグ検索欄 */
body.dark-mode #tag-search-input {
  background: #3a3a4a;
  color: #e5e5e5;
  border-color: #666;
}
body.dark-mode #tag-search-input::placeholder {
  color: #aaa;
}

/* カテゴリ管理UI */
body.dark-mode #category-management {
  background: #2a2a3a;
  border-color: #444;
}

body.dark-mode #new-category-input,
body.dark-mode #category-select {
  background: #3a3a4a;
  color: #e5e5e5;
  border-color: #666;
}

body.dark-mode #category-management button {
  background-color: #2563eb;
  color: white;
}

body.dark-mode #category-management button:hover {
  background-color: #1d4ed8;
}

/* カテゴリ表示ラベル（未分類／カテゴリ名）の色切替 */
.category-label {
  color: #0066cc;
}

body.dark-mode .category-label {
  color: #ffffff; /* ダークテーマ時は白 */
  font-weight: bold;
}

/* ダークテーマ時の補完スペース下のカテゴリセレクト対応 */
body.dark-mode #bulk-category-select {
  background: #3a3a4a;
  color: #e5e5e5;
  border-color: #666;
}


/* ── 辞書インポート用スタイル ─────────────────────── */
.dictionary-import-section input,
.dictionary-import-section button {
  margin-top: 0.5em;
  padding: 0.5em;
  border-radius: 5px;
  border: 1px solid #ccc;
}


/* ダークモード時の和訳表示（descSpan） */
body.dark-mode .extra-item span {
  color: #e5e5e5;
}


/* ダークモードでも和訳が白文字で見えるように強制指定 */
body.dark-mode .description-text {
  color: #e5e5e5 !important;
}


/* タグの下にある補足テキストも白っぽく */
body.dark-mode .description-meta {
  color: #dddddd !important;
}

/* === 3カラム用ヘッダー === */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eeeeee;
  padding: 0.5em 1em;
}

/* === 3カラムレイアウト拡張 === */
#sidebar {
  width: 220px;
  overflow-y: auto;
}
#main-content {
  flex: 1;
  padding: 1em;
}
#search-extra-panel {
  width: 300px;
}

.layout {
  display: flex;
  height: calc(100vh - 60px); /* ヘッダー除外 */
  gap: 16px;
}

/* 区切り線 */
.section {
  border-right: 1px solid #ccc;
}

/* === モバイル対応 === */
@media (max-width: 1024px) {
  html, body {
    overflow-x: hidden;
  }
  .layout {
    overflow-x: hidden;
  }
  #main-content {
    padding-left: 0.5em;
    padding-right: 0.5em;
  }
  .layout {
    flex-direction: column;
  }
  #sidebar,
  #search-extra-panel {
    display: none;
  }
  .sidebar-open #sidebar,
  .search-extra-open #search-extra-panel {
    display: block;
  }
}

/* === ダークモード強化 === */
body.dark-mode {
  background-color: #121212;
  color: #eee;
}

body.dark-mode .section,
body.dark-mode .template-section,
body.dark-mode .extra-section {
  background-color: #1e1e1e;
  color: #eee;
  border-color: #444;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode button,
body.dark-mode textarea {
  background-color: #2a2a2a;
  color: #fff;
  border: 1px solid #555;
}

body.dark-mode .prompt-output-box,
body.dark-mode .tag-container {
  background-color: #1a1a1a;
}

.extra-bulk-category {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

body.dark-mode .header {
  background-color: #1a1a1a;
  color: #eee;
  border-bottom: 1px solid #444;
}

body.dark-mode #theme-toggle {
  background-color: #2a2a2a;
  color: #fff;
  border: 1px solid #555;
}

/* === スライド式モバイルメニュー追加 === */

@media (max-width: 1024px) {
  #sidebar, #search-extra-panel {
    position: fixed;
    top: 60px; /* ヘッダーの下 */
    bottom: 0;
    width: 80%;
    max-width: 300px;
    background: #fff;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
  }

  #search-extra-panel {
    right: 0;
    left: auto;
    transform: translateX(100%);
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  body.search-extra-open #search-extra-panel {
    transform: translateX(0);
  }

  .layout {
    flex-direction: column;
  }
}


/* === モバイル時 main-content 幅調整 === */

@media (max-width: 1024px) {
  }
}


/* === モバイル時 main-content を中央寄せ・半分幅に制限 === */

@media (max-width: 1024px) {
  }
}



/* === サイドメニュー非表示時、main-content を全幅に広げる === */
@media (max-width: 1024px) {
  body.sidebar-open #main-content,
  

  }
}



/* === summaryの三角マークを非表示にする === */
details > summary {
  list-style: none;
}
details > summary::-webkit-details-marker {
  display: none;
}


/* === main-content を常に100%幅にする === */

@media (max-width: 1024px) {
  }
}


/* === モバイル表示制御 === */

@media (max-width: 1024px) {
  #sidebar-toggle,
  #search-extra-toggle {
    display: inline-block;
  }

  .close-button-container {
    visibility: hidden;
  }

  #sidebar.open .close-button-container,
  #search-extra-panel.open .close-button-container {
    visibility: visible;
  }
}

@media (min-width: 1025px) {
  #sidebar-toggle,
  #search-extra-toggle,
  .close-button-container {
    display: none !important;
  }
}



/* === ダークモード対応スタイル追加 === */
.dark-mode .section {
  background-color: #222;
  color: #eee;
}

.dark-mode .template-controls,
.dark-mode .extra-controls,
.dark-mode .extra-bulk-category {
  background-color: transparent;
  color: inherit;
}

.dark-mode input,
.dark-mode select,
.dark-mode textarea {
  background-color: #333;
  color: #eee;
  border: 1px solid #666;
}

.dark-mode button {
  background-color: #444;
  color: #eee;
  border: 1px solid #888;
}

.dark-mode .prompt-output-box {
  background-color: #111;
  border-color: #444;
}



/* === ダークモード補完: 内部セクションの背景・枠色・余白など調整 === */
.dark-mode .template-section,
.dark-mode .search-section,
.dark-mode .extra-section {
  background-color: #222;
  color: #eee;
  border-radius: 8px;
  box-shadow: none;
}

.dark-mode .template-controls,
.dark-mode .extra-controls,
.dark-mode .extra-bulk-category,
.dark-mode .template-description {
  background-color: transparent;
  color: inherit;
}

.dark-mode select,
.dark-mode input,
.dark-mode button {
  background-color: #333;
  color: #eee;
  border: 1px solid #666;
}

.dark-mode .tag-container,
.dark-mode .prompt-output-box {
  background-color: #181818;
  border-color: #444;
}



/* === ダークモード補完（折りたたみ時のパネル背景に反映） === */
.dark-mode #sidebar,
.dark-mode #search-extra-panel {
  background-color: #222;
  color: #eee;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
}

@media (max-width: 1024px) {
  #sidebar,
  #search-extra-panel {
    top: 100px !important;
  }
}
/* ☰ サイドメニューのヘッダースタイル強調 */
.template-section .section-header span {
  font-weight: bold;
  font-size: 1.1em;
}



/* === 補完スペース：コンパクトレイアウト === */
.extra-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  margin-bottom: 0.5em;
}

.extra-row select,
.extra-row button {
  flex: 1;
  padding: 0.4em 0.6em;
  font-size: 0.9em;
}

.checkbox-small label {
  font-size: 0.8em;
  display: flex;
  align-items: center;
  gap: 0.25em;
  margin-left: 0.25em;
}

.checkbox-small input[type="checkbox"] {
  transform: scale(0.85);
}


.extra-scroll-wrapper {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

.extra-list {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

@media (max-width: 1024px) {
  #search-extra-panel {
    overflow-y: auto;
    max-height: calc(100vh - 60px);
  }
}

@media (max-width: 768px) {
  #main-content {
    width: 100%;
    max-width: 100vw;
    padding: 0 1em;
    box-sizing: border-box;
  }
}

@media (max-width: 768px) {
  .layout {
    height: auto !important;
  }
  #main-content {
  }
}

@media (max-width: 1024px) {
  #search-extra-panel {
    position: fixed;
    top: 60px;
    bottom: 0;
    right: 0;
    width: 80%;
    max-width: 300px;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    pointer-events: none;
  }
  body.search-extra-open #search-extra-panel {
    transform: translateX(0);
    pointer-events: auto;
  }
}

@media (max-width: 768px) {
  .layout {
    height: auto !important;
  }
  #main-content {
  }
}

/* === main-content 縦スクロール無効化（最終優先） === */
@media (max-width: 1024px) {
  }
}

/* === 最終統一スタイル: main-content の固定＆スクロール除去 === */
@media (max-width: 1024px) {
  .layout {
    height: auto !important;
  }
  #main-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 1em !important;
    overflow-y: visible !important;
    height: auto !important;
    box-sizing: border-box;
  }
}

/* === 中央縦スクロール完全除去（1400px以下） === */
@media (max-width: 1400px) {
  .layout {
    height: auto !important;
  }
  #main-content {
    height: auto !important;
    overflow-y: visible !important;
  }
}

/* === フルサイズ時に補完スペースのタグ一覧だけ縦スクロール === */
@media (min-width: 1401px) {
  .extra-scroll-wrapper {
    overflow-y: auto;
    max-height: calc(100vh - 100px);
  }
}


/* === 修正追加: 折りたたみサイズ対応で中央崩れを防ぐ === */
@media (max-width: 1024px) {
  .layout {
    flex-direction: column !important;
    height: auto !important;
  }

  #main-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 1em !important;
    box-sizing: border-box !important;
    overflow-y: visible !important;
    height: auto !important;
  }

  #sidebar,
  #search-extra-panel {
    display: none !important;
  }

  body.sidebar-open #sidebar,
  body.search-extra-open #search-extra-panel {
    display: block !important;
    position: fixed;
    z-index: 1000;
  }
}


/* === 補完スペース：画面に収まるよう縦スクロール制限を常時有効化 === */
.extra-scroll-wrapper {
  overflow-y: auto;
  max-height: calc(100vh - 200px); /* ヘッダーやボタンを除いた高さ分 */
  min-height: 0;
  box-sizing: border-box;
}


/* === 補完スペース全体を高さ480pxに固定 === */
.extra-section {
  display: flex;
  flex-direction: column;
  height: auto;
  max-height: 480px;
  overflow: hidden;
}

.extra-scroll-wrapper {
  overflow-y: auto;
  height: 100%;
  max-height: none;
  min-height: 0;
  box-sizing: border-box;
}


/* === タグ編集エリアのスマホ横スクロール防止対応 === */
@media (max-width: 768px) {
  .tag-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .tag {
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
  }

  .tag input {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
  }
}
