/* ============================================================
   PageChatWidget — CSS  v1.0.0
   Bottom-LEFT positioned widget — never overlaps the main
   chatbot widget which sits at bottom-right.

   Colour scheme: TopTeen brand purple — matches the main site

   SECTIONS:
     1.  CSS Variables
     2.  Scoped Reset
     3.  FAB Button  (pill, bottom-left)
     4.  Chat Window
     5.  Header
     6.  Init Overlay
     7.  Messages Area
     8.  Message Bubbles & Suggestions
     9.  Markdown Styles
    10.  Typing Indicator
    11.  Input Area
    12.  Fullscreen Mode
    13.  Animations & Transitions
    14.  Mobile Responsive
============================================================ */


/* ============================================================
   1. CSS VARIABLES  — tweak theme here
============================================================ */
#pc-root {
  /* Brand — TopTeen brand purple, matching the main site */
  --pc-primary:        #3f37c9;
  --pc-primary-dark:   #3430a8;
  --pc-primary-rgb:    63, 55, 201;

  /* Bubbles */
  --pc-user-bg:        #3f37c9;
  --pc-user-text:      #ffffff;
  --pc-bot-bg:         #EEEDFF;
  --pc-bot-text:       #1F2937;

  /* Surfaces */
  --pc-surface:        #ffffff;
  --pc-header-bg:      #ffffff;
  --pc-header-border:  #ECEEFF;
  --pc-input-bg:       #F5F5FE;
  --pc-input-border:   #DDDEFF;

  /* Text */
  --pc-text-primary:   #111827;
  --pc-text-muted:     #9CA3AF;
  --pc-text-subtle:    #6B7280;

  /* Shadows */
  --pc-shadow-sm:      0 2px 8px  rgba(0,0,0,.08);
  --pc-shadow-lg:      0 24px 64px rgba(0,0,0,.14), 0 4px 16px rgba(0,0,0,.08);

  /* Radii */
  --pc-radius-window:  24px;
  --pc-radius-bubble:  20px;
  --pc-radius-input:   16px;

  /* Sizes */
  --pc-window-w:       450px;
  --pc-window-h:       620px;
  --pc-fab-h:          48px;
  --pc-header-h:       68px;
}


/* ============================================================
   2. SCOPED RESET
============================================================ */
#pc-root *,
#pc-root *::before,
#pc-root *::after { box-sizing: border-box; }

#pc-root {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--pc-text-primary);
}

#pc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 2147483644;
  opacity: 1;
  transition: opacity .2s ease;
}

#pc-backdrop.pc-hide {
  opacity: 0;
  pointer-events: none;
}


/* ============================================================
   3. FAB BUTTON  — pill shape, fixed bottom-left
============================================================ */
#pc-fab {
  position: fixed;
  bottom: 28px;
  left:   28px;
  z-index: 2147483646;

  display: inline-flex;
  align-items: center;
  gap: 9px;

  height:      var(--pc-fab-h);
  padding:     0 20px 0 16px;
  border-radius: calc(var(--pc-fab-h) / 2);

  background:  var(--pc-primary);
  border:      none;
  cursor:      pointer;
  outline:     none;

  color:       white;
  font-size:   13.5px;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;

  box-shadow: 0 6px 24px rgba(var(--pc-primary-rgb), .40);
  transition: transform .25s ease, box-shadow .25s ease, background .2s;
}

#pc-fab:hover {
  transform:  scale(1.04) translateY(-2px);
  box-shadow: 0 8px 32px rgba(var(--pc-primary-rgb), .55);
  background: var(--pc-primary-dark);
}

#pc-fab img {
  width:  22px;
  height: 22px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

#pc-fab-label { pointer-events: none; }

/* Unread badge */
#pc-badge {
  position:    absolute;
  top:    -4px;
  right:  -4px;
  min-width: 20px;
  height:    20px;
  border-radius: 10px;
  background: #EF4444;
  color:      white;
  font-size:  10px;
  font-weight: 700;
  display:    flex;
  align-items: center;
  justify-content: center;
  padding:    0 5px;
  border:     2px solid white;
}

#pc-badge.pc-hide { display: none !important; }
.pc-hide { display: none !important; }


