/* ═══════════════════════════════════════════════════════
   새기준병원 상담봇 위젯 v2.0
   NSH-BOT-WIDGET-001 — chatbot-widget.css
   
   설계 원칙:
   - 새기준병원 브랜드 블루 계열
   - 카페24 기존 CSS와 충돌 방지: 모든 클래스 nsh- 접두사
   - 모바일 우선 반응형 (320px ~ 데스크탑)
   - 접근성: 고대비, 포커스 스타일, aria 지원
═══════════════════════════════════════════════════════ */

/* ─── CSS 변수 ──────────────────────────────────────── */
:root {
  --nsh-primary:      #0F4C68;
  --nsh-primary-d:    #0A344B;
  --nsh-primary-l:    #2FA9BD;
  --nsh-accent:       #52D1BF;
  --nsh-danger:       #B94238;
  --nsh-danger-bg:    #FFF3F1;
  --nsh-green:        #1F8B80;
  --nsh-bg:           #F4FBFA;
  --nsh-bubble-bot:   #FFFFFF;
  --nsh-bubble-user:  #0F4C68;
  --nsh-text:         #1a2332;
  --nsh-text-light:   #5a6a7e;
  --nsh-border:       #CFE9E7;
  --nsh-shadow:       0 14px 42px rgba(15,76,104,0.18);
  --nsh-shadow-sm:    0 5px 18px rgba(15,76,104,0.10);
  --nsh-radius:       24px;
  --nsh-radius-sm:    18px;
  --nsh-radius-xs:    12px;
  --nsh-font:         "Pretendard", "SUIT", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --nsh-z:            2147483000;
  --nsh-panel-w:      360px;
  --nsh-panel-h:      580px;
}

/* TEO-CHATBOT-UI-1: v2.5.4 mobile/overlay spacing fix */
/* TEO-CHATBOT-UI-2: v2.5.5 narrow viewport spacing fix */
/* TEO-CHATBOT-UI-3: official guidebot brand skin */
/* TEO-CHATBOT-UI-4: warmer outpatient guidebot typography */
/* TEO-CHATBOT-UI-3: FAB position adjustment for mobile bottom nav and desktop discoverability */
/* TEO-CHATBOT-UI-4: FAB relocation for desktop discoverability and mobile bottom-nav clearance */
/* TEO-CHATBOT-UI-5: desktop FAB above call button, keep mobile position */

/* ─── 리셋 (nsh- 스코프 내) ─────────────────────────── */
#nsh-chatbot-root *,
#nsh-chatbot-root *::before,
#nsh-chatbot-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--nsh-font);
  line-height: 1.5;
}

/* ─── 루트 ──────────────────────────────────────────── */
#nsh-chatbot-root {
  position: fixed;
  bottom: 120px;
  right: 40px;
  z-index: var(--nsh-z);
  font-size: 14px;
}
#nsh-chatbot-root,
.nsh-panel,
.nsh-bubble,
.nsh-input,
.nsh-cta-btn,
.nsh-footer-note {
  font-family: var(--nsh-font);
  letter-spacing: 0;
}

/* ═══════════════════════════════════════════════════════
   FAB (플로팅 액션 버튼)
═══════════════════════════════════════════════════════ */
.nsh-fab {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 24%, #FFFFFF 0 34%, #E9FFF9 35% 100%);
  border: 1px solid rgba(82,209,191,0.58);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(15,76,104,0.18), inset 0 0 0 5px rgba(255,255,255,0.86);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
  outline: none;
  color: var(--nsh-primary);
  overflow: visible;
}
.nsh-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 14px 34px rgba(15,76,104,0.24), inset 0 0 0 5px rgba(255,255,255,0.92);
}
.nsh-fab:focus-visible {
  outline: 3px solid rgba(82,209,191,0.75);
  outline-offset: 3px;
}
.nsh-fab--open .nsh-fab-icon svg {
  transform: rotate(90deg) scale(0.85);
  opacity: 0;
}
.nsh-fab--open .nsh-fab-icon {
  background-image: none;
}
.nsh-fab-icon {
  width: 54px;
  height: 54px;
  background: url("./nsh-guidebot-icon.svg") center / contain no-repeat;
  transition: opacity 0.2s, transform 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nsh-fab-icon svg {
  display: none;
  transition: transform 0.25s, opacity 0.2s;
}
/* 닫힘 아이콘 - ✕ pseudo */
.nsh-fab--open .nsh-fab-icon::after {
  content: "✕";
  position: absolute;
  font-size: 22px;
  font-weight: 700;
  opacity: 1;
  color: var(--nsh-primary-d);
}
.nsh-fab-icon::after {
  content: "";
  position: absolute;
  opacity: 0;
  transition: opacity 0.2s;
}

/* 뱃지 */
.nsh-fab-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: var(--nsh-danger);
  color: #fff;
  border-radius: 50%;
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  line-height: 1;
}

