:host {
  --primary-color: #2d3e50;
  --background-color: #ffffff;
  --accent-color: #4e8cff;
  --widget-width: 350px;
  --widget-height: 500px;
  --font-family: 'Segoe UI', Arial, sans-serif;
  
  position: fixed;
  z-index: 10000;
  font-family: var(--font-family);
  box-sizing: border-box;
  display: block;
  visibility: visible;
}

:host *,
:host *::before,
:host *::after {
  box-sizing: border-box;
}

.chat-widget {
  position: fixed !important;
  width: var(--widget-width);
  height: var(--widget-height);
  background: var(--background-color) !important;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transition: all 0.3s ease;
  display: flex !important;
  flex-direction: column;
  font-family: var(--font-family);
  visibility: visible !important;
  opacity: 1 !important;
  
  /* Ensure all container elements use the background color and font family */
  .messages-container,
  .input-container,
  .tabs {
    background: var(--background-color) !important;
    font-family: var(--font-family);
  }

  &.position-bottom-right {
    bottom: 20px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important;
  }

  &.position-bottom-left {
    bottom: 20px !important;
    left: 20px !important;
    top: auto !important;
    right: auto !important;
  }


  &.minimized {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    cursor: pointer;

    .chat-header,
    .messages-container,
    .input-container,
    .tabs,
    .powered-by {
      display: none;
    }

    .minimize-icon {
      display: flex !important;
    }
  }

  &.hidden {
    display: none !important;
  }
  
  /* Ensure widget is visible by default */
  &:not(.hidden) {
    display: flex !important;
  }
}

/* Standalone minimize icon (outside main widget) */
:host .minimize-icon {
  position: fixed !important;
  width: 60px !important;
  height: 60px !important;
  border-radius: 50% !important;
  background: var(--primary-color) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
  z-index: 10001 !important;
  font-family: var(--font-family) !important;
  visibility: visible !important;
  opacity: 1 !important;
  position: relative !important;

  svg {
    width: 20px !important;
    height: 20px !important;
  }

  &:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3) !important;
  }

  /* Pulsing animation */
  &.pulsing {
    &::before {
      content: '';
      position: absolute;
      top: -4px;
      left: -4px;
      right: -4px;
      bottom: -4px;
      border-radius: 50%;
      background: var(--primary-color);
      opacity: 0.3;
      animation: pulse 2s infinite;
    }

    &::after {
      content: '';
      position: absolute;
      top: -8px;
      left: -8px;
      right: -8px;
      bottom: -8px;
      border-radius: 50%;
      background: var(--primary-color);
      opacity: 0.2;
      animation: pulse 2s infinite 0.5s;
    }
  }

  /* Popup message */
  .popup-message {
    position: absolute;
    bottom: 70px;
    right:0;
    background: var(--primary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10002;
    font-family: var(--font-family);
    pointer-events: none; 
  }
}

