/**
 * 御菓子処 蝶谷（ちょうや） 公式Webサイト
 * 常設お菓子選び相談チャットウィジェット スタイル
 */

:root {
  --choya-plum: #6B5382;
  --choya-plum-dark: #4F3C63;
  --choya-lilac: #ede4ee;
  --choya-cream: #fbf8f4;
  --choya-line: #e9e1e4;
  --choya-ink: #332d34;
  --choya-muted: #756c73;
  --choya-white: #ffffff;
  --choya-serif: 'Zen Old Mincho', "Yu Mincho", "Hiragino Mincho ProN", serif;
  --choya-sans: 'Noto Sans JP', "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

/* 1. フローティング起動ボタン（各ページ右下常設） */
.choya-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 20px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 26px;
  background: linear-gradient(135deg, #6B5382 0%, #4F3C63 100%);
  color: #ffffff;
  font-family: var(--choya-sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(79, 60, 99, 0.35), 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.22s, background 0.22s, opacity 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.choya-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(79, 60, 99, 0.45), 0 4px 8px rgba(0, 0, 0, 0.12);
  background: linear-gradient(135deg, #785e92 0%, #594470 100%);
}

.choya-chat-toggle:focus-visible {
  outline: 3px solid #b988b1;
  outline-offset: 3px;
}

.choya-chat-toggle.active {
  box-shadow: 0 4px 14px rgba(79, 60, 99, 0.3);
}

.choya-chat-toggle-badge {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--choya-plum);
  font-family: var(--choya-serif);
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12);
  flex: none;
}

.choya-chat-toggle-text {
  white-space: nowrap;
}

/* 2. チャットウィジェット本体（PC：小窓） */
.choya-chat-widget {
  position: fixed;
  bottom: 86px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 105px);
  z-index: 9999;
  background: var(--choya-white);
  border: 1px solid #e7dee3;
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(51, 45, 52, 0.28), 0 4px 12px rgba(51, 45, 52, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.24s cubic-bezier(0.16, 1, 0.3, 1), transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.24s;
  pointer-events: none;
}

.choya-chat-widget.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.choya-chat-widget-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ヘッダー */
.choya-widget-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--choya-line);
  background: #ffffff;
  flex: none;
}

.choya-widget-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.choya-widget-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  color: #fff;
  background: var(--choya-plum);
  font-family: var(--choya-serif);
  font-size: 20px;
}

.choya-widget-header-title {
  min-width: 0;
}

