/**
 * WB AI Chat Interface Styles
 * Modern chat interface similar to ChatGPT/Gemini
 */

/* Main container */
.wb-ai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* Toggle button */
.wb-ai-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    padding: 0 !important;
}

.wb-ai-chat-toggle.wb-ai-chat-loading {
    animation: pulse 2s infinite;
}

.wb-ai-chat-toggle.wb-ai-chat-error {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    cursor: not-allowed;
}

.wb-ai-chat-toggle.wb-ai-chat-error:hover {
    transform: none;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
}

.wb-ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.wb-ai-chat-toggle:active {
    transform: scale(0.95);
}

.wb-ai-chat-toggle svg {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Sidebar */
.wb-ai-chat-sidebar {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(420px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999998;
    overflow: hidden;
}

.wb-ai-chat-container.open .wb-ai-chat-sidebar {
    transform: translateX(0);
}

/* Header */
.wb-ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

.wb-ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.wb-ai-chat-header-buttons {
    display: flex;
    gap: 8px;
}

.wb-ai-chat-minimize,
.wb-ai-chat-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wb-ai-chat-minimize:hover,
.wb-ai-chat-close:hover {
    background: #f3f4f6;
    color: #374151;
}

/* Messages container */
.wb-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Message styles */
.wb-ai-chat-message {
    display: flex;
    margin-bottom: 8px;
}

.wb-ai-chat-message-user {
    justify-content: flex-end;
}

.wb-ai-chat-message-assistant {
    justify-content: flex-start;
}

.wb-ai-chat-message-error {
    justify-content: center;
}

.wb-ai-chat-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.wb-ai-chat-typing .wb-ai-chat-message-content {
    white-space: normal;
}

.wb-ai-chat-typing .wb-ai-chat-paragraph {
    white-space: normal;
}

.wb-ai-chat-message-user .wb-ai-chat-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.wb-ai-chat-message-assistant .wb-ai-chat-message-content {
    background: #f3f4f6;
    color: #111827;
    border-bottom-left-radius: 4px;
}

.wb-ai-chat-message-error .wb-ai-chat-message-content {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    font-size: 13px;
}

/* Paragraph styling with preserved line breaks */
.wb-ai-chat-paragraph {
    white-space: pre-wrap;
    margin-bottom: 12px;
}

.wb-ai-chat-paragraph:last-child {
    margin-bottom: 0;
}

/* Citation links in assistant messages */
.wb-ai-chat-citation-link,
.wb-ai-chat-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    border-radius: 4px;
    padding: 2px 6px;
    background: rgba(102, 126, 234, 0.1);
    transition: all 0.2s ease;
    font-size: 0.9em;
}

.wb-ai-chat-citation-link:hover,
.wb-ai-chat-link:hover {
    background: rgba(102, 126, 234, 0.2);
    text-decoration: underline;
}

.wb-ai-chat-citation-link:active,
.wb-ai-chat-link:active {
    background: rgba(102, 126, 234, 0.3);
}

/* Markdown headings */
.wb-ai-chat-heading {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
    color: #111827;
}

.wb-ai-chat-heading-1 {
    font-size: 1.5em;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.wb-ai-chat-heading-2 {
    font-size: 1.3em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 6px;
    margin-bottom: 12px;
}

.wb-ai-chat-heading-3 {
    font-size: 1.15em;
}

.wb-ai-chat-heading-4 {
    font-size: 1.1em;
}

.wb-ai-chat-heading-5 {
    font-size: 1.05em;
}

.wb-ai-chat-heading-6 {
    font-size: 1em;
    font-style: italic;
}

/* Bold text */
.wb-ai-chat-bold {
    font-weight: 600;
    color: #111827;
}

/* Lists */
.wb-ai-chat-list {
    margin: 8px 0 12px 0;
    padding-left: 20px;
}

.wb-ai-chat-list-item {
    margin: 4px 0;
    line-height: 1.4;
}

.wb-ai-chat-list-item::marker {
    color: #667eea;
}

/* Partial content display (agent thoughts) */
.wb-ai-chat-partial-content {
    font-size: 12px;
    color: #9ca3af;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-style: italic;
    opacity: 0.8;
    animation: fadeIn 0.3s ease;
}

/* Mobile styles for partial content */
@media (max-width: 768px) {
    .wb-ai-chat-partial-content {
        font-size: 11px;
        margin: 6px 12px 12px 12px;
    }
}

/* Typing indicator */
.wb-ai-chat-typing {
    opacity: 1;
    animation: fadeIn 0.3s ease;
}

.wb-ai-chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.wb-ai-chat-typing-indicator span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.wb-ai-chat-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.wb-ai-chat-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.wb-ai-chat-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Input container */
.wb-ai-chat-input-container {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
    align-items: center;
}

.wb-ai-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    height: 52px;
    box-sizing: border-box;
    max-height: 120px;
    overflow-y: auto;
}

.wb-ai-chat-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.wb-ai-chat-input::placeholder {
    color: #9ca3af;
}

.wb-ai-chat-send,
.wb-ai-chat-stop {
    width: 44px;
    height: 44px;
    padding: 0 !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    margin: 0;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: #ffffff;
    position: relative;
}

.wb-ai-chat-stop {
    background: #ffffff;
    color: #111827;
}

.wb-ai-chat-send:hover:not(:disabled),
.wb-ai-chat-stop:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.wb-ai-chat-send:active:not(:disabled),
.wb-ai-chat-stop:active:not(:disabled) {
    transform: scale(0.95);
}

.wb-ai-chat-send:disabled,
.wb-ai-chat-stop:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}


