/* CSO AI Chat Widget */

#cso-ai-container {
  --cso-primary: #4a7c59; /* TODO: match cs-omu.jp main color */
  --cso-primary-dark: #3a6349;
  --cso-bg: #ffffff;
  --cso-msg-user: #4a7c59;
  --cso-msg-assistant: #f0f0f0;
  --cso-text: #333333;
  --cso-text-light: #ffffff;
  --cso-border: #e0e0e0;
  --cso-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --cso-radius: 16px;

  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans',
    'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* Toggle Button */
#cso-ai-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--cso-primary);
  color: var(--cso-text-light);
  cursor: pointer;
  box-shadow: var(--cso-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s, background 0.2s;
}

#cso-ai-toggle:hover {
  transform: scale(1.05);
  background: var(--cso-primary-dark);
}

#cso-ai-toggle.cso-ai-open {
  display: none;
}

.cso-ai-bubble {
  position: absolute;
  bottom: 2px;
  right: 2px;
}

/* Chat Window */
#cso-ai-chat {
  width: 380px;
  height: 500px;
  background: var(--cso-bg);
  border-radius: var(--cso-radius);
  box-shadow: var(--cso-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: 0;
  right: 0;
}

#cso-ai-chat.cso-ai-hidden {
  display: none;
}

/* Header */
#cso-ai-header {
  background: var(--cso-primary);
  color: var(--cso-text-light);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 15px;
  flex-shrink: 0;
}

#cso-ai-close {
  background: none;
  border: none;
  color: var(--cso-text-light);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.8;
}

#cso-ai-close:hover {
  opacity: 1;
}

/* Messages */
#cso-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cso-ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}

.cso-ai-msg-user {
  background: var(--cso-msg-user);
  color: var(--cso-text-light);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.cso-ai-msg-assistant {
  background: var(--cso-msg-assistant);
  color: var(--cso-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.cso-ai-msg-system {
  align-self: center;
  text-align: center;
}

/* Typing indicator */
.cso-ai-typing {
  opacity: 0.6;
  animation: cso-ai-blink 1s infinite;
}

@keyframes cso-ai-blink {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 0.3;
  }
}

/* LINE button */
.cso-ai-line-btn {
  display: inline-block;
  background: #06c755;
  color: #ffffff !important;
  text-decoration: none;
  padding: 10px 24px;
  border-radius: 24px;
  font-weight: bold;
  font-size: 14px;
  transition: background 0.2s;
}

.cso-ai-line-btn:hover {
  background: #05b34c;
}

/* Input Area */
#cso-ai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--cso-border);
  flex-shrink: 0;
}

#cso-ai-input {
  flex: 1;
  border: 1px solid var(--cso-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 80px;
}

#cso-ai-input:focus {
  border-color: var(--cso-primary);
}

#cso-ai-input:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}

#cso-ai-send {
  background: var(--cso-primary);
  color: var(--cso-text-light);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

#cso-ai-send:hover:not(:disabled) {
  background: var(--cso-primary-dark);
}

#cso-ai-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile responsive */
@media (max-width: 480px) {
  #cso-ai-container {
    bottom: 12px;
    right: 12px;
  }

  #cso-ai-chat {
    width: calc(100vw - 24px);
    height: 50vh;
    bottom: 0;
    right: 0;
    border-radius: var(--cso-radius) var(--cso-radius) 0 0;
  }

  #cso-ai-toggle {
    width: 52px;
    height: 52px;
  }
}
