/* Sizzle CRM — 独自CSS。土台は Bootstrap 5.3、見た目のトークンはここで定義する */

/* ===========================================================================
   トークン
   色・角丸・影・余白をここに集約する。画面側で直接 #hex を書かないこと。
   =========================================================================== */
:root {
  --crm-side-w: 232px;

  --crm-ink:    #1a2233;   /* 本文 */
  --crm-ink-2:  #475069;   /* 副次の文字 */
  --crm-muted:  #8a94a6;   /* ラベル・補足 */
  --crm-line:   #eef1f6;   /* 罫線 */
  --crm-line-2: #e3e8f0;   /* すこし強い罫線 */
  --crm-bg:     #f4f6fb;   /* ページ背景 */
  --crm-card:   #ffffff;

  --crm-accent:    #2f6bff;
  --crm-accent-bg: #eef3ff;

  --crm-radius:    14px;
  --crm-radius-sm: 9px;
  --crm-shadow:    0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .04);

  /* カード見出しのアイコン枠の色 */
  --crm-tone-blue:   #2f6bff; --crm-tone-blue-bg:   #eaf1ff;
  --crm-tone-green:  #0f9d6e; --crm-tone-green-bg:  #e7f7f1;
  --crm-tone-amber:  #c77700; --crm-tone-amber-bg:  #fdf3e2;
  --crm-tone-violet: #6d4aff; --crm-tone-violet-bg: #f0ecff;
  --crm-tone-pink:   #d1457b; --crm-tone-pink-bg:   #fdeaf2;
  --crm-tone-slate:  #5a6784; --crm-tone-slate-bg:  #eef1f6;
}

