/**
 * Frontend CSS for A1AI Chatbot Upgrade
 *
 * @package A1AI_Chatbot_Upgrade
 */

/* Contact Form Styles */
.a1ai-contact-form-wrapper {
    max-width: 600px;
    margin: 20px 0;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: #fff;
}

.a1ai-form-title {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 24px;
    color: #333;
}

.a1ai-contact-form {
    display: flex;
    flex-direction: column;
}

.a1ai-form-field {
    margin-bottom: 15px;
}

.a1ai-form-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

.a1ai-form-input,
.a1ai-form-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    box-sizing: border-box;
}

/* AI-Enhanced Message Field Styles */
.a1ai-ai-message-container {
    position: relative;
}

.a1ai-form-textarea.a1ai-ai-enhanced {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

.a1ai-ai-chat-section {
    border: 1px solid #ccc;
    border-top: none;
    border-radius: 0 0 3px 3px;
    background-color: #f9f9f9;
    padding: 10px;
}

.a1ai-ai-chat-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.a1ai-ai-chat-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.a1ai-ai-chat-toggle .dashicons {
    font-size: 16px;
    margin-right: 5px;
}

/* AI Chat Widget */
.a1ai-ai-chat-widget {
    margin-top: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    animation: slideDown 0.3s ease;
}

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

.a1ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.a1ai-chat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.a1ai-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.a1ai-chat-close:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Chat Messages Area */
.a1ai-chat-messages {
    height: 250px;
    overflow-y: auto;
    padding: 16px;
    background: #fafafa;
    border-bottom: 1px solid #eee;
}

.a1ai-chat-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.a1ai-chat-message.a1ai-ai-message {
    align-items: flex-start;
}

.a1ai-chat-message.a1ai-user-message {
    align-items: flex-end;
}

.a1ai-message-content {
    max-width: 95%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.a1ai-ai-message .a1ai-message-content {
    background: #e3f2fd;
    color: #1565c0;
    border-bottom-left-radius: 4px;
}

.a1ai-user-message .a1ai-message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.a1ai-message-time {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    padding: 0 14px;
}

/* Chat Input Area */
.a1ai-chat-input-area {
    display: flex;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #eee;
}

.a1ai-chat-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.a1ai-chat-input:focus {
    border-color: #667eea;
}

.a1ai-chat-send {
    margin-left: 8px;
    padding: 10px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a1ai-chat-send:hover {
    background: #5a67d8;
    transform: scale(1.05);
}

.a1ai-chat-send .dashicons {
    font-size: 16px;
}

/* Chat Actions */
.a1ai-chat-actions {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: #f8f9fa;
    justify-content: space-between;
}

.a1ai-chat-finalize {
    background: #28a745;
    border-color: #28a745;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 4px;
}

.a1ai-chat-finalize:hover {
    background: #218838;
    border-color: #1e7e34;
}

.a1ai-chat-clear {
    background: #6c757d;
    border-color: #6c757d;
    color: white;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 4px;
}

.a1ai-chat-clear:hover {
    background: #5a6268;
    border-color: #545b62;
}

/* Loading and Status Indicators */
.a1ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-style: italic;
    padding: 8px 14px;
}

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

.a1ai-typing-dots span {
    width: 6px;
    height: 6px;
    background: #666;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.a1ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.a1ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Star Rating Styles */
.a1ai-stars {
    display: flex;
    gap: 5px;
    margin: 10px 0;
    user-select: none;
}

.a1ai-star {
    font-size: 24px;
    color: #ddd;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.a1ai-star:hover,
.a1ai-star.hover {
    color: #ffd700 !important;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
    transform: scale(1.1);
}

.a1ai-star.active,
.a1ai-stars .a1ai-star.active {
    color: #ffd700 !important;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3) !important;
    opacity: 1 !important;
}

.a1ai-rating-input {
    margin: 15px 0;
}

.a1ai-rating-input label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

/* Scale Rating Styles */
.a1ai-rating-scale {
    width: 100%;
    margin: 10px 0;
}

#a1ai-scale-value {
    font-weight: bold;
    color: #ffd700;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .a1ai-ai-chat-widget {
        margin: 10px -10px 0 -10px;
    }

    .a1ai-chat-messages {
        height: 200px;
    }

    .a1ai-message-content {
        max-width: 98%;
    }

    .a1ai-chat-actions {
        flex-direction: column;
        gap: 8px;
    }

    .a1ai-chat-actions button {
        width: 100%;
    }
}

.a1ai-form-input:focus,
.a1ai-form-textarea:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 5px rgba(0, 124, 186, 0.3);
}

.a1ai-form-textarea {
    resize: vertical;
    min-height: 100px;
}

.a1ai-form-submit {
    margin-top: 10px;
}

.a1ai-submit-button {
    background-color: #007cba;
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s ease;
}

.a1ai-submit-button:hover {
    background-color: #005a87;
}

.a1ai-submit-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.a1ai-form-messages {
    margin-top: 15px;
}

.a1ai-form-success {
    padding: 10px;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 3px;
    color: #155724;
}

.a1ai-form-error {
    padding: 10px;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 3px;
    color: #721c24;
}

/* Required field indicator: PHP adds ' *' to label text when field is required; no CSS asterisk to avoid double */

/* Responsive design */
@media (max-width: 768px) {
    .a1ai-contact-form-wrapper {
        padding: 15px;
        margin: 10px 0;
    }

    .a1ai-form-title {
        font-size: 20px;
    }

    .a1ai-submit-button {
        width: 100%;
    }
}

/* Chat Interface Styles */
.a1ai-chat-container {
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #f9f9f9;
    overflow: hidden;
}

.a1ai-chat-messages {
    height: 300px;
    overflow-y: auto;
    padding: 15px;
    background: white;
}

.a1ai-chat-message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.a1ai-bot-message {
    align-items: flex-start;
}

.a1ai-user-message {
    align-items: flex-end;
}

.a1ai-chat-message .message-content {
    max-width: 95%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
}

.a1ai-bot-message .message-content {
    background: #e3f2fd;
    color: #1976d2;
}

.a1ai-user-message .message-content {
    background: #007cba;
    color: white;
}

.a1ai-chat-message .message-actions {
    margin-top: 8px;
}

.a1ai-form-trigger-button {
    background: #4caf50;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.3s ease;
}

.a1ai-form-trigger-button:hover {
    background: #45a049;
}

.a1ai-chat-input-container {
    padding: 15px;
    background: #f1f1f1;
    border-top: 1px solid #ddd;
}

.a1ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
}

