/* ゴルフAIコーチ — 配色の既定値。
   **正本は config/coach.js の COACH_PUBLIC.brand**。app.js が起動時に
   同じ変数名で :root を上書きするので、コーチを差し替えるときにこのファイルは触らない。
   ここに残してあるのは、/api/coach が届く前と JS 無効時に見せるフォールバック。 */

:root {
  --navy: #1a2742;
  --gold: #c9a961;
  --gold-accent: #d4ad53;
  --cream: #faf5ec;
  --ink-on-gold: #2d1e14;
  --ink-brown: #3d2817;
  --line: rgba(61, 40, 23, 0.12);
  --danger: #b3261e;
  --danger-bg: #fdecea;

  --font-mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "MS PMincho", serif;
  --font-gothic: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo",
    system-ui, sans-serif;

  /* 役割ごとの色（2026-09-25 ライト/ダーク対応）。生徒向け画面はこちらを使う。
     上のブランド色（--navy 等）は /api/coach が :root のインライン style で上書きするため、
     テーマで変わる色は**別名の変数**にしておく（インライン指定はテーマ用ルールより強い）。
     コントラストは本文・補足とも背景に対して 4.5:1 以上。 */
  --bg: var(--cream);
  --surface: #ffffff;
  --surface-2: #f3ede1;
  --text: var(--ink-brown);
  --text-muted: #6b5a4b;
  --heading: var(--navy);
  --green: #1d6b45;
  --on-green: #ffffff;
  --accent-text: #7a5c1c; /* 明るい背景に置く金系の文字（金そのものは文字に使うと薄い） */
  --overlay: rgba(26, 39, 66, 0.55);
  --shadow: 0 6px 20px rgba(26, 39, 66, 0.12);
}

/* ダーク。data-theme は theme.js が確定させる（端末設定の追従もそちら）。 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1a17;
  --surface: #17241f;
  --surface-2: #1f2f29;
  --text: #e9e4d8;
  --text-muted: #a9b6af;
  --heading: #f1e7cf;
  --green: #4fb883;
  --on-green: #0f1a17;
  --accent-text: #d9bd7a;
  --line: rgba(233, 228, 216, 0.14);
  --danger: #ff8a80;
  --danger-bg: #3a1c1a;
  --overlay: rgba(0, 0, 0, 0.6);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-gothic);
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

/* ---------- パスコードゲート ---------- */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy);
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.gate-title {
  font-family: var(--font-mincho);
  font-size: 22px;
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--heading);
}

.gate-note {
  margin: 6px 0 22px;
  font-size: 12px;
  color: var(--text-muted);
}

.gate-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.gate-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.gate-input:focus {
  outline: 2px solid var(--gold-accent);
  outline-offset: 1px;
}

.gate-error {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

/* 「リンクを送りました」の案内。**成功／未登録を出し分けない**ので、
   常にこの1種類だけを出す（画面がメールアドレスの存在確認になるのを防ぐ）。 */
.gate-sent {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(201, 169, 97, 0.14);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.gate-button {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.gate-button:active {
  background: var(--gold-accent);
}

.gate-button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 6桁コード入力（メール送信後だけ app.js が表示する） */
.gate-code {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.gate-code-note {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  opacity: 0.85;
}

/* パスキーでログイン（副ボタン。対応端末でだけ app.js が表示する） */
.gate-passkey {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--heading);
  background: none;
  border: 1px solid var(--gold);
  border-radius: 12px;
  cursor: pointer;
}

.gate-passkey:active {
  background: rgba(201, 169, 97, 0.18);
}

.gate-passkey:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- チャット3層 ---------- */

.app {
  position: relative; /* トリミング画面（.trim）の absolute 基準 */
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  flex-shrink: 0;
  background: var(--navy);
  padding: 10px 16px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.header-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.header-text {
  text-align: left;
  min-width: 0;
}

.header-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.header-sub {
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: rgba(250, 245, 236, 0.7);
}

/* ---------- リッチメニュー ---------- */
/* LINE のリッチメニューに寄せた常設グリッド（A案・2026-09-01）。
   入力バーの下=画面最下部（index.html で .composer の後ろ）。
   中身は app.js が features フラグを見て描画する。ボタンが0個なら枠ごと隠す。 */

.richmenu {
  flex-shrink: 0;
  background: var(--navy);
  border-top: 1px solid rgba(250, 245, 236, 0.12);
  padding: 0 0 calc(8px + env(safe-area-inset-bottom, 0px));
}

/* 開閉バー: 全幅・高さ44px（どこを押しても反応する。旧: 中央の小さな文字だけ） */
.richmenu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: rgba(250, 245, 236, 0.85);
  background: none;
  border: none;
  border-bottom: 1px solid rgba(250, 245, 236, 0.12);
  cursor: pointer;
}

.richmenu-toggle:active {
  background: rgba(250, 245, 236, 0.08);
}

.richmenu-chevron {
  width: 16px;
  height: 16px;
  stroke: rgba(250, 245, 236, 0.85);
  transition: transform 0.15s ease;
}

/* 閉じている間はシェブロンを上向きに（「開く」方向を指す）。境界線も不要 */
.richmenu.collapsed .richmenu-chevron {
  transform: rotate(180deg);
}

.richmenu.collapsed .richmenu-toggle {
  border-bottom: none;
}

/* タイルは3列グリッド（5件なら 3+2 で並ぶ）。アイコン＋ラベルの縦積み */
.richmenu-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 10px 0;
}

.menu-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 68px;
  padding: 10px 4px 8px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--cream);
  background: rgba(250, 245, 236, 0.08);
  border: 1px solid rgba(201, 169, 97, 0.5);
  border-radius: 12px;
  cursor: pointer;
}

