@charset "UTF-8";

/* ==========================================================================
   AI Chat Box - 共通設定
   テーマカラーは管理画面から設定（--aicb-accent が上書きされます）
   ========================================================================== */
#aicb-faq {
  --aicb-accent: #d8281c;
  --aicb-accent-dark: color-mix(in srgb, var(--aicb-accent) 78%, #000);
  --aicb-accent-soft: color-mix(in srgb, var(--aicb-accent) 10%, #fff);
  --aicb-accent-line: color-mix(in srgb, var(--aicb-accent) 22%, #fff);
  --aicb-on-accent: #fff;
  --aicb-radius: 999px;
  --aicb-font: 13px;
  --aicb-offset-x: 18px;
  --aicb-offset-y: 18px;
  --aicb-mobile-top: 80px;

  position: fixed;
  bottom: max(var(--aicb-offset-y), env(safe-area-inset-bottom));
  z-index: 9999;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #2a2a2a;
}

#aicb-faq *,
#aicb-faq *::before,
#aicb-faq *::after {
  box-sizing: border-box;
}

/* PC / タブレット：管理画面で設定した横余白を使用 */
@media (min-width: 768px) {
  #aicb-faq.aicb-side-right {
    right: max(var(--aicb-offset-x), env(safe-area-inset-right));
    left: auto;
  }

  #aicb-faq.aicb-side-left {
    left: max(var(--aicb-offset-x), env(safe-area-inset-left));
    right: auto;
  }
}

/* テーマやリセットCSSのボタン／入力欄スタイルを打ち消す（詳細度を上げすぎない） */
#aicb-faq :where(button, input) {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  font: inherit;
  text-transform: none;
  text-shadow: none;
  box-shadow: none;
  min-height: 0;
  min-width: 0;
}

#aicb-faq :where(button) {
  cursor: pointer;
}

#aicb-faq-launch:focus-visible,
#aicb-faq button:focus-visible,
#aicb-faq input:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

/* ==========================================================================
   チャットを開くボタン（ガラス風）
   ========================================================================== */
#aicb-faq-launch {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--aicb-accent);
  background:
    linear-gradient(
      145deg,
      rgba(255, 255, 255, 0.88),
      rgba(255, 255, 255, 0.48) 55%,
      rgba(255, 255, 255, 0.72)
    ),
    rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--aicb-radius);
  box-shadow:
    inset 1px 1px 1px rgba(255, 255, 255, 0.95),
    inset 0 -2px 4px rgba(120, 120, 120, 0.12),
    0 6px 22px rgba(40, 40, 40, 0.22);
}

/* ==========================================================================
   チャットパネル本体（配置に影響しないよう absolute）
   ========================================================================== */
#aicb-faq-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px); /* PC：ボタンの上に表示 */
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100dvh - 104px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e8ded5;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 15px 45px rgba(34, 34, 34, 0.33);
}

#aicb-faq-panel[hidden] {
  display: none;
}

#aicb-faq.aicb-side-left #aicb-faq-panel {
  left: 0;
  right: auto;
}

#aicb-faq.aicb-side-left #aicb-faq-launch {
  margin-left: 0;
  margin-right: auto;
}

/* 閉じるボタン（右上） */
#aicb-faq-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.05);
  color: #666;
  font-size: 12px;
  line-height: 1;
  transition: background 0.2s;
}

#aicb-faq-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   会話ログとメッセージ
   ========================================================================== */
#aicb-faq-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 48px 16px 16px;
  background: #fdf9f5;
  font-size: var(--aicb-font);
  line-height: 1.7;
}

.aicb-faq-msg {
  max-width: 92%;
  margin-bottom: 12px;
  padding: 10px 13px;
  border: 1px solid #e8ded5;
  border-radius: 14px;
  background: #fff;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.aicb-faq-msg.is-user {
  margin-left: auto;
  background: var(--aicb-accent-soft);
  border-color: var(--aicb-accent-line);
}

.aicb-faq-msg a {
  color: var(--aicb-accent-dark);
  text-decoration: underline;
}

/* ==========================================================================
   定型質問ボタン
   ========================================================================== */
#aicb-faq-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 104px;
  overflow-y: auto;
  padding: 8px 12px;
  border-top: 1px solid #e8ded5;
  background: #fff;
}

#aicb-faq-quick:empty {
  display: none;
}

#aicb-faq-quick button {
  padding: 6px 12px;
  border: 1px solid var(--aicb-accent);
  border-radius: 16px;
  background: #fff;
  color: var(--aicb-accent-dark);
  font-size: calc(var(--aicb-font) - 1px);
  font-weight: 700;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  transition: background 0.2s;
}

#aicb-faq-quick button:hover {
  background: var(--aicb-accent-soft);
}

/* ==========================================================================
   自由入力フォーム
   ========================================================================== */
#aicb-faq-form {
  display: flex;
  gap: 7px;
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid #e8ded5;
  background: #fff;
}

#aicb-faq-input {
  flex: 1;
  min-width: 0;
  padding: 9px;
  border: 1px solid #c9c2bc;
  border-radius: 10px;
  background: #fff;
  color: #2a2a2a;
  font-size: 16px; /* iOSで入力時に勝手に拡大されるのを防ぐ */
  line-height: 1.4;
}

#aicb-faq-form button {
  flex-shrink: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--aicb-accent);
  color: var(--aicb-on-accent);
  font-size: 13px;
  font-weight: 700;
}

#aicb-faq-form button:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ==========================================================================
   スマホ：右端に縦長ボタン。開閉は右からスライド
   ========================================================================== */
