/**
 * AgentIQ Chat Widget Styles
 */

/* CSS Variables */
:root {
    --agentiq-primary-color: #0073aa;
    --agentiq-widget-size: 60px;
    --agentiq-window-width: 380px;
    --agentiq-window-height: 520px;
    --agentiq-border-radius: 16px;
    --agentiq-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
}

/* Widget Container */
.agentiq-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* Toggle Button */
.agentiq-chat-toggle {
    width: var(--agentiq-widget-size);
    height: var(--agentiq-widget-size);
    border-radius: 50%;
    background-color: var(--agentiq-primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--agentiq-shadow);
    transition: transform 0.3s ease, background-color 0.3s ease;
    color: #fff;
    padding: 0;
}

.agentiq-chat-toggle:hover {
    transform: scale(1.1);
}

.agentiq-chat-toggle:focus {
    outline: none;
    box-shadow: var(--agentiq-shadow), 0 0 0 3px rgba(0, 115, 170, 0.3);
}

.agentiq-chat-toggle .chat-icon,
.agentiq-chat-toggle .close-icon {
    width: 28px;
    height: 28px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.agentiq-chat-toggle .close-icon {
    display: none;
}

.agentiq-chat-widget.is-open .agentiq-chat-toggle .chat-icon {
    display: none;
}

.agentiq-chat-widget.is-open .agentiq-chat-toggle .close-icon {
    display: block;
}

/* Chat Window */
.agentiq-chat-window {
    position: absolute;
    bottom: calc(var(--agentiq-widget-size) + 15px);
    right: 0;
    width: var(--agentiq-window-width);
    height: var(--agentiq-window-height);
    background: #fff;
    border-radius: var(--agentiq-border-radius);
    box-shadow: var(--agentiq-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.agentiq-chat-widget.is-open .agentiq-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.agentiq-chat-header {
    background-color: var(--agentiq-primary-color);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.agentiq-chat-title {
    font-weight: 600;
    font-size: 16px;
}

.agentiq-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    border-radius: 4px;
}

.agentiq-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.agentiq-chat-close:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
}

/* Header Actions */
.agentiq-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.agentiq-chat-new {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s ease, background 0.2s ease;
    border-radius: 4px;
}

.agentiq-chat-new:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.agentiq-chat-new:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
}

.agentiq-chat-new svg {
    width: 18px;
    height: 18px;
}

/* Chat Messages Area */
.agentiq-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

/* Message Bubbles */
.agentiq-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.agentiq-message-user {
    background-color: var(--agentiq-primary-color);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.agentiq-message-assistant {
    background-color: #fff;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.agentiq-message-assistant:empty {
    display: none;
}

.agentiq-message-welcome {
    background-color: #fff;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Typing Indicator */
.agentiq-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background-color: #fff;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.agentiq-typing-dot {
    width: 8px;
    height: 8px;
    background-color: #999;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.agentiq-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.agentiq-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Container */
.agentiq-chat-input-container {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.agentiq-chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 10px 16px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color 0.2s ease;
}

.agentiq-chat-input:focus {
    outline: none;
    border-color: var(--agentiq-primary-color);
}

.agentiq-chat-input::placeholder {
    color: #999;
}

.agentiq-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--agentiq-primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: background-color 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.agentiq-chat-send:hover {
    transform: scale(1.05);
}

.agentiq-chat-send:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.3);
}

.agentiq-chat-send:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

.agentiq-chat-send svg {
    width: 18px;
    height: 18px;
}

/* Error Message */
.agentiq-error {
    background-color: #fee2e2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    align-self: center;
    text-align: center;
}

/* Scrollbar Styling */
.agentiq-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.agentiq-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.agentiq-chat-messages::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

.agentiq-chat-messages::-webkit-scrollbar-thumb:hover {
    background-color: #999;
}

/* Mobile Responsive */
@media screen and (max-width: 480px) {
    .agentiq-chat-widget {
        bottom: 10px;
        right: 10px;
    }

    .agentiq-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-height: 500px;
        right: 0;
        border-radius: 12px;
    }

    .agentiq-chat-toggle {
        width: 54px;
        height: 54px;
    }

    .agentiq-chat-toggle .chat-icon,
    .agentiq-chat-toggle .close-icon {
        width: 24px;
        height: 24px;
    }
}

/* Animation for new messages */
.agentiq-message.new {
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading state for send button */
.agentiq-chat-send.loading {
    pointer-events: none;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Pre-chat Form */
.agentiq-prechat-form {
    display: none;
    /* Hidden by default, shown via JS */
    flex-direction: column;
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.agentiq-prechat-intro {
    margin-bottom: 20px;
    text-align: center;
}

.agentiq-prechat-intro p {
    margin: 0;
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

.agentiq-prechat-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.agentiq-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.agentiq-field label {
    font-size: 13px;
    font-weight: 500;
    color: #333;
}

.agentiq-field label .required {
    color: #dc2626;
}

.agentiq-field input {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.agentiq-field input:focus {
    outline: none;
    border-color: var(--agentiq-primary-color);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.agentiq-field input::placeholder {
    color: #999;
}

.agentiq-prechat-error {
    margin-top: 12px;
    padding: 10px 12px;
    background-color: #fee2e2;
    color: #dc2626;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

.agentiq-prechat-submit {
    margin-top: 20px;
    padding: 12px 20px;
    background-color: var(--agentiq-primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.agentiq-prechat-submit:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.agentiq-prechat-submit:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.3);
}

.agentiq-prechat-submit:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
    filter: none;
}

/* Mobile adjustments for pre-chat form */
@media screen and (max-width: 480px) {
    .agentiq-prechat-form {
        padding: 16px;
    }

    .agentiq-prechat-fields {
        gap: 12px;
    }

    .agentiq-field input {
        padding: 12px;
    }
}

/* Fullscreen mode */
.agentiq-chat-widget.agentiq-fullscreen {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1000000;
    background: rgba(255, 255, 255, 0.95);
    /* High opacity white/backdrop */
    backdrop-filter: blur(5px);
    /* Modern blur effect */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-toggle {
    display: none;
}

.agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-window {
    position: relative;
    width: 100%;
    max-width: 800px;
    /* Constrain width for readability on large screens */
    height: 100%;
    max-height: 90vh;
    /* Don't touch the very edges vertically */
    bottom: auto;
    right: auto;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    opacity: 1;
    visibility: visible;
    transform: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-header {
    padding: 20px 24px;
}

.agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-messages {
    padding: 24px;
}

.agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-input-container {
    padding: 20px 24px;
}

body.agentiq-chat-fullscreen {
    overflow: hidden;
}

/* Ensure mobile takes full space */
@media screen and (max-width: 640px) {
    .agentiq-chat-widget.agentiq-fullscreen {
        padding: 0;
        background: #fff;
    }

    .agentiq-chat-widget.agentiq-fullscreen .agentiq-chat-window {
        max-height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }
}