/* =========================================================
   Chatbot — Rich UI
   base #fff / sub #f5f3f0 / accent #D62020
   ========================================================= */

:root {
  --cb-accent:        #D62020;
  --cb-accent-dark:   #B01818;
  --cb-accent-light:  #FDEAEA;
  --cb-accent-glow:   rgba(214, 32, 32, 0.22);
  --cb-text:          #1c1c1c;
  --cb-text-sub:      #888;
  --cb-border:        #ebebeb;
  --cb-bg:            #ffffff;
  --cb-bg-messages:   #f8f6f3;
  --cb-shadow-sm:     0 1px 3px rgba(0,0,0,0.07), 0 2px 8px rgba(0,0,0,0.04);
  --cb-shadow-win:
    0 2px 4px rgba(0,0,0,0.04),
    0 8px 24px rgba(0,0,0,0.10),
    0 20px 60px rgba(0,0,0,0.12);
  --cb-radius:        16px;
  --cb-radius-sm:     10px;
  --cb-radius-pill:   9999px;
  --cb-font: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", -apple-system, sans-serif;
}

/* =========================================================
   LAUNCHER
   ========================================================= */
.cb-launcher {
  position: fixed;
  right: 28px;
  bottom: 28px;
  height: 58px;
  padding: 0 22px 0 6px;
  gap: 10px;
  border-radius: var(--cb-radius-pill);
  background: var(--cb-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition:
    width 0.4s ease,
    padding 0.4s ease,
    border-radius 0.4s ease,
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    background 0.2s ease;
}

.cb-launcher-text {
  font-family: var(--cb-font);
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.cb-launcher.is-open {
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
}

.cb-launcher.is-open .cb-launcher-text {
  display: none;
}


.cb-launcher:hover {
  background: var(--cb-accent-dark);
  transform: translateY(-3px) scale(1.06);
}

.cb-launcher:active {
  transform: translateY(-1px) scale(0.97);
  transition-duration: 0.1s;
}

.cb-launcher svg { width: 26px; height: 26px; display: block; }
.cb-icon-chat, .cb-icon-close { display: flex; align-items: center; }

/* アイコン切り替え */
.cb-launcher.is-open .cb-icon-chat  { display: none; }
.cb-launcher:not(.is-open) .cb-icon-close { display: none; }


/* =========================================================
   WINDOW
   ========================================================= */
.cb-window {
  position: fixed;
  right: 28px;
  bottom: 100px;
  width: 390px;
  max-width: calc(100vw - 24px);
  height: 596px;
  max-height: calc(100dvh - 130px);
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow-win);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 3000;
  font-family: var(--cb-font);
  color: var(--cb-text);

  /* 初期状態（閉じた） */
  transform-origin: bottom right;
  transform: scale(0.82) translateY(20px);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  transition:
    transform 0.38s cubic-bezier(0.34, 1.45, 0.64, 1),
    opacity   0.22s ease;
}

.cb-window.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* =========================================================
   HEADER
   ========================================================= */
.cb-header {
  background: var(--cb-accent);
  /* 極細ノイズテクスチャ */
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 55%),
    linear-gradient(var(--cb-accent), var(--cb-accent));
  color: #fff;
  padding: 14px 16px 14px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
  position: relative;
}

/* 下境界ハイライト */
.cb-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0,0,0,0.08);
}

.cb-header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #fff;
  border: 1.5px solid rgba(255,255,255,0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  padding: 5px;
}

.cb-header__avatar svg {
  width: 22px;
  height: 22px;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
}

.cb-header__body { flex: 1; min-width: 0; }

.cb-header__title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.025em;
  line-height: 1.25;
  text-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.cb-header__sub {
  font-size: 11px;
  opacity: 0.80;
  margin-top: 2px;
  letter-spacing: 0.01em;
}

.cb-header__close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.14);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, transform 0.18s;
}

.cb-header__close:hover {
  background: rgba(255,255,255,0.28);
  transform: rotate(90deg);
}

.cb-header__close svg { width: 16px; height: 16px; }

/* =========================================================
   MESSAGES AREA
   ========================================================= */
.cb-messages-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 上下フェード */
.cb-messages-wrap::before,
.cb-messages-wrap::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 28px;
  z-index: 2;
  pointer-events: none;
}

.cb-messages-wrap::before {
  top: 0;
  background: linear-gradient(to bottom, var(--cb-bg-messages), transparent);
}

.cb-messages-wrap::after {
  bottom: 0;
  background: linear-gradient(to top, var(--cb-bg-messages), transparent);
}

.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 14px 24px;
  background: var(--cb-bg-messages);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.cb-messages::-webkit-scrollbar { width: 3px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
  border-radius: 2px;
}

/* =========================================================
   MESSAGES
   ========================================================= */
.cb-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  animation: cb-msg-in 0.36s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes cb-msg-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cb-msg--bot  { justify-content: flex-start; }
.cb-msg--user { justify-content: flex-end; }

/* アバター */
.cb-msg__avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
}

.cb-msg--bot .cb-msg__avatar {
  background: var(--cb-accent-light);
  border: 1px solid rgba(214,32,32,0.12);
  overflow: hidden;
  padding: 2px;
}

.cb-msg--bot .cb-msg__avatar svg {
  width: 25px;
  height: 25px;
  color: var(--cb-accent);
}

.cb-msg--user .cb-msg__avatar {
  background: #e8e6e4;
}

.cb-msg--user .cb-msg__avatar svg {
  width: 15px;
  height: 15px;
  color: #999;
}