/* ============================================================
   4. CHAT WINDOW — opens upward from bottom-left
============================================================ */
#pc-win {
  position: fixed;
  bottom:   92px;
  left:     28px;
  width:    var(--pc-window-w);
  height:   var(--pc-window-h);

  background:    var(--pc-surface);
  border-radius: var(--pc-radius-window);
  box-shadow:    var(--pc-shadow-lg);
  border:        1px solid rgba(0,0,0,.06);
  z-index:       2247483645;

  display:        flex;
  flex-direction: column;
  overflow:       hidden;

  transform-origin: bottom left;
  transition: transform .32s cubic-bezier(.34,1.56,.64,1),
              opacity   .25s ease,
              width     .3s ease,
              height    .3s ease,
              top       .3s ease,
              left      .3s ease,
              right     .3s ease,
              bottom    .3s ease,
              border-radius .3s ease;
              height: clamp(400px, 70vh, 700px);
}

#pc-win.pc-hide {
  transform:      scale(.65) translateY(12px);
  opacity:        0;
  pointer-events: none;
}


/* ============================================================
   5. HEADER
============================================================ */
#pc-hdr {
  background:  var(--pc-header-bg);
  height:      var(--pc-header-h);
  min-height:  var(--pc-header-h);
  padding:     0 18px;
  display:     flex;
  align-items: center;
  gap:         12px;
  flex-shrink: 0;
  border-bottom: 1.5px solid var(--pc-header-border);
}

/* Avatar circle */
#pc-hdr-avatar {
  width:  40px;
  height: 40px;
  border-radius: 50%;
  background: var(--pc-primary);
  display:    flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(var(--pc-primary-rgb), .30);
}

#pc-hdr-avatar svg {
  width:  20px;
  height: 20px;
  fill:   white;
}

#pc-hdr-avatar img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

#pc-hdr-info { flex: 1; min-width: 0; }

#pc-hdr-name {
  font-size:   15px;
  font-weight: 700;
  color:       var(--pc-text-primary);
  white-space: nowrap;
  overflow:    hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

/* Status row */
#pc-hdr-status {
  display:     flex;
  align-items: center;
  gap:         5px;
  margin-top:  2px;
}

#pc-status-dot {
  width:  7px;
  height: 7px;
  border-radius: 50%;
  background:  #4ADE80;
  flex-shrink: 0;
  transition:  background .3s;
}

#pc-status-dot.connecting { background: #FCD34D; animation: pc-pulse 1.5s infinite; }
#pc-status-dot.offline    { background: #F87171; }
#pc-status-dot.online     { background: #4ADE80; }

#pc-status-txt {
  font-size: 11.5px;
  color:     var(--pc-text-subtle);
}

/* Header action buttons */
#pc-hdr-actions {
  display:     flex;
  gap:         4px;
  flex-shrink: 0;
}

.pc-hdr-btn {
  width:  34px;
  height: 34px;
  border-radius: 10px;
  background: transparent;
  border:     none;
  cursor:     pointer;
  display:    flex;
  align-items: center;
  justify-content: center;
  color:      var(--pc-text-subtle);
  transition: background .18s, color .18s;
  outline:    none;
}

.pc-hdr-btn:hover {
  background: var(--pc-bot-bg);
  color:      var(--pc-primary);
}

.pc-hdr-btn svg {
  width:  17px;
  height: 17px;
  fill:   currentColor;
}


/* ============================================================
   6. INIT OVERLAY — visible while page is being scraped/sent
============================================================ */
#pc-overlay {
  /* absolute inside #pc-win so it covers msg+input area */
  position: absolute;
  top:      var(--pc-header-h);
  left:  0; right: 0; bottom: 0;

  background: var(--pc-surface);
  display:    flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap:        16px;
  z-index:    5;
  padding:    40px 30px;
  text-align: center;
}

.pc-overlay-spinner svg {
  width:  52px;
  height: 52px;
  fill:   var(--pc-primary);
  animation: pc-spin 1s linear infinite;
}

.pc-overlay-title {
  font-size:   17px;
  font-weight: 700;
  color:       var(--pc-text-primary);
}

.pc-overlay-sub {
  font-size: 13px;
  color:     var(--pc-text-subtle);
}

.pc-overlay-icon-err svg {
  width:  44px;
  height: 44px;
  fill:   #EF4444;
}


