/**
 * AI Readiness Chat - Styles
 * Version: 1.0.0
 * BDE Style: Modern Digital Blue-Green
 */

/* ==========================================
   CSS VARIABLES (BDE Color Palette)
   ========================================== */

:root {
    /* Primary Colors */
    --aichat-primary: #0066CC;
    --aichat-secondary: #00A896;
    --aichat-accent: #02C39A;

    /* Gradients */
    --aichat-gradient-main: linear-gradient(135deg, #0066CC 0%, #00A896 100%);
    --aichat-gradient-hover: linear-gradient(135deg, #0052A3 0%, #008577 100%);

    /* UI Colors */
    --aichat-bg-light: #F0F9FF;
    --aichat-bg-chat: #FFFFFF;
    --aichat-text-dark: #1E293B;
    --aichat-text-light: #64748B;
    --aichat-border: #E2E8F0;

    /* Message Colors */
    --aichat-user-msg: #0066CC;
    --aichat-ai-msg: #F1F5F9;
    --aichat-ai-text: #334155;

    /* Status Colors */
    --aichat-error: #EF4444;

    /* Spacing */
    --aichat-spacing-xs: 4px;
    --aichat-spacing-sm: 8px;
    --aichat-spacing-md: 16px;
    --aichat-spacing-lg: 24px;

    /* Shadows */
    --aichat-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --aichat-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --aichat-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --aichat-shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);

    /* Border Radius */
    --aichat-radius-sm: 8px;
    --aichat-radius-md: 12px;
    --aichat-radius-lg: 16px;
    --aichat-radius-full: 50%;

    /* Transitions */
    --aichat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================
   CHAT BUBBLE (Fixed Bottom Right)
   ========================================== */

.aichat-bubble-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Bubble Button */
.aichat-bubble {
    width: 60px;
    height: 60px;
    border-radius: var(--aichat-radius-full);
    background: var(--aichat-gradient-main);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: var(--aichat-shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--aichat-transition);
    position: relative;
    overflow: hidden;
}

.aichat-bubble:hover {
    background: var(--aichat-gradient-hover);
    box-shadow: var(--aichat-shadow-xl);
    transform: scale(1.05);
}

.aichat-bubble:active {
    transform: scale(0.95);
}

/* Bubble Icons */
.aichat-bubble-icon,
.aichat-bubble-icon-close {
    width: 28px;
    height: 28px;
    transition: var(--aichat-transition);
}

.aichat-bubble-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(90deg);
}

.aichat-bubble.active .aichat-bubble-icon {
    opacity: 0;
    transform: rotate(-90deg);
}

.aichat-bubble.active .aichat-bubble-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* ==========================================
   CHAT WINDOW (Fixed Position)
   ========================================== */

.aichat-window-fixed {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--aichat-bg-chat);
    border-radius: var(--aichat-radius-lg);
    box-shadow: var(--aichat-shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================
   CHAT HEADER
   ========================================== */

.aichat-header {
    background: var(--aichat-gradient-main);
    color: white;
    padding: var(--aichat-spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--aichat-radius-lg) var(--aichat-radius-lg) 0 0;
}

.aichat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.aichat-minimize {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: var(--aichat-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: var(--aichat-transition);
}

.aichat-minimize:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================
   MESSAGES AREA
   ========================================== */

.aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--aichat-spacing-md);
    background: var(--aichat-bg-light);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.aichat-messages::-webkit-scrollbar {
    width: 6px;
}

.aichat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aichat-messages::-webkit-scrollbar-thumb {
    background: var(--aichat-border);
    border-radius: 3px;
}

.aichat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--aichat-text-light);
}

/* ==========================================
   MESSAGE BUBBLES
   ========================================== */

