/*





 */

/* =============================================================================== */
/* 1. 基本的なリセットとベーススタイル（全ブラウザ共通の土台）                   */
/* =============================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body, h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure {
  margin: 0;
  padding: 0;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  font-size: 14px; /* 全体的にでかすぎるのを抑制 */
  line-height: 1.6;
  color: #1a202c;
  background-color: #f8fafc;
  text-align: left; /* 表示が中央に寄るのを防ぐ */
}

/* =============================================================================== */
/* 2. フォーム要素のリセットと再定義（枠線消失・チェックボックス対策）           */
/* =============================================================================== */

/* テキスト入力・選択ボックス：枠線を明示的に作り直す */
input[type="text"], 
input[type="search"], 
input[type="email"], 
input[type="password"], 
textarea, 
select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #cbd5e0 !important; /* 消えた枠線を復活 */
  border-radius: 6px;
  background-color: #ffffff;
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
  border-color: #3182ce !important;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

/* ❌ チェックボックス：appearance: none を解除してブラウザ標準の箱を表示 */
input[type="checkbox"], 
input[type="radio"] {
  -webkit-appearance: checkbox !important;
  appearance: checkbox !important;
  width: 16px;
  height: 16px;
  margin: 0 4px 0 0;
  vertical-align: middle;
  cursor: pointer;
}

/* ボタンの基本スタイル */
button, .btn {
  cursor: pointer;
  font-family: inherit;
}

/* =============================================================================== */
/* 3. 個別コンポーネントの修正                                                 */
/* =============================================================================== */

/* 自動リサイズテキストエリア（重複を整理） */
.autosize-textarea {
  width: 100%;
  background: transparent;
  border: none !important; /* ここは親要素の枠線に任せるため */
  outline: none;
  font-size: 1rem;
  line-height: 1.5;
  padding: 8px 10px;
  resize: none;
  max-height: 250px;
  overflow-y: auto;
  display: block;
}

/* カードタイトルの高さ調整（2行で見えない問題対策） */
.card-title {
  font-size: 1.1rem;
  font-weight: bold;
  line-height: 1.4;
  margin-bottom: 8px;
  min-height: 2.8em; /* 2行分の高さを確保 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: visible; /* 隠さない */
}

/* 絵文字アイコン（潰れ対策） */
.clip-icon, .emoji-icon {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  vertical-align: middle;
}

/* =============================================================================== */
/* 4. 特殊なボタン（送信中スピナー等）                                           */
/* =============================================================================== */
input[type="submit"][disabled] {
  cursor: wait !important;
  opacity: 0.7 !important;
  background-color: #64748b !important;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>');
  background-repeat: no-repeat;
  background-position: 12px center;
  padding-left: 36px !important;
}

/* =============================================================================== */
/* 5. メッセージ配置（チャットUI）                                             */
/* =============================================================================== */
.msg-unit.user-msg {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  width: 100% !important;
  margin-bottom: 24px;
}

.msg-unit.user-msg .markdown-content {
  max-width: 70%;
  padding: 15px 25px;
  background: #f8fafc;
  border-radius: 18px 18px 2px 18px;
  border: 1px solid #e2e8f0;
  color: #1a202c;
}

.msg-unit.ai-msg {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  width: 100% !important;
  margin-bottom: 24px;
}

.msg-unit.ai-msg .markdown-content {
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
}

/* =============================================================================== */
/* 6. 数式表示（MathJax）の調整                                               */
/* =============================================================================== */
/* 1. 数式のコンテナ自体が持つ「行」としての高さを最小化する */
mjx-container[display="true"] {
  display: inline-block !important; /* blockから変更し、余計な改行を抑制 */
  margin: 0 !important;
  padding: 0 !important;
  line-height: 0 !important;       /* 行の高さを0にして隙間を消す */
  vertical-align: middle;
  width: auto !important;          /* 横幅いっぱい広がるのを防ぐ */
}

/* 2. 数式内のSVG自体のマージンをリセット */
mjx-container[display="true"] svg {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  /* 左側の余白が気になる場合はここを 0 にしてください */
  margin-left: 0 !important;
}

/* 3. 数式の前後にある不要な改行(br)を消去 */
/* 数式が独立行設定(display="true")の場合、brがあると2重改行に見えるため */
br + mjx-container[display="true"],
mjx-container[display="true"] + br {
  display: none !important;
}

/* 4. 段落タグとの干渉を防ぐ */
p mjx-container[display="true"] {
  display: inline-block !important;
}

/* 4. もしAIが「改行・改行」と送ってきた場合の空行対策（これだけは残す） */
br + br {
  display: none !important;
}
/* ==========================================
   サイドバー (Drawer)
   ========================================== */
