/**
 * WordPress AI Support Agent - Chat Widget Styles
 * 
 * Clean, responsive CSS for the chat widget with modern design
 * Includes proper mobile responsiveness and accessibility features
 */

/* ==========================================================================
   Main Chat Widget Container
   ========================================================================== */

.wp-ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #333333;
    z-index: 99999999999;
}

.wp-ai-chat-window {
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 80px;
    height: 600px;
    max-height: calc(100vh - 120px);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .wp-ai-chat-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        max-height: calc(100vh - 20px);
    }
    
    .wp-ai-chat-window {
        margin-bottom: 70px;
        max-height: calc(100vh - 100px);
    }
}

/* ==========================================================================
   Chat Header
   ========================================================================== */

.wp-ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.wp-ai-chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.wp-ai-chat-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    object-fit: cover;
    display: inline-block;
    vertical-align: middle;
}

.wp-ai-chat-title-text {
    white-space: nowrap;
}

.wp-ai-chat-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ==========================================================================
   Control Buttons
   ========================================================================== */

.wp-ai-new-chat-btn,
.wp-ai-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wp-ai-new-chat-btn:hover,
.wp-ai-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.wp-ai-new-chat-btn:active,
.wp-ai-toggle-btn:active {
    transform: translateY(0);
}

/* ==========================================================================
   Chat Body
   ========================================================================== */

.wp-ai-chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: #ffffff;
}

/* ==========================================================================
   Messages Container
   ========================================================================== */

.wp-ai-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.wp-ai-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 400px;
}

/* Custom scrollbar */
.wp-ai-messages::-webkit-scrollbar {
    width: 6px;
}

.wp-ai-messages::-webkit-scrollbar-track {
    background: #f1f3f4;
    border-radius: 3px;
}

.wp-ai-messages::-webkit-scrollbar-thumb {
    background: #c1c8cd;
    border-radius: 3px;
}

.wp-ai-messages::-webkit-scrollbar-thumb:hover {
    background: #a8b2b9;
}

/* ==========================================================================
   Message Bubbles
   ========================================================================== */

.wp-ai-message {
    display: flex;
    margin-bottom: 8px;
    animation: messageSlideIn 0.3s ease-out;
}

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

.wp-ai-message-user {
    justify-content: flex-end;
}

.wp-ai-message-assistant {
    justify-content: flex-start;
}

.wp-ai-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.wp-ai-message-user .wp-ai-message-content {
    background: #f0ecec;
    color: #333333;
    border-bottom-right-radius: 4px;
}

.wp-ai-message-assistant .wp-ai-message-content {
    background: #f4f6f8;
    color: #333333;
    border-bottom-left-radius: 4px;
}

/* ==========================================================================
   Streaming Message Styles
   ========================================================================== */

.wp-ai-streaming-content {
    position: relative;
}

.wp-ai-streaming-cursor {
    display: inline-block;
    color: #667eea;
    font-weight: bold;
    animation: streamingCursor 1s infinite;
    margin-left: 2px;
    font-family: monospace;
}