.chat-header {
  background: var(--primary-color);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  font-family: var(--font-family);

  .agent-info {
    display: flex;
    align-items: center;
    gap: 12px;

    .agent-avatar {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      border: 2px solid rgba(255, 255, 255, 0.3);
      object-fit: cover;
    }

    .agent-details {
      h4 {
        margin: 0;
        font-size: 1.1em;
        font-weight: 600;
        font-family: var(--font-family);
      }

      p {
        margin: 0;
        font-size: 0.95em;
        opacity: 0.8;
        font-family: var(--font-family);
      }
    }
  }

  .controls {
    display: flex;
    gap: 6px;

    .control-btn {
      background: rgba(0, 0, 0, 0.1);
      border: none;
      color: #fff;
      width: 28px;
      height: 28px;
      border-radius: 50%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.1em;
      transition: background 0.2s;

      &:hover {
        background: rgba(0, 0, 0, 0.2);
      }

      &.close-btn {
        &:hover {
          background: rgba(255, 0, 0, 0.3);
        }
      }
    }
  }
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 12px 16px;
  background: var(--background-color) !important;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-family: var(--font-family);

  .message {
    display: flex;
    align-items: flex-start;
    gap: 8px;

    &.user {
      flex-direction: row-reverse;
    }

    .message-avatar {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      flex-shrink: 0;
      object-fit: cover;
      border: 1px solid #eee;
    }

    .user-avatar-icon {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      flex-shrink: 0;
      background: #4e8cff;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid #eee;
      
      svg {
        color: white;
        width: 12px;
        height: 12px;
      }
    }

    .message-content {
      max-width: 70%;

      .message-text {
        padding: 10px 14px;
        border-radius: 10px;
        font-size: 1em;
        line-height: 1.4;
        font-family: var(--font-family);
      }

      .message-time {
        font-size: 11px;
        opacity: 0.6;
        margin-top: 4px;
        font-family: var(--font-family);
      }
    }

    &.agent .message-content .message-text {
      background: #eafbe7;
      color: #222;
      border-radius: 10px 10px 10px 0;
      
      img {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
        margin: 8px 0;
        display: block;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      }
      
      a {
        color: var(--accent-color);
        text-decoration: underline;
        
        &:hover {
          text-decoration: none;
        }
      }
    }

    &.user .message-content .message-text {
      background: #e6f4ff;
      color: #222;
      border-radius: 10px 10px 0 10px;
      
      img {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
        margin: 8px 0;
        display: block;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      }
      
      a {
        color: var(--accent-color);
        text-decoration: underline;
        
        &:hover {
          text-decoration: none;
        }
      }
    }
  }

  .typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: #666;
    font-style: italic;
    font-family: var(--font-family);

    .typing-dots {
      display: flex;
      gap: 2px;

      .dot {
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: #666;
        animation: typing 1.4s infinite;

        &:nth-child(2) {
          animation-delay: 0.2s;
        }

        &:nth-child(3) {
          animation-delay: 0.4s;
        }
      }
    }
  }
}

.input-container {
  background: var(--background-color);
  border-top: 1px solid #eee;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-family: var(--font-family);

  .message-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 1em;
    outline: none;
    background: #fafbfc;
    font-family: var(--font-family);

    &:focus {
      border-color: var(--accent-color);
    }
  }

  .send-btn,
  .feature-btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
    transition: opacity 0.2s;
    position: relative;

    &:hover {
      opacity: 0.9;
    }

    svg {
      width: 14px;
      height: 14px;
    }
  }

  .feature-btn {
    color: var(--accent-color);
    
    &:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }
    
    .spinning {
      animation: spin 1s linear infinite;
    }
  }
}

/* Tabs CSS removed - functionality disabled */
/*
.tabs {
  background: var(--background-color) !important;
  border-top: 1.5px solid #e0e7ff;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 40px;
  flex-shrink: 0;
  font-family: var(--font-family);

  .tab {
    flex: 1;
    text-align: center;
    padding: 6px 0;
    color: var(--primary-color);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;

    &:hover {
      background: rgba(0, 0, 0, 0.05);
    }

    svg {
      width: 16px;
      height: 16px;
    }

    span:not(.fallback-icon) {
      font-size: 0.91em;
      font-family: var(--font-family);
    }
  }
}
*/

.powered-by {
  text-align: center;
  font-size: 0.8em;
  color: #aaa;
  padding: 6px 0;
  background: var(--background-color);
  border-top: 1px solid #f3f3f3;
  flex-shrink: 0;
  font-family: var(--font-family);
  line-height: 1.2;
  img {
    height: 18px;
    vertical-align: middle;
    margin-right: 6px;
    opacity: 0.85;
    object-fit: contain;
  }

  span, a {
    font-weight: 400;
    font-family: var(--font-family);
  }
  
  a {
    text-decoration: none;
    transition: opacity 0.2s ease;
    
    &:hover {
      opacity: 0.8;
      text-decoration: underline;
    }
  }
}

.minimize-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 24px;
  color: white;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.1;
  }
  100% {
    transform: scale(1.2);
    opacity: 0;
  }
}

@keyframes popupFadeIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

// Spinning animation for file upload
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

// Mobile responsiveness
@media (max-width: 768px) {
  .chat-widget {
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;

    .messages-container {
      height: calc(100vh - 200px);
    }
  }
}