/* ========================================
   ナースロビー - AI Chat Widget v2.0
   Value-first conversational design
   Mobile-first / Warm Cream + Teal Theme
   ======================================== */

/* ---------- Hidden utility ---------- */
.hidden {
  display: none !important;
}

/* ---------- Chat Toggle Button ---------- */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #5B787D;
  border: none;
  cursor: pointer;
  z-index: var(--z-chat);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: #FFFFFF;
  box-shadow: 0 4px 24px rgba(91, 120, 125, 0.3);
  transition: transform var(--transition), box-shadow var(--transition);
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 32px rgba(91, 120, 125, 0.45);
}

.chat-toggle .chat-toggle-icon {
  transition: transform 0.3s ease;
}

.chat-toggle.active .chat-toggle-icon {
  transform: rotate(90deg);
}

/* Pulse ring animation */
.chat-toggle-pulse {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #5B787D;
  animation: chatPulse 2s ease-out infinite;
  pointer-events: none;
}

.chat-toggle.active .chat-toggle-pulse {
  display: none;
}

@keyframes chatPulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* ---------- Proactive Peek Message ---------- */
.chat-peek {
  position: fixed;
  bottom: 96px;
  right: 24px;
  background: #FFFFFF;
  border: 1px solid #D4CFC2;
  border-radius: 16px 16px 4px 16px;
  padding: 14px 40px 14px 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  z-index: var(--z-chat);
  max-width: 260px;
  animation: peekSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  cursor: pointer;
}

@keyframes peekSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-peek-hiding {
  animation: peekSlideOut 0.3s ease forwards;
}

@keyframes peekSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(8px); }
}

.chat-peek-text {
  font-size: 0.88rem;
  color: #2D2D2D;
  line-height: 1.5;
  font-weight: 500;
}

.chat-peek-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #A0A0A0;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.chat-peek-close:hover {
  color: #6B6B6B;
}

/* ---------- Chat Window ---------- */
.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 600px;
  max-height: min(600px, 85vh);
  background: rgba(250, 250, 242, 0.97);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid #D4CFC2;
  border-radius: var(--radius-xl);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  z-index: var(--z-chat);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ---------- Chat Header ---------- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #F2EFE6;
  border-bottom: 1px solid #D4CFC2;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #5B787D;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #FFFFFF;
  flex-shrink: 0;
}

.chat-header-text h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2D2D2D;
  margin: 0;
}

.chat-header-text p {
  font-size: 0.75rem;
  color: #5B787D;
  margin: 0;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-minimize-btn,
.chat-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(212, 207, 194, 0.6);
  color: #6B6B6B;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition);
}

.chat-minimize-btn:hover,
.chat-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #2D2D2D;
}

/* ---------- Chat View Container ---------- */
#chatView {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---------- Chat Body ---------- */
.chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-body::-webkit-scrollbar {
  width: 4px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
  background: rgba(212, 207, 194, 0.7);
  border-radius: 4px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 207, 194, 1);
}

/* ---------- Chat Messages ---------- */
.chat-message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

.chat-message.ai {
  animation: messageSlideInLeft 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  align-self: flex-start;
}

.chat-message.user {
  animation: messageSlideInRight 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  align-self: flex-end;
  flex-direction: row-reverse;
}

@keyframes messageSlideIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes messageSlideInLeft {
  from { opacity: 0; transform: translateX(-12px) translateY(8px); }
  to { opacity: 1; transform: translateX(0) translateY(0); }
}

@keyframes messageSlideInRight {
  from { opacity: 0; transform: translateX(12px) translateY(8px); }
  to { opacity: 1; transform: translateX(0) translateY(0); }
}

/* AI message avatar */
.chat-message .chat-msg-avatar {
  display: none;
}

.chat-message.ai .chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #5B787D;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #FFFFFF;
  flex-shrink: 0;
  margin-top: 2px;
}

