/* realn-web スタイル (P2-1: 基礎)
   配色: 白背景 + 薄いグレー + 淡いブルー系。落ち着いた社内システム向け。
*/

:root {
  --c-bg: #f6f8fb;
  --c-surface: #ffffff;
  --c-border: #e3e8ef;
  --c-text: #1d2433;
  --c-text-muted: #6b7280;
  --c-primary: #2c6cdf;
  --c-primary-hover: #234fa6;
  --c-danger: #b91c1c;
  --c-danger-bg: #fdecea;
  --c-success: #166534;
  --c-warn: #92400e;
  --c-accent-soft: #eef3fb;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 18px rgba(15, 23, 42, 0.08);
  --maxw: 920px;
  --header-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

/* ----- header ----- */
.site-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--c-text);
}
.brand__mark {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.04em;
  color: var(--c-primary);
}
.brand__sub {
  font-size: 12px;
  color: var(--c-text-muted);
}
.site-header__nav {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--c-accent-soft);
  border-radius: 999px;
  font-size: 13px;
}
.user-chip__name { font-weight: 600; color: var(--c-text); }
.user-chip__role {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-user        { background: #e0e7ff; color: #3730a3; }
.role-super_admin { background: #fee2e2; color: var(--c-danger); }
.header-logout-form { margin: 0; }

/* ----- main / footer ----- */
.site-main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px;
}
.site-footer {
  border-top: 1px solid var(--c-border);
  padding: 14px 20px;
  text-align: center;
  color: var(--c-text-muted);
  font-size: 12px;
  background: var(--c-surface);
}

/* ----- generic page title ----- */
.page-title {
  margin: 0 0 18px;
  font-size: 22px;
  color: var(--c-text);
}

/* ----- alerts ----- */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert--error {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-color: #f5c2c2;
}
/* P3-3-γ: 状態 OK 用 alert（メンテ OFF 表示など） */
.alert--ok {
  background: #e8f3e8;
  color: #1e6b1e;
  border-color: #b6dab6;
}

/* ----- forms ----- */
.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 13px;
  color: var(--c-text-muted);
  margin-bottom: 4px;
}
.field__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--c-surface);
  color: var(--c-text);
}
.field__input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(44, 108, 223, 0.15);
}
.field__input--textarea { resize: vertical; min-height: 96px; }

/* ----- buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  background: var(--c-surface);
  color: var(--c-text);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--c-accent-soft); }
.btn--primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.btn--primary:hover {
  background: var(--c-primary-hover);
  border-color: var(--c-primary-hover);
}
.btn--ghost {
  background: transparent;
  border-color: var(--c-border);
  color: var(--c-text);
}
.btn--block { width: 100%; }

/* ----- auth (login / setup error / csrf error) ----- */
.auth-screen {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.auth-card {
  background: var(--c-surface);
  padding: 32px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
}
.auth-card__title {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: 0.06em;
  color: var(--c-primary);
}
.auth-card__lead {
  margin: 0 0 18px;
  color: var(--c-text-muted);
  font-size: 14px;
}
.auth-form { margin-top: 8px; }
.auth-card__footer {
  margin: 16px 0 0;
  text-align: center;
  color: var(--c-text-muted);
}
/* P3-3-γ: メンテナンス公開ページ用ワイドカード */
.auth-card--wide { max-width: 560px; }
.maintenance-message {
  background: #fff8e6;
  border: 1px solid #f1d57a;
  color: #6b4a00;
  padding: 16px 18px;
  border-radius: 8px;
  margin: 18px 0 22px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.55;
}

/* ----- chat (P2-5: bubble layout) ----- */
.chat-screen { display: block; }

.bubbles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.bubble-row {
  display: flex;
}
.bubble-row--user { justify-content: flex-end; }
.bubble-row--ai   { justify-content: flex-start; }
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble--user {
  background: var(--c-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.bubble--ai {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-bottom-left-radius: 4px;
}

/* Markdown レンダされた AI 回答の本文整形 */
.bubble--ai p { margin: 0 0 8px; }
.bubble--ai p:last-child { margin-bottom: 0; }
.bubble--ai ul, .bubble--ai ol { margin: 0 0 8px 1.4em; padding: 0; }
.bubble--ai li { margin: 2px 0; }
.bubble--ai h1, .bubble--ai h2, .bubble--ai h3, .bubble--ai h4 {
  margin: 12px 0 6px; line-height: 1.3;
}
.bubble--ai h1 { font-size: 18px; }
.bubble--ai h2 { font-size: 16px; }
.bubble--ai h3 { font-size: 15px; }
.bubble--ai h4 { font-size: 14px; }
.bubble--ai code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}
.bubble--ai pre {
  background: #f3f4f6;
  padding: 10px 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.92em;
}
.bubble--ai pre code { background: transparent; padding: 0; }
.bubble--ai blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--c-border);
  color: var(--c-text-muted);
}
.bubble--ai table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.bubble--ai th, .bubble--ai td {
  border: 1px solid var(--c-border);
  padding: 6px 10px;
}
.bubble--ai th { background: var(--c-accent-soft); }
.bubble--ai a { color: var(--c-primary); }

