/**
 * Editor Chat Styles
 *
 * Styles for the AI Editor Chat component in the WordPress Block Editor
 *
 * @package Simple_Ai_Auto_Post
 * @since 1.1.3
 */

/* Import existing design system for consistency */
@import url('./design-system.css');

/* Model selector styling - subtle/compact */
.saiap-model-selector {
    margin-bottom: 8px !important;
    padding: 0 !important;
    background-color: transparent !important;
    border: none !important;
}

.saiap-model-selector label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 500;
    color: #6b7280;
}

.saiap-model-selector select {
    width: 100%;
    padding: 4px 6px !important;
    font-size: 11px !important;
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    background-color: #fff;
    cursor: pointer;
    font-family: inherit;
    color: #6b7280;
}

.saiap-model-selector select:focus {
    border-color: #9ca3af;
    box-shadow: none;
    outline: none;
}

.saiap-chat-body-wrapper {
    position: relative;
    height: 60vh;
}

/* Chat Container Overrides */
.saiap-editor-chat-wrapper .components-panel__body .is-opened .components-panel__body-title {
    display: none;
}

.saiap-editor-chat-wrapper .cs-main-container {
    height: 100% !important;
    border-radius: 8px;
    border: 1px solid var(--neutral-border, #E5E7EB);
    background-color: #fff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    display: flex !important;
    flex-direction: column !important;
}

.saiap-editor-chat-wrapper .cs-chat-container {
    height: 100% !important;
}

.saiap-editor-chat-wrapper .cs-message-input__tools .cs-button--send {
    align-self: center;
}

.saiap-editor-chat-wrapper .cs-message-list {
    background-color: var(--neutral-bg);
    padding-top: 12px;
    padding-bottom: 12px;
    padding-left: 0;
    padding-right: 0;
}

/* Message Styling */
.saiap-editor-chat-wrapper .cs-message {
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.4;
}

.saiap-editor-chat-wrapper .cs-message:not(:only-child) {
    margin: 0;
}

.saiap-editor-chat-wrapper .cs-message-list__scroll-wrapper > .cs-message {
    margin-bottom: 0 !important;
}

.saiap-editor-chat-wrapper .cs-message--incoming {
    margin-right: auto;
}

.saiap-editor-chat-wrapper .cs-message--incoming .cs-message__content {
    background-color: transparent;
    color: var(--text-primary, #1F2937);
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.saiap-editor-chat-wrapper .cs-message--outgoing {
    border-radius: 12px 12px 4px 12px;
    max-width: 85%;
    margin-left: auto;
    margin-bottom: 12px !important; /* Gap before AI response */
}

.saiap-editor-chat-wrapper .cs-message--outgoing .cs-message__content {
    background-color: var(--primary-color, #1E3A8A);
    color: #fff !important;
}

.saiap-editor-chat-wrapper .cs-message--outgoing .cs-message__content p {
    color: #fff !important;
}

.saiap-editor-chat-wrapper .cs-message__content {
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: normal; /* Override chatscope pre-wrap which preserves newlines */
}

/* Tighten spacing in markdown-rendered content */
.saiap-editor-chat-wrapper .cs-message__content p {
    margin: 0 0 0.5em 0;
    font-size: 14px;
    line-height: 1.4; /* Override design-system.css 24px */
}

.saiap-editor-chat-wrapper .cs-message__content p:last-child {
    margin-bottom: 0;
}

.saiap-editor-chat-wrapper .cs-message__content ol,
.saiap-editor-chat-wrapper .cs-message__content ul {
    margin: 0 0 0.75em 0;
    padding-left: 1.25em;
    font-size: 14px;
}

.saiap-editor-chat-wrapper .cs-message__content li {
    margin-bottom: 0.25em;
    font-size: 14px;
}

.saiap-editor-chat-wrapper .cs-message__content li:last-child {
    margin-bottom: 0;
}

/* Message Input Styling */
.saiap-editor-chat-wrapper .cs-message-input {
    border-top: 1px solid var(--neutral-border, #E5E7EB);
    background-color: #fff;
    padding: 0;
}

.saiap-editor-chat-wrapper .cs-message-input__content-editor {
    border: 1px solid var(--neutral-border, #E5E7EB);
    border-radius: 0;
    padding: 12px;
    font-size: 14px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #fff;
    min-height: 62px;
    max-height: 144px;
    overflow-y: auto;
    margin: 0;
}

.saiap-editor-chat-wrapper .cs-message-input__content-editor:focus {
    outline: 2px solid var(--primary-hover, #3B82F6);
    outline-offset: 1px;
    border-color: var(--primary-color, #1E3A8A);
}

.saiap-editor-chat-wrapper .cs-message-input__content-editor[data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: var(--text-placeholder, #9CA3AF);
    font-style: italic;
}

/* Send Button */
.saiap-editor-chat-wrapper .cs-button--send {
    background-color: var(--primary-color, #1E3A8A) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    margin: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: background-color 0.2s ease-in-out !important;
}

.saiap-editor-chat-wrapper .cs-message-input__content-editor-wrapper {
    padding: 0 !important;
    margin-left: .2em !important;
}

.saiap-editor-chat-wrapper .cs-button--send:hover {
    background-color: var(--primary-hover, #3B82F6) !important;
}

.saiap-editor-chat-wrapper .cs-button--send:disabled {
    background-color: var(--text-placeholder, #9CA3AF) !important;
    cursor: not-allowed !important;
}

.saiap-editor-chat-wrapper .cs-button--send svg {
    fill: #fff !important;
    width: 16px !important;
    height: 16px !important;
}

/* Typing Indicator - override library's absolute positioning */
.saiap-editor-chat-wrapper .cs-message-list .cs-typing-indicator {
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    background-color: #fff;
    border: 1px solid var(--neutral-border, #E5E7EB);
    border-radius: 12px;
    padding: 10px 12px;
    margin: 12px 0;
    font-size: 14px;
    color: var(--text-secondary, #6B7280);
    font-style: italic;
}

.saiap-editor-chat-wrapper .cs-typing-indicator__content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.saiap-editor-chat-wrapper .cs-typing-indicator__dots {
    display: flex;
    gap: 4px;
}

.saiap-editor-chat-wrapper .cs-typing-indicator__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--primary-color, #1E3A8A);
    animation: typing-pulse 1.4s infinite ease-in-out;
}

.saiap-editor-chat-wrapper .cs-typing-indicator__dot:nth-child(1) {
    animation-delay: -0.32s;
}

.saiap-editor-chat-wrapper .cs-typing-indicator__dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Panel Integration */
.components-panel__body.is-opened>.components-panel__body-title {
    display: none;
}

.saiap-editor-chat-wrapper .components-panel__body {
    padding: 0;
}

.saiap-editor-chat-wrapper .components-panel__body-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #1F2937);
    padding: 12px 16px;
    border-bottom: 1px solid var(--neutral-border, #E5E7EB);
    margin-bottom: 0;
}

/* Chat Info Section */
.saiap-chat-info {
    margin-top: 10px;
    padding: 12px 16px;
    font-size: 12px;
    color: var(--text-secondary, #6B7280);
    background-color: var(--neutral-bg);
    border-top: 1px solid var(--neutral-border, #E5E7EB);
}

.saiap-chat-info p {
    margin: 0 0 5px 0;
    line-height: 1.4;
}

.saiap-chat-info p:last-child {
    margin-bottom: 0;
}

.saiap-chat-info strong {
    color: var(--text-primary, #1F2937);
    font-weight: 600;
}

.saiap-chat-info em {
    font-style: italic;
    color: var(--text-placeholder, #9CA3AF);
}

/* Image widget and picker styles */
.saiap-image-widget {
    padding: 8px 12px !important;
    margin: 0 !important;
}

.saiap-image-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.saiap-image-card {
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
}

.saiap-image-selected {
    border-color: #2271b1 !important;
}

/* Responsive Design */
@media (max-width: 782px) {
    .saiap-editor-chat-wrapper .cs-main-container {
        height: 300px !important;
    }
    
    .saiap-editor-chat-wrapper .cs-message {
        font-size: 13px;
    }
    
    .saiap-editor-chat-wrapper .cs-message-input__content-editor {
        font-size: 13px;
        padding: 6px 10px;
        min-height: 32px;
    }
    
    .saiap-editor-chat-wrapper .cs-button--send {
        width: 28px !important;
        height: 28px !important;
    }
    
    .saiap-editor-chat-wrapper .cs-button--send svg {
        width: 14px !important;
        height: 14px !important;
    }
}

/* Accessibility Improvements */
.saiap-editor-chat-wrapper .cs-message-input__content-editor:focus-visible {
    outline: 2px solid var(--primary-hover, #3B82F6);
    outline-offset: 2px;
}

.saiap-editor-chat-wrapper .cs-button--send:focus-visible {
    outline: 2px solid var(--primary-hover, #3B82F6);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .saiap-editor-chat-wrapper .cs-message--incoming {
        border-width: 2px;
    }
    
    .saiap-editor-chat-wrapper .cs-message-input__content-editor {
        border-width: 2px;
    }
    
    .saiap-editor-chat-wrapper .cs-button--send {
        border: 2px solid #fff !important;
    }
}