/* ============================================================
   モヒカン秘書 — チャットウィジェット
   デザインシステム "LOUD PAPER" 準拠（style.css のトークンを使用）
   ============================================================ */

/* ---------- ランチャー（右下常駐ボタン） ---------- */
.msec-launcher {
  position: fixed;
  right: clamp(1rem, 3vw, 1.5rem);
  bottom: clamp(1rem, 3vw, 1.5rem);
  z-index: 95; /* ヘッダー(100)・モバイルメニュー(120)より下 */
  display: flex;
  align-items: center;
  gap: 0.7rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.msec-launcher__avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--red);
  box-shadow: 0 8px 24px rgba(14, 13, 12, 0.35);
  background: #fff;
  overflow: hidden;
  transition: transform 0.3s var(--ease-out);
}
.msec-launcher:hover .msec-launcher__avatar,
.msec-launcher:focus-visible .msec-launcher__avatar { transform: translateY(-3px) scale(1.04); }
.msec-launcher__avatar img { width: 100%; height: 100%; display: block; }
.msec-launcher__bubble {
  background: var(--stage);
  color: var(--white);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.6em 1em;
  border-radius: 12px 12px 2px 12px;
  box-shadow: 0 6px 18px rgba(14, 13, 12, 0.25);
  white-space: nowrap;
  animation: msecBubbleIn 0.5s var(--ease-out) 1.2s backwards;
}
@keyframes msecBubbleIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msec-launcher.is-hidden { display: none; }

/* デスクトップでは視界に対してランチャーが小さく、存在に気づかれない。
   画面が広いほど大きくする（スマホは64pxのまま）。 */
@media (min-width: 861px) {
  .msec-launcher { gap: 0.9rem; }
  .msec-launcher__avatar {
    /* 画面が広いほど大きく。狭めのノートPCでも88px、ワイドでも112pxで頭打ち */
    width: clamp(88px, 6.5vw, 112px);
    height: clamp(88px, 6.5vw, 112px);
    border-width: 4px;
    box-shadow: 0 12px 32px rgba(14, 13, 12, 0.4);
  }
  .msec-launcher:hover .msec-launcher__avatar,
  .msec-launcher:focus-visible .msec-launcher__avatar {
    transform: translateY(-4px) scale(1.05);
  }
  .msec-launcher__bubble {
    font-size: 0.92rem;
    padding: 0.7em 1.15em;
    border-radius: 14px 14px 2px 14px;
  }
}

/* ---------- パネル ---------- */
.msec-panel {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.5rem);
  bottom: clamp(0.75rem, 2vw, 1.5rem);
  z-index: 96;
  width: min(400px, 92vw);
  height: min(640px, calc(100dvh - 2rem));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(14, 13, 12, 0.35);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}
.msec-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ---------- ヘッダー ---------- */
.msec-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--stage);
  color: var(--white);
}
.msec-head__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--red);
  background: #fff;
  flex: none;
  position: relative;
}
.msec-head__avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.msec-head__avatar img.is-active { opacity: 1; }
.msec-head__meta { min-width: 0; }
.msec-head__name {
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  line-height: 1.3;
}
.msec-head__role {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: rgba(249, 247, 242, 0.6);
}
.msec-head__actions { margin-left: auto; display: flex; gap: 0.25rem; }
.msec-iconbtn {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: rgba(249, 247, 242, 0.8);
  font-size: 1rem;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, color 0.2s ease;
}
.msec-iconbtn:hover, .msec-iconbtn:focus-visible { background: rgba(249, 247, 242, 0.12); color: var(--white); }