/* ============================================================
   7. MESSAGES AREA
============================================================ */
#pc-msgs {
  flex:       1;
  overflow-y: auto;
  padding:    20px 18px 10px;
  display:    flex;
  flex-direction: column;
  gap:        14px;
  scroll-behavior: smooth;
  background: var(--pc-surface);
}

#pc-msgs::-webkit-scrollbar       { width: 4px; }
#pc-msgs::-webkit-scrollbar-track { background: transparent; }
#pc-msgs::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }


/* ============================================================
   8. MESSAGE BUBBLES & SUGGESTIONS
============================================================ */
.pc-msg {
  display:        flex;
  flex-direction: column;
  max-width:      100%;
  animation:      pc-fadein .28s ease;
}

.pc-msg.pc-user { align-items: flex-end;   }
.pc-msg.pc-bot  { align-items: flex-start; }

/* Bubble */
.pc-bubble {
  max-width:   78%;
  padding:     12px 16px;
  font-size:   14.5px;
  line-height: 1.65;
  word-break:  break-word;
}

.pc-msg.pc-user .pc-bubble {
  background:    var(--pc-user-bg);
  color:         var(--pc-user-text);
  border-radius: var(--pc-radius-bubble) var(--pc-radius-bubble) 6px var(--pc-radius-bubble);
  box-shadow:    0 2px 12px rgba(var(--pc-primary-rgb), .25);
}

.pc-msg.pc-bot .pc-bubble {
  background:    var(--pc-bot-bg);
  color:         var(--pc-bot-text);
  border-radius: 6px var(--pc-radius-bubble) var(--pc-radius-bubble) var(--pc-radius-bubble);
}

/* Timestamp */
.pc-ts {
  font-size:  11px;
  color:      var(--pc-text-muted);
  margin-top: 4px;
  padding:    0 4px;
}

/* Suggested follow-up questions */
.pc-suggestions {
  display:   flex;
  flex-wrap: wrap;
  gap:       8px;
  padding:   4px 0 6px;
  animation: pc-fadein .35s ease;
}

.pc-suggestion-btn {
  display:       inline-block;
  padding:       7px 14px;
  border-radius: 20px;
  border:        1.5px solid rgba(var(--pc-primary-rgb), .35);
  background:    transparent;
  color:         var(--pc-primary);
  font-size:     13px;
  font-family:   inherit;
  font-weight:   500;
  cursor:        pointer;
  text-align:    left;
  word-break:    break-word;
  transition:    background .18s, border-color .18s, transform .12s;
  outline:       none;
}

.pc-suggestion-btn:hover {
  background:   rgba(var(--pc-primary-rgb), .08);
  border-color: var(--pc-primary);
  transform:    translateY(-1px);
}

.pc-suggestion-btn:active {
  transform:  translateY(0);
  background: rgba(var(--pc-primary-rgb), .14);
}

/* Error strip */
.pc-err-msg {
  display:     flex;
  align-items: flex-start;
  gap:         8px;
  background:  #FEF2F2;
  border:      1px solid #FECACA;
  border-radius: 10px;
  padding:     10px 12px;
  font-size:   13px;
  color:       #B91C1C;
  animation:   pc-fadein .3s ease;
}

.pc-err-msg svg {
  width:      16px;
  height:     16px;
  fill:       #EF4444;
  flex-shrink: 0;
  margin-top: 1px;
}


/* ============================================================
   9. MARKDOWN STYLES  (inside .pc-md bot bubbles)
============================================================ */
.pc-md h1, .pc-md h2, .pc-md h3,
.pc-md h4, .pc-md h5, .pc-md h6 {
  font-weight: 700;
  color:       #111827;
  line-height: 1.3;
  margin:      14px 0 6px;
}

.pc-md h1:first-child, .pc-md h2:first-child,
.pc-md h3:first-child, .pc-md h4:first-child { margin-top: 0; }

