/**
 * SSB AI Chatbot — Premium UI (ChatGPT-inspired)
 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+Sinhala:wght@400;500;600;700&family=Noto+Sans+Tamil:wght@400;500;600;700&display=swap');

:root {
  --ssb-navy: #0a192f;
  --ssb-navy-mid: #112240;
  --ssb-navy-soft: #1a3352;
  --ssb-accent: #64ffda;
  --ssb-accent-glow: rgba(100, 255, 218, 0.35);
  --ssb-gradient: linear-gradient(135deg, #0a192f 0%, #1a3352 50%, #112240 100%);
  --ssb-surface: #ffffff;
  --ssb-surface-2: #f8fafc;
  --ssb-surface-3: #f1f5f9;
  --ssb-border: rgba(15, 23, 42, 0.08);
  --ssb-text: #0f172a;
  --ssb-text-muted: #64748b;
  --ssb-user-bubble: linear-gradient(135deg, #112240 0%, #0a192f 100%);
  --ssb-bot-bubble: #ffffff;
  --ssb-shadow-lg: 0 24px 64px rgba(10, 25, 47, 0.22), 0 8px 24px rgba(10, 25, 47, 0.12);
  --ssb-shadow-sm: 0 2px 12px rgba(15, 23, 42, 0.06);
  --ssb-radius-xl: 20px;
  --ssb-radius-lg: 16px;
  --ssb-radius-md: 12px;
  --ssb-font: 'Inter', 'Noto Sans Sinhala', 'Noto Sans Tamil', system-ui, sans-serif;
  --ssb-z-launcher: 99998;
  --ssb-z-panel: 99999;
  --ssb-offset: 24px;
}

#ssb-chatbot-root {
  all: initial;
  font-family: var(--ssb-font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#ssb-chatbot-root *,
#ssb-chatbot-root *::before,
#ssb-chatbot-root *::after {
  box-sizing: border-box;
}

#ssb-chatbot-root > * {
  pointer-events: auto;
}

/* Launcher */
#ssb-chatbot-root .ssb-chatbot-launcher {
  position: fixed;
  left: var(--ssb-offset);
  bottom: var(--ssb-offset);
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: var(--ssb-gradient);
  color: var(--ssb-accent);
  box-shadow: var(--ssb-shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  z-index: var(--ssb-z-launcher);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

#ssb-chatbot-root .ssb-chatbot-launcher::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--ssb-accent-glow);
  opacity: 0;
  transition: opacity 0.3s;
  z-index: -1;
}

#ssb-chatbot-root .ssb-chatbot-launcher:hover {
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 20px 48px rgba(100, 255, 218, 0.25);
}

#ssb-chatbot-root .ssb-chatbot-launcher:hover::before {
  opacity: 1;
}

.ssb-chatbot-launcher__badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 10px;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  animation: ssb-pulse-badge 2s infinite;
}

.ssb-chatbot-launcher__badge.is-visible {
  display: flex;
}

@keyframes ssb-pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Panel */
#ssb-chatbot-root .ssb-chatbot-panel {
  position: fixed;
  left: var(--ssb-offset);
  bottom: var(--ssb-offset);
  width: 400px;
  max-width: calc(100vw - 32px);
  height: min(640px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  background: var(--ssb-surface-2);
  border-radius: var(--ssb-radius-xl);
  box-shadow: var(--ssb-shadow-lg);
  border: 1px solid var(--ssb-border);
  overflow: hidden;
  z-index: var(--ssb-z-panel);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.35s;
  backdrop-filter: blur(12px);
}

#ssb-chatbot-root .ssb-chatbot-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ssb-chatbot-panel.is-minimized .ssb-chatbot-panel__body,
.ssb-chatbot-panel.is-minimized .ssb-chatbot-panel__footer {
  display: none;
}

/* Header */
.ssb-chatbot-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--ssb-gradient);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ssb-chatbot-header__avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(100, 255, 218, 0.15);
  border: 1px solid rgba(100, 255, 218, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ssb-chatbot-header__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ssb-chatbot-header__info {
  flex: 1;
  min-width: 0;
}

.ssb-chatbot-header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.ssb-chatbot-header__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.ssb-chatbot-header__status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: ssb-pulse-online 2s infinite;
}