.side-drawer {
  position: fixed;
  top: 0;
  /* 閉じている時は、画面幅に関わらず「自分の幅」分だけ外に隠す */
  right: -450px; 
  width: 400px;
  /* スマホ等、画面が400pxより狭い場合は画面幅の85%にする */
  max-width: 85vw; 
  height: 100vh;
  background-color: #ffffff;
  box-shadow: none;
  z-index: 10001;
  padding: 20px;
  transition: right 0.3s ease-in-out;
  overflow-y: auto;
}

/* 開いた状態 */
.side-drawer.open {
  right: 0;
  box-shadow: -5px 0 20px rgba(0,0,0,0.15);
}

/* ==========================================
   開閉ハンドルボタン (Handle)
   ========================================== */
.drawer-handle {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 35px;
  height: 100px;
  background: #3182ce;
  color: white;
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 12px 0 0 12px;
  transition: right 0.3s ease-in-out;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  color: white !important; /* ボタン全体の文字色を白に */
}

/* アイコンが確実に見えるように強制設定 */
.drawer-handle i {
  color: white !important; 
  font-size: 24px !important; /* 大きさを指定 */
  display: inline-block !important;
  visibility: visible !important;
  line-height: 1 !important;
}

/* スマホ等でサイドバーのパディングを少し削る調整 */
@media (max-width: 576px) {
  .side-drawer {
    padding: 15px;
  }
}

/* 💡 重要：サイドバーが開いた時、ボタンを左端に移動させる
   サイドバーの幅(400px)分だけ左に押し出す

.side-drawer.open + .drawer-handle,
.side-drawer.open ~ .drawer-handle {
  right: 400px;
} 
*/

/* ==========================================
   モーダル関連 (Modal)
   ========================================== */
/* 共通のopenUniversalModalやBootstrapモーダルが隠れないように調整 */
.modal-backdrop {
  z-index: 10040 !important;
}

.modal {
  z-index: 10050 !important;
}
.markdown-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.95rem;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
}

.markdown-content th, 
.markdown-content td {
  border: 1px solid #e2e8f0;
  padding: 12px;
  text-align: left;
}

.markdown-content th {
  background-color: #f8fafc;
  font-weight: 600;
  color: #4a5568;
}

.markdown-content tr:nth-child(even) {
  background-color: #f1f5f9;
}

/* 箇条書きの調整 */
.markdown-content ul, 
.markdown-content ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.markdown-content li {
  margin-bottom: 0.5rem;
}

/* 1. 引用ブロック（Blockquote）の装飾 */
blockquote {
  border-left: 5px solid #cbd5e1; /* 左側の少し太いグレーの線 */
  padding: 10px 16px;             /* 内側の余白 */
  margin: 16px 0;                 /* 外側の上下余白 */
  background-color: #f8fafc;      /* うっすらとしたグレー背景 */
  color: #475569;                 /* 文字色を少し落ち着いた色に */
  border-radius: 4px;             /* 右側の角を少し丸く */
}

/* 2. インラインコード（バッククォート1つで囲んだ文字）の装飾 */
/* ※ただし、Prism.jsが色付けするコードブロック(pre code)は除外する */
code:not(pre code) {
  background-color: #f1f5f9;      /* 薄いグレー背景 */
  color: #e11d48;                 /* アクセントの赤文字（QiitaやZenn風） */
  padding: 2px 6px;
  border-radius: 4px;
  font-family: Monaco, Consolas, "Courier New", monospace; /* 等幅フォント */
  font-size: 0.9em;
  margin: 0 2px;
}
/* 信頼度評価のスタイル */

/* 信頼度評価・グラフ関連のスタイル */
.star-btn {
  font-size: 2.5rem;
  cursor: pointer;
  color: #e9ecef;
  transition: 0.1s;
  display: inline-block;
  user-select: none; /* テキスト選択を防ぐ */
}

.star-btn.active {
  color: #ffc107;
}

/* グラフの分布表示用（以前作成したものがあれば統合） */
.distribution-grid {
  display: grid;
  grid-template-columns: 20px 1fr 40px;
  gap: 8px;
  align-items: center;
}

#eval_comment {
  border: 1px solid #cbd5e0;
  padding: 12px;
  font-size: 0.95rem;
  resize: vertical; /* ユーザーが縦方向にだけ伸ばせるようにする */
}
  
#eval_comment:focus {
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

/* モーダル内のコンテンツの最大幅を少し広げる（必要に応じて） */
.modal-body .text-center.p-2 {
  max-width: 500px;
  margin: 0 auto;
}
/* 1行検索バー：安定性重視レイアウト */
.search-nav-bar {
  display: block !important;
  width: 100% !important;
  padding: 10px 15px !important;
  background: white !important;
  border-bottom: 1px solid #e2e8f0 !important;

  /* 検索バーを1行めに固定表示 */
  position: sticky;
  top: 10px;       /* 上端から少し余白を持たせて固定 */
  z-index: 1000;   /* カード（z-index:1）よりも上に表示 */
}