body {
  background: var(--crm-bg);
  color: var(--crm-ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.crm-shell { display: flex; min-height: 100vh; }
.crm-ico { flex: 0 0 auto; }

/* ===========================================================================
   サイドバー
   =========================================================================== */
.crm-side {
  width: var(--crm-side-w);
  flex: 0 0 var(--crm-side-w);
  background: linear-gradient(180deg, #171d2e 0%, #10151f 100%);
  color: #aab3c5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.crm-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: .01em;
}
.crm-brand:hover { color: #fff; }
.crm-brand-mark {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #7c5cff);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}

.crm-nav { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.crm-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin-bottom: 2px;
  color: #aab3c5;
  text-decoration: none;
  font-size: 13.5px;
  border-radius: 9px;
}
.crm-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
/* 現在地は塗りで示す。左の線だけだと小さい画面で気づきにくい */
.crm-nav a.is-active {
  background: linear-gradient(90deg, rgba(47,107,255,.30), rgba(47,107,255,.14));
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(120,160,255,.18);
}
.crm-nav a .crm-ico { opacity: .85; }
.crm-nav-sep {
  padding: 18px 12px 6px;
  font-size: 10.5px;
  letter-spacing: .12em;
  color: #6a748a;
  font-weight: 700;
}

.crm-side-foot {
  border-top: 1px solid rgba(255,255,255,.07);
  padding: 14px 16px 18px;
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.crm-me-avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: 10px;
  background: rgba(255,255,255,.10);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.crm-me { color: #fff; font-weight: 600; font-size: 13px; line-height: 1.3; }
.crm-me-role { color: #7f8aa0; font-size: 11.5px; margin-bottom: 3px; }
.crm-side-foot a { color: #93a3bd; text-decoration: none; font-size: 11.5px; }
.crm-side-foot a:hover { color: #fff; }

/* ===========================================================================
   本文の器
   =========================================================================== */
.crm-main { flex: 1; min-width: 0; }
.crm-inner { max-width: 1280px; padding: 28px 32px 72px; }

.crm-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.crm-page-head h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.crm-page-head .crm-sub { color: var(--crm-muted); font-size: 12.5px; margin-top: 5px; }
.crm-page-head .crm-sub a { color: var(--crm-muted); }

/* 顧客名の左に置く四角いアイコン */
.crm-page-mark {
  width: 46px; height: 46px; flex: 0 0 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #3b82f6, #6d4aff);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(59, 130, 246, .28);
}

/* ===========================================================================
   カード
   =========================================================================== */
.card {
  border: 1px solid var(--crm-line);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  background: var(--crm-card);
}
.card-header {
  background: var(--crm-card);
  border-bottom: 1px solid var(--crm-line);
  border-radius: var(--crm-radius) var(--crm-radius) 0 0 !important;
  font-weight: 700;
  font-size: 14px;
  padding: 14px 18px;
  color: var(--crm-ink);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-header > span:first-child { display: inline-flex; align-items: center; gap: 9px; }
.card-body { padding: 16px 18px; }
.card-footer { background: #fbfcfe; border-top: 1px solid var(--crm-line); }

/* 見出しの色付きアイコン枠 */
.crm-card-ico {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.crm-tone-blue   { color: var(--crm-tone-blue);   background: var(--crm-tone-blue-bg); }
.crm-tone-green  { color: var(--crm-tone-green);  background: var(--crm-tone-green-bg); }
.crm-tone-amber  { color: var(--crm-tone-amber);  background: var(--crm-tone-amber-bg); }
.crm-tone-violet { color: var(--crm-tone-violet); background: var(--crm-tone-violet-bg); }
.crm-tone-pink   { color: var(--crm-tone-pink);   background: var(--crm-tone-pink-bg); }
.crm-tone-slate  { color: var(--crm-tone-slate);  background: var(--crm-tone-slate-bg); }

/* 見出し右の「追加」などの小さな操作。リンクではなく淡いピルにする */
.card-header .btn-link,
.card-header a.small,
.crm-head-act {
  font-size: 12px;
  font-weight: 600;
  color: var(--crm-accent) !important;
  background: var(--crm-accent-bg);
  border-radius: 999px;
  padding: 4px 12px !important;
  text-decoration: none !important;
  border: 0;
  line-height: 1.5;
}
.card-header .btn-link:hover,
.card-header a.small:hover,
.crm-head-act:hover { background: #e0eaff; }

/* ===========================================================================
   表
   =========================================================================== */
.table { font-size: 13.5px; --bs-table-bg: transparent; }
.table > thead th {
  font-size: 11.5px;
  color: var(--crm-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--crm-line);
  white-space: nowrap;
  padding: 10px 14px;
  background: #fbfcfe;
}
.table > tbody > tr > td { padding: 12px 14px; border-color: var(--crm-line); }
.table td { vertical-align: middle; }
.table > tbody > tr:last-child > td { border-bottom: 0; }
.table-hover > tbody > tr:hover > * { background: #f8faff; }

.crm-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--crm-muted);
  font-size: 13px;
}

/* ===========================================================================
   バッジ・ボタン
   =========================================================================== */
.badge {
  font-weight: 600;
  font-size: 11px;
  padding: .32em .7em;
  border-radius: 999px;
  letter-spacing: .01em;
}
/* Bootstrap の原色は強すぎるので、淡い地＋濃い文字に置き換える */
.badge.bg-primary   { background: #e8f0ff !important; color: #1d4ed8 !important; }
.badge.bg-success   { background: #e7f7f1 !important; color: #0f7a56 !important; }
.badge.bg-danger    { background: #fdecec !important; color: #b42318 !important; }
.badge.bg-warning   { background: #fdf3e2 !important; color: #a35c00 !important; }
.badge.bg-info      { background: #e6f5fd !important; color: #0c6d92 !important; }
.badge.bg-secondary { background: #eef1f6 !important; color: #4b566b !important; }
.badge.bg-light     { background: #f6f8fb !important; color: #4b566b !important; }

.btn { border-radius: var(--crm-radius-sm); font-weight: 600; }
.btn-sm { font-size: 12.5px; padding: .34rem .75rem; }
.btn-primary { background: var(--crm-accent); border-color: var(--crm-accent); }
.btn-primary:hover { background: #2559da; border-color: #2559da; }

.form-control, .form-select { border-color: var(--crm-line-2); border-radius: var(--crm-radius-sm); }
.form-control:focus, .form-select:focus {
  border-color: #a9c2ff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .12);
}
.form-label { color: var(--crm-ink-2); }

.alert { border-radius: var(--crm-radius); border-width: 1px; font-size: 13.5px; }

/* ===========================================================================
   KPI タイル
   =========================================================================== */
.crm-kpi {
  background: var(--crm-card);
  border: 1px solid var(--crm-line);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
  padding: 16px 18px;
  height: 100%;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.crm-kpi-ico {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.crm-kpi-main { min-width: 0; }
.crm-kpi-label { font-size: 11.5px; color: var(--crm-muted); font-weight: 600; }
.crm-kpi-value { font-size: 25px; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.crm-kpi-note { font-size: 11.5px; color: var(--crm-muted); }

/* 期限超過 */
.is-overdue { color: #b42318; font-weight: 600; }

/* ---- 文字起こしのチャット表示（面談詳細） ---- */

/* 話者の色。登場順に割り当てる（transcriptSpeakerIndex が index を返す）。
   6人を超えたら先頭に戻す。1つの会議で7人以上が喋ることは実務上ほぼ無い。 */
.crm-sp-0 { --sp: #2563eb; --sp-bg: #eff4ff; --sp-line: #c7d9fd; }
.crm-sp-1 { --sp: #c2410c; --sp-bg: #fff4ec; --sp-line: #fdd6bd; }
.crm-sp-2 { --sp: #047857; --sp-bg: #ecfaf4; --sp-line: #bfe8d8; }
.crm-sp-3 { --sp: #7c3aed; --sp-bg: #f5f1ff; --sp-line: #ddd2fb; }
.crm-sp-4 { --sp: #b45309; --sp-bg: #fdf6e7; --sp-line: #f3e0b5; }
.crm-sp-5 { --sp: #be185d; --sp-bg: #fdf0f6; --sp-line: #f8cfe2; }

/* 話者の凡例。誰が何回喋ったかが分かると、会議の主導権が見える */
.crm-talk-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--crm-line);
}
.crm-talk-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sp);
  background: var(--sp-bg);
  border: 1px solid var(--sp-line);
}
.crm-talk-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sp); }
.crm-talk-chip-n { color: var(--crm-muted); font-weight: 400; }

/* 会話ログ本体 */
.crm-talk-log {
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px 16px 16px;
}

/* 1発言 = アバター + 本文。発言ごとに破線で区切る */
.crm-talk {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px dashed var(--crm-line);
}
.crm-talk:first-child { border-top: 0; }

.crm-talk-avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--sp);
  background: var(--sp-bg);
  border: 1px solid var(--sp-line);
}
.crm-talk-main { flex: 1 1 auto; min-width: 0; }

.crm-talk-who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.crm-talk-name { font-size: 12px; font-weight: 700; color: var(--sp); }
.crm-talk-time {
  font-size: 11px;
  color: var(--crm-muted);
  font-variant-numeric: tabular-nums;
}
.crm-talk-body {
  display: inline-block;
  max-width: 100%;
  padding: 8px 12px;
  background: var(--sp-bg);
  border: 1px solid var(--sp-line);
  border-left: 3px solid var(--sp);
  border-radius: 4px 10px 10px 4px;
  font-size: 13.5px;
  line-height: 1.85;
  color: var(--crm-ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 自社側の発言は右に寄せる。どちらが話しているかを一目で追えるように */
.crm-talk.is-ours { flex-direction: row-reverse; }
.crm-talk.is-ours .crm-talk-main { text-align: right; }
.crm-talk.is-ours .crm-talk-who { flex-direction: row-reverse; }
.crm-talk.is-ours .crm-talk-body {
  text-align: left;
  border-left: 1px solid var(--sp-line);
  border-right: 3px solid var(--sp);
  border-radius: 10px 4px 4px 10px;
}

/* 幅が無いと左右振り分けは逆に読みにくいので、狭い画面では全部左に揃える */
@media (max-width: 767.98px) {
  .crm-talk-avatar { display: none; }
  .crm-talk.is-ours,
  .crm-talk.is-ours .crm-talk-who { flex-direction: row; }
  .crm-talk.is-ours .crm-talk-main { text-align: left; }
  .crm-talk.is-ours .crm-talk-body {
    border-left: 3px solid var(--sp);
    border-right: 1px solid var(--sp-line);
    border-radius: 4px 10px 10px 4px;
  }
}

/* 顧客カードのタイムライン */
.crm-timeline { position: relative; padding-left: 20px; }
.crm-timeline::before {
  content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px;
  width: 2px; background: var(--crm-line);
}
.crm-timeline-item { position: relative; padding-bottom: 18px; }
.crm-timeline-item::before {
  content: ""; position: absolute; left: -18px; top: 5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff; border: 2px solid #9ca3af;
}
.crm-timeline-time { font-size: 12px; color: var(--crm-muted); }

@media (max-width: 860px) {
  .crm-shell { flex-direction: column; }
  .crm-side { width: 100%; flex: none; height: auto; position: static; }
  .crm-nav { display: flex; flex-wrap: wrap; }
  .crm-nav a { border-left: 0; border-bottom: 3px solid transparent; }
  .crm-nav a.is-active { border-left: 0; border-bottom-color: #7dd3fc; }
  .crm-nav-sep { width: 100%; }
  .crm-inner { padding: 18px 16px 48px; }
}

/* ---- 次回アクションの候補（面談詳細） ---- */
/* 候補ごとに担当・期限・時刻が違うので、1件ずつ独立したカードにして個別に登録する。
   チェックボックス一括だと入力欄を1組しか持てず、候補が増えた時点で破綻する。 */
.crm-action {
  border: 1px solid var(--crm-line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #fff;
}
.crm-action.is-done { background: #f8fafb; }
.crm-action-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.crm-action.is-done .crm-action-title { color: var(--crm-muted); }
.crm-action-note {
  font-size: 12px;
  color: var(--crm-muted);
  margin-top: 4px;
  line-height: 1.7;
}
/* AI の文言をそのまま登録させないための入力欄。読み物ではなく編集対象だと分かる見た目にする */
.crm-action-input {
  font-weight: 600;
  font-size: 13.5px;
}
.crm-action-form {
  display: grid;
  grid-template-columns: .8fr 1.4fr 1.1fr .8fr .8fr auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}
.crm-action-submit { min-width: 104px; }
/* 「推定」は AI ではなく発言から機械的に補った印。人に確認を促すために目立たせる */
.crm-action-guess {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
}

@media (max-width: 991.98px) {
  .crm-action-form { grid-template-columns: 1fr 1fr; }
  .crm-action-submit { grid-column: 1 / -1; }
}

/* ---- いまの状況（顧客カードの最上部） ---- */
/* 「最後にどういう話になっているか」と「次に誰が何をするか」を、
   スクロールせずに読み切れる位置に置くための枠。左の帯で危険度を示す。 */
.crm-situation {
  border-left: 4px solid var(--crm-line);
}
.crm-situation--danger  { border-left-color: #b42318; background: #fffafa; }
.crm-situation--warn    { border-left-color: #b45309; background: #fffdf6; }
.crm-situation--watch   { border-left-color: #6b7280; }
.crm-situation--ok      { border-left-color: #047857; }
.crm-situation--unknown { border-left-color: var(--crm-line); background: #fbfcfd; }

.crm-situation-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--crm-muted);
  letter-spacing: .04em;
}
.crm-situation-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px dashed var(--crm-line);
}
.crm-situation-row:first-of-type { border-top: 0; padding-top: 0; }
.crm-situation-key {
  font-size: 12px;
  color: var(--crm-muted);
  padding-top: 2px;
}
.crm-situation-val { min-width: 0; }
/* 本文は一覧より一段大きく。ここが一番読ませたい行 */
.crm-situation-text {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.6;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

@media (max-width: 575.98px) {
  .crm-situation-row { grid-template-columns: 1fr; gap: 2px; }
}

/* ---- 顧客チャット ---- */
.crm-chat-log { max-height: 460px; overflow-y: auto; }
.crm-chat { margin-bottom: 14px; }
.crm-chat-who {
  font-size: 11px;
  font-weight: 700;
  color: var(--crm-muted);
  margin-bottom: 3px;
}
.crm-chat-time { font-weight: 400; margin-left: 6px; opacity: .8; }
.crm-chat-body {
  font-size: 13.5px;
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 8px 12px;
  border-radius: 8px;
}
/* 質問と回答を見分けられれば十分。凝った吹き出しにはしない */
.crm-chat--user .crm-chat-body {
  background: #eff4ff;
  border: 1px solid #c7d9fd;
}
.crm-chat--assistant .crm-chat-body {
  background: #fff;
  border: 1px solid var(--crm-line);
}
/* 回答待ち。点滅させて「止まっていない」ことを伝える */
.crm-chat.is-waiting .crm-chat-body {
  color: var(--crm-muted);
  animation: crm-chat-pulse 1.2s ease-in-out infinite;
}
@keyframes crm-chat-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.crm-chat--error .crm-chat-body {
  background: #fff5f5;
  border-color: #f3c6c6;
  color: #b42318;
}

.crm-chat-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.crm-chat-presets .btn { font-size: 11.5px; padding: 2px 8px; }

/* ---- 右side の引き出し（顧客チャット） ---- */
/* 本文に置くと縦に伸びて他のカードを押し下げるので、画面に固定して必要なときだけ開く。 */

.crm-drawer-toggle {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1035;
  border: 1px solid var(--crm-line);
  border-right: 0;
  border-radius: 10px 0 0 10px;
  background: #fff;
  color: var(--crm-ink);
  padding: 14px 8px;
  font-size: 11.5px;
  line-height: 1.5;
  font-weight: 700;
  box-shadow: -2px 0 10px rgba(0, 0, 0, .06);
  cursor: pointer;
}
.crm-drawer-toggle:hover { background: #f6f8fb; }
.crm-drawer-toggle[aria-expanded="true"] { display: none; }

/* hidden を確実に効かせる。position:fixed を持つ要素は、
   何かの拍子に display が上書きされると画面に残ってしまうため明示する */
.crm-drawer[hidden] { display: none !important; }

.crm-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  z-index: 1040;
  background: #fff;
  border-left: 1px solid var(--crm-line);
  box-shadow: -6px 0 24px rgba(0, 0, 0, .10);
  /* 閉→開のアニメーション。hidden を外した直後に is-open が付く */
  transform: translateX(100%);
  transition: transform .18s ease-out;
}
.crm-drawer.is-open { transform: translateX(0); }

/* 高さを3段に割る。真ん中だけがスクロールし、入力欄は常に見えている */
.crm-drawer-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.crm-drawer-head {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid var(--crm-line);
}
.crm-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  background: var(--crm-bg);
}
.crm-drawer-foot {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-top: 1px solid var(--crm-line);
  background: #fff;
}

/* ドロワー内ではログの高さ制限を外す（親の flex が高さを決める） */
.crm-drawer .crm-chat-log { max-height: none; }

@media (max-width: 575.98px) {
  .crm-drawer { width: 100%; max-width: 100%; }
}

/* ---- タスク表 ---- */
/* 完了・見送りは消さずに残すが、目は未完了に向いてほしいので薄くする */
.crm-task-row.is-closed { opacity: .45; }
.crm-task-row.is-closed:hover { opacity: .8; }

/* ---- 横並びの対（活動履歴 ／ タスク） ---- */
/*
  狙いはレイアウトのがたつきを止めること。
    1. 行の中で背の高い方に、もう片方も合わせる（.col に d-flex、カードに w-100）
    2. 伸び続けないよう上限を決め、超えたら中身だけスクロールさせる
  カードを縦の flex にして、一覧部分（crm-pair-body）だけを伸縮・スクロールさせる。
  ヘッダーと折りたたみのフォームは縮まないので、開いても一覧が譲るだけで
  カードの外形は変わらない。
*/
:root { --crm-pair-max: 620px; }

.crm-pair-card {
  display: flex;
  flex-direction: column;
  max-height: var(--crm-pair-max);
}
.crm-pair-card > .card-header,
.crm-pair-card > .collapse,
.crm-pair-card > .collapsing { flex: 0 0 auto; }

.crm-pair-body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;   /* これが無いと flex の子が縮まず、はみ出す */
}
/* 表のヘッダーはスクロールしても残す */
.crm-pair-body thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  box-shadow: inset 0 -1px 0 var(--crm-line);
}

/* 縦に積まれる幅では高さを揃える意味がないので上限も外す */
@media (max-width: 991.98px) {
  .crm-pair-card { max-height: none; }
  .crm-pair-body { overflow-y: visible; }
}

/* ---- 連絡ツールのボタン ---- */
/* 各社の公式ロゴは同梱していない（商標のため描き起こさない）。
   サービス名とブランドに近い色だけで見分けられるようにしている。 */
.crm-channel-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  text-decoration: none;
  border: 0;
  white-space: nowrap;
}
.crm-channel-btn:hover { filter: brightness(1.12); text-decoration: none; }
.crm-channel-btn:focus-visible { outline: 2px solid #1b1f24; outline-offset: 2px; }

/* ---- 2列の定義テーブル（顧客情報・担当者モーダル） ---- */
.crm-kv th {
  width: 104px;
  font-size: 12px;
  font-weight: 600;
  color: var(--crm-muted);
  background: #fbfcfd;
  white-space: nowrap;
}
.crm-kv td { font-size: 13.5px; }
.crm-kv .crm-kv-copy {
  border: 0;
  background: none;
  padding: 0 4px;
  color: var(--crm-muted);
  font-size: 11px;
  cursor: pointer;
}
.crm-kv .crm-kv-copy:hover { color: var(--crm-ink); }

/* ---- ブロック内の小見出し ---- */
.crm-subhead {
  padding: 8px 16px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--crm-muted);
  background: #fbfcfd;
  letter-spacing: .03em;
}

/* ---- ヘルススコア推移 ---- */
/* 棒の幅は固定。flex-fill だと1日分しか無いとき横幅いっぱいの塊になる。
   高さは 100点 = 72px の固定尺度。日によって尺度が変わると比較にならない。 */
.crm-spark {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 92px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--crm-line);
  overflow-x: auto;
}
.crm-spark-col {
  flex: 0 0 22px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
}
.crm-spark-bar { width: 100%; border-radius: 2px 2px 0 0; }
.crm-spark-val { font-size: 10px; color: var(--crm-muted); margin-top: 2px; }

/* ===========================================================================
   以下は既存コンポーネントの調整（新しいトークンに合わせる）
   =========================================================================== */

/* タイムラインの点を色付きに。線は薄く */
.crm-timeline { padding-left: 22px; }
.crm-timeline::before { background: var(--crm-line); }
.crm-timeline-item::before {
  background: var(--crm-accent);
  box-shadow: 0 0 0 3px #fff, 0 0 0 4.5px var(--crm-accent-bg);
  width: 9px; height: 9px; left: -21px; top: 6px;
}
.crm-timeline-time { font-size: 11.5px; color: var(--crm-muted); }
.crm-timeline-item { padding-bottom: 20px; }

/* 対のカード（活動履歴 / タスク）は影を二重にしない */
.crm-pair-card { box-shadow: var(--crm-shadow); }

/* 連絡ツールのボタン */
.crm-channel-btn {
  padding: 7px 16px;
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: 0 2px 6px rgba(16,24,40,.12);
}

/* 小見出し */
.crm-subhead {
  padding: 10px 18px;
  font-size: 11px;
  letter-spacing: .06em;
  background: #fbfcfe;
  border-bottom: 1px solid var(--crm-line);
}

/* 定義テーブル */
.crm-kv th {
  width: 92px;
  font-size: 11.5px;
  background: #fbfcfe;
  padding: 11px 14px;
}
.crm-kv td { font-size: 13px; padding: 11px 14px; }

/* 顧客情報は4列。ラベルが詰まらないよう幅を決める */
.crm-kv--wide th { width: 104px; }

/* 引き出し */
.crm-drawer { border-left: 1px solid var(--crm-line); }
.crm-drawer-head { padding: 14px 18px; }
.crm-drawer-body { background: var(--crm-bg); padding: 18px; }
.crm-drawer-foot { padding: 14px 18px; }
.crm-drawer-toggle {
  border-radius: 12px 0 0 12px;
  border-color: var(--crm-line);
  box-shadow: -3px 0 14px rgba(16,24,40,.10);
}

/* チャットの吹き出し */
.crm-chat-body { border-radius: 10px; font-size: 13px; }
.crm-chat--user .crm-chat-body { background: var(--crm-accent-bg); border-color: #d7e3ff; }

/* 文字起こし */
.crm-talk-body { border-radius: 10px; }

/* 次回アクションの候補 */
.crm-action { border-radius: var(--crm-radius-sm); border-color: var(--crm-line-2); }

/* ===========================================================================
   ヘルススコア推移（折れ線）
   =========================================================================== */
.crm-trend { display: flex; gap: 20px; align-items: stretch; flex-wrap: wrap; }
.crm-trend-chart { flex: 1 1 380px; min-width: 0; }
.crm-trend-chart svg { width: 100%; height: 150px; display: block; }
.crm-trend-x {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--crm-muted);
  margin-top: 6px;
}
/* 現在値。グラフの隣に置いて「いま何点か」を数字でも押さえる */
.crm-trend-now {
  flex: 0 0 210px;
  border-left: 1px solid var(--crm-line);
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.crm-trend-now-label { font-size: 11.5px; color: var(--crm-muted); font-weight: 600; }
.crm-trend-now-value { font-size: 38px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.crm-trend-now-max { font-size: 13px; color: var(--crm-muted); font-weight: 500; }
.crm-trend-delta { font-size: 12px; font-weight: 700; }
.crm-trend-delta.is-up   { color: #0f7a56; }
.crm-trend-delta.is-down { color: #b42318; }

@media (max-width: 767.98px) {
  .crm-trend-now { flex: 1 1 100%; border-left: 0; padding-left: 0; border-top: 1px solid var(--crm-line); padding-top: 14px; }
  .crm-inner { padding: 20px 16px 56px; }
}

/* ===========================================================================
   連絡ツール（顧客カード）
   =========================================================================== */

/* 顧客名の右に出るメインの連絡先。カードを開いて最初に押すボタンなので大きく扱う */
.crm-ch-primary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.crm-channel-btn--lg {
  padding: 10px 20px;
  border-radius: 12px;
  gap: 10px;
  font-size: 14.5px;
  line-height: 1.3;
  box-shadow: 0 6px 16px rgba(16, 24, 40, .18);
}
.crm-channel-btn--lg:hover { filter: brightness(1.08); }
.crm-channel-btn--lg svg { flex: 0 0 auto; }
.crm-channel-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}
.crm-channel-btn-main { font-weight: 700; }
.crm-channel-btn-sub {
  font-size: 11px;
  font-weight: 500;
  opacity: .82;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 連絡ツール一覧。1件 = 1行。左に頭文字、中央に内容、右にボタン。
   以前は縦に積んでいて、1件でカードの高さを使い切っていた。 */
.crm-ch-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--crm-line);
}
.crm-ch-item:last-child { border-bottom: 0; }
.crm-ch-item.is-off { opacity: .55; }
.crm-ch-mark {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  margin-top: 1px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}
.crm-ch-body { flex: 1 1 auto; min-width: 0; }
.crm-ch-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.crm-ch-name { font-size: 13.5px; font-weight: 700; }
.crm-ch-meta {
  font-size: 12px;
  color: var(--crm-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crm-ch-note {
  font-size: 11.5px;
  color: var(--crm-muted);
  margin-top: 4px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.crm-ch-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 2px;
}

/* KPI タイルはアイコンがある時だけ横並びにする。
   crm-kpi-main で包んでいない書き方のページ（ダッシュボード・ヘルス・同期）が
   ラベル・数値・注記を横一列に並べてしまうのを防ぐ。 */
.crm-kpi { display: block; }
.crm-kpi:has(.crm-kpi-ico) { display: flex; align-items: flex-start; gap: 14px; }

/* 数値ではなく操作を置くタイル（請求の対象月など）。中身が溢れないよう縦積み */
.crm-kpi--form { display: block; }
.crm-kpi--form .form-check-label { color: var(--crm-muted); }
.crm-kpi--form input[type="month"] { max-width: 100%; }

@media (max-width: 575.98px) {
  .crm-ch-item { flex-wrap: wrap; }
  .crm-ch-actions { width: 100%; padding-left: 46px; }
  .crm-ch-primary { justify-content: flex-start; }
  .crm-channel-btn-sub { max-width: 150px; }
}

/* ===========================================================================
   しずるん（AI チャットのキャラクター）
   =========================================================================== */

/* 引き出しを開くタブ。絵を載せるので縦積みにする */
.crm-drawer-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px 12px;
}
.crm-drawer-toggle-face {
  width: 44px;
  height: auto;
  display: block;
  /* ホバーでひょこっと動く。押せるものだと分かればよいので控えめに */
  transition: transform .18s ease;
}
.crm-drawer-toggle:hover .crm-drawer-toggle-face { transform: translateY(-3px); }
.crm-drawer-toggle-label { display: block; }

/* 引き出しの見出しに置く小さい絵 */
.crm-shizurun-badge {
  width: 24px;
  height: auto;
  vertical-align: -6px;
  margin-right: 2px;
}

/* 会話がまだ無いときのあいさつ */
.crm-chat-intro {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.crm-shizurun-hello { width: 62px; height: auto; flex: 0 0 62px; }

/* 回答の横に出る絵。
   発言の箱を「絵 + 本文」の横並びにするため、本文側を crm-chat-main で包んでいる。 */
.crm-chat--assistant {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.crm-chat-main { flex: 1 1 auto; min-width: 0; }
.crm-shizurun-face {
  width: 46px;
  height: auto;
  flex: 0 0 46px;
  margin-top: 14px; /* 名前の行ではなく、吹き出しの高さに合わせる */
}

/* 考えている間は、絵もゆっくり上下させる。
   文字だけが点滅しているより「動いている」ことが伝わる。 */
.crm-chat.is-waiting .crm-shizurun-face {
  animation: crm-shizurun-bob 1.6s ease-in-out infinite;
}
@keyframes crm-shizurun-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

/* 動きを減らす設定にしている人には動かさない */
@media (prefers-reduced-motion: reduce) {
  .crm-chat.is-waiting .crm-shizurun-face { animation: none; }
  .crm-drawer-toggle:hover .crm-drawer-toggle-face { transform: none; }
}

/* 引き出しの見出し。顧客名が長いと折り返して2行になるので、
   題は固定にして顧客名を下の行に小さく置く */
.crm-drawer-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crm-drawer-title-text { display: flex; flex-direction: column; min-width: 0; }
.crm-drawer-title .crm-shizurun-badge { width: 30px; margin: 0; vertical-align: 0; }
.crm-drawer-title-sub {
  font-size: 11.5px;
  color: var(--crm-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* フォーム内の小見出し（「この場は」など）。
   label 要素だと最初のラジオに紐づいてしまうので div で出している */
.crm-field-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--crm-muted);
  margin-bottom: 4px;
}

/* 顧客を名前で探して選ぶ（main.js が select を差し替えて作る） */
.crm-picker { position: relative; }

.crm-picker-menu {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin-top: 2px;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--crm-border, #dee2e6);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .10);
}

.crm-picker-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  background: none;
  border-bottom: 1px solid #f1f3f5;
}
.crm-picker-item:last-child { border-bottom: 0; }
.crm-picker-item:hover,
.crm-picker-item.is-active { background: #eef3ff; }

.crm-picker-name { display: block; font-size: 13px; }
.crm-picker-meta {
  display: block;
  font-size: 11px;
  color: var(--crm-muted, #6c757d);
}

.crm-picker-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--crm-muted, #6c757d);
}

/* ===========================================================================
   ヘルプ（/help/）
   =========================================================================== */
.crm-help-search { width: 320px; max-width: 100%; }

.crm-help-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; margin-bottom: 16px;
  background: var(--crm-card); border: 1px solid var(--crm-line-2);
  border-left: 4px solid var(--crm-tone-green);
  border-radius: var(--crm-radius); box-shadow: var(--crm-shadow);
  color: var(--crm-ink); text-decoration: none;
}
.crm-help-hero:hover { border-color: var(--crm-tone-green); color: var(--crm-ink); }
.crm-help-hero-title { display: block; font-weight: 700; font-size: 15px; }
.crm-help-hero-text  { display: block; color: var(--crm-ink-2); font-size: 12.5px; margin-top: 2px; }

.crm-help-item { padding: 12px 16px; }
.crm-help-item-title { font-weight: 600; color: var(--crm-ink); }
.crm-help-item-text  { font-size: 12px; color: var(--crm-muted); margin-top: 2px; }

.crm-help-aside { position: sticky; top: 20px; }
.crm-help-toc .list-group-item { border-left: 0; border-right: 0; }

/* 本文 */
.crm-help-body { padding: 26px 30px; line-height: 1.85; font-size: 14px; }
.crm-help-body > :last-child { margin-bottom: 0; }
.crm-help-lead {
  color: var(--crm-ink-2); font-size: 14.5px;
  padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--crm-line);
}
.crm-help-body h2 {
  font-size: 17px; font-weight: 700; margin: 30px 0 12px; padding-top: 4px;
  scroll-margin-top: 16px;
}
.crm-help-body h2:first-of-type { margin-top: 6px; }
.crm-help-body h3 { font-size: 14.5px; font-weight: 700; margin: 20px 0 8px; }
.crm-help-body table { font-size: 13px; }
.crm-help-body code {
  background: var(--crm-bg); color: var(--crm-ink); padding: 1px 5px; border-radius: 5px; font-size: 12.5px;
}

/* 番号付きの手順 */
.crm-help-steps { list-style: none; counter-reset: step; padding-left: 0; margin: 0 0 16px; }
.crm-help-steps > li {
  counter-increment: step; position: relative;
  padding: 2px 0 12px 40px; margin: 0;
}
.crm-help-steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 2px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--crm-accent-bg); color: var(--crm-accent);
  font-weight: 700; font-size: 13px; line-height: 26px; text-align: center;
}
.crm-help-steps > li::after {
  content: ""; position: absolute; left: 12.5px; top: 32px; bottom: 2px;
  border-left: 1px dashed var(--crm-line-2);
}
.crm-help-steps > li:last-child::after { display: none; }
.crm-help-steps ul { margin: 4px 0 0; padding-left: 18px; }

/* 画面の場所・ボタン名 */
.crm-help-path {
  display: inline-block; padding: 0 7px; border-radius: 6px;
  background: var(--crm-bg); border: 1px solid var(--crm-line-2);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.crm-help-path-sep { color: var(--crm-muted); margin: 0 5px; font-weight: 400; }
.crm-help-ui { font-weight: 700; color: var(--crm-ink); }
.crm-help-ui::before { content: "「"; font-weight: 400; color: var(--crm-muted); }
.crm-help-ui::after  { content: "」"; font-weight: 400; color: var(--crm-muted); }

/* 注意書き */
.crm-help-note {
  border-left: 4px solid var(--crm-tone-blue); background: var(--crm-tone-blue-bg);
  border-radius: var(--crm-radius-sm); padding: 10px 14px; margin: 0 0 16px; font-size: 13px;
}
.crm-help-note > :last-child { margin-bottom: 0; }
.crm-help-note-title { font-weight: 700; display: block; margin-bottom: 2px; }
.crm-help-note.is-warn   { border-left-color: var(--crm-tone-amber); background: var(--crm-tone-amber-bg); }
.crm-help-note.is-danger { border-left-color: #b42318; background: #fff4f3; }
.crm-help-note.is-ok     { border-left-color: var(--crm-tone-green); background: var(--crm-tone-green-bg); }

/* チェックリスト */
.crm-help-check { list-style: none; padding-left: 0; margin: 0 0 16px; }
.crm-help-check > li {
  position: relative; padding: 10px 12px 10px 40px; margin-bottom: 8px;
  border: 1px solid var(--crm-line-2); border-radius: var(--crm-radius-sm);
}
.crm-help-check > li::before {
  content: ""; position: absolute; left: 13px; top: 14px;
  width: 16px; height: 16px; border: 2px solid var(--crm-line-2); border-radius: 4px; background: #fff;
}
.crm-help-check-who { font-size: 11.5px; color: var(--crm-muted); font-weight: 600; }

/* 画面の中に置く「使い方」リンク */
.crm-help-link {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 500; color: var(--crm-muted); text-decoration: none;
}
.crm-help-link:hover { color: var(--crm-accent); }

@media (max-width: 767.98px) {
  .crm-help-body { padding: 20px 18px; }
  .crm-page-head { flex-wrap: wrap; }
  .crm-help-search { width: 100%; }
}