.menu-button svg {
  width: 26px;
  height: 26px;
  stroke: var(--gold);
}

.menu-button:active {
  background: rgba(201, 169, 97, 0.28);
}

/* ---------- 初回同意（免責） ---------- */

.consent-panel {
  position: absolute;
  inset: 0;
  z-index: 30; /* history-panel(20) / trim より上。同意前は他の操作より優先する */
  background: rgba(26, 39, 66, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.consent-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.consent-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 17px;
  font-weight: 600;
  color: var(--heading);
}

.consent-body {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.consent-link {
  margin: 0 0 16px;
  font-size: 13px;
}

.consent-link a {
  color: var(--heading);
}

.consent-error {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.consent-agree {
  width: 100%;
  padding: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.consent-agree:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- 過去のやり取り ---------- */

.history-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(26, 39, 66, 0.55);
  display: flex;
  align-items: flex-end;
}

.history-card {
  width: 100%;
  max-height: 82%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
}

.history-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.history-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 15px;
  font-weight: 600;
  color: var(--heading);
}

.history-close {
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
}

.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 10px;
}

.history-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.history-row.assistant {
  display: flex;
  gap: 8px;
}

.history-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  margin-top: 2px;
}

.history-content {
  min-width: 0;
  flex: 1;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.history-badge {
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(201, 169, 97, 0.24);
  color: var(--ink-on-gold);
  font-weight: 700;
}

.history-body {
  margin-top: 2px;
  font-size: 14px;
}

.history-body p {
  margin: 0;
}

.history-body .disclaimer-note {
  margin-top: 0.5em;
}

.history-row.assistant .history-body {
  color: var(--text);
}

.history-row.user .history-body {
  color: var(--heading);
  font-weight: 600;
}

.history-empty {
  margin: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- パスキー登録の促しバナー（ログイン後・未登録時に1回） ---------- */

.passkey-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(201, 169, 97, 0.16);
  border-bottom: 1px solid rgba(201, 169, 97, 0.4);
}

.passkey-banner-text {
  margin: 0;
  font-size: 12px;
  color: var(--text);
}

.passkey-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.passkey-banner-go {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border-radius: 999px;
  text-decoration: none;
}

.passkey-banner-close {
  padding: 6px 4px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty {
  margin: 24px auto 0;
  max-width: 420px;
  text-align: center;
}

.empty-lead {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-muted);
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.chip {
  max-width: 100%;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 999px;
  cursor: pointer;
}

.chip:active {
  background: rgba(201, 169, 97, 0.18);
}

/* ---------- 吹き出し ---------- */

.row {
  display: flex;
}

.row.user {
  justify-content: flex-end;
}

.row.assistant {
  justify-content: flex-start;
  align-items: flex-end;
  gap: 6px;
}

.bubble-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.75;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.row.user .bubble {
  background: var(--gold);
  color: var(--ink-on-gold);
  border-bottom-right-radius: 4px;
}

.row.assistant .bubble {
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(61, 40, 23, 0.08);
}

/* AI 応答内のリンク（markdown.js の自動リンク化）。指で押しやすいよう下線＋太めに */
.row.assistant .bubble a {
  color: var(--heading);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
  word-break: break-all;
}

.bubble.thinking {
  color: var(--text-muted);
}

.video-progress {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: min(270px, 78vw);
  border: 1px solid rgba(201, 169, 97, 0.28);
  background: linear-gradient(180deg, #fff 0%, rgba(250, 245, 236, 0.78) 100%);
}

.video-progress-spinner {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(201, 169, 97, 0.34);
  border-top-color: var(--gold-accent);
  border-radius: 50%;
  animation: video-progress-spin 0.9s linear infinite;
}

.video-progress-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.video-progress-label {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  color: var(--navy);
}

.video-progress-kicker,
.video-progress-main {
  display: block;
}

.video-progress-kicker {
  font-size: 11px;
  line-height: 1.2;
  color: rgba(61, 40, 23, 0.72);
}

.video-progress-main {
  line-height: 1.35;
}

.video-progress-elapsed {
  font-size: 11px;
  line-height: 1.25;
  color: rgba(61, 40, 23, 0.72);
}

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

@media (prefers-reduced-motion: reduce) {
  .video-progress-spinner {
    animation: none;
  }
}

/* 限定Markdownの出力要素 */
.bubble p {
  margin: 0;
}

.bubble p + p {
  margin-top: 0.35em;
}

.bubble ul {
  margin: 0.4em 0;
  padding-left: 1.2em;
}

.bubble li {
  margin: 0.15em 0;
}

.bubble strong {
  font-weight: 700;
}

.md-gap {
  height: 0.5em;
}

/* AI回答の吹き出し・履歴に常設する免責注記。COACH_PUBLIC.disclaimer.bubbleNote。 */
.disclaimer-note {
  margin: 0.5em 0 0;
  padding-top: 0.4em;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
}

.error {
  align-self: center;
  max-width: 90%;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* ---------- 入力バー ---------- */

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  /* 最下部はリッチメニューなので safe-area はそちらが持つ */
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* リッチメニューが枠ごと隠れている（ボタン0個）時だけ、入力バーが最下部になるので
   safe-area を入力バー側で持つ */
.app:has(.richmenu[hidden]) .composer {
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}

.input {
  flex: 1;
  min-height: 44px;
  max-height: 128px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: none;
}

.input:focus {
  outline: 2px solid var(--gold-accent);
  outline-offset: 1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.video-button {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  width: 44px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--gold);
  border-radius: 14px;
  cursor: pointer;
}

.video-button svg {
  width: 22px;
  height: 22px;
  stroke: var(--text);
}

.video-button:active {
  background: rgba(201, 169, 97, 0.25);
}

.video-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* スコアカード写真の吹き出し（生徒側）。縮小したサムネイル＋1行の説明 */
/* ---------- 画像での質問の添付欄（入力バーの直上） ---------- */

.image-attach {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.image-attach[hidden] {
  display: none;
}

.image-attach-thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.image-attach-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}

.image-attach-cancel {
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.image-attach-cancel:disabled {
  opacity: 0.4;
}

.bubble-photo {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 12px;
  margin-bottom: 6px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.5);
}

.send {
  flex-shrink: 0;
  height: 44px;
  padding: 0 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}

.send:active {
  background: var(--gold-accent);
}

.send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- v4 動画トリミング ---------- */

.trim {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(26, 39, 66, 0.55);
}

.trim-panel {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
}

.trim-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--heading);
  text-align: center;
}

.trim-video {
  display: block;
  width: 100%;
  max-height: 42dvh;
  background: #000;
  border-radius: 12px;
  object-fit: contain;
}

.trim-length {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.trim-length.over {
  color: var(--danger);
}

/* 2ハンドルスライダー: range を2本重ねる。つまみだけタッチを受ける */
.range-wrap {
  position: relative;
  height: 40px;
  margin: 0 6px;
}

.range-track,
.range-fill {
  position: absolute;
  top: 18px;
  height: 4px;
  border-radius: 2px;
}

.range-track {
  left: 0;
  right: 0;
  background: rgba(61, 40, 23, 0.18);
}

.range-fill {
  background: var(--gold);
}

.range-wrap .range {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-wrap .range:focus {
  outline: none;
}

.range-wrap .range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.range-wrap .range::-moz-range-thumb {
  pointer-events: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  cursor: pointer;
}

.trim-hint {
  margin: 2px 0 4px;
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
}

/* 制限の常時表示（v5）。ヒントより一段強い色で、常に見える位置に置く */
.trim-note {
  margin: 0 0 14px;
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
}

.trim-actions {
  display: flex;
  gap: 10px;
}

.trim-cancel,
.trim-submit {
  flex: 1;
  padding: 13px 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
}

.trim-cancel {
  flex: 0 0 32%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

.trim-submit {
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
}

.trim-submit:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- 利用規約ページ ---------- */

.terms-page {
  min-height: 100dvh;
}

.terms {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px calc(48px + env(safe-area-inset-bottom, 0px));
}

.terms-title {
  font-family: var(--font-mincho);
  font-size: 22px;
  margin: 0 0 24px;
  color: var(--heading);
}

.terms-section {
  margin-bottom: 22px;
}

.terms-section h2 {
  font-size: 15px;
  margin: 0 0 8px;
  color: var(--heading);
}

.terms-section p {
  margin: 0;
  font-size: 14px;
  line-height: 1.8;
}

.terms-back {
  margin-top: 32px;
  font-size: 14px;
}

.terms-back a {
  color: var(--heading);
}

/* ---------- 自分のカルテ（karte.html） ---------- */
/* 見た目は .history-* 系を踏襲する。独立ページなので枠だけここで持つ。 */

.karte-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

.karte-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.karte-back {
  display: inline-block;
  font-size: 13px;
  color: var(--heading);
}

.karte-page-title {
  margin: 8px 0 0;
  font-family: var(--font-mincho);
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
}

.karte-page-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.karte-list {
  padding-top: 10px;
}

.karte-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.karte-row.profile {
  background: rgba(201, 169, 97, 0.1);
  border-radius: 10px;
  padding: 12px;
}

.karte-date {
  margin: 0 0 6px;
  font-family: var(--font-mincho);
  font-size: 14px;
  font-weight: 600;
  color: var(--heading);
}

.karte-field,
.karte-raw {
  margin: 0 0 4px;
  font-size: 14px;
}

.karte-label {
  display: inline-block;
  min-width: 3.5em;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(201, 169, 97, 0.24);
  color: var(--ink-on-gold);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.karte-links {
  margin: 6px 0 0;
}

.karte-link {
  display: inline-block;
  margin-right: 10px;
  font-size: 13px;
  color: var(--heading);
}

.karte-empty {
  margin: 32px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* AI メモ・月ごとのまとめ（memo-render.js） */
.memo-section {
  margin: 24px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.memo-section h2 {
  margin: 0 0 6px;
  font-family: var(--font-mincho);
  font-size: 16px;
  color: var(--heading);
}

.memo-section h3 {
  margin: 12px 0 4px;
  font-size: 14px;
  color: var(--heading);
}

.memo-section p {
  margin: 0 0 4px;
  font-size: 14px;
}

.memo-note,
.memo-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.monthly-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

/* ---------- Pシステム教科書（p-system.html） ---------- */

.textbook-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px));
}

.textbook-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.textbook-back {
  display: inline-block;
  font-size: 13px;
  color: var(--heading);
}

.textbook-page-title {
  margin: 8px 0 0;
  font-family: var(--font-mincho);
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
}

.textbook-intro {
  margin: 16px 0;
  font-size: 14px;
  line-height: 1.8;
}

.textbook-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
  padding: 10px;
  background: rgba(201, 169, 97, 0.1);
  border-radius: 12px;
}

.textbook-toc a {
  min-width: 40px;
  padding: 4px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: rgba(201, 169, 97, 0.24);
  border-radius: 999px;
}

.textbook-section {
  padding: 20px 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: 12px;
}

.textbook-section-title {
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
}

.textbook-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.textbook-caption {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.textbook-note {
  margin: 24px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ---------- 設定ページ（settings.html） ---------- */
/* 枠は .karte-page 系と同じ独立ページ型。 */

.settings-page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

.settings-header {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.settings-back {
  display: inline-block;
  font-size: 13px;
  color: var(--heading);
}

.settings-page-title {
  margin: 8px 0 0;
  font-family: var(--font-mincho);
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
}

.settings-page-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.settings-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.settings-section-title {
  margin: 0 0 8px;
  font-family: var(--font-mincho);
  font-size: 15px;
  font-weight: 600;
  color: var(--heading);
}

.settings-note {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

.settings-list {
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.settings-row-main {
  min-width: 0;
}

.settings-row-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.settings-row-meta {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

.settings-delete {
  flex-shrink: 0;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
  background: none;
  border: 1px solid var(--danger);
  border-radius: 10px;
  cursor: pointer;
}

.settings-empty {
  margin: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.settings-error {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.settings-primary {
  width: 100%;
  padding: 13px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-on-gold);
  background: var(--gold);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.settings-primary:active {
  background: var(--gold-accent);
}

.settings-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.settings-secondary {
  width: 100%;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

/* 履歴の日付見出し（本日/昨日/日付＋曜日）。行の時刻は時刻のみ */
.history-date {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 4px;
}

.history-date::before,
.history-date::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.history-date span {
  flex-shrink: 0;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(201, 169, 97, 0.16);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

/* ---------- 管理ページ（admin/） ---------- */
/* PC主体のサイドバー型レイアウト。900px 未満はサイドバーを上部の横スクロールナビに畳む。
   生徒向けチャット画面のスタイルとは独立（.admin-body 配下のみに効かせる）。 */

.admin-body {
  --admin-bg: #f6f5f2;
  --admin-card: #ffffff;
  --admin-border: rgba(26, 39, 66, 0.1);
  --admin-border-strong: rgba(26, 39, 66, 0.16);
  --admin-muted: rgba(61, 40, 23, 0.6);
  --admin-shadow: 0 1px 2px rgba(26, 39, 66, 0.05);
  height: auto;
  min-height: 100%;
  background: var(--admin-bg);
  font-size: 15px;
}

/* アイコンスプライトの定義本体は描画しない */
.admin-sprite {
  display: none;
}

.admin-ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- シェル ---------- */

.admin-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

.admin-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  flex: none;
  width: 244px;
  height: 100vh;
  padding: 0;
  background: var(--admin-card);
  border-right: 1px solid var(--admin-border);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--admin-border);
}

.admin-brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.admin-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.admin-brand-name {
  font-family: var(--font-mincho);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.admin-brand-sub {
  font-size: 11px;
  color: var(--admin-muted);
}

.admin-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 20px;
}

.admin-nav-group {
  margin: 14px 0 6px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--admin-muted);
}

.admin-nav-group:first-child {
  margin-top: 4px;
}

.admin-tab,
.admin-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 2px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  color: var(--ink-brown);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* SVG や span を押しても closest('.admin-tab') が確実に効くように */
.admin-tab > * {
  pointer-events: none;
}

.admin-tab:hover,
.admin-nav-link:hover {
  background: rgba(26, 39, 66, 0.05);
}

.admin-tab.is-active {
  font-weight: 700;
  color: var(--navy);
  background: rgba(201, 169, 97, 0.18);
}

.admin-tab.is-active .admin-ico {
  color: var(--navy);
}

.admin-sidebar-foot {
  padding: 10px;
  border-top: 1px solid var(--admin-border);
}

.admin-main {
  flex: 1;
  min-width: 0;
  padding: 22px 28px calc(48px + env(safe-area-inset-bottom, 0px));
}

/* ---------- ヘッダー ---------- */

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-header-text {
  min-width: 0;
}

.admin-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 22px;
  font-weight: 600;
  color: var(--navy);
}

.admin-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--admin-muted);
}

.admin-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  background: var(--admin-card);
  border: 1px solid var(--admin-border-strong);
  border-radius: 10px;
  box-shadow: var(--admin-shadow);
  cursor: pointer;
}

.admin-refresh:disabled {
  opacity: 0.5;
  cursor: default;
}

.admin-body .settings-error {
  margin-bottom: 16px;
}

/* ---------- ステータスタイル ---------- */

.admin-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.admin-tile {
  padding: 14px 16px;
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: 16px;
  box-shadow: var(--admin-shadow);
}

.admin-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.admin-tile-label {
  font-size: 12.5px;
  color: var(--admin-muted);
}

.admin-tile-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--navy);
  background: rgba(201, 169, 97, 0.18);
  border-radius: 8px;
}

.admin-tile-value {
  margin: 8px 0 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--navy);
}

.admin-tile-note {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--admin-muted);
}

/* 動的読み込みタイルは admin-system.js が className を差し替えるため、
   タイル側の子孫セレクタで見た目を与える（JS 側は既存文言のまま）。 */
.admin-tile > .settings-note {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

.admin-tile > .settings-note.admin-danger {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--danger);
}

/* ---------- カード ---------- */

.admin-card {
  padding: 18px 20px;
  margin-bottom: 16px;
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: 16px;
  box-shadow: var(--admin-shadow);
}

.admin-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-family: var(--font-mincho);
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
}

.admin-card-title .admin-ico {
  color: var(--gold);
}

/* ---------- 表 ---------- */

.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--admin-card);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--admin-border);
  white-space: nowrap;
}