.wb-ai-chat-send svg,
.wb-ai-chat-stop svg {
    fill: currentColor;
    stroke: currentColor;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    outline: none;
}

.wb-ai-chat-input:disabled {
    background: #f9fafb;
    cursor: not-allowed;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Spinner */
.wb-ai-chat-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Scrollbar styling */
.wb-ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.wb-ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

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

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

.wb-ai-chat-input::-webkit-scrollbar {
    width: 4px;
}

.wb-ai-chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.wb-ai-chat-input::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 2px;
}

/* Responsive design */
@media (max-width: 480px) {
    .wb-ai-chat-sidebar {
        width: calc(100vw - 40px);
        height: calc(100vh - 140px);
        bottom: 100px;
        right: 20px;
    }

    .wb-ai-chat-toggle {
        width: 56px;
        height: 56px;
    }

    .wb-ai-chat-message-content {
        max-width: 85%;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .wb-ai-chat-sidebar {
        border: 2px solid #000;
    }

    .wb-ai-chat-message-user .wb-ai-chat-message-content {
        border: 2px solid #000;
    }

    .wb-ai-chat-message-assistant .wb-ai-chat-message-content {
        border: 2px solid #000;
    }
}

/* Focus styles for accessibility */
.wb-ai-chat-toggle:focus,
.wb-ai-chat-minimize:focus,
.wb-ai-chat-close:focus,
.wb-ai-chat-send:focus,
.wb-ai-chat-input:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Full-page chat interface */
.wb-ai-chat-full-page {
    width: 100%;
    height: calc(100vh - var(--wp-admin--admin-bar--height, 0px) - var(--header-height, 0px));
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.wb-ai-chat-full-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

.wb-ai-chat-full-page-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #111827;
}

.wb-ai-chat-full-page-header .wb-ai-chat-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wb-ai-chat-full-page-header .wb-ai-chat-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.wb-ai-chat-full-page-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    background: #f8fafc;
}

.wb-ai-chat-full-page-input-container {
    padding: 24px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.wb-ai-chat-full-page-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    height: 56px;
    box-sizing: border-box;
    max-height: 120px;
    overflow-y: auto;
}

.wb-ai-chat-full-page-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.wb-ai-chat-full-page-send {
    width: 48px;
    height: 48px;
    padding: 0 !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    margin: 0;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: #ffffff;
}

.wb-ai-chat-full-page-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.wb-ai-chat-full-page-send:active:not(:disabled) {
    transform: scale(0.95);
}

.wb-ai-chat-full-page-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.wb-ai-chat-full-page-send svg {
    fill: currentColor;
    stroke: currentColor;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    outline: none;
}

/* Full-page loading state */
.wb-ai-chat-full-page-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #6b7280;
}

.wb-ai-chat-full-page-loading p {
    margin: 16px 0 0 0;
    font-size: 16px;
}

/* Responsive adjustments for full-page */
@media (max-width: 768px) {
    .wb-ai-chat-full-page {
        height: calc(100vh - var(--wp-admin--admin-bar--height, 0px) - var(--header-height-mobile, 0px));
        border-radius: 0;
    }

    .wb-ai-chat-full-page-header {
        padding: 16px 20px;
    }

    .wb-ai-chat-full-page-header h2 {
        font-size: 20px;
    }

    .wb-ai-chat-full-page-messages {
        padding: 20px;
        gap: 16px;
    }

    .wb-ai-chat-full-page-input-container {
        padding: 20px;
    }

    .wb-ai-chat-full-page-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 10px 16px;
        height: 48px;
    }

    .wb-ai-chat-full-page-send {
        width: 44px;
        height: 44px;
    }
}

/* Responsive adjustments for horizontal orientation */
@media (max-height: 768px) {
    .wb-ai-chat-full-page {
        min-height: 450px;
    }
    .wb-ai-chat-sidebar {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
    }
}