/* 検索バー全体のコンテナ：要素が入り切らない場合に折り返さない設定 */
.search-form {
  display: flex;
  align-items: center;
  gap: 8px; /* 要素間の隙間を少し詰める */
  flex-wrap: nowrap; /* 勝手に折り返さない */
  width: 100%;
}

/* 検索とリセットを包むエリアも横並び */
.search-section.actions {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 8px !important;
  flex-shrink: 0 !important; /* 💡 縮ませない、追い出さない */
}

/* 各セクションの設定 */
.search-section {
  min-width: 0; /* flexの子要素が縮小できるようにする */
  flex-shrink: 0; /* 勝手に潰れすぎないようにする */
}

/* キーワード入力欄：ここだけ「余ったスペースを全部使う」設定 */
.main-query {
  flex-grow: 1;
  min-width: 150px; /* 最低限この幅は確保 */
}

.search-section.main-query {
  flex-grow: 1 !important; /* これだけが伸び縮みする */
}

/* ボタンとリンクの最小限のデザイン */
.search-button, .reset-button {
  height: 38px !important;
  display: flex !important;
  align-items: center !important;
  white-space: nowrap !important; /* 💡 文字を折り返さない */
  padding: 0 15px !important;
  border-radius: 6px !important;
  font-size: 0.85rem !important;
}

.search-button {
  background-color: #3182ce !important;
  color: white !important;
  border: none !important;
  cursor: pointer;
}

.reset-button {
  background-color: #edf2f7 !important;
  color: #4a5568 !important;
  border: 1px solid #cbd5e0 !important;
  text-decoration: none !important;
}

.search-field {
  width: 100%;
  height: 36px; /* 高さを少し低くしてスリムに */
  padding: 0 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  box-sizing: border-box;
  font-size: 0.85rem;
}

//* ドロップダウン（カテゴリ・タグ）：幅を固定または制限する */
.search-section.dropdown {
  width: 140px; /* ボタンの横幅を固定して重なりを防ぐ */
  position: relative;
}

.dropdown-label {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 10px; /* パディングを詰める */
  background: #f8fafc;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.8rem; /* 文字を少し小さく */
  cursor: pointer;
  white-space: nowrap; /* 💡 文字の折り返しを禁止 */
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 40px; /* ラベルのすぐ下に配置 */
  left: 0;
  background: white;
  min-width: 220px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 1100;
}

/* ホバー時にドロップダウンを表示 */
.dropdown:hover .dropdown-content {
  display: block;
}

.scroll-area {
  max-height: 250px;
  overflow-y: auto;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
  cursor: pointer;
}

.check-item:hover {
  background: #f7fafc;
}

/* --- 並び替えスイッチ：再構成版 --- */
.sort-toggle-group {
  display: flex;        /* 中のボタンを横に並べる */
  background: #f1f5f9;  /* スイッチ全体の背景色（薄いグレー） */
  padding: 2px;         /* 外枠とボタンの間の隙間 */
  border-radius: 6px;   /* 全体の角を丸く */
  flex-shrink: 0;       /* 画面が狭くなっても潰さない */
  white-space: nowrap;  /* 改行禁止 */
  margin: 0 5px;
}

/* ボタン単体の設定 */
.sort-toggle-group .sort-btn {
  padding: 4px 10px;  /* クリックしやすく余白を確保 */
  font-size: 0.8rem;
  text-decoration: none;
  color: #64748b;     /* 通常時の文字色 */
  border-radius: 4px; /* ボタン個別の角丸 */
  transition: all 0.2s;
}

/* 💡 選択中のスタイル：ここが「分からしめる」キモです */
.sort-toggle-group .sort-btn.active {
  background: white;        /* 選択中だけ白く浮かせる */
  color: #1e293b;           /* 文字をはっきりさせる */
  font-weight: bold;        /* 太字 */
  box-shadow: 0 1px 2px rgba(0,0,0,0.1); /* 軽い影で立体感を出す */
}

/* ホバー時（選択中ではない方） */
.sort-toggle-group .sort-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.5);
}

/* 選択中のホバー（白を維持） */
.sort-toggle-group .sort-btn.active:hover {
  background: white;
}

/* フィルタリング中のセクション（背景を薄い青や強調色に） */
.search-section.dropdown.filtering-active {
  background-color: #e0f2fe; /* 薄い水色 */
  border: 1px solid #7dd3fc;
  border-radius: 6px;
}

/* ラベルの文字色も変えるとより分かりやすい */
.search-section.dropdown.filtering-active .dropdown-label {
  color: #0369a1;
  font-weight: bold;
}

/* 検索キーワード入力中も色を変えたい場合はこちら */
.inner-search-field {
  background-color: #f8fafc;
}

/* 解除ボタン（×）のスタイル */
.clear-filter-link {
  margin-left: 5px;
  color: #ef4444; /* 赤系 */
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: bold;
  padding: 0 4px;
}

.clear-filter-link:hover {
  background-color: #fee2e2;
  border-radius: 50%;
}