.chat-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.chat-form {
  background: var(--c-surface);
  padding: 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

#chat-submit.is-loading {
  opacity: 0.7;
  cursor: progress;
}

/* ----- feedback UI (P3-1a) ----- */
.feedback {
  margin: -6px 0 18px;
  padding: 14px;
  background: #f7fafc;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius);
}
.feedback__lead {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--c-text-muted);
}
.feedback__lead small { font-weight: normal; color: var(--c-text-muted); }
.feedback__forms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.feedback__form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 10px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.feedback__btn {
  align-self: flex-start;
}
.feedback__btn--good:hover { background: #dcfce7; border-color: #bbf7d0; }
.feedback__btn--bad:hover  { background: var(--c-danger-bg); border-color: #f5c2c2; }

@media (max-width: 640px) {
  .feedback__forms { grid-template-columns: 1fr; }
}

/* ----- announcement banner (P3-3-β) ----- */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border-left: 4px solid transparent;
  box-shadow: var(--shadow-sm);
}
.banner__title {
  font-weight: 700;
  margin-bottom: 4px;
}
.banner__body {
  font-size: 14px;
  line-height: 1.6;
}
.banner__body p { margin: 0 0 6px; }
.banner__body p:last-child { margin-bottom: 0; }
.banner__body ul, .banner__body ol { margin: 0 0 6px 1.4em; }
.banner__body code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}
.banner__body a { color: inherit; text-decoration: underline; }
.banner--info {
  background: #eef3fb;
  color: #1e40af;
  border-left-color: var(--c-primary);
}
.banner--warning {
  background: #fef3c7;
  color: #92400e;
  border-left-color: #f59e0b;
}
.banner--maintenance {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-left-color: var(--c-danger);
}
.banner--maintenance .banner__title { font-weight: 800; }

/* ----- form check (P3-3-β) ----- */
.field--check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field--check input[type="checkbox"] { width: auto; }