/* Calculate header height dynamically */
:root {
    --header-height: 0px;
    --header-height-mobile: 0px;
}

/* Agent Status Badge */
.wb-ai-chat-agent-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 12px;
    font-size: 12px;
    color: #667eea;
    margin-bottom: 8px;
    width: fit-content;
}

.wb-ai-chat-agent-status-icon {
    font-size: 14px;
}

.wb-ai-chat-agent-status-text {
    font-weight: 500;
}

/* Sources Consulted Section */
.wb-ai-chat-sources-section {
    margin-top: 16px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.wb-ai-chat-sources-header h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.wb-ai-chat-sources-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wb-ai-chat-source-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.wb-ai-chat-source-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.wb-ai-chat-source-link {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease;
}

.wb-ai-chat-source-link:hover {
    background: rgba(102, 126, 234, 0.05);
}

.wb-ai-chat-source-title {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
    margin-bottom: 2px;
    line-height: 1.3;
    word-break: break-word;
}

.wb-ai-chat-source-date {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.2;
}

/* Chain of Thought Section */
.wb-ai-chat-cot-section {
    margin-top: 8px;
    white-space: normal;
}

.wb-ai-chat-cot-header {
    margin-bottom: 8px;
}

.wb-ai-chat-cot-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    margin: 0;
    background: transparent;
    border: none;
    font-size: 11px;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.2s ease;
    font-family: inherit;
}

.wb-ai-chat-cot-toggle:hover {
    color: #6b7280;
}

.wb-ai-chat-cot-toggle-icon {
    font-size: 10px;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.wb-ai-chat-cot-toggle-icon svg {
    width: 1em;
    height: 1em;
}

.wb-ai-chat-cot-toggle[aria-expanded="true"] .wb-ai-chat-cot-toggle-icon {
    transform: rotate(180deg);
}

.wb-ai-chat-cot-toggle-text {
    font-weight: 500;
}

.wb-ai-chat-cot-content {
    margin-top: 8px;
    animation: slideDown 0.3s ease;
}

.wb-ai-chat-cot-text {
    background: #1f2937;
    color: #f9fafb;
    padding: 12px;
    border-radius: 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    margin: 0;
    border: none;
}


/* Thinking State UI Components */
.wb-ai-chat-thinking-state {
    margin: 0;
    padding: 0;
}
.wb-ai-chat-thinking-planning .wb-ai-chat-typing-indicator {
    flex-shrink: 0;
}

.wb-ai-chat-thinking-text {
    color: var(--wb-ai-chat-text-secondary, #6c757d);
    font-style: italic;
    font-size: 14px;
}

.wb-ai-chat-thinking-status {
    font-size: 13px;
    color: var(--wb-ai-chat-accent-text, #1976d2);
}

.wb-ai-chat-thinking-status .wb-ai-chat-typing-indicator {
    flex-shrink: 0;
}

.wb-ai-chat-thinking-status-text {
    font-weight: 500;
    color: var(--wb-ai-chat-text-secondary, #6c757d);
}

.wb-ai-chat-thinking-stream .wb-ai-chat-message-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wb-ai-chat-thinking-thought-text {
    color: var(--wb-ai-chat-text-secondary, #6c757d);
    font-size: 13px;
    line-height: 1.5;
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Small typing indicator variant */
.wb-ai-chat-typing-small .wb-ai-chat-typing-indicator span {
    width: 4px;
    height: 4px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .wb-ai-chat-agent-status {
        font-size: 11px;
        padding: 3px 6px;
        margin-bottom: 6px;
    }

    .wb-ai-chat-sources-section {
        margin-top: 12px;
        padding: 8px;
    }

    .wb-ai-chat-sources-header h4 {
        font-size: 13px;
        margin-bottom: 8px;
    }

    .wb-ai-chat-source-card {
        margin-bottom: 6px;
    }

    .wb-ai-chat-source-link {
        padding: 6px 8px;
    }

    .wb-ai-chat-source-title {
        font-size: 12px;
    }

    .wb-ai-chat-source-date {
        font-size: 10px;
    }

    .wb-ai-chat-cot-section {
        margin-top: 6px;
    }

    .wb-ai-chat-cot-toggle {
        font-size: 10px;
    }

    .wb-ai-chat-cot-text {
        padding: 8px;
        font-size: 11px;
    }
}

/* Animations */
@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        max-height: 1000px;
        transform: translateY(0);
    }
}

/* Print styles - hide chat interface when printing */
@media print {
    .wb-ai-chat-container,
    .wb-ai-chat-full-page {
        display: none !important;
    }
}