/* 펄스 링 */
.nsh-fab-pulse {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(82,209,191,0.75);
  animation: nsh-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes nsh-pulse {
  0%   { transform: scale(1);   opacity: 0.6; }
  100% { transform: scale(1.7); opacity: 0; }
}
.nsh-fab--open .nsh-fab-pulse {
  animation: none;
  opacity: 0;
}

/* ═══════════════════════════════════════════════════════
   패널
═══════════════════════════════════════════════════════ */
.nsh-panel {
  position: absolute;
  bottom: 82px;
  right: 0;
  width: var(--nsh-panel-w);
  height: var(--nsh-panel-h);
  background: linear-gradient(180deg, #F8FFFD 0%, var(--nsh-bg) 100%);
  border-radius: var(--nsh-radius);
  box-shadow: var(--nsh-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(.34,1.56,.64,1), opacity 0.22s ease;
  border: 1px solid rgba(207,233,231,0.92);
}
.nsh-panel--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ─── 헤더 ──────────────────────────────────────────── */
.nsh-header {
  background: linear-gradient(135deg, #0F4C68 0%, #168B91 54%, #52D1BF 100%);
  padding: 15px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.nsh-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.nsh-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #FFFFFF url("./nsh-guidebot-icon.svg") center / 39px 39px no-repeat;
  border: 2px solid rgba(255,255,255,0.72);
  color: transparent;
  font-weight: 700;
  font-size: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nsh-header-title {
  color: #fff;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: 0;
}
.nsh-header-sub {
  color: rgba(255,255,255,0.84);
  font-size: 12px;
  margin-top: 2px;
}
.nsh-close {
  background: rgba(255,255,255,0.16);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.nsh-close:hover { background: rgba(255,255,255,0.26); }
.nsh-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ─── 개인정보 배너 ──────────────────────────────────── */
.nsh-privacy-banner {
  background: rgba(237,251,248,0.78);
  border-bottom: 1px solid rgba(207,233,231,0.72);
  padding: 8px 15px;
  font-size: 12px;
  color: var(--nsh-primary);
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  line-height: 1.5;
}
.nsh-privacy-icon { font-size: 13px; flex-shrink: 0; }
.nsh-privacy-banner strong { color: #9F372F; }

/* ─── 메시지 영역 ─────────────────────────────────────── */
.nsh-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 15px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.nsh-messages::-webkit-scrollbar { width: 4px; }
.nsh-messages::-webkit-scrollbar-track { background: transparent; }
.nsh-messages::-webkit-scrollbar-thumb { background: var(--nsh-border); border-radius: 2px; }

/* ─── 메시지 행 ──────────────────────────────────────── */
.nsh-msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  animation: nsh-fadein 0.22s ease;
  max-width: 100%;
}
@keyframes nsh-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nsh-msg--user {
  flex-direction: row-reverse;
}
.nsh-msg--emergency .nsh-bubble--bot {
  background: var(--nsh-danger-bg);
  border: 1.5px solid rgba(185,66,56,0.28);
}

/* ─── 아바타 소형 ─────────────────────────────────────── */
.nsh-avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #FFFFFF url("./nsh-guidebot-icon.svg") center / 27px 27px no-repeat;
  border: 1px solid rgba(82,209,191,0.42);
  box-shadow: 0 3px 10px rgba(15,76,104,0.10);
  color: transparent;
  font-weight: 700;
  font-size: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ─── 말풍선 ──────────────────────────────────────────── */
.nsh-bubble {
  padding: 13px 15px;
  border-radius: var(--nsh-radius-sm);
  font-size: 14.2px;
  line-height: 1.74;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.nsh-bubble--bot {
  background: var(--nsh-bubble-bot);
  color: var(--nsh-text);
  border: 1px solid rgba(207,233,231,0.95);
  border-radius: 9px var(--nsh-radius-sm) var(--nsh-radius-sm) var(--nsh-radius-sm);
  box-shadow: var(--nsh-shadow-sm);
  max-width: 270px;
}
.nsh-bubble--bot p { margin-bottom: 8px; }
.nsh-bubble--bot p:last-child { margin-bottom: 0; }

.nsh-bubble--user {
  background: var(--nsh-bubble-user);
  color: #fff;
  border-radius: var(--nsh-radius-sm) 9px var(--nsh-radius-sm) var(--nsh-radius-sm);
  max-width: 230px;
  box-shadow: 0 5px 16px rgba(15,76,104,0.15);
}

/* 타이핑 인디케이터 */
.nsh-bubble--typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}
.nsh-dot {
  width: 7px;
  height: 7px;
  background: var(--nsh-accent);
  border-radius: 50%;
  animation: nsh-blink 1.2s infinite;
  opacity: 0.4;
}
.nsh-dot:nth-child(2) { animation-delay: 0.2s; }
.nsh-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes nsh-blink {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ─── 안내 목록 (인사말) ──────────────────────────────── */
.nsh-notice-list {
  margin-top: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nsh-notice-item {
  font-size: 13px;
  color: var(--nsh-primary);
  background: #EDFBF8;
  border-left: 3px solid var(--nsh-accent);
  padding: 8px 10px;
  border-radius: 0 var(--nsh-radius-xs) var(--nsh-radius-xs) 0;
  line-height: 1.62;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.nsh-notice-item strong { color: var(--nsh-danger); }

/* 인라인 링크 */
.nsh-link-inline {
  color: var(--nsh-primary);
  font-weight: 600;
  text-decoration: underline;
}
.nsh-link-inline:hover { color: var(--nsh-primary-d); }

/* ─── CTA 버튼 그룹 ──────────────────────────────────── */
.nsh-cta-group {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  max-width: 292px;
}
.nsh-cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s, border-color 0.15s;
  border: 1px solid rgba(47,169,189,0.30);
  background: #F0FBF9;
  color: var(--nsh-primary);
  line-height: 1.4;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  letter-spacing: 0;
}
.nsh-cta-btn:hover {
  background: #0F4C68;
  border-color: #0F4C68;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(27,94,139,0.22);
}
.nsh-cta-btn:focus-visible {
  outline: 2px solid var(--nsh-accent);
  outline-offset: 2px;
}
.nsh-cta-btn--emergency {
  border-color: rgba(185,66,56,0.34);
  background: #FFF7F5;
  color: #9F372F;
  font-weight: 700;
}
.nsh-cta-btn--emergency:hover {
  background: var(--nsh-danger);
  border-color: var(--nsh-danger);
  color: #fff;
}

/* ─── 입력 영역 ───────────────────────────────────────── */
.nsh-input-area {
  border-top: 1px solid var(--nsh-border);
  padding: 13px 15px 12px;
  background: rgba(255,255,255,0.96);
  flex-shrink: 0;
}
.nsh-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  background: #F7FFFD;
  border: 1.5px solid var(--nsh-border);
  border-radius: 20px;
  padding: 10px 11px 10px 15px;
  transition: border-color 0.15s;
}
.nsh-input-wrap:focus-within {
  border-color: var(--nsh-accent);
  box-shadow: 0 0 0 3px rgba(82,209,191,0.18);
}
.nsh-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  color: var(--nsh-text);
  outline: none;
  min-height: 24px;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.62;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.nsh-input::placeholder { color: #8fa1aa; }
.nsh-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--nsh-primary) 0%, var(--nsh-green) 100%);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.nsh-send:hover { background: linear-gradient(135deg, var(--nsh-primary-d) 0%, #176F68 100%); transform: scale(1.05); }
.nsh-send:focus-visible { outline: 2px solid var(--nsh-primary); outline-offset: 2px; }
.nsh-send:active { transform: scale(0.95); }

.nsh-footer-note {
  font-size: 11.5px;
  color: var(--nsh-text-light);
  text-align: center;
  margin-top: 10px;
  line-height: 1.45;
}
.nsh-emergency-link {
  color: #9F372F;
  font-weight: 700;
  text-decoration: none;
}
.nsh-emergency-link:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════
   모바일 반응형
═══════════════════════════════════════════════════════ */

/* 스마트폰 세로 (< 480px) */
@media (max-width: 479px) {
  #nsh-chatbot-root {
    bottom: calc(env(safe-area-inset-bottom) + 108px);
    right: 18px;
  }
  .nsh-panel {
    position: fixed;
    top: max(104px, calc(env(safe-area-inset-top) + 88px));
    right: 8px;
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px));
    left: 8px;
    width: auto;
    height: auto;
    max-height: calc(100dvh - 126px);
    border-radius: 22px;
    transform: translateY(calc(100% + 16px));
    transform-origin: bottom center;
  }
  .nsh-panel--open {
    transform: translateY(0);
  }
  #nsh-chatbot-root .nsh-panel.nsh-panel--open {
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .nsh-messages {
    min-height: 0;
    overflow-y: auto;
    /* TEO-CHATBOT-UI-2: v2.5.5 message top padding fine-tune */
    padding: 36px 15px 20px;
  }
  .nsh-input-area {
    padding-bottom: max(22px, calc(env(safe-area-inset-bottom) + 18px));
  }
  .nsh-footer-note {
    margin-top: 10px;
    padding-bottom: 3px;
  }
  .nsh-bubble--bot { max-width: calc(100vw - 80px); }
  .nsh-cta-group   { max-width: calc(100vw - 80px); }
  .nsh-bubble--user { max-width: calc(100vw - 64px); }
  .nsh-fab {
    width: 60px;
    height: 60px;
  }
  .nsh-fab-icon {
    width: 50px;
    height: 50px;
  }
}

/* 데스크톱: 우측 Quick 메뉴 대표전화 버튼 위쪽에 배치 */
@media (min-width: 1026px) {
  #nsh-chatbot-root {
    top: 190px;
    right: 150px;
    bottom: auto;
  }
  .nsh-panel {
    position: fixed;
    top: 110px;
    right: 230px;
    bottom: auto;
    transform-origin: top right;
  }
  .nsh-fab:not(.nsh-fab--open)::after {
    content: "상담봇";
    position: absolute;
    top: 50%;
    right: calc(100% + 10px);
    transform: translateY(-50%);
    min-width: 52px;
    padding: 7px 10px;
    border: 1px solid rgba(82,209,191,0.36);
    border-radius: 999px;
    background: rgba(255,255,255,0.94);
    color: var(--nsh-primary);
    box-shadow: 0 6px 18px rgba(15,76,104,0.12);
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
    z-index: 2;
  }
}

/* 태블릿 (480px ~ 767px) */
@media (min-width: 480px) and (max-width: 767px) {
  .nsh-panel {
    width: 340px;
    height: min(520px, calc(100dvh - 126px));
    max-height: calc(100dvh - 126px);
  }
  .nsh-messages {
    padding-top: 20px;
  }
  .nsh-input-area {
    padding-bottom: 14px;
  }
}

/* 데스크탑 넓은 화면 */
@media (min-width: 1200px) {
  :root {
    --nsh-panel-w: 380px;
    --nsh-panel-h: 600px;
  }
}

/* ─── 접근성: 고대비 모드 ─────────────────────────────── */
@media (prefers-contrast: high) {
  .nsh-bubble--bot   { border-width: 2px; }
  .nsh-cta-btn       { border-width: 2px; }
  .nsh-privacy-banner { background: #D6EAF8; }
}

/* ─── 다크 모드 (선택적) ──────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --nsh-bg:          #1a2332;
    --nsh-bubble-bot:  #243044;
    --nsh-text:        #e8edf4;
    --nsh-text-light:  #8a9ab0;
    --nsh-border:      #2e4060;
  }
  .nsh-input-area { background: #1f2d3e; }
  .nsh-input-wrap { background: #1a2332; }
  .nsh-input { color: #e8edf4; }
  .nsh-privacy-banner { background: #1f3050; }
  .nsh-notice-item { background: #1f3050; }
  .nsh-cta-btn { background: #243044; }
  .nsh-cta-btn:hover { background: var(--nsh-primary); }
}

/* ─── 애니메이션 줄이기 (접근성) ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .nsh-fab,
  .nsh-panel,
  .nsh-msg,
  .nsh-cta-btn,
  .nsh-dot { animation: none; transition: none; }
  .nsh-fab-pulse { display: none; }
}

#nsh-chatbot-root .nsh-panel.nsh-panel--open {
  transform: scale(1) translateY(0) !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