.admin-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-table th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--admin-muted);
  background: rgba(26, 39, 66, 0.03);
}

.admin-cell-email {
  font-size: 12px;
  color: rgba(61, 40, 23, 0.7);
}

tr.is-hidden {
  opacity: 0.55;
}

.admin-view {
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  background: none;
  border: 1px solid var(--admin-border-strong);
  border-radius: 9px;
  cursor: pointer;
}

.admin-view:hover {
  border-color: var(--gold);
}

/* ---------- 会話ログ ---------- */

.admin-log {
  max-height: 62vh;
  overflow-y: auto;
  padding: 4px 2px;
}

.admin-log-date {
  margin: 12px 0 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-brown);
}

.admin-log-row {
  margin: 6px 0;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
}

.admin-log-row.user {
  background: rgba(201, 169, 97, 0.15);
}

.admin-log-row.assistant {
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
}

.admin-log-meta {
  margin: 0 0 2px;
  font-size: 11px;
  color: rgba(61, 40, 23, 0.55);
}

.admin-log-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- フォーム ---------- */

.admin-note-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.admin-note-form .admin-input {
  flex: 1 1 190px;
  width: auto;
  min-width: 0;
}

.admin-note-form .admin-textarea,
.admin-note-form .admin-label {
  flex: 1 1 100%;
}

