@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;600&display=swap');

:root {
  --chat-bg-primary: #ffffff;
  --chat-bg-secondary: #f8fafc;
  --chat-bg-message-ai: #f1f5f9;
  --chat-bg-message-user: #2563eb;
  --chat-text-primary: #1e293b;
  --chat-text-secondary: #64748b;
  --chat-accent: #2563eb;
  --chat-accent-hover: #1d4ed8;
  --chat-border: #e2e8f0;
  --chat-shadow: rgba(0, 0, 0, 0.08);
  --chat-font: 'Noto Sans JP', 'Noto Sans SC', system-ui, sans-serif;
}

.toyo-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  z-index: 9998;
}

.toyo-chat-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.45);
}

.toyo-chat-bubble svg {
  width: 26px;
  height: 26px;
  fill: white;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.toyo-chat-bubble.open .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.toyo-chat-bubble.open .icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.toyo-chat-bubble .icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.toyo-chat-container {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 540px;
  background: var(--chat-bg-primary);
  border-radius: 20px;
  border: 1px solid var(--chat-border);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.3s ease;
  font-family: var(--chat-font);
}

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

.toyo-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  min-height: 64px;
}

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

.toyo-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.toyo-chat-avatar svg {
  width: 22px;
  height: 22px;
  fill: #2563eb;
}

.toyo-chat-title {
  font-size: 15px;
  font-weight: 600;
  color: white;
}

.toyo-chat-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 6px;
}

.toyo-chat-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

.toyo-chat-lang-selector {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.15);
  padding: 3px;
  border-radius: 8px;
}

.toyo-chat-lang-btn {
  padding: 5px 8px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--chat-font);
}

.toyo-chat-lang-btn:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.toyo-chat-lang-btn.active {
  background: white;
  color: #2563eb;
}

.toyo-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--chat-bg-secondary);
  min-height: 55%;
}

.toyo-chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.toyo-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

.toyo-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

.toyo-chat-message {
  max-width: 85%;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  animation: messageIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: visible;
  word-break: break-word;
}

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

.toyo-chat-message.ai {
  align-self: flex-start;
  background: var(--chat-bg-primary);
  color: var(--chat-text-primary);
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 1px 3px var(--chat-shadow);
}

.toyo-chat-message.user {
  align-self: flex-end;
  background: var(--chat-bg-message-user);
  color: white;
  border-radius: 18px 4px 18px 18px;
}

.toyo-chat-message.typing {
  display: flex;
  gap: 5px;
  padding: 16px 20px;
}

.toyo-chat-message.typing span {
  width: 8px;
  height: 8px;
  background: var(--chat-accent);
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.toyo-chat-message.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.toyo-chat-message.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

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

.toyo-chat-faq {
  padding: 0 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--chat-bg-secondary);
  max-height: 28%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--chat-border) transparent;
  flex-shrink: 0;
}

.toyo-chat-faq::-webkit-scrollbar {
  width: 6px;
}

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

.toyo-chat-faq::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

.toyo-chat-faq::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

.toyo-chat-faq-title {
  font-size: 12px;
  color: var(--chat-text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

.toyo-chat-faq-btn {
  padding: 12px 16px;
  background: var(--chat-bg-primary);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  color: var(--chat-text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-family: var(--chat-font);
}

.toyo-chat-faq-btn:hover {
  background: var(--chat-bg-secondary);
  border-color: var(--chat-accent);
  color: var(--chat-accent);
}

.toyo-chat-input-area {
  padding: 16px 20px;
  background: var(--chat-bg-primary);
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
  max-height: 140px;
  flex-shrink: 0;
}

.toyo-chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--chat-bg-secondary);
  border: 1px solid var(--chat-border);
  border-radius: 24px;
  color: var(--chat-text-primary);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: var(--chat-font);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.toyo-chat-input::placeholder {
  color: var(--chat-text-secondary);
}

.toyo-chat-input:focus {
  border-color: var(--chat-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.toyo-chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  background: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.toyo-chat-send-btn:hover {
  background: var(--chat-accent-hover);
}

.toyo-chat-send-btn:active {
  transform: scale(0.95);
}

.toyo-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toyo-chat-send-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

@media (max-width: 480px) {
  .toyo-chat-container {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .toyo-chat-bubble {
    bottom: 16px;
    right: 16px;
  }

  .toyo-chat-container.open ~ .toyo-chat-bubble {
    opacity: 0;
    pointer-events: none;
  }

  .toyo-chat-header {
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .toyo-chat-input-area {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
