/* HarMit 共有スタイル（menu.html / chat.html / login.html）
   常時ライトモード。ヘッダー（.topbar）だけ黒(#111)のモノトーンにする。
   OSのダーク設定に連動した自動切替はしない（メディアクエリでの分岐は使わない）。 */
:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --border: #e0e2e6;
  --fg: #1a1a1a;
  --accent: #111111;
  --accent-hover: #333333;
  --muted: #6b7280;
  --header-bg: #111;   /* .topbar 専用: 黒モノトーンヘッダー */
  --header-fg: #ffffff;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 -apple-system, "Hiragino Kaku Gothic ProN", sans-serif;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ---- ヘッダー共通（黒モノトーン） ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--header-bg); /* #111 */
  color: var(--header-fg);
  border-bottom: 1px solid #000;
}

.brand { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .02em; color: var(--header-fg); }

.user-area { display: flex; align-items: center; gap: 14px; }

.user-chip { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #b8bcc4; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #23262b;
  border: 1px solid #33363c;
  font-size: 11px;
  color: var(--header-fg);
}

.logout-link {
  font-size: 12px;
  color: #b8bcc4;
  padding: 6px 12px;
  border: 1px solid #33363c;
  border-radius: 6px;
}

.logout-link:hover { color: #fff; border-color: var(--accent); }

/* ---- menu.html ---- */
.menu-main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.menu-lead { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.menu-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s ease, transform .15s ease;
}

.menu-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.menu-card-title { font-size: 14px; font-weight: 700; }
.menu-card-title::after { content: " \2192"; color: var(--accent); }

.menu-card-desc { font-size: 12px; color: var(--muted); }

/* ---- chat.html ---- */
.chat-heading { display: flex; align-items: baseline; gap: 12px; }

.back-link { font-size: 12px; color: #b8bcc4; }
.back-link:hover { color: #fff; }

.status-area { display: flex; align-items: center; gap: 12px; font-size: 11px; color: #b8bcc4; }

/* ヘッダー下、左にセッション一覧サイドバー・右にチャット本体を並べる行 */
.chat-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 220px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#newChat {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  font-size: 13px;
  flex: none;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.session-item {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item:hover { background: var(--bg); color: var(--fg); }
.session-item.active { background: var(--accent); color: #fff; }

.chat-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-main { flex: 1; overflow: auto; }

.msgs {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { padding: 9px 13px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; max-width: 85%; }
.msg.ai { background: var(--panel); border: 1px solid var(--border); align-self: flex-start; max-width: 92%; }
.msg.error { background: #fdecec; color: #9b1c1c; border: 1px solid #f3b4b4; align-self: flex-start; max-width: 92%; }

/* ---- 待機バブル（送信直後〜最初のdelta到達まで表示。ミニ顔20px＋「考え中」＋点滅ドット） ---- */
.msg.waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 92%;
  color: var(--muted);
}
.waiting-face { display: inline-flex; align-items: center; flex: none; color: #111111; }
.waiting-label { font-size: 13px; }
.waiting-dots { display: inline-flex; align-items: center; gap: 3px; }
.waiting-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--muted);
  animation: waiting-blink 1.2s ease-in-out infinite;
}
.waiting-dots span:nth-child(2) { animation-delay: .2s; }
.waiting-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes waiting-blink {
  0%, 80%, 100% { opacity: .2; }
  40% { opacity: 1; }
}

/* HarMitの回答はrenderMarkdown()でHTML化される。ブロック要素の既定マージンを整える。 */
.msg.ai > :first-child { margin-top: 0; }
.msg.ai > :last-child { margin-bottom: 0; }
.msg.ai h1, .msg.ai h2, .msg.ai h3, .msg.ai h4, .msg.ai h5, .msg.ai h6 { margin: 12px 0 6px; line-height: 1.4; }
.msg.ai h1 { font-size: 1.25em; }
.msg.ai h2 { font-size: 1.15em; }
.msg.ai h3 { font-size: 1.05em; }
.msg.ai p { margin: 6px 0; }
.msg.ai ul, .msg.ai ol { margin: 6px 0; padding-left: 22px; }
.msg.ai li { margin: 2px 0; }
.msg.ai a { color: var(--accent); text-decoration: underline; }
.msg.ai pre {
  background: #f1f2f4;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
}
.msg.ai code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: #f1f2f4;
  border-radius: 4px;
  padding: 1px 5px;
}
.msg.ai pre code { background: none; padding: 0; }

.md-table-wrap { overflow-x: auto; max-width: 100%; margin: 8px 0; }
.md-table { border-collapse: collapse; width: 100%; font-size: .92em; }
.md-table th, .md-table td { border: 1px solid #e5e7eb; padding: 6px 10px; text-align: left; vertical-align: top; }
.md-table th { background: #f6f7f8; font-weight: 600; }
blockquote { border-left: 3px solid #d1d5db; margin: 8px 0; padding: 4px 12px; color: #4b5563; }
hr { border: none; border-top: 1px solid #e5e7eb; margin: 12px 0; }

/* ---- ナレッジ承認カード ---- */
.msg.insight-card {
  background: #fff8e6;
  border: 1px solid #eed9a0;
  align-self: flex-start;
  max-width: 92%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insight-question { margin: 0; font-weight: 700; font-size: 13px; }
.insight-summary { margin: 0; font-size: 13px; color: var(--fg); white-space: pre-wrap; }
.insight-actions { display: flex; gap: 8px; }
.insight-approve, .insight-reject { height: 32px; padding: 0 14px; font-size: 12px; }
.insight-approve { background: #BF0000; color: #fff; }
.insight-approve:hover:not(:disabled) { background: #970000; }
.insight-reject { background: #fff; color: var(--fg); border: 1px solid var(--border); }
.insight-reject:hover { border-color: var(--accent); }
.insight-result { margin: 0; font-size: 12px; color: var(--muted); }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
  font: inherit;
}

textarea:focus { outline: none; border-color: var(--accent); }

.send-area { display: flex; align-items: center; gap: 10px; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  height: 40px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

/* グローバルなbutton:hoverにはしない: 詳細度(0,2,1)が他画面のクラス定義(0,1,0)/(0,2,0)を
   貫通して壊す(.insight-reject / .hp-toggle / .sources-chip / .harmit-fab 等が波及被害を受けた)。
   デフォルトのaccent背景を実際に使う#send・#newChatだけに限定する。 */
#send:hover:not(:disabled),
#newChat:hover:not(:disabled) { background: var(--accent-hover); }

button:disabled { opacity: .4; cursor: default; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #d8dbe0;
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}

.spinner[hidden] { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .menu-main { padding: 24px 14px 32px; }
  .msgs { padding: 14px; }
  .input-row { padding: 12px 14px; flex-wrap: wrap; }
  .chat-body { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