.pc-md h1 { font-size: 1.25em; border-bottom: 2px solid #D6D4F7; padding-bottom: 5px; }
.pc-md h2 { font-size: 1.12em; border-bottom: 1px solid #D6D4F7; padding-bottom: 4px; }
.pc-md h3 { font-size: 1.05em; }

.pc-md p          { margin: 6px 0; }
.pc-md p:first-child { margin-top: 0; }
.pc-md p:last-child  { margin-bottom: 0; }

.pc-md strong { font-weight: 700; color: #111827; }
.pc-md em     { font-style: italic; color: #374151; }
.pc-md del    { text-decoration: line-through; color: #6B7280; }

.pc-md ul, .pc-md ol { padding-left: 22px; margin: 8px 0; }
.pc-md li             { margin: 4px 0; }
.pc-md ul li::marker  { color: var(--pc-primary); }
.pc-md ol li::marker  { color: var(--pc-primary); font-weight: 700; }

.pc-md a {
  color:           var(--pc-primary);
  text-decoration: none;
  border-bottom:   1px solid #C4C0F0;
  transition:      border-color .2s;
  word-break:      break-all;
}
.pc-md a:hover { border-bottom-color: var(--pc-primary); }

/* Inline code */
.pc-md :not(pre) > code {
  font-family:   'Courier New', monospace;
  font-size:     .87em;
  background:    #E8E7FA;
  color:         #3430a8;
  padding:       1px 5px;
  border-radius: 4px;
}

/* Code block wrapper (from custom renderer) */
.pc-code-block { position: relative; margin: 10px 0; }

.pc-code-block pre {
  background:    #1E1E2E;
  border-radius: 10px;
  padding:       14px 16px;
  overflow-x:    auto;
  margin:        0;
}

.pc-code-block pre code {
  background:  none !important;
  color:       #CDD6F4 !important;
  padding:     0 !important;
  font-size:   .85em;
  font-family: 'Courier New', monospace;
}

.pc-copy-btn {
  position:   absolute;
  top:        8px;
  right:      8px;
  padding:    3px 8px;
  background: rgba(255,255,255,.10);
  color:      #CDD6F4;
  border:     1px solid rgba(255,255,255,.18);
  border-radius: 5px;
  font-size:  11px;
  cursor:     pointer;
  transition: background .2s;
  font-family: inherit;
}
.pc-copy-btn:hover { background: rgba(255,255,255,.22); }

/* Blockquote */
.pc-md blockquote {
  border-left:   3px solid var(--pc-primary);
  margin:        8px 0;
  padding:       8px 14px;
  background:    #EEEDFF;
  border-radius: 0 8px 8px 0;
  color:         #374151;
  font-style:    italic;
}

/* Tables */
.pc-table-wrap {
  overflow-x:    auto;
  margin:        10px 0;
  border-radius: 8px;
  box-shadow:    0 1px 4px rgba(0,0,0,.10);
}

.pc-md table {
  width:           100%;
  border-collapse: collapse;
  font-size:       .88em;
}

.pc-md th {
  background:   var(--pc-primary);
  color:        white;
  padding:      8px 12px;
  text-align:   left;
  font-weight:  600;
  white-space:  nowrap;
}

.pc-md td {
  padding:      7px 12px;
  border-bottom: 1px solid #E5E7EB;
  color:        #374151;
}

.pc-md tr:last-child td       { border-bottom: none; }
.pc-md tr:nth-child(even) td  { background: #F9FAFB; }

/* Horizontal rule */
.pc-md hr {
  border:      none;
  border-top:  1px solid #D6D4F7;
  margin:      12px 0;
}


/* ============================================================
   10. TYPING INDICATOR
============================================================ */
#pc-ind-area {
  padding:        4px 18px 6px;
  flex-shrink:    0;
  display:        flex;
  flex-direction: column;
  gap:            6px;
  background:     var(--pc-surface);
}

.pc-indicator {
  display:     inline-flex;
  align-items: center;
  gap:         7px;
  padding:     6px 12px;
  border-radius: 20px;
  font-size:   12.5px;
  animation:   pc-fadein .3s ease;
  align-self:  flex-start;
  background:  var(--pc-surface);
  border:      1px solid var(--pc-input-border);
  color:       var(--pc-text-subtle);
  box-shadow:  var(--pc-shadow-sm);
}

.pc-dot-row {
  display:     flex;
  gap:         3px;
  align-items: center;
}

.pc-dot-row span {
  width:  6px;
  height: 6px;
  border-radius: 50%;
  background: #8B87D8;
  animation:  pc-dotbounce 1.2s infinite;
}

.pc-dot-row span:nth-child(2) { animation-delay: .2s; }
.pc-dot-row span:nth-child(3) { animation-delay: .4s; }


/* ============================================================
   11. INPUT AREA
============================================================ */
#pc-input-area {
  padding:     12px 18px 16px;
  background:  var(--pc-surface);
  flex-shrink: 0;
  border-top:  1.5px solid var(--pc-header-border);
}

#pc-input-row {
  display:     flex;
  align-items: flex-end;
  gap:         10px;
}

#pc-input {
  flex:         1;
  padding:      12px 16px;
  border:       1.5px solid var(--pc-input-border);
  border-radius: var(--pc-radius-input);
  font-size:    14px;
  line-height:  1.5;
  font-family:  inherit;
  resize:       none;
  outline:      none;
  max-height:   120px;
  min-height:   46px;
  height:       46px;
  color:        var(--pc-text-primary);
  background:   var(--pc-input-bg);
  overflow-y:   auto;
  transition:   border-color .2s, background .2s, box-shadow .2s;
}

#pc-input:focus {
  border-color: var(--pc-primary);
  background:   white;
  box-shadow:   0 0 0 3px rgba(var(--pc-primary-rgb), .12);
}

#pc-input::placeholder { color: var(--pc-text-muted); }
#pc-input:disabled     { opacity: .5; cursor: not-allowed; }

/* Send button */
#pc-send {
  width:  46px;
  height: 46px;
  border-radius: 50%;
  background:  var(--pc-primary);
  border:      none;
  cursor:      pointer;
  flex-shrink: 0;
  display:     flex;
  align-items: center;
  justify-content: center;
  box-shadow:  0 3px 14px rgba(var(--pc-primary-rgb), .35);
  transition:  transform .2s, box-shadow .2s, opacity .2s, background .2s;
  outline:     none;
}