.admin-note-form .settings-primary,
.admin-note-form .settings-secondary {
  flex: none;
  width: auto;
  padding: 10px 20px;
}

.admin-input,
.admin-textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink-brown);
  background: var(--admin-card);
  border: 1px solid var(--admin-border-strong);
  border-radius: 10px;
}

.admin-input:focus,
.admin-textarea:focus {
  outline: 2px solid rgba(201, 169, 97, 0.5);
  outline-offset: 1px;
}

.admin-textarea {
  min-height: 80px;
  resize: vertical;
}

.admin-label {
  display: block;
  margin: 14px 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: rgba(61, 40, 23, 0.7);
}

.admin-note-form .admin-label {
  margin: 0;
}

/* ---------- 集計 ---------- */

.admin-subtitle {
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}

.admin-bar-chart {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 14px 0;
}

.admin-bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 40px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(61, 40, 23, 0.7);
}

.admin-bar-track {
  height: 10px;
  background: rgba(26, 39, 66, 0.06);
  border-radius: 6px;
  overflow: hidden;
}

.admin-bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 6px;
}

.admin-words-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 12px 0;
}

.admin-words-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--ink-brown);
}

.admin-words-list li {
  margin: 2px 0;
}

/* ---------- 修正メモ ---------- */

.admin-notes .settings-row {
  background: var(--admin-bg);
}