/* AI bubble */
.chat-message.ai .chat-bubble {
  background: #F2EFE6;
  border: 1px solid #D4CFC2;
  border-radius: 2px 16px 16px 16px;
  padding: 12px 16px;
  color: #4A4A4A;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* User bubble */
.chat-message.user .chat-bubble {
  background: rgba(91, 120, 125, 0.1);
  border: 1px solid rgba(91, 120, 125, 0.25);
  border-radius: 16px 2px 16px 16px;
  padding: 12px 16px;
  color: #4A4A4A;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ---------- Typing Indicator ---------- */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 4px 0;
  animation: typingFadeIn 0.3s ease forwards;
  opacity: 0;
}

@keyframes typingFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-typing .chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #5B787D;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #FFFFFF;
  flex-shrink: 0;
}

.chat-typing-dots {
  background: #F2EFE6;
  border: 1px solid #D4CFC2;
  border-radius: 2px 16px 16px 16px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-typing-dots span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5B787D;
  opacity: 0.3;
  animation: typingPulse 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 70%, 100% { transform: translateY(0) scale(1); opacity: 0.3; }
  35% { transform: translateY(-5px) scale(1.15); opacity: 1; }
}

/* ---------- Chat Input Area ---------- */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: #F2EFE6;
  border-top: 1px solid #D4CFC2;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #D4CFC2;
  background: #FFFFFF;
  color: #4A4A4A;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: var(--font-main);
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color var(--transition);
}

.chat-input:focus {
  outline: none;
  border-color: #5B787D;
  box-shadow: 0 0 0 3px rgba(91, 120, 125, 0.1);
}

.chat-input::placeholder {
  color: #A0A0A0;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #5B787D;
  border: none;
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: all var(--transition);
}

.chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(91, 120, 125, 0.35);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chat-send-btn.loading {
  pointer-events: none;
  font-size: 0;
}

.chat-send-btn.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: chatSpin 0.6s linear infinite;
}

@keyframes chatSpin {
  to { transform: rotate(360deg); }
}

/* ---------- Quick Reply Buttons ---------- */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
  align-self: flex-start;
  animation: repliesSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

@keyframes repliesSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-quick-reply {
  background: rgba(91, 120, 125, 0.06);
  border: 1px solid rgba(91, 120, 125, 0.2);
  color: #5B787D;
  padding: 10px 18px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-main);
}

.chat-quick-reply:hover {
  background: rgba(91, 120, 125, 0.14);
  border-color: #5B787D;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(91, 120, 125, 0.15);
}

.chat-quick-reply:active {
  transform: translateY(0);
  box-shadow: none;
}

/* LINE-highlighted quick reply */
.chat-quick-reply-line {
  background: rgba(6, 199, 85, 0.08);
  border-color: rgba(6, 199, 85, 0.3);
  color: #06C755;
  font-weight: 600;
}

.chat-quick-reply-line:hover {
  background: rgba(6, 199, 85, 0.15);
  border-color: #06C755;
}

/* ---------- Facility Cards (Value Delivery) ---------- */
.chat-facility-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
  animation: messageSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

.chat-facility-card {
  background: #FFFFFF;
  border: 1px solid #E5E0D5;
  border-radius: 12px;
  padding: 14px 16px;
  transition: border-color 0.2s ease;
}

.chat-facility-card:hover {
  border-color: #5B787D;
}

.facility-card-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #2D2D2D;
  margin-bottom: 6px;
  line-height: 1.4;
}

.facility-card-highlight {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(91, 120, 125, 0.08);
  border: 1px solid rgba(91, 120, 125, 0.2);
  border-radius: 50px;
  font-size: 0.75rem;
  color: #5B787D;
  font-weight: 500;
  margin-bottom: 8px;
}

.facility-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.78rem;
  color: #6B6B6B;
}

.facility-card-details span {
  white-space: nowrap;
}