/* ----- admin/feedback 詳細 (P3-1b) ----- */
.dash-card__sub { margin-top: 4px; color: var(--c-text-muted); }
.qa-block-body {
  white-space: pre-wrap;
  padding: 12px 14px;
  border-radius: var(--radius);
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.qa-block-body--question {
  background: var(--c-accent-soft);
  border: 1px solid #d6e1f2;
}
.qa-block-body--answer {
  background: #f7f8fa;
  border: 1px solid var(--c-border);
}
.qa-block-body--answer p { margin: 0 0 8px; }
.qa-block-body--answer p:last-child { margin-bottom: 0; }
.qa-block-body--answer ul, .qa-block-body--answer ol {
  margin: 0 0 8px 1.4em;
}

.fb-detail-card {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #fafbfd;
}
.fb-detail-card__head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--c-text-muted);
}
.fb-detail-card__table { margin-top: 6px; background: var(--c-surface); }
.comment-block {
  white-space: pre-wrap;
  margin: 0;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* ----- feedback status pill + filter (P3-2-α) ----- */
.fb-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.fb-status--new                  { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.fb-status--reviewing            { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.fb-status--prompt_fix_needed    { background: #fed7aa; color: #9a3412; border-color: #fdba74; }
.fb-status--knowledge_fix_needed { background: #fed7aa; color: #9a3412; border-color: #fdba74; }
.fb-status--fixed                { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.fb-status--no_action            { background: #f3f4f6; color: #6b7280; border-color: #e5e7eb; }

.filter-form {
  background: #f7fafc;
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-field--check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.filter-field__label {
  font-size: 12px;
  color: var(--c-text-muted);
}
.filter-date-pair {
  display: flex;
  gap: 6px;
  align-items: center;
}
.filter-date-pair input { width: 100%; }

.notice {
  margin-top: 14px;
  font-size: 12px;
  color: var(--c-text-muted);
}
.notice--muted {
  background: #fafafa;
  border-left: 3px solid var(--c-border);
  padding: 8px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ----- buttons size variant ----- */
.btn--sm {
  padding: 5px 12px;
  font-size: 13px;
}

/* ----- admin layout (P2-3a) ----- */
.is-admin .site-main {
  max-width: 1200px;
}
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
}
.admin-sidebar {
  background: var(--c-surface);
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  height: fit-content;
  position: sticky;
  top: calc(var(--header-h) + 16px);
}
.admin-sidebar__title {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.admin-sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.admin-sidebar__nav a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--c-text);
  text-decoration: none;
  font-size: 14px;
}
.admin-sidebar__nav a:hover { background: var(--c-accent-soft); }
.admin-sidebar__nav a.active {
  background: var(--c-primary);
  color: #fff;
  font-weight: 600;
}
.admin-sidebar__sep { border: none; border-top: 1px solid var(--c-border); margin: 14px 0; }
.admin-sidebar__back {
  display: block;
  padding: 6px 12px;
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: 13px;
}
.admin-sidebar__back:hover { color: var(--c-primary); }

.admin-main { min-width: 0; }

.breadcrumb {
  font-size: 12px;
  color: var(--c-text-muted);
  margin: 0 0 6px;
}
.breadcrumb a { color: var(--c-text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--c-primary); text-decoration: underline; }

/* ----- dashboard cards ----- */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.dash-card {
  background: var(--c-surface);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}
.dash-card__label {
  font-size: 11px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.dash-card__value {
  font-size: 28px;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.1;
}
.dash-card__value--muted { color: var(--c-text-muted); }
.dash-card__value--warn  { color: var(--c-warn); }

/* ----- panel ----- */
.panel {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.panel__title {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--c-text);
}

/* ----- data table ----- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: middle;
}
.data-table thead th {
  background: var(--c-accent-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text-muted);
}
.data-table tbody tr:hover { background: #fafbfd; }
.data-table code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ----- status pill ----- */
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.status-pill--ok   { background: #dcfce7; color: #166534; }
.status-pill--warn { background: #fef3c7; color: var(--c-warn); }
.status-pill--off  { background: #f3f4f6; color: var(--c-text-muted); }

/* ----- forms in admin (P2-3b) ----- */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack .field { margin: 0; }
.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 6px;
}
.field__help {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--c-text-muted);
}
.field__input--sm { padding: 6px 10px; font-size: 13px; }
.field__input[readonly] {
  background: #f3f4f6;
  color: var(--c-text-muted);
}

/* ----- action bar / table actions (P2-3b) ----- */
.action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
/* CSV プレビューのエラー行 */
.row--error { background: var(--c-danger-bg); }
.row--error small { color: var(--c-danger); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* /admin/users 一覧: セル内の不自然な折り返しを防ぎ、横スクロールで対応。
   （他の admin テーブル（フィードバック等）には影響させないため --users で限定） */
.data-table--users { width: auto; min-width: 100%; }
.data-table--users th,
.data-table--users td { white-space: nowrap; }
/* 表示名だけは長い場合に省略（タイトル属性で全文ホバー表示） */
.data-table--users td.col-name {
  white-space: nowrap; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis;
}
/* 操作ボタンは横並びを維持（縦積みで行が間延びしない） */
.data-table--users td.actions { flex-wrap: nowrap; align-items: flex-start; }
/* パスワード再設定フォーム: 横スクロール表では絶対配置ポップアップが位置ずれ・見切れして
   操作できなくなるため、インライン展開（開くと行内に展開）にして必ず到達できるようにする */
.data-table--users .details-form {
  position: static;
  margin-top: 6px;
  white-space: normal;
  flex-wrap: wrap;
}
.data-table--users .details-form .field__input { min-width: 160px; }

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.inline-form { margin: 0; display: inline; }
.inline-details { display: inline-block; }
.inline-details summary {
  cursor: pointer;
  list-style: none;
}
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] summary { background: var(--c-accent-soft); }
.details-form {
  position: absolute;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 10px;
  margin-top: 6px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.row--self { background: #fff8e1; }

/* ----- audit event pills (P2-4) ----- */
.event-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #e0e7ff;
  color: #3730a3;
}
.event-login_success      { background: #dcfce7; color: #166534; }
.event-login_failure      { background: var(--c-danger-bg); color: var(--c-danger); }
.event-logout             { background: #e0e7ff; color: #3730a3; }
.event-chat_send          { background: #ddd6fe; color: #5b21b6; }
.event-user_create        { background: #dcfce7; color: #166534; }
.event-user_edit          { background: #fef3c7; color: var(--c-warn); }
.event-user_toggle_active { background: #fef3c7; color: var(--c-warn); }
.event-user_password_reset{ background: #fef3c7; color: var(--c-warn); }
.event-lock_clear         { background: #fee2e2; color: var(--c-danger); }
.event-admin_access_denied{ background: var(--c-danger-bg); color: var(--c-danger); font-weight: 700; }

/* ----- flash (P2-3b) ----- */
.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash--success {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}
.flash--error {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-color: #f5c2c2;
}

/* ----- responsive ----- */
@media (max-width: 800px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: static;
    margin-bottom: 14px;
  }
  .admin-sidebar__nav { flex-direction: row; flex-wrap: wrap; }
  .admin-sidebar__nav a { padding: 6px 10px; font-size: 13px; }
  .admin-sidebar__sep, .admin-sidebar__back { display: none; }
}
@media (max-width: 640px) {
  .site-header__inner { padding: 0 14px; }
  .site-main { padding: 18px 14px; }
  .brand__sub { display: none; }
  .user-chip__role { display: none; }
  .auth-card { padding: 24px 20px; }
}

/* ============================================================
   realn Knowledge Assistant — リッチチャット UI（UI 刷新）
   ============================================================ */
:root {
  --c-accent: #7c5cff;        /* アクセント: 紫 */
  --c-cyan: #06b6d4;          /* アクセント: シアン */
  --radius-lg: 16px;
  --radius-xl: 22px;
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
}

/* 上質なヘッダー（全ページ共通・マークアップ非変更で CSS のみ） */
.site-header {
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid rgba(227, 232, 239, 0.9);
}

/* 進化的強化トグル: JS 有効でリッチ / 無効でクラシック */
.chat-app { display: none; }
html.js .chat-app { display: flex; flex-direction: column; min-height: 0; }
html.js .chat-classic { display: none; }

/* チャットページは広め + 淡いグラデーション背景 */
body.is-chat {
  background:
    radial-gradient(1100px 480px at 12% -8%, #eaf1ff 0%, rgba(234, 241, 255, 0) 60%),
    radial-gradient(900px 420px at 100% 0%, #eef7fb 0%, rgba(238, 247, 251, 0) 55%),
    var(--c-bg);
}
body.is-chat .site-main { max-width: 1200px; }

/* JS 有効時のみ: ページ全体をビューポート高に収め、スレッド内だけスクロール
   （二重スクロールの解消）。no-JS フォールバックは通常スクロールのまま。 */
html.js body.is-chat { height: 100vh; height: 100dvh; overflow: hidden; }
html.js body.is-chat .site-main {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; padding: 14px 20px 12px;
}

/* アクセシビリティ */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--c-primary); font: inherit; text-decoration: underline;
}
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: 4px;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px;
  cursor: pointer; color: var(--c-text);
}
.icon-btn:hover { background: var(--c-accent-soft); }

/* ----- モバイル用ツールバー ----- */
.chat-toolbar { display: none; }
.chat-toolbar__title { font-weight: 700; font-size: 15px; }
.chat-toolbar__mark { color: var(--c-primary); }

/* ----- レイアウト ----- */
.chat-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
}

/* ----- 左サイドバー ----- */
.chat-sidebar {
  display: flex; flex-direction: column; gap: 16px;
  min-width: 0; min-height: 0; overflow-y: auto; padding-right: 2px;
}
.chat-sidebar__section {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); padding: 14px;
}
.chat-sidebar__title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--c-text-muted); margin: 0 0 10px;
}
.chat-sidebar__empty { font-size: 13px; color: var(--c-text-muted); margin: 6px 0 0; }
.conversation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.conversation-item {
  display: flex; align-items: center; gap: 4px;
  border-radius: 8px;
}
.conversation-item--active { background: var(--c-accent-soft); }
.conversation-item__open {
  flex: 1; min-width: 0; text-align: left; background: none; border: none;
  padding: 8px 10px; font: inherit; font-size: 13px; color: var(--c-text);
  cursor: pointer; border-radius: 8px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.conversation-item__open:hover { background: var(--c-accent-soft); }
.conversation-item__del {
  background: none; border: none; color: var(--c-text-muted); cursor: pointer;
  padding: 4px 8px; border-radius: 6px; font-size: 12px;
}
.conversation-item__del:hover { background: var(--c-danger-bg); color: var(--c-danger); }
.history-note {
  font-size: 11px; color: var(--c-text-muted); margin: 12px 0 0; line-height: 1.5;
}
.btn--block { width: 100%; }
/* 新規会話状態（どの会話も選択されていない）を示す */
.new-chat-btn--current { box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.35); }
.new-chat-btn--current::after { content: " ●"; font-size: 10px; opacity: 0.9; }

/* 管理者ミニパネル */
.admin-mini {
  background: linear-gradient(180deg, #faf8ff 0%, var(--c-surface) 100%);
  border: 1px solid #e7e0ff; border-radius: var(--radius-lg); padding: 14px;
}
.admin-mini__stats { display: flex; gap: 10px; margin-bottom: 10px; }
.admin-mini__stat {
  flex: 1; background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; padding: 8px; text-align: center;
}
.admin-mini__num { display: block; font-size: 22px; font-weight: 700; color: var(--c-accent); }
.admin-mini__label { font-size: 10px; color: var(--c-text-muted); }

/* ----- 中央メイン ----- */
.chat-main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-md); overflow: hidden;
}
.chat-thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 22px 22px 8px; scroll-behavior: smooth; }

/* ----- ウェルカム ----- */
.welcome { max-width: 760px; margin: 8px auto; animation: fadeUp 0.4s ease; }
.welcome__badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--c-accent); background: #f1edff; border: 1px solid #e3dbff;
  padding: 4px 12px; border-radius: 999px; margin-bottom: 14px;
}
.welcome__title { font-size: 24px; line-height: 1.35; margin: 0 0 8px; }
.welcome__lead { color: var(--c-text-muted); margin: 0 0 18px; }
.welcome__notices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.welcome__note {
  font-size: 13px; line-height: 1.6; margin: 0; padding: 10px 14px; border-radius: 10px;
}
.welcome__note--info { background: var(--c-accent-soft); color: #1e40af; }
.welcome__note--warn { background: #fef6e7; color: #92400e; }
.welcome__note a { color: inherit; text-decoration: underline; }
.welcome__subtitle { font-size: 14px; color: var(--c-text-muted); margin: 18px 0 10px; }

/* カテゴリチップ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.chip {
  border: 1px solid var(--c-border); background: var(--c-surface);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px;
  cursor: pointer; color: var(--c-text); transition: background 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--c-accent-soft); }
.chip--active {
  background: var(--c-primary); color: #fff; border-color: var(--c-primary);
}

/* 質問例カード */
.prompt-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px;
}
.prompt-card {
  display: flex; align-items: stretch; border: 1px solid var(--c-border);
  border-radius: 12px; background: var(--c-surface); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.prompt-card:hover {
  border-color: #c7d6f5; box-shadow: var(--shadow-md); transform: translateY(-1px);
}
.prompt-card__fill {
  flex: 1; text-align: left; background: none; border: none; cursor: pointer;
  padding: 12px 14px; font: inherit; font-size: 13.5px; color: var(--c-text); line-height: 1.5;
}
.prompt-card__go {
  border: none; border-left: 1px solid var(--c-border); background: var(--c-accent-soft);
  color: var(--c-primary); cursor: pointer; padding: 0 14px; font-size: 16px;
  opacity: 0; transition: opacity 0.15s; min-width: 44px;
}
.prompt-card:hover .prompt-card__go, .prompt-card__go:focus-visible { opacity: 1; }
.prompt-card__go:hover { background: var(--c-primary); color: #fff; }

/* ----- メッセージ ----- */
.msg { margin: 0 0 18px; max-width: 760px; }
.msg--user { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; }
.msg__bubble {
  padding: 11px 15px; border-radius: 16px; line-height: 1.6;
  word-wrap: break-word; overflow-wrap: anywhere; box-shadow: var(--shadow-sm);
  animation: fadeUp 0.28s ease;
}
.msg--user .msg__bubble {
  background: linear-gradient(135deg, var(--c-primary) 0%, #3b78e6 100%);
  color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; max-width: 80%;
}
.msg__meta { font-size: 11px; color: var(--c-text-muted); margin-top: 4px; }
.msg__who { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.msg__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px;
  font-weight: 700; font-size: 13px; color: #fff; overflow: hidden; position: relative;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
}
/* 画像アイコン版（assistant-icon.png）。読み込み失敗時は JS が fallback を表示 */
.msg__avatar--image { background: var(--c-surface); border: 1px solid var(--c-border); }
.msg__avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg__avatar-fallback {
  display: none; width: 100%; height: 100%;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  color: #fff; font-weight: 700; font-size: 13px;
}
.welcome__avatar {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px; margin-bottom: 10px;
}
.welcome__avatar .msg__avatar-fallback { font-size: 18px; }
.msg__name { font-size: 12px; font-weight: 600; color: var(--c-text-muted); }
.msg__bubble--ai {
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border); border-bottom-left-radius: 5px;
}

/* トラスト行 */
.trust { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 8px 0 0; }
.trust-badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.trust-badge--ok { background: #e7f6ec; color: #166534; }
.trust-badge--ok::before { content: "✓"; }
.trust-badge--none { background: #f1f3f6; color: var(--c-text-muted); }
.trust-link {
  background: none; border: none; color: var(--c-primary); cursor: pointer;
  font: inherit; font-size: 13px; text-decoration: underline; padding: 0;
}
.trust-note { font-size: 12px; color: var(--c-text-muted); }

/* アクション行 */
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.action {
  border: 1px solid var(--c-border); background: var(--c-surface); border-radius: 8px;
  padding: 5px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--c-text);
  transition: background 0.12s, border-color 0.12s;
}
.action:hover { background: var(--c-accent-soft); }
.action--good:hover { background: #dcfce7; border-color: #bbf7d0; }
.action--bad:hover { background: var(--c-danger-bg); border-color: #f5c2c2; }

/* フィードバックパネル */
.fb-panel {
  margin-top: 10px; padding: 12px; background: #f7fafc;
  border: 1px dashed var(--c-border); border-radius: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.fb-panel__lead { margin: 0; font-size: 13px; color: var(--c-text-muted); }
.fb-panel__actions { display: flex; gap: 8px; }
.field--err { border-color: var(--c-danger) !important; box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12); }
.fb-panel__err { margin: 0; font-size: 12.5px; color: var(--c-danger); font-weight: 600; }
.fb-status { font-size: 13px; padding: 8px 10px; border-radius: 8px; }
.fb-status--good { background: #e7f6ec; color: #166534; }
.fb-status--bad { background: #fff4e5; color: #92400e; }

/* エラー / 通知カード */
.error-card {
  display: flex; gap: 12px; padding: 14px; border-radius: 12px;
  background: var(--c-danger-bg); border: 1px solid #f5c2c2; max-width: 600px;
}
.error-card__icon { font-size: 20px; color: var(--c-danger); }
.error-card__title { margin: 0 0 4px; font-weight: 700; color: #7f1d1d; font-size: 14px; }
.error-card__msg { margin: 0 0 8px; color: #7f1d1d; font-size: 14px; }
.error-card__actions { display: flex; gap: 8px; }
.error-card__debug { margin-top: 8px; }
.error-card__debug summary { cursor: pointer; font-size: 12px; color: var(--c-text-muted); }
.error-card__pre {
  margin: 6px 0 0; padding: 8px 10px; background: #2a1212; color: #fbd5d5;
  border-radius: 6px; font-size: 11.5px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word; overflow-x: auto;
}
.notice-card {
  padding: 10px 14px; border-radius: 10px; background: var(--c-accent-soft);
  color: var(--c-text-muted); font-size: 13px; max-width: 600px;
}

/* ローディングステップ（生成中だけ密に。dot↔文言は少し空け、文言↔お辞儀はゼロ） */
.msg--loading .msg__who { margin-bottom: 2px; }
.msg--loading .loading-steps {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0; margin-top: 0; line-height: 1.1; flex-wrap: wrap;
}
/* 文言＋お辞儀を 1 つのインラインまとまりに（間隔ゼロ・改行で割れない） */
.loading-text {
  display: inline-flex; align-items: center; gap: 0;
  white-space: nowrap; line-height: 1.1;
}
.msg--loading .loading-label { line-height: 1.1; }
.loading-label { font-size: 13.5px; color: var(--c-text-muted); }
.loading-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c-primary); animation: pulse 1.1s ease-in-out infinite;
}
/* お辞儀アニメ（文言の直後に密着） */
.loading-bow-wrap { display: inline-flex; align-items: center; margin-left: 0; line-height: 1; }
.loading-bow {
  height: 20px; width: auto; margin-left: 0; border-radius: 4px;
  vertical-align: -3px; background: transparent;
}
.loading-bow-fallback { display: inline-block; margin-left: 0; font-size: 18px; line-height: 1; }

/* ----- コンポーザー ----- */
.composer-disclaimer {
  margin: 0; padding: 8px 16px; font-size: 11.5px; color: var(--c-text-muted);
  background: #fbfcfe; border-top: 1px solid var(--c-border); text-align: center;
}
.composer { padding: 12px 16px 16px; background: var(--c-surface); }
.composer__box {
  display: flex; align-items: flex-end; gap: 10px;
  border: 1.5px solid var(--c-border); border-radius: 16px; padding: 8px 8px 8px 14px;
  background: var(--c-surface); transition: border-color 0.15s, box-shadow 0.15s;
}
.composer__box:focus-within {
  border-color: var(--c-primary); box-shadow: 0 0 0 4px rgba(44, 108, 223, 0.12);
}
.composer__input {
  flex: 1; border: none; outline: none; resize: none; font: inherit; font-size: 15px;
  line-height: 1.5; background: transparent; color: var(--c-text); max-height: 180px;
}
.composer__send {
  border: none; cursor: pointer; border-radius: 12px; padding: 9px 18px;
  background: linear-gradient(135deg, var(--c-primary), #3b78e6); color: #fff;
  font: inherit; font-weight: 600; white-space: nowrap; transition: filter 0.12s, background 0.12s;
}
.composer__send:hover { filter: brightness(1.05); }
.composer__send--stop { background: linear-gradient(135deg, #b91c1c, #dc2626); }
.composer__meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; padding: 0 4px; font-size: 11.5px; color: var(--c-text-muted);
}
.composer__hint kbd {
  background: #eef1f6; border: 1px solid var(--c-border); border-radius: 4px;
  padding: 0 4px; font-size: 10px; font-family: inherit;
}
.composer__counter--warn { color: var(--c-warn); font-weight: 600; }
.composer-error {
  margin: 8px 4px 0; padding: 8px 12px; background: var(--c-danger-bg);
  color: var(--c-danger); border-radius: 8px; font-size: 13px;
}

/* ----- 参照元ドロワー（オフキャンバス） ----- */
.source-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 90vw;
  background: var(--c-surface); border-left: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg); z-index: 60; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s ease; visibility: hidden;
}
.source-drawer--open { transform: translateX(0); visibility: visible; }
.source-drawer__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--c-border);
}
.source-drawer__title { margin: 0; font-size: 16px; }
.source-drawer__body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.source-empty { color: var(--c-text-muted); font-size: 13px; }
.source-card {
  border: 1px solid var(--c-border); border-radius: 12px; padding: 12px 14px;
  margin-bottom: 12px; background: #fcfdff;
}
.source-card__name { font-weight: 600; font-size: 14px; margin-bottom: 6px; word-break: break-word; }
.source-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.source-card__ds {
  font-size: 11px; color: var(--c-text-muted); background: var(--c-accent-soft);
  padding: 2px 8px; border-radius: 999px;
}
.source-card__score { display: flex; align-items: center; gap: 6px; }
.score-bar { width: 60px; height: 6px; border-radius: 999px; background: #e6ebf3; overflow: hidden; }
.score-bar__fill { display: block; height: 100%; background: linear-gradient(90deg, var(--c-cyan), var(--c-primary)); }
.source-card__score-num { font-size: 11px; color: var(--c-text-muted); }
.source-card__excerpt {
  margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--c-border);
  color: var(--c-text); font-size: 13px; line-height: 1.6; background: #f7fafc;
  border-radius: 0 6px 6px 0; white-space: pre-wrap; word-break: break-word;
}
.source-card__actions { display: flex; gap: 10px; }

/* スクリム（モバイルのオフキャンバス背景） */
.chat-scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); z-index: 55;
}

/* ----- アニメーション ----- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scale(0.7); opacity: 0.5; } 50% { transform: scale(1.1); opacity: 1; } }

/* ----- レスポンシブ ----- */
@media (max-width: 960px) {
  body.is-chat .site-main { padding: 0; max-width: 100%; }
  .chat-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 14px; background: rgba(255,255,255,0.9); border-bottom: 1px solid var(--c-border);
    position: sticky; top: var(--header-h); z-index: 40;
  }
  .chat-layout {
    grid-template-columns: 1fr; flex: 1 1 auto; min-height: 0; gap: 0;
  }
  .chat-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 280px; max-width: 85vw;
    background: var(--c-bg); z-index: 60; padding: 16px; transform: translateX(-100%);
    transition: transform 0.25s ease; box-shadow: var(--shadow-lg);
  }
  .chat-sidebar--open { transform: translateX(0); }
  .chat-main { border-radius: 0; border-left: none; border-right: none; }
}
@media (min-width: 961px) {
  .chat-toolbar { display: none; }
  /* デスクトップではスクリムはドロワー時のみ JS が表示 */
}
@media (max-width: 600px) {
  .chat-thread { padding: 16px 14px 6px; }
  .welcome__title { font-size: 20px; }
  .prompt-cards { grid-template-columns: 1fr; }
  /* 参照元は下からのボトムシート */
  .source-drawer {
    top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-width: 100%;
    height: 78vh; border-left: none; border-top: 1px solid var(--c-border);
    border-radius: 18px 18px 0 0; transform: translateY(100%);
  }
  .source-drawer--open { transform: translateY(0); }
  .msg, .welcome { max-width: 100%; }
}

/* ----- 動きを減らす設定 ----- */
@media (prefers-reduced-motion: reduce) {
  *, .msg__bubble, .welcome, .prompt-card { animation: none !important; transition: none !important; }
  .chat-thread { scroll-behavior: auto; }
}