.admin-note.done {
  opacity: 0.6;
}

.admin-note-body {
  margin: 2px 0;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 危険操作・ダイアログ ---------- */

.admin-danger {
  color: var(--danger);
}

.admin-view.admin-danger {
  border-color: var(--danger);
}

.settings-primary.admin-danger {
  color: #fff;
  background: var(--danger);
}

.admin-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  color: var(--ink-brown);
  background: var(--admin-card);
  border: none;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.admin-dialog::backdrop {
  background: rgba(26, 39, 66, 0.5);
}

.admin-dialog .admin-input {
  margin: 6px 0 4px;
}

/* ---------- AI設定 ---------- */

.admin-pre {
  padding: 12px 14px;
  white-space: pre-wrap;
  overflow-x: auto;
  font-size: 12px;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
}

.admin-preview-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
}

.admin-preview-q {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-brown);
}

.admin-preview-a {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(61, 40, 23, 0.85);
}

/* ---------- 900px 未満: サイドバーを上部の横スクロールナビに畳む ---------- */

@media (max-width: 899px) {
  .admin-shell {
    display: block;
  }

  .admin-sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--admin-border);
  }

  .admin-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .admin-nav-group {
    display: none;
  }

  .admin-tab {
    width: auto;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .admin-sidebar-foot {
    padding: 6px 12px;
    border-top: 1px solid var(--admin-border);
  }

  .admin-nav-link {
    width: auto;
  }

  .admin-main {
    padding: 18px 14px calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .admin-words-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- 動画・記事URL 一覧（検索・絞り込み・並び替え） ---------- */

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-toolbar .admin-input {
  width: auto;
  flex: 0 1 auto;
  min-width: 0;
}

.admin-toolbar input[type="search"] {
  flex: 1 1 220px;
}

.admin-toolbar-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--admin-muted);
}