/* 吹き出し */
.cb-msg__bubble {
  max-width: 76%;
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: 0.01em;
}

.cb-msg--bot .cb-msg__bubble {
  background: #fff;
  border-radius: var(--cb-radius-sm) var(--cb-radius-sm) var(--cb-radius-sm) 3px;
  box-shadow: var(--cb-shadow-sm);
  color: var(--cb-text);
}

.cb-msg--user .cb-msg__bubble {
  background: #D62020;
  color: #fff;
  border-radius: var(--cb-radius-sm) var(--cb-radius-sm) 3px var(--cb-radius-sm);
  box-shadow:
    0 2px 8px rgba(180, 20, 20, 0.32),
    0 1px 2px rgba(0,0,0,0.10);
  text-shadow: 0 1px 2px rgba(0,0,0,0.10);
}

.cb-link {
  color: var(--cb-accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cb-link:hover {
  color: var(--cb-accent-dark);
}

/* =========================================================
   TYPING INDICATOR
   ========================================================= */
.cb-typing {
  display: inline-flex;
  gap: 5px;
  padding: 4px 2px;
  align-items: center;
}

.cb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c8c4be;
  animation: cb-wave 1.6s ease-in-out infinite;
}

.cb-typing span:nth-child(1) { animation-delay: 0s; }
.cb-typing span:nth-child(2) { animation-delay: 0.18s; }
.cb-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes cb-wave {
  0%, 60%, 100% { transform: translateY(0);    background: #c8c4be; }
  30%           { transform: translateY(-7px); background: var(--cb-accent); }
}

/* =========================================================
   SUGGESTIONS
   ========================================================= */
.cb-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 2px 0 18px 36px;
  animation: cb-msg-in 0.36s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.cb-suggestions__label {
  width: 100%;
  font-size: 10.5px;
  color: var(--cb-text-sub);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 1px;
  letter-spacing: 0.03em;
}

.cb-suggestions__label svg { width: 11px; height: 11px; }

.cb-chip {
  background: var(--cb-bg);
  border: 1.5px solid rgba(214,32,32,0.35);
  color: var(--cb-accent);
  padding: 5px 13px;
  border-radius: var(--cb-radius-pill);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--cb-font);
  line-height: 1.4;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 3px rgba(214,32,32,0.10);
  transition:
    background  0.18s ease,
    color       0.18s ease,
    border-color 0.18s ease,
    transform   0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow  0.18s ease;
}

.cb-chip:hover {
  background: var(--cb-accent);
  color: #fff;
  border-color: var(--cb-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(214,32,32,0.30);
}

.cb-chip:active {
  transform: translateY(0);
  transition-duration: 0.08s;
}

/* =========================================================
   INPUT AREA
   ========================================================= */
.cb-input {
  border-top: 1px solid var(--cb-border);
  background: var(--cb-bg);
  padding: 11px 12px;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  flex-shrink: 0;
}

.cb-input__textarea {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 20px;
  padding: 9px 16px;
  font-family: var(--cb-font);
  font-size: 13.5px;
  line-height: 1.5;
  max-height: 100px;
  min-height: 38px;
  resize: none;
  outline: none;
  background: #f8f7f5;
  color: var(--cb-text);
  transition:
    border-color 0.2s ease,
    background   0.2s ease,
    box-shadow   0.2s ease;
}

.cb-input__textarea:focus {
  border-color: var(--cb-accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--cb-accent-glow);
}

.cb-input__textarea::placeholder { color: #bbb; }

.cb-input__textarea::-webkit-scrollbar { display: none; }
.cb-input__textarea { scrollbar-width: none; }

.cb-input__send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  background: var(--cb-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(214,32,32,0.35);
  transition:
    background 0.18s ease,
    transform  0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.18s ease;
}

.cb-input__send:hover:not(:disabled) {
  background: var(--cb-accent-dark);
  transform: scale(1.1);
  box-shadow: 0 4px 14px rgba(214,32,32,0.45);
}

.cb-input__send:active:not(:disabled) {
  transform: scale(0.92);
  transition-duration: 0.08s;
}

.cb-input__send:disabled {
  background: #d8d4ce;
  box-shadow: none;
  cursor: not-allowed;
}

.cb-input__send svg { width: 16px; height: 16px; }

/* =========================================================
   FOOTER
   ========================================================= */
.cb-footer {
  font-size: 10px;
  color: #b8b4ae;
  text-align: center;
  padding: 6px 10px;
  background: var(--cb-bg);
  border-top: 1px solid #f0eeec;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* =========================================================
   BACKDROP（モバイル キーボード隙間を塗りつぶす）
   ========================================================= */
.cb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2998;
  pointer-events: none;
}

.cb-backdrop.is-open {
  display: block;
}

/* =========================================================
   MOBILE
   ========================================================= */
@media (max-width: 480px) {
  /* モバイルでは背景を白で完全に塗りつぶす */
  .cb-backdrop {
    background: var(--cb-bg);
  }

  .cb-window {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    border-radius: 0;
    /* scale アニメーションを外してページが透けないようにする */
    transform: translateY(30px);
  }

  .cb-window.is-open {
    transform: translateY(0);
  }

  .cb-launcher {
    right: 85px;
    bottom: 18px;
    box-shadow: none;
    height: 52px;
    padding: 0 22px 0 5px;
  }

  .cb-launcher-text {
    font-size: 15px;
  }

  /* iOS Safari のズームイン防止（font-size が 16px 未満だとズームする） */
  .cb-input__textarea {
    font-size: 16px;
  }
}