.a1ai-chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

.a1ai-chat-input:focus {
    border-color: #007cba;
    box-shadow: 0 0 5px rgba(0, 124, 186, 0.3);
}

.a1ai-chat-send-button {
    background: #007cba;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s ease;
}

.a1ai-chat-send-button:hover {
    background: #005a87;
}

.a1ai-chat-send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Hybrid Form Popup */
.a1ai-form-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a1ai-form-popup-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.a1ai-form-popup-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.a1ai-form-popup-header h4 {
    margin: 0;
    color: #333;
}

.a1ai-form-popup-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a1ai-form-popup-close:hover {
    color: #000;
}

.a1ai-form-popup-body {
    padding: 20px;
}

.a1ai-form-popup-body .a1ai-form-title {
    display: none;
}

/* Form Type Specific Styles */
.a1ai-organic-chat .a1ai-form-title {
    margin-bottom: 15px;
}

/* Organic chatbot uses normal chatbot UI (input + send); hide only standalone-form elements if present */
.a1ai-organic-contact-form .a1ai-contact-form,
.a1ai-organic-contact-form .a1ai-form-field,
.a1ai-organic-contact-form .a1ai-form-input,
.a1ai-organic-contact-form .a1ai-form-textarea,
.a1ai-organic-contact-form .a1ai-form-submit,
.a1ai-organic-contact-form .a1ai-submit-button,
.a1ai-organic-contact-form label[for*="a1ai_name"],
.a1ai-organic-contact-form label[for*="a1ai_email"],
.a1ai-organic-contact-form label[for*="a1ai_message"],
.a1ai-organic-contact-form .a1ai-ai-chat-toggle,
.a1ai-organic-contact-form .a1ai-ai-message-container {
    display: none !important;
}

/* Organic forms should show only the chat interface */
.a1ai-organic-contact-form .a1ai-chatbot-messages {
    display: block !important;
}

/* Ensure organic chat interface is visible */
.a1ai-organic-contact-form .a1ai-organic-chat-interface,
.a1ai-organic-contact-form .a1ai-chat-container,
.a1ai-organic-chat .a1ai-chat-container {
    display: block !important;
}

.a1ai-hybrid-form .a1ai-form-title {
    margin-bottom: 15px;
}

/* Hybrid Form Styles - Use existing chat widget but hide header */
.a1ai-contact-form-wrapper[data-form-type*="hybrid"] .a1ai-ai-chat-widget {
    margin-top: 0;
    border-radius: 8px;
}

.a1ai-contact-form-wrapper[data-form-type*="hybrid"] .a1ai-chat-header {
    display: none;
}

/* Loading States */
.a1ai-chat-loading {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 15px;
    color: #666;
    font-style: italic;
}

.a1ai-chat-loading::after {
    content: '...';
    animation: a1ai-dots 1.5s infinite;
}

@keyframes a1ai-dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Chat Scrollbar */
.a1ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.a1ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.a1ai-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.a1ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Responsive chat */
@media (max-width: 768px) {
    .a1ai-chat-messages {
        height: 250px;
    }

    .a1ai-chat-message .message-content {
        max-width: 98%;
        font-size: 13px;
    }

    .a1ai-form-popup-content {
        width: 95%;
        max-height: 90vh;
    }

    .a1ai-chat-input-wrapper {
        flex-direction: column;
        gap: 8px;
    }

    .a1ai-chat-send-button {
        align-self: flex-end;
        padding: 8px 16px;
    }
}