.aichat-message {
    margin-bottom: var(--aichat-spacing-md);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.aichat-message-content {
    padding: 12px 16px;
    border-radius: var(--aichat-radius-md);
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.5;
}

/* User Message (Right-aligned, Blue) */
.aichat-message-user {
    align-items: flex-end;
}

.aichat-message-user .aichat-message-content {
    background: var(--aichat-user-msg);
    color: white;
    border-bottom-right-radius: 4px;
}

/* AI Message (Left-aligned, Gray) */
.aichat-message-ai {
    align-items: flex-start;
}

.aichat-message-ai .aichat-message-content {
    background: var(--aichat-ai-msg);
    color: var(--aichat-ai-text);
    border-bottom-left-radius: 4px;
}

/* Error Message */
.aichat-message-error .aichat-message-content {
    background: #FEE2E2;
    color: var(--aichat-error);
    border-left: 3px solid var(--aichat-error);
}

/* ==========================================
   TYPING INDICATOR
   ========================================== */

.aichat-typing {
    align-items: flex-start;
}

.aichat-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--aichat-ai-msg);
    border-radius: var(--aichat-radius-md);
    border-bottom-left-radius: 4px;
}

.aichat-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--aichat-text-light);
    border-radius: var(--aichat-radius-full);
    animation: typingDot 1.4s infinite;
}

.aichat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.aichat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ==========================================
   INPUT AREA
   ========================================== */

.aichat-input-area {
    display: flex;
    gap: var(--aichat-spacing-sm);
    padding: var(--aichat-spacing-md);
    background: white;
    border-top: 1px solid var(--aichat-border);
    align-items: flex-end;
}

.aichat-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--aichat-border);
    border-radius: var(--aichat-radius-md);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: var(--aichat-transition);
}