.admin-table-videos td {
  white-space: normal;
  vertical-align: middle;
}

.admin-table-videos .admin-cell-title {
  min-width: 240px;
  font-weight: 600;
}

.admin-table-videos .admin-cell-email a,
.admin-table-videos .admin-cell-email {
  white-space: nowrap;
}

.admin-table-videos .admin-cell-actions {
  white-space: nowrap;
  text-align: right;
}

.admin-table-videos tr.is-editing td {
  background: rgba(201, 162, 77, 0.12);
}

.admin-table-videos tbody tr:hover td {
  background: rgba(26, 39, 66, 0.03);
}

.admin-empty {
  text-align: center;
  color: var(--admin-muted);
  padding: 24px 12px;
}

.admin-sort {
  padding: 0;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--admin-muted);
  background: none;
  border: none;
  cursor: pointer;
}

.admin-sort:hover {
  color: var(--navy);
}

.admin-sort.is-asc::after {
  content: " \25B2";
  font-size: 9px;
}

.admin-sort.is-desc::after {
  content: " \25BC";
  font-size: 9px;
}

.admin-chip {
  display: inline-block;
  white-space: nowrap;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--admin-border-strong);
  color: var(--navy);
}

.admin-chip-article {
  background: rgba(26, 39, 66, 0.06);
}