@keyframes ssb-pulse-online {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.ssb-chatbot-header__actions {
  display: flex;
  gap: 4px;
}

.ssb-chatbot-header__btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.ssb-chatbot-header__btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: var(--ssb-accent);
}

/* Body + scrollbar */
.ssb-chatbot-panel__body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, #eef2f7 0%, #f8fafc 40%, #f1f5f9 100%);
}

.ssb-chatbot-messages-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 12px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.ssb-chatbot-messages-wrap::-webkit-scrollbar {
  width: 6px;
}

.ssb-chatbot-messages-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.ssb-chatbot-messages-wrap::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.ssb-chatbot-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Messages */
.ssb-chatbot-msg {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 92%;
  animation: ssb-msg-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes ssb-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ssb-chatbot-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
  margin-left: auto;
}

.ssb-chatbot-msg--bot {
  align-self: flex-start;
}

.ssb-chatbot-msg__avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.ssb-chatbot-msg--bot .ssb-chatbot-msg__avatar {
  background: var(--ssb-surface);
  color: var(--ssb-navy-mid);
  border: 1px solid var(--ssb-border);
  box-shadow: var(--ssb-shadow-sm);
}

.ssb-chatbot-msg--user .ssb-chatbot-msg__avatar {
  background: var(--ssb-surface-3);
  color: var(--ssb-text-muted);
}

.ssb-chatbot-msg__content {
  min-width: 0;
  max-width: 100%;
}

.ssb-chatbot-msg__bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  letter-spacing: 0.01em;
}

/* Sinhala / Tamil readability */
.ssb-chatbot-msg__bubble:lang(si),
.ssb-chatbot-msg__bubble.ssb-lang-si {
  font-family: 'Noto Sans Sinhala', 'Inter', sans-serif;
  line-height: 1.85;
  font-size: 15px;
}

.ssb-chatbot-msg__bubble:lang(ta),
.ssb-chatbot-msg__bubble.ssb-lang-ta {
  font-family: 'Noto Sans Tamil', 'Inter', sans-serif;
  line-height: 1.8;
  font-size: 15px;
}

.ssb-chatbot-msg--user .ssb-chatbot-msg__bubble {
  background: var(--ssb-user-bubble);
  color: #f8fafc;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px rgba(10, 25, 47, 0.2);
}

.ssb-chatbot-msg--bot .ssb-chatbot-msg__bubble {
  background: var(--ssb-bot-bubble);
  color: var(--ssb-text);
  border: 1px solid var(--ssb-border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--ssb-shadow-sm);
}

/* Markdown in bubbles */
.ssb-chatbot-msg__bubble p {
  margin: 0 0 0.65em;
}

.ssb-chatbot-msg__bubble p:last-child {
  margin-bottom: 0;
}

.ssb-chatbot-msg__bubble ul,
.ssb-chatbot-msg__bubble ol {
  margin: 0.4em 0 0.65em;
  padding-left: 1.25em;
}

.ssb-chatbot-msg__bubble li {
  margin-bottom: 0.35em;
  line-height: 1.6;
}

.ssb-chatbot-msg__bubble strong {
  font-weight: 600;
  color: inherit;
}