.aichat-input:focus {
    outline: none;
    border-color: var(--aichat-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.aichat-input:disabled {
    background: var(--aichat-bg-light);
    cursor: not-allowed;
}

.aichat-send-btn {
    background: var(--aichat-gradient-main);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--aichat-radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--aichat-transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    height: 42px;
}

.aichat-send-btn:hover:not(:disabled) {
    background: var(--aichat-gradient-hover);
    transform: translateY(-1px);
    box-shadow: var(--aichat-shadow-md);
}

.aichat-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.aichat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading spinner */
.aichat-send-btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: var(--aichat-radius-full);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================
   INLINE CHAT (Optional)
   ========================================== */

.aichat-container[data-mode="inline"] .aichat-window {
    max-width: 600px;
    margin: 0 auto;
    border: 1px solid var(--aichat-border);
    border-radius: var(--aichat-radius-lg);
    box-shadow: var(--aichat-shadow-md);
    overflow: hidden;
}

.aichat-container[data-mode="inline"] .aichat-messages {
    height: 400px;
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */

@media (max-width: 768px) {
    .aichat-bubble-container {
        bottom: 16px;
        right: 16px;
    }

    .aichat-window-fixed {
        bottom: 90px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
        height: calc(100vh - 120px);
    }

    .aichat-bubble {
        width: 56px;
        height: 56px;
    }

    .aichat-bubble-icon,
    .aichat-bubble-icon-close {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 480px) {
    .aichat-header h3 {
        font-size: 16px;
    }

    .aichat-messages {
        padding: var(--aichat-spacing-sm);
    }

    .aichat-message-content {
        max-width: 85%;
        font-size: 14px;
    }

    .aichat-input-area {
        padding: var(--aichat-spacing-sm);
    }
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */

.aichat-bubble:focus,
.aichat-send-btn:focus,
.aichat-input:focus {
    outline: 2px solid var(--aichat-primary);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .aichat-bubble,
    .aichat-send-btn {
        border: 2px solid currentColor;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --aichat-bg-light: #1E293B;
        --aichat-bg-chat: #0F172A;
        --aichat-text-dark: #F1F5F9;
        --aichat-text-light: #94A3B8;
        --aichat-border: #334155;
        --aichat-ai-msg: #334155;
        --aichat-ai-text: #E2E8F0;
    }
}

/* ==========================================
   MARKDOWN CONTENT STYLES
   ========================================== */

.aichat-markdown {
    line-height: 1.6;
    word-wrap: break-word;
}

/* Headings */
.aichat-markdown h1,
.aichat-markdown h2,
.aichat-markdown h3 {
    margin: 12px 0 8px;
    font-weight: 600;
    color: #0066CC;  /* BDE primary */
}

.aichat-markdown h1 {
    font-size: 1.4em;
    border-bottom: 1px solid #E2E8F0;
    padding-bottom: 8px;
}

.aichat-markdown h2 {
    font-size: 1.25em;
}

.aichat-markdown h3 {
    font-size: 1.1em;
}

.aichat-markdown h4 {
    font-size: 1em;
    font-weight: 600;
    margin: 8px 0 4px;
}

/* Text Formatting */
.aichat-markdown strong {
    font-weight: 600;
    color: #0066CC;
}

.aichat-markdown em {
    font-style: italic;
}

.aichat-markdown p {
    margin: 8px 0;
}

/* Lists */
.aichat-markdown ul,
.aichat-markdown ol {
    margin: 8px 0;
    padding-left: 24px;
}

.aichat-markdown li {
    margin: 4px 0;
}

.aichat-markdown li::marker {
    color: #00A896;  /* BDE accent */
    font-weight: 600;
}

/* Code */
.aichat-markdown code {
    background: rgba(0, 102, 204, 0.08);
    border: 1px solid rgba(0, 102, 204, 0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #0066CC;
}

.aichat-markdown pre {
    background: #F6F8FA;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.aichat-markdown pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
}

/* Blockquotes */
.aichat-markdown blockquote {
    border-left: 4px solid #00A896;  /* BDE accent */
    background: rgba(0, 168, 150, 0.05);
    padding: 8px 16px;
    margin: 8px 0;
    color: #64748B;
}

.aichat-markdown blockquote p:last-child {
    margin-bottom: 0;
}

/* Links */
.aichat-markdown a {
    color: #0066CC;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.aichat-markdown a:hover {
    border-bottom-color: #0066CC;
}

/* Horizontal Rule */
.aichat-markdown hr {
    border: none;
    border-top: 1px solid #E2E8F0;
    margin: 16px 0;
}

/* Tables */
.aichat-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 0.9em;
}

.aichat-markdown th,
.aichat-markdown td {
    border: 1px solid #E2E8F0;
    padding: 8px 12px;
    text-align: left;
}

.aichat-markdown th {
    background: #F6F8FA;
    font-weight: 600;
    color: #0066CC;
}

.aichat-markdown tr:nth-child(even) {
    background: #F9F9F9;
}

/* Dark Mode for Markdown */
@media (prefers-color-scheme: dark) {
    .aichat-markdown h1,
    .aichat-markdown h2,
    .aichat-markdown h3,
    .aichat-markdown strong {
        color: #4DA3FF;
    }

    .aichat-markdown code {
        background: rgba(77, 163, 255, 0.15);
        border-color: rgba(77, 163, 255, 0.3);
        color: #4DA3FF;
    }

    .aichat-markdown pre {
        background: #1E1E1E;
        border-color: #444;
    }

    .aichat-markdown blockquote {
        border-left-color: #00DDC0;
        background: rgba(0, 221, 192, 0.08);
    }

    .aichat-markdown a {
        color: #4DA3FF;
    }

    .aichat-markdown th {
        background: #2A2A2A;
        color: #4DA3FF;
    }

    .aichat-markdown th,
    .aichat-markdown td {
        border-color: #444;
    }

    .aichat-markdown tr:nth-child(even) {
        background: #252525;
    }
}

/* Responsive for Markdown */
@media (max-width: 768px) {
    .aichat-markdown h1 { font-size: 1.2em; }
    .aichat-markdown h2 { font-size: 1.1em; }

    .aichat-markdown pre {
        padding: 8px;
        font-size: 0.85em;
    }

    .aichat-markdown table {
        font-size: 0.85em;
    }
}