.admin-chip-video {
  background: rgba(201, 162, 77, 0.16);
}

.admin-chip-active {
  color: #1f6b3a;
  border-color: rgba(31, 107, 58, 0.35);
  background: rgba(31, 107, 58, 0.08);
}

.admin-chip-hidden {
  color: var(--admin-muted);
  background: rgba(26, 39, 66, 0.04);
}

.admin-row-menu {
  position: relative;
  display: inline-block;
  margin-left: 6px;
}

.admin-row-menu > summary {
  list-style: none;
  display: inline-block;
  padding: 6px 10px;
}

.admin-row-menu > summary::-webkit-details-marker {
  display: none;
}

.admin-row-menu-list {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: 4px;
  background: var(--admin-card);
  border: 1px solid var(--admin-border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(26, 39, 66, 0.14);
}

.admin-row-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  text-align: left;
  color: var(--navy);
  background: none;
  border: none;
  border-radius: 7px;
  cursor: pointer;
}

.admin-row-menu-item:hover {
  background: rgba(26, 39, 66, 0.05);
}

/* ---------- AIに渡るテキスト（区画カード） ---------- */

.admin-prompt-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-prompt-section {
  padding: 12px 14px;
  border: 1px solid var(--admin-border);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  background: var(--admin-card);
}

.admin-prompt-section.is-fixed {
  border-left-color: var(--admin-border-strong);
}

.admin-prompt-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.admin-prompt-section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

.admin-prompt-section .admin-pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
}

.admin-prompt-section .settings-note {
  margin: 0 0 8px;
}

