/**
 * Perfect365 RAG Chat Widget Styles
 * Modern, responsive design with theme support
 */

/* Global Viewport Fix for iOS Safari/Chrome and Android browsers */
html, body {
  /* Use the dynamic viewport height (modern iOS & Chrome) */
  min-height: 100dvh;
  
  /* Fallback for older iOS Safari */
  min-height: -webkit-fill-available;
  
  /* Ensure content stays above iOS browser footer / home indicator */
  padding-bottom: env(safe-area-inset-bottom);
  padding-bottom: constant(safe-area-inset-bottom); /* older iOS support */
  
  /* Prevent accidental overflow */
  overflow-x: hidden;
  
  /* Better mobile viewport handling */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Additional viewport fixes for the widget container */
.perfect365-chat-widget {
  /* Use dynamic viewport height for better mobile support */
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  
  /* Ensure proper positioning on mobile */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  
  /* Prevent iOS bounce scrolling */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

/* CRITICAL: Force full-screen on mobile - Must override all other styles */
@media (max-width: 768px) {
    .perfect365-chat-widget__container,
    .perfect365-chat-widget--bottom-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        transform: none !important;
        inset: 0 !important;
    }
    
    /* Force the entire widget to be full-screen */
    .perfect365-chat-widget {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 10000 !important;
    }
    
    /* Additional fullscreen class for extra override */
    .perfect365-chat-widget--fullscreen {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 10000 !important;
    }
    
    .perfect365-chat-widget--fullscreen .perfect365-chat-widget__container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        transform: none !important;
        inset: 0 !important;
    }
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --text-muted: #5a626e;
    --border-color: #e5e7eb;
    --border-hover: #d1d5db;
    --bg-muted: #0a0a0a;
    --success-color: #059669;
    --error-color: #dc2626;
    --warning-color: #d97706;
    --info-color: #0891b2;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Widget Container - Core positioning and interaction handling */
.perfect365-chat-widget {
    position: fixed;
    z-index: 999999; /* Very high z-index to stay above most elements */
    pointer-events: none; /* Make entire widget container transparent to clicks */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    transition: all 0.3s ease;
    /* Ensure proper stacking context */
    isolation: isolate;
    /* Prevent any interference with page layout */
    box-sizing: border-box;
    max-width: 100vw;
}

/* Enable pointer events only for interactive elements */
.perfect365-chat-widget__container,
.perfect365-chat-widget__toggle {
    pointer-events: auto !important; /* Force enable pointer events */
}

/* When widget is open, increase its z-index */
.perfect365-chat-widget--open {
    z-index: 1000000; /* Even higher z-index when open */
}

/* Ensure all widget children use border-box */
.perfect365-chat-widget *,
.perfect365-chat-widget *::before,
.perfect365-chat-widget *::after {
    box-sizing: border-box;
}

/* Cursor-based positioning class */
.perfect365-chat-widget--cursor-positioned {
    position: fixed !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    inset: auto !important;
}

/* Override any existing positioning with maximum specificity */
.perfect365-chat-widget.perfect365-chat-widget--cursor-positioned {
    position: fixed !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    inset: auto !important;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .perfect365-chat-widget__container {
        max-width: 90vw !important;
        max-height: 90vh !important;
        width: 90vw !important;
        height: 80vh !important;
    }
    
    .perfect365-chat-widget--cursor-positioned {
        /* Center on mobile if positioning fails */
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
    }
    
    /* Ensure toggle button is visible on mobile */
    .perfect365-chat-widget__toggle {
        width: 56px;
        height: 56px;
        bottom: 20px;
        right: 20px;
    }
    
    .perfect365-chat-widget__toggle svg {
        width: 24px;
        height: 24px;
    }
    
    /* Enhanced mobile touch targets */
    .perfect365-chat-widget__minimize,
    .perfect365-chat-widget__close {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .perfect365-chat-widget__send {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Better mobile scrolling */
    .perfect365-chat-widget__messages {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Prevent zoom on iOS input */
    .perfect365-chat-widget__input {
        font-size: 16px;
    }
}

/* Position Variants */
.perfect365-chat-widget--bottom-right {
    bottom: 20px;
    right: 20px;
}

.perfect365-chat-widget--bottom-left {
    bottom: 20px;
    left: 20px;
}

.perfect365-chat-widget--top-right {
    top: 20px;
    right: 20px;
}

.perfect365-chat-widget--top-left {
    top: 20px;
    left: 20px;
}

/* Toggle Button */
.perfect365-chat-widget__toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
    transition: all 0.3s ease;
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    pointer-events: auto !important;
    /* Prevent any unwanted margin/padding */
    margin: 0;
    padding: 0;
    /* Ensure proper sizing */
    box-sizing: border-box;
    /* Prevent text selection */
    user-select: none;
    -webkit-user-select: none;
    /* Improve touch handling */
    touch-action: manipulation;
}

.perfect365-chat-widget__toggle:hover {
    background: var(--primary-hover);
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(37, 99, 235, 0.4);
}

.perfect365-chat-widget__toggle:active {
    transform: translateY(-1px);
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .perfect365-chat-widget__toggle {
        min-width: 44px;
        min-height: 44px;
    }
    
    .perfect365-chat-widget__toggle:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .perfect365-chat-widget__toggle:hover {
        transform: none;
        box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
    }
}

.perfect365-chat-widget__toggle svg {
    width: 28px;
    height: 28px;
}

/* Chat Container */
.perfect365-chat-widget__container {
    position: absolute;
    bottom: 90px;
    right: 0;
    width: 400px;
    height: 600px;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
    /* Ensure proper layout for fixed input */
    min-height: 0; /* Allow flex items to shrink */
    /* Prevent interference with page layout */
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    pointer-events: auto !important;
    /* Ensure proper stacking context */
    isolation: isolate;
    /* Prevent any unwanted margin collapse */
    margin: 0;
    padding: 0;
}

/* Mobile: Three-container layout structure - Only when widget is open */
@media (max-width: 768px) {
    .perfect365-chat-widget--open .perfect365-chat-widget__container {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        height: 100dvh !important;
        height: -webkit-fill-available !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        border: none !important;
        overflow: hidden !important;
    }
    
    /* Header Container - Fixed at top (only when open) */
    .perfect365-chat-widget--open .perfect365-chat-widget__header {
        flex-shrink: 0 !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
        background: #667EEA !important; /* Fixed color for both themes */
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Messages Container - Scrollable middle section (only when open) */
    .perfect365-chat-widget--open .perfect365-chat-widget__messages {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
        padding: 16px !important;
        /* Remove fixed positioning and height calculations */
        position: relative !important;
        height: auto !important;
        max-height: none !important;
        /* Ensure proper spacing */
        margin-bottom: 0 !important;
        padding-bottom: 20px !important;
    }
    
    /* Input Container - Fixed at bottom (only when open) */
    .perfect365-chat-widget--open .perfect365-chat-widget__input-container {
        flex-shrink: 0 !important;
        position: sticky !important;
        bottom: 0 !important;
        background: var(--bg-color) !important;
        border-top: 1px solid var(--border-color) !important;
        padding: 16px !important;
        z-index: 100 !important;
        /* Remove fixed positioning */
        position: sticky !important;
        left: auto !important;
        right: auto !important;
        width: auto !important;
        /* Add safe area support for iOS */
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: calc(16px + constant(safe-area-inset-bottom, 0px)) !important;
    }
}

.perfect365-chat-widget--open .perfect365-chat-widget__container {
    display: flex;
    animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.perfect365-chat-widget--minimized .perfect365-chat-widget__container {
    display: none !important;
}

.perfect365-chat-widget--minimized .perfect365-chat-widget__toggle {
    display: flex !important;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* Position-specific container positioning */
.perfect365-chat-widget--bottom-right .perfect365-chat-widget__container {
    bottom: 90px;
    right: 0;
}

.perfect365-chat-widget--bottom-left .perfect365-chat-widget__container {
    bottom: 90px;
    left: 0;
}

.perfect365-chat-widget--top-right .perfect365-chat-widget__container {
    top: 90px;
    right: 0;
}

.perfect365-chat-widget--top-left .perfect365-chat-widget__container {
    top: 90px;
    left: 0;
}

/* Mobile responsive container positioning overrides - Now handled by three-container layout above */
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget__container--top-left {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    /* Mobile full-screen enhancements - WhatsApp/Telegram style */
    .perfect365-chat-widget__header {
        position: sticky !important;
        top: 0 !important;
        z-index: 100 !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-radius: 0 !important;
    }
    
    .perfect365-chat-widget__messages {
        /* Use dynamic viewport height for better mobile support - Account for header + input + safe areas */
        height: calc(100dvh - 240px) !important; /* Increased space for header + input + safe areas */
        height: calc(100vh - 240px) !important; /* Fallback */
        height: calc(-webkit-fill-available - 240px) !important; /* iOS Safari fallback */
        max-height: calc(100dvh - 240px) !important;
        max-height: calc(100vh - 240px) !important; /* Fallback */
        max-height: calc(-webkit-fill-available - 240px) !important; /* iOS Safari fallback */
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
        /* Ensure content stays above iOS browser footer */
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: calc(40px + constant(safe-area-inset-bottom, 0px)) !important; /* older iOS support */
        /* Ensure messages don't overlap with input */
        margin-bottom: 0 !important;
        /* Better scrolling behavior */
        overflow-y: auto !important;
        flex: 1 !important;
        /* Ensure messages are visible above input */
        position: relative !important;
        z-index: 1 !important;
    }
    
    .perfect365-chat-widget__input-container {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: var(--bg-color) !important;
        border-top: 1px solid var(--border-color) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        /* Ensure input stays above iOS browser footer */
        padding-bottom: env(safe-area-inset-bottom) !important;
        padding-bottom: constant(safe-area-inset-bottom) !important; /* older iOS support */
        /* Ensure input container has proper spacing */
        z-index: 1000 !important;
        width: 100% !important;
        flex-shrink: 0 !important;
        /* Remove any transforms that might cause positioning issues */
        transform: none !important;
    }


@media (max-width: 480px) {
    .perfect365-chat-widget__container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    /* Mobile full-screen enhancements for smaller screens */
    .perfect365-chat-widget__messages {
        height: calc(100vh - 120px) !important;
        max-height: calc(100vh - 120px) !important;
        padding: 12px !important;
    }
    
    .perfect365-chat-widget__input-container {
        padding: 12px !important;
    }
}

/* Position-specific toggle button positioning */
.perfect365-chat-widget--bottom-right .perfect365-chat-widget__toggle {
    bottom: 20px;
    right: 20px;
}

.perfect365-chat-widget--bottom-left .perfect365-chat-widget__toggle {
    bottom: 20px;
    left: 20px;
}

/* Cursor-positioned widget container */
.perfect365-chat-widget--cursor-positioned .perfect365-chat-widget__container {
    position: absolute !important;
    bottom: auto !important;
    right: auto !important;
    top: auto !important;
    left: auto !important;
    width: 400px;
    height: 600px;
}

/* Mobile responsive overrides for cursor positioning */
@media (max-width: 768px) {
    .perfect365-chat-widget--cursor-positioned .perfect365-chat-widget__container {
        position: fixed !important;
        bottom: 80px !important;
        right: 20px !important;
        left: auto !important;
        width: 320px !important;
        height: 500px !important;
        top: auto !important;
        max-width: calc(100vw - 40px) !important;
        max-height: 70vh !important;
    }
}

@media (max-width: 480px) {
    .perfect365-chat-widget--cursor-positioned .perfect365-chat-widget__container {
        bottom: 70px !important;
        right: 10px !important;
        left: auto !important;
        width: 280px !important;
        height: 450px !important;
        max-width: calc(100vw - 20px) !important;
        max-height: 65vh !important;
    }
}

/* Ensure cursor-positioned widget has proper z-index and overrides all positioning */
.perfect365-chat-widget--cursor-positioned {
    z-index: 9999 !important;
    position: fixed !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    inset: auto !important;
}

/* Override any inline styles that might interfere */
.perfect365-chat-widget--cursor-positioned[style*="inset"] {
    inset: auto !important;
}

/* Maximum specificity override for cursor positioning */
.perfect365-chat-widget.perfect365-chat-widget--cursor-positioned[style] {
    position: fixed !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    inset: auto !important;
}

.perfect365-chat-widget--top-right .perfect365-chat-widget__toggle {
    top: 20px;
    right: 20px;
}

.perfect365-chat-widget--top-left .perfect365-chat-widget__toggle {
    top: 20px;
    left: 20px;
}

/* Header - Ensure it's always visible */
.perfect365-chat-widget__header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 10px;
    background: #667EEA !important; /* Fixed color for both themes */
    color: white;
    border-radius: 20px 20px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 10; /* Ensure header is above messages */
    min-height: 40px;
    flex-wrap: nowrap;
    overflow: visible;
    flex-shrink: 0; /* Don't shrink the header */
}

.perfect365-chat-widget__title {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.025em;
    flex-shrink: 0;
    min-width: 0;
}

/* Perfect365 Logo Styles */
.perfect365-chat-widget__title .perfect365-logo {
    display: flex;
    align-items: baseline;
    letter-spacing: 0.05em;
    justify-content: flex-start;
    margin-bottom: 4px;
}

.perfect365-chat-widget__title .perfect365-logo .perfect {
    font-style: italic;
    font-weight: 300;
    color: white;
    font-size: 16px;
}

.perfect365-chat-widget__title .perfect365-logo .number {
    font-weight: 400;
    color: #facc15; /* yellow-500 */
    font-size: 16px;
}

.perfect365-chat-widget__title .tagline {
    font-weight: 400;
    color: white;
    letter-spacing: 0.2em;
    font-size: 9px;
    opacity: 0.9;
    text-align: left;
    line-height: 1.2;
}

.perfect365-chat-widget__title svg {
    width: 22px;
    height: 22px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Session Controls */
.perfect365-chat-widget__session-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0 12px;
    flex-shrink: 0;
    min-width: 0;
}

.perfect365-chat-widget__session-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.perfect365-chat-widget__session-btn:hover {
    background: var(--bg-muted);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Touch device optimizations for session buttons */
@media (hover: none) and (pointer: coarse) {
    .perfect365-chat-widget__session-btn {
        min-height: 44px;
        padding: 8px 12px;
    }
    
    .perfect365-chat-widget__session-btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    .perfect365-chat-widget__session-btn:hover {
        transform: none;
    }
}

.perfect365-chat-widget__session-btn--start {
    background: #28a745;
    border-color: #28a745;
    color: white;
}

.perfect365-chat-widget__session-btn--start:hover {
    background: #218838;
    border-color: #1e7e34;
}

.perfect365-chat-widget__session-btn--end {
    background: #dc3545;
    border-color: #dc3545;
    color: white;
}

.perfect365-chat-widget__session-btn--end:hover {
    background: #c82333;
    border-color: #bd2130;
}

/* Dark theme adjustments for session controls */
.perfect365-chat-widget--dark .perfect365-chat-widget__session-controls {
    border-color: var(--border-color);
}

.perfect365-chat-widget--dark .perfect365-chat-widget__session-btn {
    background: var(--bg-color);
    border-color: var(--border-color);
    color: var(--text-color);
}

/* Responsive design for session controls */
@media (max-width: 480px) {
    .perfect365-chat-widget__session-controls {
        margin: 0 8px;
        gap: 6px;
    }
    
    .perfect365-chat-widget__session-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* Responsive design for header */
@media (max-width: 600px) {
    .perfect365-chat-widget__header {
        padding: 12px 16px;
        min-height: 35px;
    }
    
    .perfect365-chat-widget__title .perfect365-logo .perfect,
    .perfect365-chat-widget__title .perfect365-logo .number {
        font-size: 16px;
    }
    
    .perfect365-chat-widget__title .tagline {
        font-size: 9px;
        letter-spacing: 0.2em;
    }
    
    .perfect365-chat-widget__session-controls {
        margin: 0 8px;
        gap: 4px;
    }
    
    .perfect365-chat-widget__session-btn {
        padding: 4px 8px;
        font-size: 10px;
    }
    
    
    .perfect365-chat-widget__minimize,
    .perfect365-chat-widget__close {
        padding: 4px;
        align-items: center;
        width: 25px;
        height: 25px;
    }
}

/* Header controls - Always visible */
.perfect365-chat-widget__header-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 11; /* Higher than header */
    flex-shrink: 0;
    min-width: 0;
}

.perfect365-chat-widget__minimize,
.perfect365-chat-widget__close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 12; /* Highest z-index for controls */
    width: 25px;
    height: 25px;
}

.perfect365-chat-widget__minimize:hover,
.perfect365-chat-widget__close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.perfect365-chat-widget__minimize:active,
.perfect365-chat-widget__close:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* Touch device optimizations for header controls */
@media (hover: none) and (pointer: coarse) {
    .perfect365-chat-widget__minimize,
    .perfect365-chat-widget__close {
        min-width: 40px;
        min-height: 40px;
    }
    
    .perfect365-chat-widget__minimize:active,
    .perfect365-chat-widget__close:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .perfect365-chat-widget__minimize:hover,
    .perfect365-chat-widget__close:hover {
        transform: none;
    }
}

/* Messages Container */
.perfect365-chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 80px; /* Uniform padding for all devices */
    background: var(--bg-color);
    scroll-behavior: smooth;
    /* Better height calculation to prevent overlap with input */
    height: calc(100% - 160px); /* Account for header (80px) + input (80px) */
    min-height: 200px; /* Minimum height */
    max-height: calc(100% - 160px); /* Prevent overflow */
    /* Ensure proper scrolling behavior */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* Add bottom margin to prevent overlap with input */
    margin-bottom: 0; /* Remove extra margin since we're using calc */
}

/* Desktop-specific messages container - Override mobile rules */
@media (min-width: 769px) {
    .perfect365-chat-widget__messages {
        height: calc(100% - 122px) !important; /* Account for header (80px) + input (80px) */
        max-height: calc(100% - 122px) !important; /* Prevent overflow */
        min-height: 200px !important; /* Minimum height */
        flex: 1 !important;
        overflow-y: auto !important;
        padding: 20px !important;
        padding-bottom: 0px !important; /* Uniform padding for all devices */
        background: var(--bg-color) !important;
        scroll-behavior: smooth !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        margin-bottom: 0 !important;
    }
}

/* Force desktop messages height - Maximum specificity */
@media (min-width: 769px) {
    .perfect365-chat-widget__container .perfect365-chat-widget__messages {
        height: calc(100% - 122px) !important;
        max-height: calc(100% - 122px) !important;
        min-height: 200px !important;
    }
}

/* Mobile messages optimizations - Now handled by three-container layout above */
@media (max-width: 768px) {
    .perfect365-chat-widget__messages {
        /* Styles are now handled by the three-container layout above */
        /* Additional mobile-specific optimizations */
        padding: 16px !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Mobile form - Center send button properly */
    .perfect365-chat-widget__form {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 8px !important;
        padding: 8px !important;
        /* Ensure proper vertical centering */
        min-height: 48px !important;
    }
    
    /* Mobile send button - Center and proper sizing */
    .perfect365-chat-widget__send {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        /* Move arrow 30px to left */
        margin-right: 2px;
    }
    
    .perfect365-chat-widget__message {
        margin-bottom: 18px;
    }
    
    .perfect365-chat-widget__message-content {
        padding: 14px 16px;
        max-width: 90%;
    }
}

.perfect365-chat-widget__messages::-webkit-scrollbar {
    width: 6px;
}

.perfect365-chat-widget__messages::-webkit-scrollbar-track {
    background: transparent;
}

.perfect365-chat-widget__messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.perfect365-chat-widget__messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Message Styles */
.perfect365-chat-widget__message {
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User message styling - container right-aligned, text left-aligned */
.perfect365-chat-widget__message--user {
    text-align: right;
}

.perfect365-chat-widget__message--bot,
.perfect365-chat-widget__message--welcome,
.perfect365-chat-widget__message--error,
.perfect365-chat-widget__message--system {
    text-align: left;
}

.perfect365-chat-widget__message-content {
    display: inline-block;
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
}

.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content {
    background: var(--primary-color);
    color: white !important; /* Force white text for visibility */
    border-bottom-right-radius: 6px;
    text-align: left !important;
    direction: ltr !important;
}

.perfect365-chat-widget__message--bot .perfect365-chat-widget__message-content,
.perfect365-chat-widget__message--welcome .perfect365-chat-widget__message-content {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 6px;
}

.perfect365-chat-widget__message--error .perfect365-chat-widget__message-content {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border: 1px solid #fecaca !important;
    border-bottom-left-radius: 6px !important;
}

/* Ensure error message text is visible */
.perfect365-chat-widget__message--error .perfect365-chat-widget__message-text {
    color: #dc2626 !important;
}

.perfect365-chat-widget__message--system .perfect365-chat-widget__message-content {
    background: #fffbeb;
    color: #d97706;
    border: 1px solid #fed7aa;
    border-bottom-left-radius: 6px;
}

/* Message Content Styling */
.perfect365-chat-widget__message-text {
    word-wrap: break-word;
    line-height: 1.6;
    color: var(--text-color);
}

.perfect365-chat-widget__message--user .perfect365-chat-widget__message-text {
    color: white !important;
    text-align: left !important;
    direction: ltr !important;
}

/* Ensure all text elements within user messages are left-aligned for proper wrapping */
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-text,
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-text * {
    text-align: left !important;
    direction: ltr !important;
}

/* Force left alignment for user message content with maximum specificity */
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content {
    text-align: left !important;
    direction: ltr !important;
    unicode-bidi: bidi-override;
}

/* Additional specificity for user message text */
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content .perfect365-chat-widget__message-text {
    text-align: left !important;
    direction: ltr !important;
    unicode-bidi: bidi-override;
}

/* Maximum specificity for user message text alignment - targets the exact selector */
#perfect365-chat-widget > div > div.perfect365-chat-widget__messages > div.perfect365-chat-widget__message.perfect365-chat-widget__message--user > div {
    text-align: left !important;
    direction: ltr !important;
    unicode-bidi: bidi-override;
}

/* Force left alignment for all user message content */
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content,
.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content * {
    text-align: left !important;
    direction: ltr !important;
}

/* See More Functionality */
.perfect365-chat-widget__message-text {
    position: relative;
    overflow: visible;
}

/* Message text styling - full height display */
.perfect365-chat-widget__message-text {
    line-height: 1.6;
    word-wrap: break-word;
    overflow: visible;
}















/* Enhanced Message Formatting */
.perfect365-chat-widget__message-text strong {
    font-weight: 600;
    color: var(--text-color);
}

.perfect365-chat-widget__message-text em {
    font-style: italic;
    color: var(--text-muted);
}

/* Message headers (h1, h2, h3) */
.perfect365-chat-widget__message-text h1,
.perfect365-chat-widget__message-text h2,
.perfect365-chat-widget__message-text h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.perfect365-chat-widget__message-text h1 {
    font-size: 18px;
    color: var(--primary-color);
}

.perfect365-chat-widget__message-text h2 {
    font-size: 16px;
    color: var(--text-color);
}

.perfect365-chat-widget__message-text h3 {
    font-size: 14px;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.perfect365-chat-widget__message-header {
    font-weight: 600;
    font-size: 1.1em;
    margin: 8px 0 4px 0;
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.perfect365-chat-widget__message-paragraph {
    margin: 6px 0;
    line-height: 1.6;
}

.perfect365-chat-widget__message-list-item {
    margin: 4px 0;
    padding-left: 8px;
    line-height: 1.5;
}

.perfect365-chat-widget__bullet {
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 8px;
}

.perfect365-chat-widget__number {
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 8px;
}

.perfect365-chat-widget__spacer {
    height: 8px;
    margin: 4px 0;
}

/* Dark theme adjustments for formatting */
.perfect365-chat-widget--dark .perfect365-chat-widget__message-header {
    color: var(--primary-color);
    border-bottom-color: var(--border-color);
}

.perfect365-chat-widget--dark .perfect365-chat-widget__message-text h1,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-text h2,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-text h3 {
    color: var(--text-color);
}

.perfect365-chat-widget--dark .perfect365-chat-widget__message-text h3 {
    border-bottom-color: var(--border-color);
}

.perfect365-chat-widget--dark .perfect365-chat-widget__bullet,
.perfect365-chat-widget--dark .perfect365-chat-widget__number {
    color: var(--primary-color);
}

.perfect365-chat-widget__message-text {
    font-size: 14px;
    line-height: 1.5;
}

.perfect365-chat-widget__message-timestamp {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

/* Message Metadata */
.perfect365-chat-widget__message-confidence {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 6px;
}

.perfect365-chat-widget__message-confidence .confidence-label {
    font-weight: 500;
}

.perfect365-chat-widget__message-confidence .confidence-value {
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
}

.perfect365-chat-widget__message-confidence .confidence-value.high {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.perfect365-chat-widget__message-confidence .confidence-value.medium {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.perfect365-chat-widget__message-confidence .confidence-value.low {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.perfect365-chat-widget__message--bot .perfect365-chat-widget__message-confidence {
    border-top-color: var(--border-color);
}

.perfect365-chat-widget__message-timestamp {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.perfect365-chat-widget__message--user .perfect365-chat-widget__message-timestamp {
    text-align: left;
}

/* Sources */
.perfect365-chat-widget__message-sources {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 123, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(0, 123, 255, 0.1);
}

.perfect365-chat-widget__sources-title {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary-color);
    text-align: center;
}

.perfect365-chat-widget__source {
    font-size: 12px;
    margin-bottom: 6px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    border: 1px solid rgba(0, 123, 255, 0.2);
    transition: all 0.2s ease;
}

.perfect365-chat-widget__source:hover {
    background: rgba(255, 255, 255, 1);
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
}

.perfect365-chat-widget__source-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.perfect365-chat-widget__source-number {
    background: var(--primary-color);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
}

.perfect365-chat-widget__source-score {
    margin-left: auto;
    font-size: 10px;
    color: #666;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
}

.perfect365-chat-widget__source-content {
    font-size: 11px;
    color: #666;
    font-style: italic;
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    border-left: 3px solid var(--primary-color);
}

.perfect365-chat-widget__source-score {
    color: var(--info-color);
    font-weight: 500;
}

/* Typing Indicator */
.perfect365-chat-widget__typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.perfect365-chat-widget__typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.perfect365-chat-widget__typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.perfect365-chat-widget__typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.perfect365-chat-widget__input-container {
    padding: 12px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 20px 20px;
    flex-shrink: 0; /* Don't shrink */
    position: sticky; /* Stick to bottom */
    bottom: 0; /* Always at bottom */
    z-index: 10; /* Ensure it's above messages */
    /* Ensure input container has proper spacing from messages */
    margin-top: auto; /* Push to bottom */
    min-height: 80px; /* Ensure minimum height for input area */
    /* Prevent container from overflowing */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.perfect365-chat-widget__form {
    display: flex;
    align-items: center; /* Center vertically instead of flex-end */
    gap: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 8px;
    transition: all 0.2s ease;
    justify-content: flex-end;
    /* Prevent form from overflowing container */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.perfect365-chat-widget__form:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    transform: translateY(-1px);
    transition: all 0.2s ease;
}

.perfect365-chat-widget__input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-color);
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 20px;
    max-height: 120px;
    text-align: left;
    direction: ltr;
    transition: all 0.2s ease;
    /* Prevent input from causing overflow */
    min-width: 0;
    max-width: calc(100% - 60px); /* Account for send button and gap */
    box-sizing: border-box;
}

.perfect365-chat-widget__input:focus {
    background: rgba(37, 99, 235, 0.05);
    border-radius: 8px;
}

/* Mobile input optimizations */
@media (max-width: 768px) {
    .perfect365-chat-widget__input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px 14px;
        min-height: 24px;
        /* Better mobile input handling */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 0;
        /* Prevent zoom on focus */
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        /* Better touch handling */
        touch-action: manipulation;
    }
    
    .perfect365-chat-widget__form {
        padding: 8px;
        border-radius: 22px;
    }
    
    /* Enhanced mobile input container - Now handled by three-container layout above */
    .perfect365-chat-widget__input-container {
        /* Styles are now handled by the three-container layout above */
        /* Additional mobile-specific optimizations */
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
    }
    
    /* Adjust messages container height for mobile - Now handled by three-container layout above */
    .perfect365-chat-widget__messages {
        /* Styles are now handled by the three-container layout above */
        /* Additional mobile-specific optimizations */
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
        overflow-y: auto !important;
    }
}

.perfect365-chat-widget__input::placeholder {
    color: var(--text-color);
}

.perfect365-chat-widget__send {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    /* Prevent button from coming out on desktop */
    max-width: 36px;
    max-height: 36px;
    overflow: hidden;
    margin-right: 2px;
}

.perfect365-chat-widget__send:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.perfect365-chat-widget__send:active {
    transform: scale(0.95);
}

/* Touch device optimizations for send button */
@media (hover: none) and (pointer: coarse) {
    .perfect365-chat-widget__send {
        min-width: 44px;
        min-height: 44px;
    }
    
    .perfect365-chat-widget__send:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .perfect365-chat-widget__send:hover {
        transform: none;
    }
}

.perfect365-chat-widget__send svg {
    width: 18px;
    height: 18px;
}

/* Dark Theme */
.perfect365-chat-widget--dark {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --border-color: #333333;
    --shadow-color: rgba(0,0,0,0.3);
}

.perfect365-chat-widget--dark .perfect365-chat-widget__message--bot .perfect365-chat-widget__message-content {
    background: #2a2a2a;
    border-color: #444;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__message--typing .perfect365-chat-widget__message-content {
    background: #2a2a2a;
    border-color: #444;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__input {
    color: white;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__input::placeholder {
    color: #888;
}



/* Responsive Design */
@media (max-width: 480px) {
    .perfect365-chat-widget__container {
        width: 280px !important;
        height: 450px !important;
        bottom: 80px;
        right: 20px;
        left: auto;
        border-radius: 16px;
        max-width: calc(100vw - 40px) !important;
        max-height: 65vh !important;
    }
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container {
        left: 20px;
        right: auto;
    }
    
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        top: 80px;
        right: 20px;
        left: auto;
        height: 450px !important;
        max-height: 65vh !important;
    }
    
    .perfect365-chat-widget__toggle {
        width: 52px;
        height: 52px;
        bottom: 15px;
        right: 15px;
    }
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__toggle {
        left: 15px;
    }
    
    .perfect365-chat-widget__container {
        bottom: 70px;
    }
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container {
        bottom: 70px;
    }
    
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        top: 70px;
    }
    
    /* Enhanced mobile touch experience */
    .perfect365-chat-widget__header {
        min-height: 65px;
        padding: 10px 14px;
    }
    
    .perfect365-chat-widget__input-container {
        padding: 16px;
    }
    
    .perfect365-chat-widget__form {
        padding: 4px;
        border-radius: 22px;
    }
    
    .perfect365-chat-widget__input {
        padding: 10px 14px;
        font-size: 16px;
        min-height: 24px;
    }
    
    .perfect365-chat-widget__send {
        width: 38px;
        height: 38px;
    }
    
    .perfect365-chat-widget__send svg {
        width: 18px;
        height: 18px;
    }
}

/* Animation Classes */
.perfect365-chat-widget__container {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.perfect365-chat-widget--open .perfect365-chat-widget__container {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Message Animation */
.perfect365-chat-widget__message {
    opacity: 0;
    transform: translateY(10px);
    animation: messageSlideIn 0.3s ease forwards;
}

@keyframes messageSlideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hover Effects */
.perfect365-chat-widget__message--bot .perfect365-chat-widget__message-content:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.perfect365-chat-widget__message--user .perfect365-chat-widget__message-content:hover {
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

/* Focus States */
.perfect365-chat-widget__toggle:focus,
.perfect365-chat-widget__close:focus,
.perfect365-chat-widget__send:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Loading States */
.perfect365-chat-widget__send.loading {
    pointer-events: none;
    opacity: 0.7;
}

.perfect365-chat-widget__send.loading svg {
    animation: spin 1s linear infinite;
}

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

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .perfect365-chat-widget__container,
    .perfect365-chat-widget__message,
    .perfect365-chat-widget__toggle,
    .perfect365-chat-widget__send {
        transition: none;
        animation: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .perfect365-chat-widget__container {
        border: 2px solid var(--text-color);
    }
    
    .perfect365-chat-widget__message--bot .perfect365-chat-widget__message-content {
        border: 2px solid var(--text-color);
    }
    
    .perfect365-chat-widget__input {
        border: 2px solid var(--text-color);
    }
}

/* Enhanced Source Display */
.perfect365-chat-widget__message-sources {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 123, 255, 0.05);
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.perfect365-chat-widget__sources-title {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-size: 13px;
}

.perfect365-chat-widget__source {
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    border: 1px solid rgba(0, 123, 255, 0.2);
}

.perfect365-chat-widget__source:last-child {
    margin-bottom: 0;
}

.perfect365-chat-widget__source-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.perfect365-chat-widget__source-number {
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

.perfect365-chat-widget__source-score {
    color: var(--info-color);
    font-size: 12px;
    font-weight: 500;
}

.perfect365-chat-widget__source-content {
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.4;
}

/* Confidence score */
.perfect365-chat-widget__message-confidence {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

.perfect365-chat-widget__message-confidence .confidence-value.high {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.perfect365-chat-widget__message-confidence .confidence-value.medium {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.perfect365-chat-widget__message-confidence .confidence-value.low {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

/* Responsive design */
@media (max-width: 480px) {
    .perfect365-chat-widget__container {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
        left: 20px;
    }
    
    .perfect365-chat-widget--bottom-left .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        left: 20px;
        right: 20px;
    }
    
    .perfect365-chat-widget--top-right .perfect365-chat-widget__container,
    .perfect365-chat-widget--top-left .perfect365-chat-widget__container {
        top: 80px;
    }
    
    .perfect365-chat-widget__message-content {
        max-width: 90%;
    }
    
    /* Mobile feedback button adjustments - Compact */
    .perfect365-chat-widget__feedback-system {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    
    .perfect365-chat-widget__feedback-buttons {
        gap: 6px;
    }
    
    .perfect365-chat-widget__feedback-btn {
        padding: 6px 10px;
        height: 28px;
        font-size: 12px;
    }
}

/* Dark theme support */
.perfect365-chat-widget--dark {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --text-muted: #a0a0a0;
    --border-color: #333333;
    --border-hover: #444444;
    --bg-muted: #2a2a2a;
}

/* Focus states for accessibility */
.perfect365-chat-widget__toggle:focus,
.perfect365-chat-widget__minimize:focus,
.perfect365-chat-widget__close:focus,
.perfect365-chat-widget__send:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.perfect365-chat-widget__input:focus {
    outline: none;
}

/* Feedback System Styles - Compact ChatGPT-like Design */
.perfect365-chat-widget__feedback-system {
    margin-top: 8px;
    padding: 0;
    background: transparent;
    border: none;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 10 !important;
}

.perfect365-chat-widget__feedback-title {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
    font-weight: 400;
    white-space: nowrap;
}

.perfect365-chat-widget__feedback-buttons {
    display: flex;
    gap: 4px;
}

.perfect365-chat-widget__feedback-btn {
    flex: none;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: auto;
    height: 24px;
}

.perfect365-chat-widget__feedback-btn:hover {
    background: var(--bg-muted);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.perfect365-chat-widget__feedback-btn--positive:hover {
    background: rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
    color: #16a34a;
}

.perfect365-chat-widget__feedback-btn--negative:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #dc2626;
}

.perfect365-chat-widget__feedback-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Additional compact feedback styles */
.perfect365-chat-widget__feedback-system.compact {
    margin-top: 6px;
    gap: 6px;
}

.perfect365-chat-widget__feedback-title.compact {
    font-size: 11px;
}

.perfect365-chat-widget__feedback-btn.compact {
    padding: 3px 6px;
    height: 20px;
    font-size: 10px;
}

/* Simplified feedback submitted message - Compact */
.perfect365-chat-widget__feedback-submitted {
    text-align: left;
    color: var(--success-color);
    font-size: 11px;
    font-weight: 400;
    padding: 0;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Feedback Error State - Compact */
.perfect365-chat-widget__feedback-error {
    color: var(--error-color);
    font-size: 11px;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.perfect365-chat-widget__feedback-error > span {
    font-size: 14px;
    display: inline;
    margin: 0;
}

.perfect365-chat-widget__feedback-error > div:not(.perfect365-chat-widget__feedback-retry) {
    margin: 0;
}

.perfect365-chat-widget__feedback-retry {
    margin: 0;
    display: flex;
    gap: 4px;
}

.perfect365-chat-widget__feedback-retry .perfect365-chat-widget__feedback-btn {
    font-size: 10px;
    padding: 3px 6px;
    height: 20px;
}

/* Feedback Debug (Development Only) */
.perfect365-chat-widget__feedback-debug {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    font-family: monospace;
    background: #f5f5f5;
    padding: 2px 4px;
    border-radius: 3px;
    border: 1px solid #ddd;
}

/* Recommendation Questions */
.perfect365-chat-widget__recommendations {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.perfect365-chat-widget__recommendations-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 12px;
    text-align: center;
}

.perfect365-chat-widget__recommendation-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.perfect365-chat-widget__recommendation-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    line-height: 1.4;
    font-family: inherit;
}

.perfect365-chat-widget__recommendation-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.perfect365-chat-widget__recommendation-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

/* Dark theme support for recommendations */
.perfect365-chat-widget--dark .perfect365-chat-widget__recommendations {
    background: #2a2a2a;
    border-color: #444;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__recommendation-btn {
    background: #333;
    border-color: #555;
    color: #fff;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__recommendation-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Link Styles */
.perfect365-chat-widget__link,
.perfect365-chat-widget__message-text .perfect365-chat-widget__link,
.perfect365-chat-widget__message-content .perfect365-chat-widget__link {
    color: #ffffff !important;
    text-decoration: none !important;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    display: inline-block;
    margin: 2px 4px;
}

.perfect365-chat-widget__link:hover,
.perfect365-chat-widget__message-text .perfect365-chat-widget__link:hover,
.perfect365-chat-widget__message-content .perfect365-chat-widget__link:hover {
    color: #ffffff !important;
    text-decoration: none !important;
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.perfect365-chat-widget__link:active,
.perfect365-chat-widget__message-text .perfect365-chat-widget__link:active,
.perfect365-chat-widget__message-content .perfect365-chat-widget__link:active {
    color: #ffffff !important;
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

/* Dark theme support for links */
.perfect365-chat-widget--dark .perfect365-chat-widget__link,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-text .perfect365-chat-widget__link,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-content .perfect365-chat-widget__link {
    color: #ffffff !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__link:hover,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-text .perfect365-chat-widget__link:hover,
.perfect365-chat-widget--dark .perfect365-chat-widget__message-content .perfect365-chat-widget__link:hover {
    color: #ffffff !important;
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%) !important;
}

/* Show More/Less Functionality */
.perfect365-chat-widget__show-more-container {
    margin-top: 8px;
}

.perfect365-chat-widget__show-more-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.perfect365-chat-widget__show-more-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.perfect365-chat-widget__show-more-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.perfect365-chat-widget__long-answer {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-muted);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    animation: fadeIn 0.3s ease-in-out;
}

.perfect365-chat-widget__loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 0;
}

.perfect365-chat-widget__long-content {
    line-height: 1.6;
}

.perfect365-chat-widget__error {
    color: var(--error-color);
    font-style: italic;
    padding: 8px 0;
}

/* Dark theme support for show more/less */
.perfect365-chat-widget--dark .perfect365-chat-widget__show-more-btn {
    border-color: #4b5563;
    color: #60a5fa;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__show-more-btn:hover {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__long-answer {
    background: #1f2937;
    border-color: #374151;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__loading {
    color: #9ca3af;
}

.perfect365-chat-widget--dark .perfect365-chat-widget__error {
    color: #f87171;
}

/* Animation for smooth expand/collapse */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}