/* ---------- メッセージ領域 ---------- */
.msec-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  /* CSSで smooth にすると scrollTop 代入まで毎回アニメーションになり、
     追従の再指定が互いを打ち消してしまう。滑らかさは JS 側で
     scrollTo({behavior:"smooth"}) を明示して出す。 */
  scroll-behavior: auto;
  overscroll-behavior: contain;
}
.msec-row { display: flex; gap: 0.55rem; align-items: flex-end; }
.msec-row--bot { justify-content: flex-start; }
.msec-row--user { justify-content: flex-end; }
.msec-row__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  border: 1.5px solid var(--line);
  background: #fff;
}
.msec-row__avatar img { width: 100%; height: 100%; display: block; }
.msec-msg {
  max-width: 80%;
  padding: 0.7em 1em;
  font-size: 0.88rem;
  line-height: 1.8;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msec-msg--bot {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px 12px 12px 3px;
  color: var(--ink);
}
.msec-msg--user {
  background: var(--stage);
  color: var(--white);
  border-radius: 12px 12px 3px 12px;
}
.msec-msg--system {
  align-self: center;
  font-size: 0.75rem;
  color: var(--ink-soft);
  background: var(--paper-dim);
  border-radius: 999px;
  padding: 0.35em 1em;
  max-width: 92%;
  text-align: center;
}

/* タイピングインジケーター */
.msec-typing {
  display: inline-flex;
  gap: 5px;
  padding: 0.85em 1em;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px 12px 12px 3px;
}
.msec-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: msecTyping 1.2s infinite;
}
.msec-typing span:nth-child(2) { animation-delay: 0.15s; }
.msec-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes msecTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- 選択肢 ---------- */
.msec-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-left: calc(32px + 0.55rem);
}
.msec-choice {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--red);
  border-radius: 999px;
  padding: 0.5em 1.1em;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s var(--ease-out);
}
.msec-choice:hover, .msec-choice:focus-visible {
  background: var(--red);
  color: var(--white);
  transform: translateY(-1px);
}
.msec-choices.is-disabled .msec-choice {
  pointer-events: none;
  opacity: 0.45;
  border-color: var(--line);
}

/* テンプレート一覧は縦積み。文言が長く、横並びだと読みづらいため */
.msec-choices--template { flex-direction: column; align-items: flex-start; }
.msec-choices--template .msec-choice { width: 100%; text-align: left; border-radius: 14px; }