@media (max-width: 767px) {
  #aicb-faq {
    top: calc(var(--aicb-mobile-top) + env(safe-area-inset-top));
    bottom: auto;
  }

  #aicb-faq.aicb-side-right { right: 0 !important; left: auto !important; }
  #aicb-faq.aicb-side-left { left: 0 !important; right: auto !important; }

  #aicb-faq-launch {
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 0.08em;
    gap: 7px;
    min-height: 146px;
    margin: 0 0 0 auto;
    padding: 14px 10px;
    border-radius: 16px 0 0 16px;
    /* 閉じたとき：パネルが引っ込んだ後に右端からスライドして戻る */
    transition:
      transform 450ms cubic-bezier(0.22, 1, 0.36, 1) 200ms,
      opacity 250ms ease 200ms,
      visibility 0s;
  }

  /* 開いている間は右へ隠す（display:none にしない） */
  #aicb-faq-launch[aria-expanded="true"] {
    transform: translateX(110%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      transform 450ms cubic-bezier(0.22, 1, 0.36, 1),
      opacity 250ms ease,
      visibility 0s linear 450ms;
  }

  #aicb-faq-panel {
    top: 0;
    bottom: auto;
    right: 0;
    width: min(380px, calc(100vw - 12px));
    height: min(
      530px,
      calc(100dvh - var(--aicb-mobile-top) - 80px - env(safe-area-inset-top) - env(safe-area-inset-bottom))
    );
    border-radius: 16px 0 0 16px;
  }

  /* 開くアニメーション */
  #aicb-faq-panel:not([hidden]) {
    transform-origin: top right;
    animation: aicb-faq-panel-in 550ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  @keyframes aicb-faq-panel-in {
    0% {
      opacity: 0;
      transform: translateX(110%) scaleX(0.85);
    }
    75% {
      opacity: 1;
      transform: translateX(-6px) scaleX(1.015);
    }
    100% {
      opacity: 1;
      transform: translateX(0) scaleX(1);
    }
  }

  /* 閉じるアニメーション */
  #aicb-faq-panel.is-closing:not([hidden]) {
    pointer-events: none;
    animation: aicb-faq-panel-out 420ms cubic-bezier(0.55, 0, 0.85, 0.4) both;
  }

  @keyframes aicb-faq-panel-out {
    0% {
      opacity: 1;
      transform: translateX(0) scaleX(1);
    }
    100% {
      opacity: 0;
      transform: translateX(110%) scaleX(0.85);
    }
  }

  #aicb-faq.aicb-side-left #aicb-faq-launch {
    margin: 0 auto 0 0;
    border-radius: 0 16px 16px 0;
  }
  #aicb-faq.aicb-side-left #aicb-faq-launch[aria-expanded="true"] {
    transform: translateX(-110%);
  }
  #aicb-faq.aicb-side-left #aicb-faq-panel {
    left: 0; right: auto;
    border-radius: 0 16px 16px 0;
  }
  #aicb-faq.aicb-side-left #aicb-faq-panel:not([hidden]) {
    transform-origin: top left;
    animation-name: aicb-faq-panel-in-left;
  }
  #aicb-faq.aicb-side-left #aicb-faq-panel.is-closing:not([hidden]) {
    animation-name: aicb-faq-panel-out-left;
  }
  @keyframes aicb-faq-panel-in-left {
    0% { opacity: 0; transform: translateX(-110%) scaleX(0.85); }
    75% { opacity: 1; transform: translateX(6px) scaleX(1.015); }
    100% { opacity: 1; transform: translateX(0) scaleX(1); }
  }
  @keyframes aicb-faq-panel-out-left {
    0% { opacity: 1; transform: translateX(0) scaleX(1); }
    100% { opacity: 0; transform: translateX(-110%) scaleX(0.85); }
  }
}

/* 動きを減らす設定の利用者向け */
@media (prefers-reduced-motion: reduce) {
  #aicb-faq-launch,
  #aicb-faq-panel {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

/* AI Chat Box launch icon */
#aicb-faq-launch .aicb-launch-icon {
  width: 1.25em;
  height: 1.25em;
  flex: 0 0 auto;
  display: block;
}

#aicb-faq-launch .aicb-launch-label {
  min-width: 0;
}

/* ==========================================================================
   ライセンス未契約・期限切れ時のブランド表示
   - チャット本体とは独立したfixed要素で、テーマ側のoverflowの影響を受けにくくする
   - 可能な限り前面に表示するためCSSで扱える最大級のz-indexを使用
   ========================================================================== */
.aicb-license-brand {
  position: fixed;
  z-index: 2147483647;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  max-width: min(240px, calc(100vw - 20px));
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 7px;
  background: rgba(18, 18, 18, 0.62);
  -webkit-backdrop-filter: blur(8px) saturate(145%);
  backdrop-filter: blur(8px) saturate(145%);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.30), inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", Arial, sans-serif;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.015em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75), 0 0 4px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

@media (min-width: 768px) {
  .aicb-license-brand.aicb-side-right {
    right: max(var(--aicb-offset-x, 18px), env(safe-area-inset-right));
    bottom: max(2px, env(safe-area-inset-bottom));
  }
  .aicb-license-brand.aicb-side-left {
    left: max(var(--aicb-offset-x, 18px), env(safe-area-inset-left));
    bottom: max(2px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 767px) {
  .aicb-license-brand {
    top: calc(var(--aicb-mobile-top, 80px) + env(safe-area-inset-top) + 152px);
    bottom: auto;
    transform: rotate(90deg);
    transform-origin: top right;
  }
  .aicb-license-brand.aicb-side-right {
    right: 0;
    left: auto;
  }
  .aicb-license-brand.aicb-side-left {
    left: 0;
    right: auto;
    transform: rotate(-90deg);
    transform-origin: top left;
  }
}
