/* ===============================
   WordPress Plugin / styles.css — Refined & Isolated
   =============================== */

/* 
   We wrap everything in #chat-widget-root to isolate from theme styles.
   We also use high specificity to override any theme defaults.
*/

#chat-widget-root {
  /* CSS Variables Scope */
  --tsa-accent: #00a878;
  /* Updated color */
  --tsa-bg: #f4f6fb;
  --tsa-card: #ffffff;
  --tsa-muted: #69707d;
  --tsa-bot-bg: #f1f5ff;
  --tsa-user-bg: #e6ffef;
  --tsa-bubble-radius: 14px;
  --tsa-widget-width: 360px;
  --tsa-launcher-size: 64px;

  /* Reset inheritance */
  all: initial;
  font-family: 'Inter', sans-serif;
  /* Fallback to system sans if Inter not loaded */
  line-height: 1.5;
  color: #0f1724;
}

/* Reset box-sizing for all children */
#chat-widget-root * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: inherit;
}

/* =========== WIDGET LAUNCHER ============ */
#chat-widget-root .chat-launcher {
  position: fixed;
  right: 30px;
  /* Moved slightly left */
  bottom: 100px;
  /* Moved up */
  z-index: 2147483647;
  /* Max z-index */
  width: var(--tsa-launcher-size);
  height: var(--tsa-launcher-size);
  border-radius: 50%;
  background: var(--tsa-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0, 168, 120, 0.25), 0 4px 12px rgba(16, 24, 40, 0.12);
  cursor: pointer;
  transition: transform 160ms ease;
  border: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

#chat-widget-root .chat-launcher:hover {
  transform: translateY(-3px);
}

#chat-widget-root .chat-launcher svg {
  width: 26px;
  height: 26px;
  display: block;
}

/* =========== PANEL ============ */
#chat-widget-root .chat-panel {
  position: fixed;
  right: 30px;
  /* Aligned with launcher */
  bottom: calc(90px + var(--tsa-launcher-size) + 12px);
  /* Aligned with launcher */
  width: var(--tsa-widget-width);
  /* Fix height issues */
  height: 500px;
  max-height: 70vh;
  border-radius: 12px;
  background: var(--tsa-card);
  box-shadow: 0 18px 50px rgba(16, 24, 40, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 2147483647;
  transform-origin: 100% 100%;
  animation: tsaPanelIn 200ms ease;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

@keyframes tsaPanelIn {
  from {
    transform: translateY(8px) scale(.99);
    opacity: 0
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1
  }
}

/* HEADER */
#chat-widget-root .chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #f1f3f8;
  background: #fff;
  flex-shrink: 0;
  /* Prevent header from shrinking */
}

#chat-widget-root .chat-header .title {
  font-size: 15px;
  font-weight: 600;
  color: #0f1724;
}

#chat-widget-root .chat-header .sub {
  font-size: 12px;
  color: var(--tsa-muted);
}

#chat-widget-root .chat-header .close {
  font-size: 18px !important;
  line-height: 1;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* BODY */
#chat-widget-root .chat-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Scroll fix */
  overflow-y: auto !important;
  overflow-x: hidden;
  flex-grow: 1;
  /* Take remaining space */
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.96));
  overscroll-behavior: contain;
  /* Prevent body scroll when widget scrolls */
}

/* message row */
#chat-widget-root .msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
}

#chat-widget-root .msg-row.bot {
  justify-content: flex-start;
}

#chat-widget-root .msg-row.user {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

/* avatar */
#chat-widget-root .avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.06);
  background: #ffffff;
}

#chat-widget-root .avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
}

/* Hide repeated bot avatars */
#chat-widget-root .msg-row.bot+.msg-row.bot .avatar {
  visibility: hidden;
  width: 0;
  margin-right: 0;
  flex-basis: 0;
  padding: 0;
}

/* BUBBLES */
#chat-widget-root .bubble {
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--tsa-bubble-radius);
  font-size: 14px;
  line-height: 1.4;
  animation: tsaBubbleIn 220ms ease;
}

