/* =========================================
   チャット形式の無料相談（追従バナー・チャット画面）
   parts/chat.php と一緒に全ページで読み込む。style.css の変数（--pink など）を利用
========================================= */

/* ---------- スマホ：画面下の相談ボタン ---------- */
.sp-consult { display: none; }
@media (max-width: 768px) {
  .sp-consult {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
    transform: translateY(110%);
    transition: transform .25s ease;
  }
  .sp-consult.is-show { transform: translateY(0); }
  .sp-consult__btn {
    display: block;
    padding: 8px 12px 10px;
    border-radius: var(--radius-pill);
    background: var(--orange);
    box-shadow: 0 4px 0 var(--orange-dark);
    color: #fff;
    text-align: center;
    text-decoration: none;
    line-height: 1.35;
  }
  .sp-consult__sub { display: block; font-size: 11px; font-weight: 700; opacity: .95; }
  .sp-consult__main { display: block; font-size: 16px; font-weight: 700; }
  /* 「気になる」バーが出ているときはそちらを優先 */
  .has-favbar .sp-consult { display: none; }
}

/* ---------- スマホ：チャット形式の無料相談 ---------- */
.sp-consult__btn {
  width: 100%;
  border: 0;
  font-family: inherit;
  cursor: pointer;
}
.sp-chat[hidden] { display: none; }
.sp-chat {
  position: fixed;
  inset: 0;
  z-index: 1000;
}
.sp-chat__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  transition: opacity .25s;
}
.sp-chat__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: min(88vh, 88dvh);
  background: #fff7f9;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .12);
  transform: translateY(100%);
  transition: transform .25s ease;
}
.sp-chat.is-open .sp-chat__overlay { opacity: 1; }
.sp-chat.is-open .sp-chat__panel { transform: translateY(0); }
html.sp-chat-open, html.sp-chat-open body { overflow: hidden; }

.sp-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--pink);
  color: #fff;
  border-radius: 18px 18px 0 0;
}
.sp-chat__title { margin: 0; font-size: 15px; font-weight: 700; }
.sp-chat__close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.sp-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.sp-chat__msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}
.sp-chat__msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #f0e6e9;
  border-bottom-left-radius: 4px;
}
.sp-chat__msg--user {
  align-self: flex-end;
  background: var(--pink);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sp-chat__typing { display: flex; gap: 4px; padding: 14px; }
.sp-chat__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pink);
  opacity: .4;
  animation: sp-chat-dot 1s infinite;
}
.sp-chat__typing span:nth-child(2) { animation-delay: .15s; }
.sp-chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sp-chat-dot { 50% { opacity: 1; transform: translateY(-3px); } }

.sp-chat__summary {
  align-self: stretch;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 4px 0 0;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #f0e6e9;
  border-radius: 12px;
  font-size: 14px;
}
.sp-chat__summary dt { color: var(--pink-dark); font-weight: 700; }
.sp-chat__summary dd { margin: 0; word-break: break-all; }

.sp-chat__foot {
  flex: 0 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #f0e6e9;
}
.sp-chat__foot:empty { padding: 0; border: 0; }
.sp-chat__choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}
.sp-chat__choice {
  padding: 10px 14px;
  border: 1px solid var(--pink);
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--pink-dark);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.sp-chat__choice:active { background: var(--pink); color: #fff; }
.sp-chat__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.sp-chat__input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid #ddd;
  border-radius: 24px;
  font-size: 16px; /* iPhone で入力時に拡大されないように */
}
.sp-chat__send {
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 24px;
  background: var(--orange);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
}
.sp-chat__error {
  grid-column: 1 / -1;
  margin: 0;
  color: #d33;
  font-size: 13px;
}
.sp-chat__error:empty { display: none; }
.sp-chat__confirm { display: grid; gap: 10px; text-align: center; }
.sp-chat__note { margin: 0; font-size: 13px; }
.sp-chat__note a { color: var(--pink-dark); text-decoration: underline; }
.sp-chat__submit {
  padding: 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--orange);
  box-shadow: 0 4px 0 var(--orange-dark);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
}
.sp-chat__submit:disabled { opacity: .6; }
.sp-chat__redo {
  border: 0;
  background: none;
  color: var(--c-sub);
  font-family: inherit;
  font-size: 13px;
  text-decoration: underline;
}
@media (min-width: 769px) {
  .sp-chat { display: none !important; }
}

