/* ============================================
   WHYNET Chatbot Widget — Self-contained styles
   ============================================ */

:root {
  --cb-brand: var(--color-brand, #2a188f);
  --cb-surface: var(--color-surface, #170a4a);
  --cb-mint: #bef3df;
  --cb-light: #f5f6f8;
  --cb-line: #dfe2ec;
  --cb-text: #2c2c2c;
  --cb-muted: #747986;
  --cb-shadow: 0 16px 40px rgba(23, 10, 74, 0.18);
}

/* ---- Floating Prompt Bar ---- */
#chatbot-dock {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  z-index: 60;
  width: min(540px, calc(100% - 2rem));
  height: 74px;
  padding: 12px;
  gap: 12px;
  border-radius: 9999px;
  border: 1px solid rgb(190 243 223 / 55%);
  display: flex;
  align-items: center;
  transform: translateX(-50%);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 10%), rgb(255 255 255 / 2%)),
    rgb(23 10 74 / 48%);
  backdrop-filter: blur(20px) saturate(1.35) brightness(1.04);
  -webkit-backdrop-filter: blur(20px) saturate(1.35) brightness(1.04);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 16%),
    0 10px 30px rgb(23 10 74 / 22%),
    0 2px 15px rgb(23 10 74 / 18%);
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
#chatbot-dock:focus-within {
  border-color: var(--cb-mint);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 18%),
    0 12px 34px rgb(23 10 74 / 28%),
    0 2px 15px rgb(23 10 74 / 20%);
}
#chatbot-dock[hidden] {
  display: none;
}
.chatbot-dock-icon {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cb-mint);
  font-size: 26px;
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}
#chatbot-dock-input {
  min-width: 0;
  flex: 1;
  height: 48px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 16px;
}
#chatbot-dock-input::placeholder {
  color: rgb(255 255 255 / 72%);
}
#chatbot-dock-send {
  position: relative;
  overflow: hidden;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 8%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--cb-mint);
  color: var(--cb-brand);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 55%), 0 4px 14px rgb(23 10 74 / 22%);
  transition: background-color 0.2s ease, color 0.2s ease;
}
#chatbot-dock-send::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgb(255 255 255 / 16%), rgb(42 24 143 / 7%));
  opacity: 1;
  transition: opacity 0.2s ease;
}
#chatbot-dock-send:hover {
  background-color: #9fe0c7;
  color: var(--cb-surface);
}
#chatbot-dock-send:hover::before {
  opacity: 0;
}
@media (max-width: 767px) {
  #chatbot-dock {
    bottom: 1rem;
    height: 60px;
    padding: 8px;
    gap: 8px;
  }
  .chatbot-dock-icon,
  #chatbot-dock-send {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
  }
  .chatbot-dock-icon {
    font-size: 23px;
  }
  #chatbot-dock-input {
    height: 44px;
    font-size: 14px;
  }
}

/* ---- Panel ---- */
#chatbot-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 70;
  width: 100%;
  max-width: 390px;
  height: 100dvh;
  max-height: 620px;
  background: #fff;
  border: 0;
  border-radius: 0;
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.5s ease;
  pointer-events: none;
}
#chatbot-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
@media (min-width: 768px) {
  #chatbot-panel {
    bottom: 1.25rem;
    right: 1.25rem;
    border-radius: 0;
    max-height: 600px;
  }
}

/* ---- Header ---- */
#chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--cb-surface);
  color: #fff;
  border: 1px solid #fff;
  border-bottom: 0;
  box-sizing: border-box;
  flex-shrink: 0;
}
.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 26px;
}
.chatbot-header-logo {
  width: auto;
  height: 25px;
  object-fit: contain;
}
.chatbot-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  opacity: 0.85;
}
.chatbot-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cb-mint);
}
#chatbot-minimize {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
#chatbot-minimize:hover {
  background: rgba(255, 255, 255, 0.15);
}
#chatbot-minimize .material-symbols-sharp {
  font-size: 22px;
  line-height: 1;
}

/* ---- Messages Area ---- */
#chatbot-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--cb-light);
  scroll-behavior: smooth;
}
#chatbot-messages::-webkit-scrollbar {
  width: 7px;
}
#chatbot-messages::-webkit-scrollbar-track {
  background: #d8e1f4;
  border-radius: 0;
}
#chatbot-messages::-webkit-scrollbar-thumb {
  background: #2a0880;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
#chatbot-messages {
  scrollbar-color: #2a0880 #d8e1f4;
  scrollbar-width: auto;
}
@supports selector(::-webkit-scrollbar) {
  #chatbot-messages {
    scrollbar-color: auto;
  }
}

/* Welcome message */
.cb-welcome {
  text-align: left;
  padding: 14px 16px;
  background: #fff;
  border-left: 3px solid var(--cb-mint);
  font-size: 13px;
  color: var(--cb-muted);
  line-height: 1.6;
}

