/* =========================================================
   右下のチャット(lib/chat.php の hp_chat_widget / js/hp-chat.js)
   1rem = 10px(base.css の html 62.5% が前提)
   色: --hpc-c(ボタン・見出し・自分の吹き出し)は指定が無ければアクセント色
       --hpc-on はその上の文字色
   --hpc-b … 下からの位置(下部バーがあるときは hp-chat.js がバーの高さを入れる)
   PC  … 右下に「チャットで質問する」のボタン → 右下にチャット画面
   SP  … 右下に丸いアイコン → 画面の下からチャット画面
   ========================================================= */

.hpc {
  --hpc-c: var(--hp-accent, #c9a86c);
  --hpc-on: var(--hp-on-accent, #ffffff);
  --hpc-b: 0px;
  --hpc-gap: 2rem;
  display: none;
  font-family: var(--hp-font, inherit);
  line-height: 1.6;
  color: #1f2328;
}

.hp-js .hpc {
  display: block;
}

/* 年齢認証が出ている間は出さない */
.hp-lock .hpc {
  display: none;
}

.hpc *,
.hpc *::before,
.hpc *::after {
  box-sizing: border-box;
}

.hpc [hidden] {
  display: none !important;
}

/* ---------- ボタン(PC: 文字つき / SP: 丸いアイコン) ---------- */
.hpc-launch {
  position: fixed;
  right: calc(var(--hpc-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--hpc-gap) + var(--hpc-b) + env(safe-area-inset-bottom, 0px));
  z-index: 9000;
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  height: 5.2rem;
  padding: 0 2.2rem 0 1.8rem;
  border: 0;
  border-radius: 999px;
  background: var(--hpc-c);
  color: var(--hpc-on);
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 0.6rem 2rem rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hpc-launch:hover {
  transform: translateY(-0.2rem);
  box-shadow: 0 0.8rem 2.4rem rgba(0, 0, 0, 0.3);
}

.hpc-launch:focus-visible {
  outline: 0.3rem solid var(--hpc-c);
  outline-offset: 0.3rem;
}

.hpc-launch__icon {
  font-size: 2.2rem;
  line-height: 1;
}

.hpc-launch__badge {
  position: absolute;
  top: -0.6rem;
  right: -0.4rem;
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.6rem;
  border: 0.2rem solid #ffffff;
  border-radius: 999px;
  background: #e5243b;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.8rem;
  text-align: center;
}

.hpc.is-open .hpc-launch {
  display: none;
}

/* ---------- チャット画面 ---------- */
.hpc-panel {
  position: fixed;
  right: calc(var(--hpc-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--hpc-gap) + var(--hpc-b) + env(safe-area-inset-bottom, 0px));
  z-index: 9001;
  display: flex;
  flex-direction: column;
  width: 37rem;
  height: 56rem;
  max-height: calc(100vh - 4rem - var(--hpc-b));
  max-height: calc(100dvh - 4rem - var(--hpc-b));
  overflow: hidden;
  border-radius: 1.6rem;
  background: #ffffff;
  box-shadow: 0 1.2rem 4rem rgba(0, 0, 0, 0.3);
  animation: hpc-in 0.22s ease;
}

@keyframes hpc-in {
  from {
    opacity: 0;
    transform: translateY(1.6rem);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.hpc-cover {
  display: none;
}

.hpc-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.2rem 1.2rem 1.6rem;
  background: var(--hpc-c);
  color: var(--hpc-on);
}

.hpc-head__icon {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-size: 1.8rem;
}

.hpc-head__txt {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.hpc-head__title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.4;
}

.hpc-head__sub {
  overflow: hidden;
  font-size: 1.2rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0.85;
}

.hpc-head__x {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 3.6rem;
  height: 3.6rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.8rem;
  cursor: pointer;
}

.hpc-head__x:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- やりとり ---------- */
.hpc-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  padding: 1.6rem 1.4rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #f4f5f7;
  -webkit-overflow-scrolling: touch;
}

.hpc-day {
  align-self: center;
  padding: 0.2rem 1rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  color: #555b66;
  font-size: 1.1rem;
}

.hpc-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 82%;
}

.hpc-msg.is-me {
  align-self: flex-end;
  align-items: flex-end;
}

.hpc-bubble {
  margin: 0;
  padding: 0.9rem 1.3rem;
  border-radius: 1.4rem 1.4rem 1.4rem 0.4rem;
  background: #ffffff;
  color: #1f2328;
  font-size: 1.4rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.06);
}

.hpc-msg.is-me .hpc-bubble {
  border-radius: 1.4rem 1.4rem 0.4rem 1.4rem;
  background: var(--hpc-c);
  color: var(--hpc-on);
}

.hpc-msg.is-greet .hpc-bubble {
  white-space: normal;
}

.hpc-msg__meta {
  margin-top: 0.3rem;
  color: #8a8f98;
  font-size: 1.1rem;
}

.hpc-msg.is-sending {
  opacity: 0.6;
}

/* ---------- お名前・メール(はじめの1通まで) ---------- */
.hpc-who {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem 1.4rem 0;
  border-top: 0.1rem solid #e6e8ec;
  background: #ffffff;
}

.hpc-who__lead {
  margin: 0;
  color: #6b7280;
  font-size: 1.15rem;
  line-height: 1.5;
}

.hpc-input {
  width: 100%;
  height: 3.8rem;
  padding: 0 1.2rem;
  border: 0.1rem solid #d7dbe1;
  border-radius: 0.8rem;
  background: #ffffff;
  color: #1f2328;
  font: inherit;
  font-size: 1.6rem;
}

.hpc-input:focus {
  border-color: var(--hpc-c);
  outline: none;
}

.hpc-input.is-error {
  border-color: #e5243b;
}

.hpc-err {
  flex-shrink: 0;
  margin: 0;
  padding: 0.8rem 1.4rem 0;
  background: #ffffff;
  color: #e5243b;
  font-size: 1.25rem;
}

/* ---------- 入力欄 ---------- */
.hpc-form {
  display: flex;
  flex-shrink: 0;
  align-items: flex-end;
  gap: 0.8rem;
  padding: 1rem 1.2rem;
  background: #ffffff;
}

.hpc-who[hidden] ~ .hpc-form {
  border-top: 0.1rem solid #e6e8ec;
}

.hpc-trap {
  position: absolute;
  left: -9999px;
  width: 0.1rem;
  height: 0.1rem;
  opacity: 0;
}

.hpc-text {
  flex: 1;
  min-height: 4.2rem;
  max-height: 14rem;
  padding: 0.9rem 1.2rem;
  border: 0.1rem solid #d7dbe1;
  border-radius: 1.2rem;
  background: #f8f9fa;
  color: #1f2328;
  font: inherit;
  font-size: 1.6rem;
  line-height: 1.5;
  resize: none;
}

.hpc-text:focus {
  border-color: var(--hpc-c);
  background: #ffffff;
  outline: none;
}

.hpc-send {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 4.2rem;
  height: 4.2rem;
  border: 0;
  border-radius: 50%;
  background: var(--hpc-c);
  color: var(--hpc-on);
  font-size: 1.7rem;
  cursor: pointer;
}

.hpc-send:disabled {
  opacity: 0.45;
  cursor: default;
}

.hpc-foot {
  flex-shrink: 0;
  margin: 0;
  padding: 0 1.4rem 1rem;
  background: #ffffff;
  color: #8a8f98;
  font-size: 1.1rem;
  text-align: center;
}

.hpc.is-blocked .hpc-form,
.hpc.is-blocked .hpc-who {
  display: none;
}

/* ---------- スマホ ---------- */
@media (max-width: 899px) {
  .hpc {
    --hpc-gap: 1.4rem;
  }

  .hpc-launch {
    justify-content: center;
    width: 5.6rem;
    height: 5.6rem;
    padding: 0;
  }

  .hpc-launch__label {
    position: absolute;
    width: 0.1rem;
    height: 0.1rem;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .hpc-launch__icon {
    font-size: 2.4rem;
  }

  .hpc-cover {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: block;
    background: rgba(0, 0, 0, 0.4);
  }

  .hpc-cover[hidden] {
    display: none;
  }

  .hpc-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: 82vh;
    height: 82dvh;
    max-height: none;
    border-radius: 1.6rem 1.6rem 0 0;
    animation-name: hpc-up;
  }

  .hpc-form {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .hpc-foot {
    display: none;
  }

  @keyframes hpc-up {
    from {
      transform: translateY(100%);
    }

    to {
      transform: none;
    }
  }
}

/* スマホで開いている間は、うしろのページを動かさない */
html.hpc-lock,
html.hpc-lock body {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .hpc-panel,
  .hpc-launch {
    animation: none;
    transition: none;
  }
}
