/* AI 채팅 — 플로팅 버튼 (#scroll-top: bottom 23px + height 50px) */
:root {
  --aichat-scroll-top-bottom: 23px;
  --aichat-scroll-top-size: 50px;
  --aichat-fab-gap: 16px;
  --aichat-fab-icon-size: 56px;
  --aichat-fab-label-size: 22px;
  --aichat-fab-bottom: calc(var(--aichat-scroll-top-bottom) + var(--aichat-scroll-top-size) + var(--aichat-fab-gap) + var(--aichat-fab-label-size) - 10px);
}

@keyframes aichat-fab-nudge {
  0%,
  88%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  92% {
    transform: translate3d(0, -5px, 0);
  }

  96% {
    transform: translate3d(0, 0, 0);
  }

  98% {
    transform: translate3d(0, -2px, 0);
  }
}

.aichat-fab {
  position: fixed;
  right: 14px;
  bottom: var(--aichat-fab-bottom);
  z-index: 10040;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  animation: aichat-fab-nudge 5s ease-in-out infinite;
}

.aichat-fab__icon-wrap {
  position: relative;
  width: var(--aichat-fab-icon-size);
  height: var(--aichat-fab-icon-size);
  flex-shrink: 0;
}

.aichat-fab__pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(20, 160, 119, 0.25);
  animation: aichat-fab-pulse 5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes aichat-fab-pulse {
  0%,
  88%,
  100% {
    transform: scale(1);
    opacity: 0;
  }

  90% {
    transform: scale(1.15);
    opacity: 0.45;
  }

  94% {
    transform: scale(1.35);
    opacity: 0;
  }
}

.aichat-fab__icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--aichat-fab-icon-size);
  height: var(--aichat-fab-icon-size);
  border-radius: 50%;
  background: rgba(240, 240, 240, 0.5);
  color: var(--bh-primary);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  box-sizing: border-box;
}

.aichat-fab__label {
  position: relative;
  z-index: 1;
  order: 2;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--bh-primary);
  color: var(--bh-white);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.aichat-fab__icon-wrap {
  order: 1;
}

.aichat-fab:hover .aichat-fab__icon {
  transform: scale(1.04);
}

/* 레이어 팝업 */
.aichat-layer {
  position: fixed;
  inset: 0;
  z-index: 10100;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 20px calc(var(--aichat-fab-bottom) + 96px) 20px;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.aichat-layer.is-open {
  pointer-events: auto;
  visibility: visible;
  opacity: 1;
}

.aichat-layer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.aichat-layer__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--bh-white);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.aichat-layer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bh-light);
  background: var(--bh-white);
}

.aichat-layer__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--bh-dark);
}

.aichat-layer__actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.aichat-layer__fullscreen,
.aichat-layer__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--bh-light);
  color: var(--bh-dark);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.aichat-layer__fullscreen:hover,
.aichat-layer__close:hover {
  background: #e8e8e8;
  color: var(--bh-dark);
}

body.aichat-layer-open {
  overflow: hidden;
}

/* 채팅 패널 (레이어·전체 페이지 공통) */
.aichat-panel .content {
  background: var(--bh-white);
}

.aichat-panel__right {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 420px;
}

.aichat-panel__top {
  flex-shrink: 0;
  width: 100%;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--bh-light);
}

.aichat-panel .chat[data-chat="ai-counsel"] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 16px;
  border-top: 0;
  height: auto;
}

.aichat-panel .chat[data-chat="ai-counsel"]::-webkit-scrollbar {
  width: 6px;
}

.aichat-panel .chat[data-chat="ai-counsel"]::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.aichat-panel .conversation-start {
  width: 100%;
  margin-bottom: 10px;
  text-align: center;
}

.aichat-panel .conversation-start span {
  font-size: 12px;
  color: var(--bh-secondary);
}

.aichat-panel .bubble {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  position: relative;
  display: inline-block;
  clear: both;
  margin-bottom: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  max-width: 90%;
  width: fit-content;
  overflow-wrap: break-word;
  word-break: break-word;
}

.aichat-panel .bubble.me {
  float: right;
  color: inherit;
  background: var(--bh-light);
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 0;
}

.aichat-panel .bubble.you {
  float: left;
  color: var(--bh-white);
  background-color: var(--bh-primary);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 18px;
}

.aichat-root.flat-dashboard-messages .aichat-panel__right .write,
.aichat-panel .write {
  position: relative;
  flex-shrink: 0;
  left: auto;
  bottom: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--bh-light);
  background: var(--bh-white);
  box-sizing: border-box;
}

.aichat-root.flat-dashboard-messages .aichat-panel__right .write .write-box,
.aichat-panel .write-box {
  position: relative;
  flex: 1;
  min-width: 0;
  width: auto;
  margin-right: 0;
  float: none;
}

.aichat-panel .aichat-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 4px;
  background: var(--bh-light);
  font-size: 14px;
  color: var(--bh-black);
  outline: none;
  box-sizing: border-box;
}

.aichat-panel .aichat-input::placeholder {
  color: var(--bh-secondary);
}

.aichat-panel .aichat-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 4px;
  background-color: var(--bh-primary);
  color: var(--bh-white);
  text-decoration: none;
  font-size: 16px;
}

.aichat-panel .aichat-send::before {
  content: none;
  display: none;
}

.aichat-panel .aichat-send:hover {
  opacity: 0.92;
  color: var(--bh-white);
}

.aichat-panel .bubble.you .aichat-login-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  color: var(--bh-white);
  background: var(--bh-dark);
  border-radius: 4px;
}

.aichat-panel .bubble.you .aichat-login-btn:hover {
  color: var(--bh-white);
  opacity: 0.9;
}

.aichat-layer .aichat-panel__top {
  display: none;
}

.aichat-layer__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.aichat-layer .aichat-root,
.aichat-layer .wrapper-messages.aichat-panel,
.aichat-layer .content.flex {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.aichat-layer .aichat-panel__right {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "chat"
    "write";
  flex: 1;
  min-height: 0;
  height: 100%;
}

.aichat-layer .chat[data-chat="ai-counsel"] {
  grid-area: chat;
  flex: none;
  min-height: 0;
  height: auto;
  overflow-y: auto;
}

.aichat-layer .flat-dashboard-messages .right .write,
.aichat-layer .aichat-panel .write {
  grid-area: write;
  position: relative !important;
  bottom: auto !important;
  left: auto !important;
  width: 100% !important;
  margin-top: 0;
  flex-shrink: 0;
}

@media (max-width: 575px) {
  :root {
    --aichat-fab-icon-size: 52px;
    --aichat-fab-gap: 14px;
  }

  .aichat-fab {
    right: 14px;
    bottom: var(--aichat-fab-bottom);
  }

  .aichat-fab__icon {
    font-size: 24px;
  }

  .aichat-layer {
    padding: 20px;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    align-items: stretch;
    justify-content: center;
    box-sizing: border-box;
  }

  .aichat-layer__backdrop {
    background: rgba(0, 0, 0, 0.55);
  }

  .aichat-layer__dialog {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: 100%;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .aichat-layer .aichat-panel__right {
    height: 100%;
    min-height: 0;
    flex: 1;
  }
}