.ssb-chatbot-msg__bubble code {
  font-family: ui-monospace, monospace;
  font-size: 0.9em;
  background: rgba(15, 23, 42, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.ssb-chatbot-msg--user .ssb-chatbot-msg__bubble code {
  background: rgba(255, 255, 255, 0.12);
}

.ssb-chatbot-msg__bubble pre {
  margin: 0.5em 0;
  padding: 12px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}

.ssb-chatbot-msg__bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.ssb-chatbot-msg__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 0 4px;
}

.ssb-chatbot-msg--user .ssb-chatbot-msg__meta {
  justify-content: flex-end;
}

.ssb-chatbot-msg__time {
  font-size: 11px;
  color: var(--ssb-text-muted);
}

.ssb-chatbot-msg__copy {
  position: relative;
  border: none;
  background: transparent;
  color: var(--ssb-text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

.ssb-chatbot-msg__copy:hover {
  background: var(--ssb-surface-3);
  color: var(--ssb-navy);
}

.ssb-chatbot-msg__copy.is-copied {
  color: #059669;
}

.ssb-chatbot-msg__copy[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: var(--ssb-navy);
  color: #fff;
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.ssb-chatbot-msg__copy[data-tooltip]:hover::after {
  opacity: 1;
}

/* Typing */
.ssb-chatbot-typing-row {
  display: none;
  align-items: flex-end;
  gap: 10px;
  padding: 0 4px 8px;
}

.ssb-chatbot-typing-row.is-visible {
  display: flex;
  animation: ssb-msg-in 0.3s ease;
}

.ssb-chatbot-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 18px;
  background: var(--ssb-surface);
  border: 1px solid var(--ssb-border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  box-shadow: var(--ssb-shadow-sm);
}

.ssb-chatbot-typing span {
  width: 8px;
  height: 8px;
  background: #94a3b8;
  border-radius: 50%;
  animation: ssb-typing-dot 1.4s infinite ease-in-out both;
}

.ssb-chatbot-typing span:nth-child(1) { animation-delay: 0s; }
.ssb-chatbot-typing span:nth-child(2) { animation-delay: 0.16s; }
.ssb-chatbot-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes ssb-typing-dot {
  0%, 80%, 100% { transform: scale(0.65); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Skeleton */
.ssb-chatbot-skeleton {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: var(--ssb-surface);
  border-radius: 18px;
  border: 1px solid var(--ssb-border);
  max-width: 75%;
}

.ssb-chatbot-skeleton.is-visible {
  display: flex;
}

.ssb-chatbot-skeleton span {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: ssb-shimmer 1.2s infinite;
}

.ssb-chatbot-skeleton span:nth-child(1) { width: 100%; }
.ssb-chatbot-skeleton span:nth-child(2) { width: 85%; }
.ssb-chatbot-skeleton span:nth-child(3) { width: 60%; }

@keyframes ssb-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Suggestions */
.ssb-chatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.ssb-chatbot-suggestion {
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ssb-navy);
  background: var(--ssb-surface);
  border: 1px solid var(--ssb-border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--ssb-shadow-sm);
}

.ssb-chatbot-suggestion:hover {
  border-color: var(--ssb-accent-dark, #4bc9ab);
  background: rgba(100, 255, 218, 0.08);
  transform: translateY(-1px);
}

/* Footer */
.ssb-chatbot-panel__footer {
  flex-shrink: 0;
  padding: 12px 14px 14px;
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid var(--ssb-border);
  backdrop-filter: blur(8px);
}

.ssb-chatbot-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 6px;
  background: var(--ssb-surface);
  border: 1px solid var(--ssb-border);
  border-radius: var(--ssb-radius-lg);
  box-shadow: var(--ssb-shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ssb-chatbot-input-row:focus-within {
  border-color: rgba(17, 34, 64, 0.25);
  box-shadow: 0 0 0 3px rgba(100, 255, 218, 0.15);
}

.ssb-chatbot-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 8px;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--ssb-text);
  resize: none;
  max-height: 120px;
  min-height: 24px;
  caret-color: var(--ssb-navy-mid);
}

.ssb-chatbot-input:focus {
  outline: none;
}

.ssb-chatbot-input::placeholder {
  color: #94a3b8;
}

.ssb-chatbot-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--ssb-radius-md);
  background: var(--ssb-gradient);
  color: var(--ssb-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.ssb-chatbot-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px var(--ssb-accent-glow);
}

.ssb-chatbot-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.ssb-chatbot-powered {
  margin: 10px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--ssb-text-muted);
}

/* Mobile */
@media (max-width: 576px) {
  :root {
    --ssb-offset: 0;
  }

  #ssb-chatbot-root .ssb-chatbot-panel.is-open {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  #ssb-chatbot-root .ssb-chatbot-launcher {
    left: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }

  .ssb-chatbot-messages-wrap {
    padding: 16px 12px 8px;
  }

  .ssb-chatbot-msg__bubble {
    font-size: 15px;
  }
}
