/**
 * 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);
}

/* ── Markdown content resets inside message bubbles ─── */
.agentiq-message h1,
.agentiq-message h2,
.agentiq-message h3,
.agentiq-message h4,
.agentiq-message h5,
.agentiq-message h6 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-weight: 600;
    margin: 8px 0 4px 0;
    line-height: 1.4;
    padding: 0;
    border: none;
    color: inherit;
}

.agentiq-message h1 { font-size: 15px; }
.agentiq-message h2 { font-size: 14px; }
.agentiq-message h3,
.agentiq-message h4,
.agentiq-message h5,
.agentiq-message h6 { font-size: 13px; }

.agentiq-message p {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 0 0 8px 0;
    font-size: 14px;
    line-height: 1.5;
}

.agentiq-message p:last-child {
    margin-bottom: 0;
}

.agentiq-message ul,
.agentiq-message ol {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 4px 0 8px 0;
    padding-left: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.agentiq-message ul:last-child,
.agentiq-message ol:last-child {
    margin-bottom: 0;
}

.agentiq-message li {
    margin-bottom: 4px;
    line-height: 1.5;
    font-size: 14px;
}

.agentiq-message code {
    background: rgba(0, 0, 0, 0.07);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    line-height: 1.5;
}

.agentiq-message pre {
    background: rgba(0, 0, 0, 0.07);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
    line-height: 1.5;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.agentiq-message pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
}

.agentiq-message blockquote {
    border-left: 3px solid var(--agentiq-primary-color);
    margin: 6px 0;
    padding: 4px 10px;
    opacity: 0.8;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    line-height: 1.5;
}

.agentiq-message a {
    color: var(--agentiq-primary-color);
    text-decoration: underline;
    font-size: inherit;
    font-family: inherit;
}

.agentiq-message strong {
    font-weight: 600;
}

.agentiq-message em {
    font-style: italic;
}

.agentiq-message hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 8px 0;
}

/* User message — keep text white for all inner elements */
.agentiq-message-user p,
.agentiq-message-user li,
.agentiq-message-user h1,
.agentiq-message-user h2,
.agentiq-message-user h3,
.agentiq-message-user h4,
.agentiq-message-user h5,
.agentiq-message-user h6,
.agentiq-message-user a,
.agentiq-message-user code {
    color: #fff;
}

.agentiq-message-user code {
    background: rgba(255, 255, 255, 0.2);
}

.agentiq-message-user pre {
    background: rgba(255, 255, 255, 0.15);
}

/* 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);
    }
}


/* ── Suggested Questions ─────────────────────────────── */
.agentiq-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0 8px 0;
    align-self: stretch;
    justify-content: flex-end;
    max-width: 100%;
}

.agentiq-suggestion-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border: 1.5px solid var(--agentiq-primary-color);
    border-radius: 20px;
    background: #fff;
    color: var(--agentiq-primary-color);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease,
                transform 0.12s ease, box-shadow 0.18s ease;
    white-space: normal;
    text-align: left;
    max-width: 100%;
    word-break: break-word;
}

.agentiq-suggestion-btn:hover {
    background: var(--agentiq-primary-color);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 115, 170, 0.25);
}

.agentiq-suggestion-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.25);
}

.agentiq-suggestion-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

@media screen and (max-width: 480px) {
    .agentiq-suggestion-btn {
        font-size: 12px;
        padding: 5px 11px;
    }
}