/* ---------- チャット：LINE 風の吹き出し（オペレーターのアイコン付き） ---------- */
.sp-chat__panel { background: #eef2f7; }
.sp-chat__head { gap: 10px; justify-content: flex-start; }
.sp-chat__head-avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #fff;
  object-fit: cover;
}
.sp-chat__head-text { flex: 1 1 auto; min-width: 0; }
.sp-chat__status { margin: 2px 0 0; font-size: 11px; opacity: .9; }
.sp-chat__status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #4cd964;
  vertical-align: 1px;
}
.sp-chat__log { gap: 12px; }
.sp-chat__row { display: flex; align-items: flex-start; gap: 8px; }
.sp-chat__row--user { justify-content: flex-end; }
.sp-chat__avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}
.sp-chat__stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  max-width: calc(100% - 48px);
}
.sp-chat__name { margin: 0 0 -2px; font-size: 11px; color: #555; }
.sp-chat__line {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 100%;
}
.sp-chat__row--user .sp-chat__line { flex-direction: row-reverse; max-width: 82%; }
.sp-chat__time { flex: 0 0 auto; font-size: 10px; color: #8a8f98; line-height: 1; }
.sp-chat__msg { max-width: none; position: relative; }
.sp-chat__msg--bot {
  align-self: auto;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
}
.sp-chat__msg--user {
  align-self: auto;
  border-radius: 18px;
  background: var(--pink);
}
/* 吹き出しのしっぽ（最初の1つだけ） */
.sp-chat__name + .sp-chat__line .sp-chat__msg--bot::before {
  content: "";
  position: absolute;
  top: 8px;
  left: -6px;
  border: 6px solid transparent;
  border-right-color: #fff;
  border-left: 0;
}
.sp-chat__row--user .sp-chat__msg--user::after {
  content: "";
  position: absolute;
  top: 8px;
  right: -6px;
  border: 6px solid transparent;
  border-left-color: var(--pink);
  border-right: 0;
}
.sp-chat__summary.sp-chat__msg { padding: 12px 14px; }

/* ---------- チャット：求人への相談 ---------- */
.sp-chat__jobcard {
  align-self: stretch;
  margin: 0 0 4px;
  padding: 10px 14px;
  border-left: 4px solid var(--pink);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}
.sp-chat__jobcard-company { margin: 0; color: var(--c-sub); font-weight: 700; }
.sp-chat__jobcard-title { margin: 2px 0 0; font-weight: 700; line-height: 1.5; }
.sp-chat__skip {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 8px 16px;
  border: 1px solid var(--pink);
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--pink-dark);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
}
.sp-chat__summary dd { white-space: pre-line; }

/* PC では右下に小さなチャット画面として表示（求人ページの相談ボタンから開く） */
@media (min-width: 769px) {
  .sp-chat { display: block !important; }
  .sp-chat[hidden] { display: none !important; }
  .sp-chat__panel {
    left: auto;
    right: 24px;
    bottom: 24px;
    width: 400px;
    height: min(640px, calc(100vh - 48px));
    border-radius: 18px;
    transform: translateY(24px);
    opacity: 0;
    transition: transform .25s ease, opacity .25s ease;
  }
  .sp-chat.is-open .sp-chat__panel { transform: none; opacity: 1; }
  .sp-chat__overlay { background: rgba(0, 0, 0, .25); }
}

/* ---------- 追従バナー：ピンク ---------- */
@media (max-width: 768px) {
  .sp-consult__btn {
    background: var(--pink);
    box-shadow: 0 4px 0 var(--pink-dark);
  }
  .sp-consult__btn:active { background: var(--pink-dark); }
}

/* ---------- チャット内の送信ボタン：ピンク ---------- */
.sp-chat__send { background: var(--pink); }
.sp-chat__submit {
  background: var(--pink);
  box-shadow: 0 4px 0 var(--pink-dark);
}


/* ---------- 追従バナー：オペレーターのアイコン付き ---------- */
@media (max-width: 768px) {
  .sp-consult__btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px 7px 8px;
    text-align: left;
  }
  .sp-consult__avatar {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #fff;
    object-fit: cover;
    background: #fff;
  }
  .sp-consult__text { flex: 1 1 auto; min-width: 0; text-align: center; }
  .sp-consult__main { font-size: min(15px, 3.9vw); white-space: nowrap; }
}
@media (max-width: 768px) {
  .sp-consult__btn { gap: 8px; padding: 7px 10px 7px 6px; }
  /* 20文字が1行に収まるよう、画面幅に合わせて文字サイズを調整 */
  .sp-consult__main { font-size: clamp(10px, calc((100vw - 104px) / 21.5), 15px); letter-spacing: 0; }
}

/* 追従バナーがあるページは、フッターの最下部がバナーに隠れないよう余白を取る（/service/ など） */
@media (max-width: 768px) {
  body:has(#sp-consult) .site-footer { padding-bottom: 84px; }
}

/* ---------- PC：右下に相談バナー（押すと右下にチャットが開く） ---------- */
@media (min-width: 769px) {
  .sp-consult {
    display: block;
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 60;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity .3s ease, transform .3s ease;
  }
  .sp-consult.is-show { opacity: 1; transform: none; }
  /* チャットを開いている間は隠す */
  html.sp-chat-open .sp-consult { opacity: 0; pointer-events: none; }
  /* 「気になる求人」バー（画面下中央）と重ならないよう上にずらす */
  .has-favbar .sp-consult { bottom: 88px; }
  .sp-consult__btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: auto;
    padding: 10px 26px 10px 10px;
    border-radius: var(--radius-pill);
    background: var(--pink);
    box-shadow: 0 10px 24px rgba(228, 92, 131, .35);
    color: #fff;
    text-align: left;
    line-height: 1.4;
    transition: transform .2s, background .2s, box-shadow .2s;
  }
  .sp-consult__btn:hover {
    background: var(--pink-dark);
    transform: translateY(-2px);
    box-shadow: 0 14px 28px rgba(228, 92, 131, .4);
  }
  .sp-consult__avatar {
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid #fff;
    object-fit: cover;
    background: #fff;
  }
  .sp-consult__text { display: block; }
  .sp-consult__sub { display: block; font-size: 12px; font-weight: 700; opacity: .92; }
  .sp-consult__main { display: block; font-size: 15px; font-weight: 700; white-space: nowrap; }
  /* ページ最下部（フッターのコピーライト）がバナーに隠れないように */
  body:has(#sp-consult) .footer-main { padding-bottom: 96px; }
}

/* 求人詳細のスマホは画面下の「この求人について相談する」ボタンがあるので、追従バナーは PC だけ出す */
@media (max-width: 768px) {
  .single-job .sp-consult { display: none; }
}
