/**
 * MTV AI Chat Widget Styles
 *
 * @package MTV_AI_Chat
 * @since 1.0.0
 */

:root {
    --mtv-chat-primary: #f58220;
    --mtv-chat-primary-dark: #d97418;
    --mtv-chat-bg: #ffffff;
    --mtv-chat-border: #e0e0e0;
    --mtv-chat-text: #333333;
    --mtv-chat-text-light: #666666;
    --mtv-chat-assistant-bg: #f0f0f0;
    --mtv-chat-user-bg: #f58220;
    --mtv-chat-user-text: #ffffff;
    --mtv-chat-error-bg: #fef2f2;
    --mtv-chat-error-text: #dc2626;
    --mtv-chat-radius: 12px;
}

/* Widget Container */
.mtv-ai-chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--mtv-chat-text);
    background: var(--mtv-chat-bg);
    border: 1px solid var(--mtv-chat-border);
    border-radius: var(--mtv-chat-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Header */
.mtv-ai-chat-header {
    background: var(--mtv-chat-primary);
    color: #fff;
    padding: 14px 16px;
}

.mtv-ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mtv-ai-chat-header-icon {
    flex-shrink: 0;
    opacity: 0.9;
}

.mtv-ai-chat-header-icon svg {
    display: block;
}

.mtv-ai-chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
}

.mtv-ai-chat-subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.85;
    line-height: 1.3;
}

/* Messages Area */
.mtv-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
}

.mtv-ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.mtv-ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mtv-ai-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Message Bubbles */
.mtv-ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: mtv-chat-fade-in 0.3s ease;
}

@keyframes mtv-chat-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mtv-ai-chat-message-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--mtv-chat-text-light);
    margin-bottom: 4px;
    padding: 0 4px;
}