.facility-card-more {
  text-align: center;
  font-size: 0.8rem;
  color: #5B787D;
  font-weight: 500;
  padding: 8px 0 4px;
}

/* ---------- LINE Card (CTA) ---------- */
.chat-line-card {
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border: 1px solid rgba(6, 199, 85, 0.2);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

.chat-line-card-btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: #06C755;
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-main);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(6, 199, 85, 0.3);
}

.chat-line-card-btn:hover {
  background: #05b04c;
  transform: translateY(-1px);
}

.chat-line-card-btn:active {
  transform: translateY(0);
}

.chat-line-card-trust {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 0.72rem;
  color: #6b7280;
}

.chat-line-card-trust span {
  position: relative;
  padding-left: 14px;
}

.chat-line-card-trust span::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: #06C755;
  font-weight: 700;
}

/* Soft LINE card variant */
.chat-line-card-soft {
  background: rgba(250, 250, 242, 0.8);
  border-color: #D4CFC2;
  padding: 14px 16px;
}

.chat-line-card-note {
  font-size: 0.8rem;
  color: #6B6B6B;
  margin-bottom: 10px;
}

.chat-line-card-btn-soft {
  background: #FFFFFF;
  color: #06C755;
  border: 2px solid #06C755;
  box-shadow: none;
  font-size: 0.9rem;
  padding: 12px 16px;
}

.chat-line-card-btn-soft:hover {
  background: rgba(6, 199, 85, 0.06);
}

/* ---------- LINE Nudge (gentle, inline) ---------- */
.chat-line-nudge {
  text-align: center;
  padding: 8px 0;
  animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

.chat-line-nudge-btn {
  display: inline-block;
  padding: 10px 24px;
  background: #06C755;
  color: #FFFFFF;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  font-family: var(--font-main);
  transition: background 0.2s, transform 0.1s;
}

.chat-line-nudge-btn:hover {
  background: #05b04c;
  transform: translateY(-1px);
}

/* ---------- Body scroll lock (mobile) ---------- */
body.chat-open-mobile {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ---------- Mobile Full Screen ---------- */
@media (max-width: 640px) {
  .chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: none;
    overscroll-behavior: contain;
  }

  .chat-window.open {
    transform: none;
  }

  .chat-body {
    flex: 1;
    min-height: 0;
    overscroll-behavior: contain;
  }

  .chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 58px;
    height: 58px;
    font-size: 1.5rem;
  }

  .chat-peek {
    bottom: 86px;
    right: 16px;
    max-width: 240px;
  }

  /* Prevent iOS zoom on input focus */
  .chat-input {
    font-size: 16px;
  }

  /* Touch-friendly buttons */
  .chat-line-card-btn,
  .chat-line-card-btn-soft,
  .chat-line-nudge-btn {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Quick reply: larger touch target */
  .chat-quick-reply {
    padding: 12px 20px;
    font-size: 0.88rem;
  }

  /* Facility cards: more padding */
  .chat-facility-card {
    padding: 16px 18px;
  }
}

/* ---------- Accessibility: reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .chat-window {
    transition: opacity 0.01ms, visibility 0.01ms, transform 0.01ms;
  }

  .chat-message,
  .chat-message.ai,
  .chat-message.user {
    animation: none;
    opacity: 1;
  }

  .chat-typing {
    animation: none;
    opacity: 1;
  }

  .chat-typing-dots span {
    animation: none;
    opacity: 0.7;
  }

  .chat-toggle-pulse {
    animation: none;
    display: none;
  }

  .chat-toggle .chat-toggle-icon {
    transition: none;
  }

  .chat-quick-replies,
  .chat-facility-cards,
  .chat-line-card,
  .chat-line-nudge {
    animation: none;
    opacity: 1;
  }

  .chat-quick-reply {
    transition: none;
  }

  .chat-peek {
    animation: none;
    opacity: 1;
  }
}