/* 補助導線（急ぎ・料金・添付）は主導線より弱く見せる */
.msec-choices--side { margin-top: -0.35rem; }
.msec-choices--side .msec-choice {
  font-size: 0.74rem;
  font-weight: 500;
  padding: 0.4em 0.9em;
  border-color: var(--line);
  color: var(--ink-60, #6b6560);
}
.msec-choices--side .msec-choice:hover,
.msec-choices--side .msec-choice:focus-visible {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
}

/* 「その他（自分で書く）」は選択肢ではなく逃げ道なので、控えめに */
.msec-choice--other {
  border-style: dashed;
  border-color: var(--line);
  color: var(--ink-60, #6b6560);
  font-weight: 500;
}

/* ---------- 連絡先ミニフォーム ---------- */
.msec-contact {
  margin-left: calc(32px + 0.55rem);
  background: #fff;
  border: 1.5px solid var(--red);
  border-radius: 16px;
  padding: 1rem 1.05rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.msec-contact__field { display: flex; flex-direction: column; gap: 0.3rem; }
.msec-contact__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-60, #6b6560);
}
.msec-contact__input {
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--paper, #f4f1ea);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.6em 0.75em;
  width: 100%;
}
.msec-contact__input:focus {
  outline: none;
  border-color: var(--red);
  background: #fff;
}
.msec-contact__error {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--red-text-light, #b52a22);
}
.msec-contact__submit {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--white);
  background: var(--red);
  border: 0;
  border-radius: 999px;
  padding: 0.75em 1.2em;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s var(--ease-out);
}
.msec-contact__submit:hover:not(:disabled) { transform: translateY(-1px); }
.msec-contact__submit:disabled { opacity: 0.55; cursor: default; }
.msec-contact.is-done { opacity: 0.55; pointer-events: none; }

/* ---------- 入力欄 ---------- */
.msec-input {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #fff;
  border-top: 1px solid var(--line);
}
.msec-input__field {
  flex: 1;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6em 0.9em;
  resize: none;
  max-height: 7.5em;
  min-height: 2.6em;
}
.msec-input__field:focus {
  outline: none;
  border-color: var(--red);
}
.msec-input__attach,
.msec-input__send {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  transition: background 0.2s ease, transform 0.2s var(--ease-out);
}
.msec-input__attach {
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.msec-input__attach:hover, .msec-input__attach:focus-visible { border-color: var(--red); color: var(--red-text-light); }
.msec-input__send {
  background: var(--red);
  color: var(--white);
}
.msec-input__send:hover, .msec-input__send:focus-visible { background: var(--red-deep); transform: translateY(-1px); }
.msec-input__send:disabled { background: var(--line); cursor: not-allowed; transform: none; }

/* ---------- フッター ---------- */
.msec-foot {
  flex: none;
  padding: 0.4rem 1rem 0.6rem;
  background: #fff;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-align: center;
}
.msec-foot a { text-decoration: underline; }

/* ---------- モバイル ---------- */
@media (max-width: 480px) {
  .msec-panel {
    width: 90vw; /* 仕様08: モバイルでは画面幅の90%以内 */
    height: min(78dvh, 640px);
    right: 5vw;
    bottom: 0.5rem;
  }
  .msec-launcher__bubble { display: none; }
  .msec-msg { max-width: 86%; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .msec-launcher__bubble { animation: none; }
  .msec-panel { transition: none; }
  .msec-typing span { animation: none; opacity: 0.6; }
}

/* 印刷時は非表示 */
@media print {
  .msec-launcher, .msec-panel { display: none !important; }
}

/* ---------- 進捗表示 ---------- */
.msec-progress {
  flex: none;
  margin: 0;
  padding: 0 1rem;
  max-height: 0;
  overflow: hidden;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  text-align: right;
  background: #fff;
  transition: max-height 0.25s ease, padding 0.25s ease;
}
.msec-progress.is-visible { max-height: 2em; padding: 0.35rem 1rem 0; }

/* ---------- 送信前確認 ---------- */
.msec-confirm {
  border: 1.5px solid var(--red);
  border-radius: 12px;
  background: #fff;
  padding: 0.9rem 1rem 1rem;
}
.msec-confirm__title {
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}
.msec-confirm__list { display: grid; gap: 0.55rem; margin-bottom: 1rem; }
.msec-confirm__row {
  display: grid;
  grid-template-columns: 7em 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
  line-height: 1.7;
}
.msec-confirm__row dt {
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  padding-top: 0.15em;
}
.msec-confirm__row dd { margin: 0; overflow-wrap: break-word; }
.msec-confirm__actions { display: grid; gap: 0.5rem; }
.msec-confirm__send,
.msec-confirm__edit {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 999px;
  padding: 0.7em 1.2em;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s var(--ease-out);
}
.msec-confirm__send {
  background: var(--red);
  color: var(--white);
  border: 0;
}
.msec-confirm__send:hover, .msec-confirm__send:focus-visible { background: var(--red-deep); transform: translateY(-1px); }
.msec-confirm__edit {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.msec-confirm__edit:hover, .msec-confirm__edit:focus-visible { border-color: var(--ink-soft); }
.msec-confirm.is-done { opacity: 0.55; }
.msec-confirm.is-done button { pointer-events: none; }

@media (max-width: 480px) {
  .msec-confirm__row { grid-template-columns: 1fr; gap: 0.1rem; }
}

/* ---------- 添付ファイル ---------- */
.msec-input__file { display: none; }
.msec-files {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0;
  background: #fff;
}
.msec-file {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  max-width: 100%;
  font-size: 0.72rem;
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35em 0.7em;
}
.msec-file::before {
  content: "📄";
  font-size: 0.85em;
}
.msec-file__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14em;
}
.msec-file__size { color: var(--ink-soft); flex: none; }
.msec-input__attach:disabled { opacity: 0.4; cursor: not-allowed; }