.mtv-ai-chat-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Assistant messages - left aligned, gray */
.mtv-ai-chat-message--assistant {
    align-self: flex-start;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble {
    background: var(--mtv-chat-assistant-bg);
    color: var(--mtv-chat-text);
    border-bottom-left-radius: 4px;
    white-space: normal;
}

/* Markdown styles inside assistant message bubbles */
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble p {
    margin: 0 0 8px;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble p:last-child {
    margin-bottom: 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h1,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h2,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h3,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h4 {
    margin: 12px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h1:first-child,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h2:first-child,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h3:first-child,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h4:first-child {
    margin-top: 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h1 { font-size: 1.15em; }
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h2 { font-size: 1.1em; }
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h3 { font-size: 1.05em; }
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble h4 { font-size: 1em; }

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble ul,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble li {
    margin-bottom: 2px;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble li:last-child {
    margin-bottom: 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble code {
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: rgba(0, 0, 0, 0.07);
    padding: 1px 5px;
    border-radius: 4px;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble pre {
    margin: 8px 0;
    padding: 10px 12px;
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.5;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--mtv-chat-primary);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 0 4px 4px 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble blockquote p {
    margin: 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble a {
    color: var(--mtv-chat-primary-dark);
    text-decoration: underline;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble a:hover {
    color: var(--mtv-chat-primary);
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble strong {
    font-weight: 600;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 10px 0;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble th,
.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble td {
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 4px 8px;
    text-align: left;
}

.mtv-ai-chat-message--assistant .mtv-ai-chat-message-bubble th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

/* User messages - right aligned, orange */
.mtv-ai-chat-message--user {
    align-self: flex-end;
}

.mtv-ai-chat-message--user .mtv-ai-chat-message-name {
    text-align: right;
}

.mtv-ai-chat-message--user .mtv-ai-chat-message-bubble {
    background: var(--mtv-chat-user-bg);
    color: var(--mtv-chat-user-text);
    border-bottom-right-radius: 4px;
}

/* Error messages */
.mtv-ai-chat-message--error .mtv-ai-chat-message-bubble {
    background: var(--mtv-chat-error-bg);
    color: var(--mtv-chat-error-text);
    border: 1px solid #fecaca;
    font-size: 13px;
}

.mtv-ai-chat-retry-btn {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 12px;
    background: var(--mtv-chat-error-text);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.mtv-ai-chat-retry-btn:hover {
    opacity: 0.9;
}

/* Typing indicator */
.mtv-ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--mtv-chat-assistant-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 60px;
}

.mtv-ai-chat-typing-dot {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: mtv-chat-bounce 1.4s infinite ease-in-out both;
}

.mtv-ai-chat-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.mtv-ai-chat-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes mtv-chat-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.mtv-ai-chat-input-area {
    border-top: 1px solid var(--mtv-chat-border);
    padding: 12px 16px 8px;
    background: var(--mtv-chat-bg);
}

.mtv-ai-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.mtv-ai-chat-input {
    flex: 1;
    border: 1px solid var(--mtv-chat-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color 0.2s;
}

.mtv-ai-chat-input:focus {
    border-color: var(--mtv-chat-primary);
    box-shadow: 0 0 0 2px rgba(247, 148, 29, 0.15);
}

.mtv-ai-chat-input::placeholder {
    color: #aaa;
}

button.mtv-ai-chat-send {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--mtv-chat-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    padding: 0;
}

button.mtv-ai-chat-send:hover {
    background: var(--mtv-chat-primary-dark);
}

button.mtv-ai-chat-send:active {
    transform: scale(0.95);
}

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

.mtv-ai-chat-send svg {
    display: block;
}

.mtv-ai-chat-powered {
    text-align: center;
    font-size: 10px;
    color: #bbb;
    margin-top: 6px;
    padding-bottom: 2px;
}

/* Hide original form container when chat is active */
.mtv-ai-chat-form-hidden {
    display: none !important;
}

/* Embedded Mode - blends into parent container */
.mtv-ai-chat-embedded {
    max-width: 100%;
    margin: 0 auto;
}

/* Embedded Mode - self-contained chat widget */
.mtv-ai-chat-embedded .mtv-ai-chat-widget {
    max-width: 100%;
    background: #fff;
    border: 1px solid var(--mtv-chat-border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    max-height: 550px;
}

.mtv-ai-chat-embedded .mtv-ai-chat-header {
    background: var(--mtv-chat-primary);
}

.mtv-ai-chat-embedded .mtv-ai-chat-messages {
    min-height: 200px;
    max-height: 380px !important;
    height: auto !important;
    background: #fafafa;
    overflow-y: auto;
    flex: 1 1 auto;
}

.mtv-ai-chat-embedded .mtv-ai-chat-input-area {
    background: #fff;
    border-top: 1px solid var(--mtv-chat-border);
}

.mtv-ai-chat-embedded .mtv-ai-chat-powered {
    color: #999;
}

/* Floating Widget Wrapper */
.mtv-ai-chat-floating-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2147483647; /* Max 32-bit int - must be above Tidio (999999999) */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.mtv-ai-chat-toggle {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--mtv-chat-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: background 0.2s, transform 0.1s;
}

.mtv-ai-chat-toggle:hover {
    background: var(--mtv-chat-primary-dark);
    transform: scale(1.05);
}

.mtv-ai-chat-toggle[aria-expanded="true"] {
    display: none;
}

.mtv-ai-chat-floating-panel {
    width: 380px;
    max-height: 520px;
    display: flex;
    flex-direction: column;
}

.mtv-ai-chat-floating-panel .mtv-ai-chat-widget {
    max-width: 100%;
    max-height: 520px;
    height: 520px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.mtv-ai-chat-floating-panel .mtv-ai-chat-messages {
    height: auto !important;
    flex: 1;
    min-height: 0;
}

/* Responsive */
@media (max-width: 480px) {
    .mtv-ai-chat-floating-wrapper {
        bottom: 10px;
        right: 10px;
        left: 10px;
    }

    .mtv-ai-chat-floating-panel {
        width: 100%;
    }
}

/* Responsive - widget itself */
@media (max-width: 480px) {
    .mtv-ai-chat-widget {
        border-radius: 8px;
        font-size: 15px;
    }

    .mtv-ai-chat-message {
        max-width: 88%;
    }

    .mtv-ai-chat-input {
        font-size: 16px; /* Prevents iOS zoom */
    }
}