@keyframes tsaBubbleIn {
  from {
    transform: translateY(6px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#chat-widget-root .bot .bubble {
  background: var(--tsa-bot-bg);
  color: #0f1724;
  border-bottom-left-radius: 2px;
}

#chat-widget-root .user .bubble {
  background: var(--tsa-user-bg);
  color: #064e3b;
  border-bottom-right-radius: 2px;
  white-space: nowrap;
  display: inline-block;
  width: auto;
  min-width: min-content;
}

/* SCROLL INDICATORS */
#chat-widget-root .scroll-indicator {
  position: absolute;
  right: 12px;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  border: 1px solid rgba(0, 0, 0, 0.05);
  color: var(--tsa-accent);
}

#chat-widget-root .scroll-indicator.visible {
  opacity: 1;
  pointer-events: auto;
}

#chat-widget-root .scroll-indicator.up {
  top: 60px;
}

#chat-widget-root .scroll-indicator.down {
  bottom: 140px;
}

#chat-widget-root .scroll-indicator svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* TYPING */
#chat-widget-root .typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  height: 20px;
  padding: 0 4px;
}

#chat-widget-root .typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: tsaBounce 1s infinite ease-in-out;
}

#chat-widget-root .typing .dot:nth-child(2) {
  animation-delay: 0.12s;
}

#chat-widget-root .typing .dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes tsaBounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: .45;
  }

  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Options cards */
#chat-widget-root .options-container {
  flex-shrink: 0;
}

#chat-widget-root .options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

#chat-widget-root .option {
  background: #fbfbff;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #eef2ff;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: #1f2d6b;
  transition: transform 140ms ease;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.04);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  /* Ensure links look like buttons */
  white-space: nowrap;
}

#chat-widget-root .option:hover {
  transform: translateY(-2px);
  background: #f0f4ff;
}

#chat-widget-root .option.whatsapp-option {
  background: #25d366;
  color: #ffffff;
  border-color: #1da851;
}

#chat-widget-root .option.whatsapp-option svg {
  fill: currentColor;
}

/* FOOTER */
#chat-widget-root .chat-footer {
  font-size: 11px;
  color: var(--tsa-muted);
  padding: 8px 12px;
  border-top: 1px solid #f1f3f8;
  text-align: center;
  flex-shrink: 0;
  background: #fff;
}

/* YOUTUBE CARDS */
#chat-widget-root .youtube-card-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

#chat-widget-root .youtube-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid rgba(16, 24, 40, 0.04);
  text-decoration: none;
  color: inherit;
}

#chat-widget-root .youtube-card img {
  width: 80px;
  height: 45px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

#chat-widget-root .youtube-card .title {
  font-weight: 600;
  font-size: 13px;
  color: #0f1724;
  margin-bottom: 2px;
}

#chat-widget-root .youtube-card .url {
  font-size: 11px;
  color: #2563eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* DIALOG */
#chat-widget-root .widget-online-dialog {
  font-family: 'Inter', sans-serif;
}

/* SCROLLBAR */
#chat-widget-root .chat-body::-webkit-scrollbar {
  width: 6px;
}

#chat-widget-root .chat-body::-webkit-scrollbar-thumb {
  background: rgba(16, 24, 40, 0.1);
  border-radius: 8px;
}

/* ===============================
   MOBILE OPTIMIZATIONS
   =============================== */
@media (max-width: 480px) {
  #chat-widget-root {
    --tsa-widget-width: 300px;
    /* Reduced width */
    --tsa-launcher-size: 56px;
  }

  #chat-widget-root .chat-panel {
    right: 16px;
    bottom: calc(80px + var(--tsa-launcher-size) + 10px);
    /* Adjusted for mobile launcher pos */
    width: calc(100vw - 32px);
    /* Responsive width with margins */
    max-width: 340px;
    height: 60vh;
    /* Reduced height to avoid masking too much */
    max-height: 450px;
  }

  #chat-widget-root .chat-launcher {
    right: 16px;
    bottom: 80px;
    /* Keep elevated on mobile too */
  }

  #chat-widget-root .chat-body {
    padding: 10px;
  }

  #chat-widget-root .bubble {
    font-size: 13px;
    padding: 8px 12px;
  }
}