/* Message bubbles */
.cb-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: cb-fade-in 0.3s ease;
}
.cb-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.cb-msg-ai {
  align-self: flex-start;
}
.cb-msg-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.cb-msg-ai .cb-msg-avatar {
  color: var(--cb-brand);
  border-radius: 50%;
}
.cb-msg-ai .cb-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cb-msg-user .cb-msg-avatar {
  display: none;
}
.cb-msg-bubble {
  padding: 10px 14px;
  border-radius: 0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.cb-msg-ai .cb-msg-bubble {
  background: #fff;
  color: var(--cb-text);
  border: 1px solid var(--cb-line);
  white-space: normal;
}
.cb-msg-user .cb-msg-bubble {
  background: var(--cb-brand);
  color: #fff;
}

/* Markdown rendered in AI responses */
.cb-markdown > :first-child { margin-top: 0; }
.cb-markdown > :last-child { margin-bottom: 0; }
.cb-markdown p { margin: 0 0 0.65em; }
.cb-markdown h1,
.cb-markdown h2,
.cb-markdown h3,
.cb-markdown h4 {
  margin: 0.9em 0 0.4em;
  color: var(--cb-text);
  font-weight: 700;
  line-height: 1.35;
}
.cb-markdown h1 { font-size: 1.3em; }
.cb-markdown h2 { font-size: 1.2em; }
.cb-markdown h3,
.cb-markdown h4 { font-size: 1.1em; }
.cb-markdown ul,
.cb-markdown ol {
  margin: 0.45em 0 0.7em;
  padding-left: 1.4em;
}
.cb-markdown ul { list-style: disc; }
.cb-markdown ol { list-style: decimal; }
.cb-markdown li + li { margin-top: 0.25em; }
.cb-markdown blockquote {
  margin: 0.65em 0;
  padding-left: 0.8em;
  border-left: 3px solid var(--cb-mint);
  color: var(--cb-muted);
}
.cb-markdown code {
  padding: 0.12em 0.3em;
  background: var(--cb-light);
  color: var(--cb-brand);
  font-family: Consolas, Monaco, monospace;
  font-size: 0.9em;
}
.cb-markdown pre {
  max-width: 100%;
  margin: 0.65em 0;
  padding: 0.75em;
  overflow-x: auto;
  background: #170a4a;
  color: #fff;
}
.cb-markdown pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}
.cb-markdown a {
  color: var(--cb-brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cb-markdown table {
  display: block;
  max-width: 100%;
  margin: 0.65em 0;
  overflow-x: auto;
  border-collapse: collapse;
}
.cb-markdown th,
.cb-markdown td {
  padding: 0.4em 0.55em;
  border: 1px solid var(--cb-line);
  text-align: left;
  white-space: nowrap;
}
.cb-markdown th { background: var(--cb-light); }

/* Typing indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.cb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a1a1aa;
  animation: cb-bounce 1.2s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }

/* Error message */
.cb-error {
  align-self: center;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 0;
  font-size: 13px;
  text-align: center;
}

/* ---- Quick Replies ---- */
#chatbot-quick-replies {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  flex-shrink: 0;
  overflow-x: auto;
  background: var(--cb-light);
  border-top: 1px solid var(--cb-line);
}
#chatbot-quick-replies::-webkit-scrollbar { display: none; }
.cb-quick-reply {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 999px;
  border: 0;
  background: #d8e1f4;
  color: var(--cb-brand);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.cb-quick-reply:hover {
  background: var(--cb-surface);
  color: #fff;
}

/* ---- Input Area ---- */
#chatbot-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid var(--cb-line);
  flex-shrink: 0;
}
#chatbot-input {
  flex: 1;
  height: 40px;
  border: 1px solid var(--cb-line);
  border-radius: 0;
  padding: 0 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
#chatbot-input:focus {
  border-color: var(--cb-brand);
  box-shadow: none;
}
#chatbot-input::placeholder {
  color: #a1a1aa;
}
#chatbot-send {
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 0;
  border: none;
  background-color: var(--cb-mint);
  color: var(--cb-brand);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}
#chatbot-send::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 28% 12%, rgb(255 255 255 / 48%), transparent 26%);
  opacity: 1;
  transition: opacity 0.2s ease;
}
#chatbot-send:hover {
  background-color: #9fe0c7;
}
#chatbot-send:hover::before {
  opacity: 0;
}
#chatbot-send:active { transform: none; }
#chatbot-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
#chatbot-dock-send .send-icon,
#chatbot-send .send-icon {
  position: relative;
  z-index: 1;
  width: 42%;
  height: 42%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: none;
  transform: translate(-1px, 1px);
}

#chatbot-dock-send:focus-visible,
#chatbot-minimize:focus-visible,
.cb-quick-reply:focus-visible,
#chatbot-send:focus-visible {
  outline: 2px solid var(--cb-mint);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  #chatbot-dock,
  #chatbot-dock-send {
    transition-duration: 0.01ms;
  }
}

/* ---- Animations ---- */
@keyframes cb-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes cb-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}