.choya-widget-header-title strong {
  display: block;
  font-size: 13.5px;
  color: var(--choya-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.choya-widget-header-title small {
  display: block;
  margin-top: 1px;
  color: var(--choya-muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.choya-widget-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.choya-widget-shop-link {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--choya-plum);
  text-decoration: none;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--choya-lilac);
  white-space: nowrap;
  transition: background 0.15s;
}

.choya-widget-shop-link:hover {
  background: #e2d5e4;
}

.choya-widget-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--choya-line);
  border-radius: 50%;
  background: #fbf9fb;
  color: var(--choya-muted);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.choya-widget-close-btn .close-text {
  display: none;
}

.choya-widget-close-btn:hover {
  background: #eee6ed;
  color: var(--choya-ink);
}

.choya-widget-close-btn:focus-visible {
  outline: 3px solid #b988b1;
  outline-offset: 2px;
}

/* メッセージエリア */
.choya-widget-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 14px;
  background: linear-gradient(#fdfbf9, #fbf8f6);
  scroll-behavior: smooth;
  font-family: var(--choya-sans);
}

.choya-chat-widget .message {
  max-width: 90%;
  margin: 0 0 15px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.choya-chat-widget .message.user {
  margin-left: auto;
  justify-content: flex-end;
}

.choya-chat-widget .mark {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 8px;
  background: var(--choya-lilac);
  color: var(--choya-plum);
  display: grid;
  place-items: center;
  font-family: var(--choya-serif);
  font-size: 14px;
}

.choya-chat-widget .bubble {
  padding: 11px 13px;
  border: 1px solid var(--choya-line);
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  line-height: 1.7;
  font-size: 12.5px;
  overflow-wrap: anywhere;
  color: var(--choya-ink);
}

.choya-chat-widget .message.user .bubble {
  border: 0;
  color: #fff;
  background: var(--choya-plum);
  border-radius: 14px 14px 4px 14px;
}

.choya-chat-widget .bubble p {
  margin: 0;
  white-space: pre-line;
}

.choya-chat-widget .bubble p + p {
  margin-top: 8px;
}

.choya-chat-widget .links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.choya-chat-widget .links a {
  border: 1px solid #d8c6d5;
  border-radius: 8px;
  padding: 6px 9px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  background: #fff;
  color: var(--choya-plum);
  transition: background 0.15s;
}

.choya-chat-widget .links a:hover {
  background: #fdf6fb;
}

.choya-chat-widget .results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.choya-chat-widget .product {
  border: 1px solid var(--choya-line);
  border-radius: 10px;
  padding: 9px 10px;
  background: #fcfafb;
}

.choya-chat-widget .product strong {
  display: block;
  font-size: 11.5px;
  color: var(--choya-ink);
}

.choya-chat-widget .product .price {
  color: var(--choya-plum);
  margin: 3px 0;
  font-weight: 700;
  font-size: 11.5px;
}

.choya-chat-widget .product .desc {
  color: var(--choya-muted);
  font-size: 10.5px;
  line-height: 1.55;
}

.choya-chat-widget .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 6px 0 0 32px;
}

.choya-chat-widget .chip {
  border: 1px solid #d8c7d5;
  background: #fff;
  color: var(--choya-plum);
  border-radius: 20px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.choya-chat-widget .chip:hover {
  background: #f5ecf4;
  transform: translateY(-1px);
}

/* 入力エリア */
.choya-widget-composer {
  border-top: 1px solid var(--choya-line);
  background: #fff;
  padding: 12px 14px 10px;
  flex: none;
}

.choya-widget-composer form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.choya-widget-composer input {
  min-width: 0;
  flex: 1;
  border: 1px solid #ddd3d9;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--choya-ink);
  font-family: var(--choya-sans);
  font-size: 12.5px;
}

.choya-widget-composer input:focus-visible {
  outline: 2px solid var(--choya-plum);
}

.choya-widget-composer input::placeholder {
  color: #a1969c;
}

.choya-widget-composer .send {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--choya-plum);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
  flex: none;
}

.choya-widget-composer .send:hover {
  background: var(--choya-plum-dark);
}

.choya-widget-composer .footnote {
  margin: 7px 1px 0;
  color: #8b8186;
  font-size: 9.5px;
  line-height: 1.45;
}

/* 3. スマートフォン表示（768px以下：操作しやすい全画面表示） */
@media (max-width: 768px) {
  .choya-chat-toggle {
    bottom: 18px;
    right: 18px;
    height: 48px;
    padding: 0 16px 0 10px;
    font-size: 13px;
  }

  .choya-chat-toggle-badge {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  /* 全画面オーバーレイ */
  .choya-chat-widget {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    z-index: 10000;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  .choya-chat-widget.active {
    transform: translateY(0);
  }

  .choya-widget-header {
    padding: 12px 14px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .choya-widget-avatar {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .choya-widget-header-title strong {
    font-size: 13px;
  }

  .choya-widget-header-title small {
    font-size: 10px;
  }

  /* スマホの閉じるボタンは指でタップしやすく「✕ 閉じる」と明記 */
  .choya-widget-close-btn {
    width: auto;
    height: 34px;
    padding: 0 12px;
    border-radius: 17px;
    background: var(--choya-lilac);
    color: var(--choya-plum);
    font-weight: 700;
    font-size: 12px;
  }

  .choya-widget-close-btn .close-text {
    display: inline;
  }

  .choya-widget-messages {
    padding: 16px 14px;
  }

  .choya-chat-widget .message {
    max-width: 95%;
  }

  .choya-chat-widget .chips {
    margin-left: 0;
  }

  .choya-widget-composer {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .choya-widget-composer input {
    font-size: 14px; /* iOS自動ズーム防止 (16px以下だがモダンSafariで制御) */
    padding: 11px 12px;
  }
}

/* スマホ全画面表示中の背面スクロール固定 */
body.choya-chat-open {
  overflow: hidden !important;
  touch-action: none;
}

@media (prefers-reduced-motion: reduce) {
  .choya-chat-toggle,
  .choya-chat-widget,
  .choya-chat-widget .chip {
    transition: none !important;
  }
}