/* ---------- 管理画面: カルテ ---------- */
.admin-karte-notice { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; background: rgba(201, 162, 39, 0.12); font-size: 0.9rem; line-height: 1.6; }
.admin-karte-kind { display: flex; gap: 16px; border: 0; padding: 0; margin: 0 0 8px; }
.admin-karte-list { display: grid; gap: 12px; margin-top: 20px; }
.admin-karte-row.is-hidden { opacity: 0.55; }
.admin-karte-field, .admin-karte-raw { margin: 4px 0; white-space: pre-wrap; }
.admin-karte-label { display: inline-block; min-width: 3em; font-weight: 600; margin-right: 8px; }
.admin-karte-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }
.admin-karte-link { word-break: break-all; }
.admin-karte-actions { display: flex; gap: 8px; align-items: flex-start; }
/* スコアカード（写真＋読み取り結果） */
.admin-scorecard-figure { display: inline-block; margin: 6px 0; }
.admin-scorecard-thumb { display: block; max-width: 100%; max-height: 260px; border-radius: 8px; border: 1px solid var(--line); background: #fff; object-fit: contain; }
.admin-scorecard-analysis { margin: 6px 0; }
.admin-scorecard-details { margin: 6px 0; }
.admin-scorecard-details summary { cursor: pointer; font-size: 0.9rem; }
.admin-scorecard-holes th, .admin-scorecard-holes td { white-space: nowrap; font-size: 0.85rem; }

/* ---------- AI メモ（管理画面） ---------- */
.admin-memo-body { margin: 6px 0; white-space: pre-wrap; word-break: break-word; font: inherit; line-height: 1.7; }
.admin-memo-subtitle { margin: 24px 0 8px; font-size: 1rem; }
.admin-memo-monthly-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 8px 0 12px; }
.admin-memo-toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.admin-memo-usage { margin-bottom: 16px; }
.admin-memo-edit { width: 100%; min-height: 220px; }

/* ---------- 管理「ナレッジ資料」タブ（admin-rag.js） ---------- */

.rag-form .admin-textarea.rag-text {
  min-height: 160px;
  font-size: 13px;
}

.rag-label {
  flex: 1 1 100%;
  margin: 4px 0 -4px;
  font-size: 12px;
  color: var(--admin-muted);
}

.rag-preview,
.rag-answer {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--admin-border);
}

.rag-summary {
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--navy);
}

.rag-block-title {
  margin: 10px 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}

.rag-block-title:empty {
  display: none;
}

.rag-list {
  max-height: 260px;
  margin: 0;
  padding-left: 1.2em;
  overflow: auto;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.rag-details summary {
  margin: 8px 0;
  font-size: 13px;
  cursor: pointer;
}

.rag-pre {
  max-height: 420px;
  margin: 6px 0 12px;
  padding: 12px;
  overflow: auto;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(26, 39, 66, 0.04);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
}

.rag-pre.rag-reply {
  max-height: none;
  background: var(--admin-card);
}

.rag-samples {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-note-form .settings-secondary.rag-sample {
  padding: 6px 12px;
  font-size: 12px;
}

.rag-doc + .rag-doc {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--admin-border);
}

.rag-doc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.rag-doc-title {
  margin: 0;
  font-weight: 700;
  color: var(--navy);
}

.rag-doc-head .settings-secondary,
.rag-ops .settings-primary,
.rag-ops .settings-secondary {
  width: auto;
  padding: 4px 10px;
  font-size: 12px;
}

.rag-ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rag-body-row td {
  padding: 0 8px;
  border-bottom: 0;
}

.rag-body-row td:empty {
  display: none;
}

.admin-log-sources {
  margin-top: 4px;
  color: var(--navy);
}

/* 監修済みの見本。既存の会話の流れと配色を維持し、画像全体を切り取らず表示する。 */
.reference-image {
  margin: 14px 0 8px;
  padding: 0;
  border: 1px solid var(--gold, #c4a55c);
  border-radius: 12px;
  overflow: hidden;
  background: var(--cream, #f8f5ed);
}
.reference-image a { display: block; }
.reference-image a:focus-visible { outline: 3px solid var(--navy, #1b2942); outline-offset: -3px; }
.reference-image img { display: block; width: 100%; height: auto; object-fit: contain; }
.reference-image figcaption { padding: 9px 12px; font-size: 12px; line-height: 1.65; color: var(--navy, #1b2942); }