@keyframes streamingCursor {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Typing animation improvements */
.wp-ai-streaming-content {
    position: relative;
    transition: none;
}

.wp-ai-streaming-content[data-typing="true"] {
    cursor: pointer;
}

.wp-ai-streaming-content[data-typing="true"]:hover {
    background-color: rgba(102, 126, 234, 0.05);
    border-radius: 8px;
    padding: 2px 4px;
    margin: -2px -4px;
}

/* Smooth streaming text appearance */
.wp-ai-streaming-content {
    transition: none;
}

.wp-ai-streaming-content p,
.wp-ai-streaming-content div,
.wp-ai-streaming-content span {
    display: inline;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.wp-ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    margin: 0 20px 16px 20px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    max-width: 80px;
}

.wp-ai-typing-dots {
    display: flex;
    gap: 3px;
}

.wp-ai-typing-dots span {
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

.wp-ai-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.wp-ai-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

.wp-ai-typing-text {
    font-size: 12px;
    color: #666666;
    font-style: italic;
}

/* ==========================================================================
   Input Container
   ========================================================================== */

.wp-ai-input-container {
    padding: 16px 20px 20px 20px;
    background: #ffffff;
    border-top: 1px solid #e1e5e9;
}

.wp-ai-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 24px;
    padding: 8px;
    transition: all 0.2s ease;
}

.wp-ai-input-wrapper:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Updated input without wrapper */
.wp-ai-form {
    width: 100%;
}

/* ==========================================================================
   Input Field
   ========================================================================== */

.wp-ai-input {
    flex: 1;
    width: 100%;
    border: 1px solid #e1e5e9;
    background: #f8f9fa;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    color: #333333;
    border-radius: 24px;
    resize: none;
    outline: none;
    font-family: inherit;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.wp-ai-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.wp-ai-input::placeholder {
    color: #999999;
}

.wp-ai-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==========================================================================
   Send Button
   ========================================================================== */

.wp-ai-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.wp-ai-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.wp-ai-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.wp-ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.wp-ai-send-icon {
    font-size: 14px;
    line-height: 1;
}

/* ==========================================================================
   Link Buttons (in AI responses)
   ========================================================================== */

.wp-ai-link-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-align: center;
    margin: 0;
    background: transparent;
    border: none;
    text-decoration: underline;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.wp-ai-link-button:hover {
    text-decoration: none;
}

.wp-ai-link-button:active {
    transform: translateY(0);
}

/* ==========================================================================
   Loading States
   ========================================================================== */

.wp-ai-loading {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 99999999999;
}

.wp-ai-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e1e5e9;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Error States
   ========================================================================== */

.wp-ai-error {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #ffffff;
    border: 1px solid #e74c3c;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    max-width: 320px;
    z-index: 99999999999;
}

.wp-ai-error-message {
    text-align: center;
}

.wp-ai-error-message strong {
    color: #e74c3c;
    display: block;
    margin-bottom: 8px;
}

.wp-ai-error-message p {
    color: #666666;
    margin: 0 0 16px 0;
    font-size: 14px;
}

.wp-ai-retry-btn {
    background: #e74c3c;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.wp-ai-retry-btn:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */

/* Focus styles for keyboard navigation */
.wp-ai-new-chat-btn:focus,
.wp-ai-toggle-btn:focus,
.wp-ai-input:focus,
.wp-ai-send-btn:focus,
.wp-ai-retry-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .wp-ai-chat-widget,
    .wp-ai-new-chat-btn,
    .wp-ai-toggle-btn,
    .wp-ai-input-wrapper,
    .wp-ai-send-btn,
    .wp-ai-link-button,
    .wp-ai-message {
        transition: none;
        animation: none;
    }
    
    .wp-ai-typing-dots span {
        animation: none;
    }
    
    .wp-ai-loading-spinner {
        animation: none;
        border-top-color: #667eea;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .wp-ai-chat-widget {
        border: 2px solid #000000;
    }
    
    .wp-ai-chat-header {
        background: #000000;
        color: #ffffff;
    }
    
    .wp-ai-message-user .wp-ai-message-content {
        background: #000000;
        color: #ffffff;
    }
    
    .wp-ai-message-assistant .wp-ai-message-content {
        background: #ffffff;
        color: #000000;
        border: 2px solid #000000;
    }
}

/* ==========================================================================
   Chat Bubble (when closed)
   ========================================================================== */

.wp-ai-chat-bubble {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
    overflow: hidden;
    z-index: 99999999999;
}

.wp-ai-chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.wp-ai-chat-bubble:active {
    transform: scale(0.95);
}

.wp-ai-bubble-icon {
    font-size: 24px;
    position: relative;
    z-index: 99999999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wp-ai-bubble-icon svg {
    width: 36px;
    height: 36px;
}

/* Close icon - thick line arrow pointing down */
.wp-ai-bubble-icon.wp-ai-bubble-close {
    font-size: 0;
    width: 20px;
    height: 20px;
    position: relative;
    display: inline-block;
}

.wp-ai-bubble-icon.wp-ai-bubble-close::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    width: 12px;
    height: 12px;
    border-bottom: 4px solid currentColor;
    border-right: 4px solid currentColor;
}

/* Old class name for backwards compatibility */
.wp-ai-chat-bubble .wp-ai-chat-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

/* Pulse animation for the chat bubble */
.wp-ai-chat-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    animation: wp-ai-pulse 2s infinite;
}

@keyframes wp-ai-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

/* Mobile responsiveness for chat bubble */
@media (max-width: 480px) {
    .wp-ai-chat-bubble {
        width: 50px;
        height: 50px;
    }
    
    .wp-ai-bubble-icon,
    .wp-ai-chat-bubble .wp-ai-chat-icon {
        width: 28px;
        height: 28px;
    }
    
    .wp-ai-bubble-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .wp-ai-bubble-icon.wp-ai-bubble-close {
        width: 18px;
        height: 18px;
    }
    
    .wp-ai-bubble-icon.wp-ai-bubble-close::before {
        width: 10px;
        height: 10px;
        border-bottom: 3px solid currentColor;
        border-right: 3px solid currentColor;
    }
}

/* ==========================================================================
   Animation Effects
   ========================================================================== */

/* Slide In/Out Animation */
@keyframes wpai-slidein {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Animation Classes */
.wpai-animate-slidein {
    animation: wpai-slidein 0.4s ease-out;
}

.wpai-animate-slideout {
    animation: wpai-slideout 0.4s ease-out;
}

/* ==========================================================================
   Visitor Form Styles
   ========================================================================== */

.wp-ai-visitor-form-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    overflow-y: auto;
}

.wp-ai-visitor-form-content {
    max-width: 320px;
    width: 100%;
}

.wp-ai-visitor-form-title {
    font-size: 18px;
    font-weight: 600;
    color: #333333;
    margin: 0 0 8px 0;
    text-align: center;
}

.wp-ai-visitor-form-description {
    font-size: 14px;
    color: #666666;
    margin: 0 0 24px 0;
    text-align: center;
    line-height: 1.5;
}

.wp-ai-visitor-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.wp-ai-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wp-ai-form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #333333;
}

.wp-ai-form-group label .required {
    color: #e74c3c;
}

.wp-ai-form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    background: #ffffff;
    color: #333333;
    font-family: inherit;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.wp-ai-form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.wp-ai-form-group input::placeholder {
    color: #999999;
}

.wp-ai-visitor-form-submit {
    width: 100%;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.wp-ai-visitor-form-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.wp-ai-visitor-form-submit:active {
    transform: translateY(0);
}

.wp-ai-visitor-form-submit:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Mobile responsiveness for visitor form */
@media (max-width: 480px) {
    .wp-ai-visitor-form-container {
        padding: 20px 16px;
    }
    
    .wp-ai-visitor-form-content {
        max-width: 100%;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .wp-ai-chat-widget,
    .wp-ai-loading,
    .wp-ai-error {
        display: none !important;
    }
}
