/* =========================================
   Comes AI Chat Widget
   ========================================= */

/* --- Floating Button --- */
#comes-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #004a99, #3385ff);
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(0, 74, 153, 0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(1) rotate(0deg);
  opacity: 1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: chatBtnPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes chatBtnPop {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

#comes-chat-btn:hover {
  transform: scale(1.1) translateY(-3px);
  box-shadow: 0 14px 35px rgba(0, 74, 153, 0.5);
}

#comes-chat-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: all 0.3s ease;
}

/* Notification dot */
#comes-chat-btn::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ff4d4d;
  border-radius: 50%;
  border: 2px solid white;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(255, 77, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

#comes-chat-btn.is-open::after {
  display: none;
}
#comes-chat-btn.is-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0) rotate(180deg);
  animation: none;
}

/* --- Chat Panel --- */
#comes-chat-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 380px;
  height: 560px;
  max-width: calc(100vw - 56px);
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 74, 153, 0.18), 0 4px 20px rgba(0,0,0,0.1);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0, 74, 153, 0.12);
  transform-origin: bottom right;
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.3, 0.64, 1);
}

#comes-chat-panel.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* --- Panel Header --- */
.comes-chat-header {
  background: linear-gradient(135deg, #004a99 0%, #1a6bc7 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.comes-chat-header-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.3rem;
}

.comes-chat-header-info {
  flex: 1;
}

.comes-chat-header-info h4 {
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 2px 0;
}

.comes-chat-header-info p {
  color: rgba(255,255,255,0.75);
  font-size: 0.72rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.comes-chat-header-info p::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #4cff91;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(76, 255, 145, 0.8);
}

.comes-chat-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s;
  flex-shrink: 0;
}

.comes-chat-close:hover {
  background: rgba(255,255,255,0.3);
}

/* --- Messages Area --- */
.comes-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #f7f9fc;
  scroll-behavior: smooth;
}

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

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

.comes-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 74, 153, 0.2);
  border-radius: 4px;
}

/* --- Message Bubbles --- */
.comes-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: msgIn 0.3s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

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

.comes-msg.ai {
  align-self: flex-start;
}

.comes-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.comes-msg-avatar {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #004a99, #3385ff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.comes-msg-bubble {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.88rem;
  line-height: 1.6;
  word-break: break-word;
}

.comes-msg.ai .comes-msg-bubble {
  background: white;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border: 1px solid rgba(0, 74, 153, 0.06);
}

.comes-msg.user .comes-msg-bubble {
  background: linear-gradient(135deg, #004a99, #1a6bc7);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 12px rgba(0, 74, 153, 0.3);
}

/* Suggestion chips */
.comes-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.comes-chat-chip {
  background: white;
  border: 1.5px solid rgba(0, 74, 153, 0.25);
  color: #004a99;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.comes-chat-chip:hover {
  background: #004a99;
  color: white;
  border-color: #004a99;
  transform: translateY(-1px);
}

/* --- Typing Indicator --- */
.comes-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  animation: msgIn 0.3s ease both;
}

.comes-typing-dots {
  background: white;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border: 1px solid rgba(0, 74, 153, 0.06);
}

.comes-typing-dots span {
  width: 7px;
  height: 7px;
  background: #004a99;
  border-radius: 50%;
  opacity: 0.4;
  animation: typingDot 1.2s infinite;
}

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

@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* --- Input Area --- */
.comes-chat-footer {
  background: white;
  border-top: 1px solid rgba(0, 74, 153, 0.08);
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#comes-chat-input {
  flex: 1;
  border: 1.5px solid rgba(0, 74, 153, 0.2);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 16px; /* iOSフォーカス時の自動ズーム防止 */
  font-family: inherit;
  color: #1a1a1a;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color 0.2s;
  background: #f7f9fc;
}

#comes-chat-input::placeholder {
  color: #aab;
}

#comes-chat-input:focus {
  border-color: #004a99;
  background: white;
}

#comes-chat-send {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #004a99, #3385ff);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  box-shadow: 0 3px 10px rgba(0, 74, 153, 0.3);
}

#comes-chat-send:hover {
  transform: scale(1.08);
  box-shadow: 0 5px 15px rgba(0, 74, 153, 0.4);
}

#comes-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#comes-chat-send svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* Footer branding */
.comes-chat-branding {
  text-align: center;
  font-size: 0.65rem;
  color: #bbb;
  padding: 4px 0 0;
  flex-basis: 100%;
}

.comes-msg-bubble a {
  color: #004a99;
  text-decoration: underline;
  font-weight: 600;
  transition: opacity 0.2s;
}
.comes-msg-bubble a:hover {
  opacity: 0.8;
}
.comes-msg.user .comes-msg-bubble a {
  color: #ffffff;
}

/* --- Responsive (Mobile) --- */
@media (max-width: 480px) {
  #comes-chat-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 85dvh;
    max-width: 100%;
    max-height: 85dvh;
    border-radius: 20px 20px 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  #comes-chat-btn {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }
}

/* --- Chat Heading Styles (Markdown parse targets) --- */
.chat-h3 {
  display: block;
  font-weight: 700;
  font-size: 0.98rem;
  color: #004a99;
  margin-top: 16px;
  margin-bottom: 8px;
  border-bottom: 1.5px solid rgba(0, 74, 153, 0.18);
  padding-bottom: 4px;
}
.chat-h4 {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  color: #004a99;
  margin-top: 12px;
  margin-bottom: 4px;
  border-bottom: 1px dashed rgba(0, 74, 153, 0.25);
  padding-bottom: 4px;
}
.chat-h4::before {
  content: "◆";
  font-size: 0.7rem;
  color: #3385ff;
  margin-right: 6px;
  vertical-align: middle;
}
.comes-msg.user .chat-h3,
.comes-msg.user .chat-h4 {
  color: white;
  border-color: rgba(255, 255, 255, 0.4);
}
.comes-msg.user .chat-h4::before {
  color: white;
}

/* --- Red Highlight Style --- */
.highlight-red {
  color: #ff3333; /* 暗い背景でも読みやすい少し明るめの赤 */
  font-weight: 700;
}
.comes-msg.user .highlight-red {
  color: #ffcccc; /* ユーザー側のメッセージ（青背景）内ではピンク寄りの薄い赤にして可読性を確保 */
}

/* --- Floating Button Icon Toggle --- */
#comes-chat-btn svg#comes-chat-icon-close {
  display: none;
}
#comes-chat-btn.is-open svg#comes-chat-icon-open {
  display: none;
}
#comes-chat-btn.is-open svg#comes-chat-icon-close {
  display: block !important;
}
