/* ── CHAT WIDGET VARIABLES ──────────────────────────────────── */
:root {
  --chat-bg:           #0d0d0d;
  --chat-surface:      #1a1a1a;
  --chat-surface-2:    #222222;
  --chat-border:       #2a2a2a;
  --chat-accent:       #ff5500;
  --chat-accent-hover: #e64d00;
  --chat-text:         #f0f0f0;
  --chat-text-muted:   #888888;
  --chat-user-bubble:  #ff5500;
  --chat-bot-bubble:   #222222;
  --chat-shadow:       0 8px 40px rgba(0, 0, 0, 0.7);
  --chat-radius:       16px;
  --chat-btn-size:     56px;
  --chat-panel-width:  380px;
  --chat-panel-height: 520px;
  --chat-transition:   0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── FLOATING TOGGLE BUTTON ─────────────────────────────────── */
#chat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--chat-btn-size);
  height: var(--chat-btn-size);
  border-radius: 50%;
  background-color: var(--chat-accent);
  border: none;
  cursor: pointer;
  z-index: 9998;
  box-shadow: 0 4px 20px rgba(255, 85, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease,
              transform 0.2s ease,
              box-shadow 0.2s ease;
}

#chat-toggle-btn:hover {
  background-color: var(--chat-accent-hover);
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(255, 85, 0, 0.65);
}

#chat-toggle-btn:active {
  transform: scale(0.96);
}

#chat-toggle-btn svg {
  width: 24px;
  height: 24px;
  fill: #fff;
  transition: opacity 0.15s ease, transform 0.2s ease;
}

.icon-chat  { display: block; }
.icon-close { display: none; }

#chat-toggle-btn.is-open .icon-chat  { display: none; }
#chat-toggle-btn.is-open .icon-close { display: block; }

/* ── CHAT PANEL ─────────────────────────────────────────────── */
#chat-panel {
  position: fixed;
  bottom: calc(var(--chat-btn-size) + 12px + 24px);
  right: 24px;
  width: var(--chat-panel-width);
  height: var(--chat-panel-height);
  background-color: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition:
    opacity var(--chat-transition),
    transform var(--chat-transition);
}

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

/* ── PANEL HEADER ───────────────────────────────────────────── */
#chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background-color: var(--chat-surface-2);
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--chat-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--chat-text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 11px;
  color: #4ade80;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.chat-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #4ade80;
  display: inline-block;
  flex-shrink: 0;
}

/* ── HEADER CLOSE BUTTON ────────────────────────────────────── */
#chat-close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--chat-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

#chat-close-btn:hover {
  background-color: rgba(255, 85, 0, 0.15);
  border-color: var(--chat-accent);
  transform: scale(1.1);
}

#chat-close-btn:active {
  transform: scale(0.93);
}

#chat-close-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* ── MESSAGES AREA ──────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

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

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

#chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--chat-border);
  border-radius: 2px;
}

/* ── MESSAGE BUBBLES ────────────────────────────────────────── */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: msgFadeIn 0.22s ease;
}

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

.chat-message.user      { align-self: flex-end;  align-items: flex-end; }
.chat-message.assistant { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-message.user .chat-bubble {
  background-color: var(--chat-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
  background-color: var(--chat-bot-bubble);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--chat-border);
}

/* ── TYPING INDICATOR ───────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  background-color: var(--chat-bot-bubble);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
  animation: msgFadeIn 0.22s ease;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--chat-text-muted);
  animation: typingBounce 1.2s infinite ease-in-out;
}

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

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

/* ── INPUT AREA ─────────────────────────────────────────────── */
#chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--chat-border);
  background-color: var(--chat-surface-2);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  resize: none;
  background-color: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-text);
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  padding: 9px 12px;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s ease;
}

#chat-input:focus {
  border-color: var(--chat-accent);
}

#chat-input::placeholder {
  color: var(--chat-text-muted);
}

#chat-input:disabled {
  opacity: 0.5;
}

#chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
}

#chat-send-btn:hover:not(:disabled) {
  background-color: var(--chat-accent-hover);
  transform: scale(1.08);
}

#chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#chat-send-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
  margin-left: 2px;
}

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 90svh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  #chat-toggle-btn {
    bottom: 16px;
    right: 16px;
  }
}