#pc-send:hover:not(:disabled) {
  transform:  scale(1.07);
  background: var(--pc-primary-dark);
  box-shadow: 0 5px 18px rgba(var(--pc-primary-rgb), .50);
}

#pc-send:active:not(:disabled) { transform: scale(.95); }

#pc-send:disabled { opacity: .4; cursor: not-allowed; }

#pc-send svg {
  width:     18px;
  height:    18px;
  fill:      white;
  transform: translateX(1px);
}

#pc-input-hint {
  font-size:  11px;
  color:      var(--pc-text-muted);
  text-align: right;
  margin-top: 6px;
}


/* ============================================================
   12. FULLSCREEN MODE  (20 % margin on every side)
============================================================ */
#pc-win.pc-fullscreen {
  top:    10% !important;
  left:   10% !important;
  right:  10% !important;
  bottom: 10% !important;
  width:  80% !important;
  height: 80% !important;
  border-radius: var(--pc-radius-window) !important;
  transform-origin: center center !important;
}

#pc-win.pc-fullscreen.pc-hide {
  transform: scale(.88);
  opacity:   0;
}


/* ============================================================
   13. ANIMATIONS & TRANSITIONS
============================================================ */
@keyframes pc-fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

@keyframes pc-pulse {
  0%, 100% { opacity: 1;  }
  50%       { opacity: .3; }
}

@keyframes pc-dotbounce {
  0%, 100% { transform: translateY(0);    }
  50%       { transform: translateY(-5px); }
}

@keyframes pc-spin {
  from { transform: rotate(0deg);   }
  to   { transform: rotate(360deg); }
}


/* ============================================================
   14. MOBILE RESPONSIVE
============================================================ */
@media (max-width: 480px) {
  #pc-win {
    width:  100vw  !important;
    height: 100dvh !important;
    bottom: 0      !important;
    left:   0      !important;
    right:  0      !important;
    border-radius: 0 !important;
  }

  #pc-win.pc-fullscreen {
    top:    0 !important;
    left:   0 !important;
    right:  0 !important;
    bottom: 0 !important;
    width:  100%   !important;
    height: 100dvh !important;
    border-radius: 0 !important;
  }

  /* On mobile, shift FAB up a bit and hide text label */
  #pc-fab        { bottom: 18px; left: 18px; padding: 0 14px; }
  #pc-fab-label  { display: none; }
}
