/* 
 * Sia Intelligence Concierge V2.1 Styles
 * Theme: Ultra-Premium Glassmorphism & BusinessDay Branding
 */

:root {
    --sia-surface: rgba(255, 255, 255, 0.75);
    --sia-surface-opaque: #ffffff;
    --sia-blur: blur(16px);
    --sia-border: 1px solid rgba(0, 0, 0, 0.08);
    --sia-shadow: 0 16px 48px -12px rgba(0, 0, 0, 0.1), 0 4px 12px 0 rgba(0, 0, 0, 0.03);
    
    --sia-text-primary: #1e2025;
    --sia-text-secondary: #5d616d;
    
    --sia-accent: #cc0000; /* BusinessDay primary red */
    --sia-accent-hover: #b30000;
    --sia-accent-glow: rgba(204, 0, 0, 0.15);
    
    --sia-bubble-size: 60px;
    --sia-widget-width: 385px;
    --sia-widget-height: 620px;
    
    --sia-user-msg-bg: linear-gradient(135deg, #cc0000 0%, #ff2a2a 100%);
    --sia-user-msg-text: #ffffff;
    --sia-bot-msg-bg: #ffffff;
    --sia-bot-msg-border: 1px solid rgba(0, 0, 0, 0.06);
    --sia-bot-msg-text: #1e2025;
    
    --sia-card-border: rgba(0, 0, 0, 0.06);
    --sia-card-bg: rgba(125, 125, 125, 0.04);
    --sia-card-hover-bg: rgba(204, 0, 0, 0.03);
}

/* Dark Mode Variables (System Preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --sia-surface: rgba(20, 20, 24, 0.85);
        --sia-surface-opaque: #161619;
        --sia-border: 1px solid rgba(255, 255, 255, 0.08);
        --sia-shadow: 0 20px 48px -12px rgba(0, 0, 0, 0.6), 0 4px 20px 0 rgba(0, 0, 0, 0.3);
        --sia-text-primary: #f0f1f5;
        --sia-text-secondary: #9fa2ad;
        
        --sia-user-msg-bg: linear-gradient(135deg, #cc0000 0%, #b30000 100%);
        --sia-user-msg-text: #ffffff;
        --sia-bot-msg-bg: #1e1e24;
        --sia-bot-msg-border: 1px solid rgba(255, 255, 255, 0.06);
        --sia-bot-msg-text: #f0f1f5;
        
        --sia-card-border: rgba(255, 255, 255, 0.06);
        --sia-card-bg: rgba(255, 255, 255, 0.04);
        --sia-card-hover-bg: rgba(204, 0, 0, 0.08);
    }
}

/* Fallback/Overrides for Manual Theme Toggling (WP Preview Dashboard support) */
[data-theme="dark"], .dark-mode-preview {
    --sia-surface: rgba(20, 20, 24, 0.85);
    --sia-surface-opaque: #161619;
    --sia-border: 1px solid rgba(255, 255, 255, 0.08);
    --sia-shadow: 0 20px 48px -12px rgba(0, 0, 0, 0.6), 0 4px 20px 0 rgba(0, 0, 0, 0.3);
    --sia-text-primary: #f0f1f5;
    --sia-text-secondary: #9fa2ad;
    
    --sia-user-msg-bg: linear-gradient(135deg, #cc0000 0%, #b30000 100%);
    --sia-user-msg-text: #ffffff;
    --sia-bot-msg-bg: #1e1e24;
    --sia-bot-msg-border: 1px solid rgba(255, 255, 255, 0.06);
    --sia-bot-msg-text: #f0f1f5;
    
    --sia-card-border: rgba(255, 255, 255, 0.06);
    --sia-card-bg: rgba(255, 255, 255, 0.04);
    --sia-card-hover-bg: rgba(204, 0, 0, 0.08);
}

/* Reset inside widget */
#sia-widget-root * {
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* The Bubble Trigger */
#sia-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--sia-bubble-size);
    height: var(--sia-bubble-size);
    border-radius: 50%;
    background: var(--sia-surface);
    backdrop-filter: var(--sia-blur);
    -webkit-backdrop-filter: var(--sia-blur);
    border: var(--sia-border);
    box-shadow: var(--sia-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.35s ease;
}

#sia-bubble:hover {
    transform: scale(1.06);
    box-shadow: 0 12px 40px 0 rgba(204, 0, 0, 0.15), var(--sia-shadow);
}

#sia-bubble svg {
    width: 30px;
    height: 30px;
    fill: var(--sia-text-primary);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* The Main Widget Window */
#sia-widget-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--sia-widget-width);
    height: var(--sia-widget-height);
    background: var(--sia-surface-opaque);
    border: var(--sia-border);
    box-shadow: var(--sia-shadow);
    border-radius: 20px;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    
    /* Animation defaults */
    opacity: 0;
    transform: translateY(24px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#sia-widget-window.sia-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.sia-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--sia-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--sia-surface-opaque);
    z-index: 10;
}

.sia-header-title-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sia-header-info {
    display: flex;
    flex-direction: column;
}

.sia-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--sia-text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
}

.sia-header-subtitle {
    font-size: 11px;
    font-weight: 400;
    color: var(--sia-text-secondary);
    margin-top: 2px;
}

/* Pulsing Status Dot */
.sia-status-dot {
    width: 7px;
    height: 7px;
    background-color: #00cc66;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 6px #00cc66;
    animation: siaPulse 2s infinite ease-in-out;
}

@keyframes siaPulse {
    0% { transform: scale(0.85); opacity: 0.6; box-shadow: 0 0 0 0 rgba(0, 204, 102, 0.7); }
    50% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 0 5px rgba(0, 204, 102, 0); }
    100% { transform: scale(0.85); opacity: 0.6; box-shadow: 0 0 0 0 rgba(0, 204, 102, 0); }
}

.sia-close-btn {
    background: transparent;
    border: none;
    color: var(--sia-text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.sia-close-btn:hover {
    background: rgba(125, 125, 125, 0.12);
    color: var(--sia-text-primary);
}

/* Chat Area */
.sia-chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    background: var(--sia-surface-opaque);
}

/* Scrollbar Styling */
.sia-chat-area::-webkit-scrollbar {
    width: 6px;
}
.sia-chat-area::-webkit-scrollbar-track {
    background: transparent;
}
.sia-chat-area::-webkit-scrollbar-thumb {
    background: rgba(125, 125, 125, 0.2);
    border-radius: 10px;
}
.sia-chat-area::-webkit-scrollbar-thumb:hover {
    background: rgba(125, 125, 125, 0.4);
}

/* Message Container for Bot with Avatar */
.sia-msg-bot-container {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    align-self: flex-start;
    max-width: 85%;
    animation: siaFadeIn 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.sia-bot-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--sia-border);
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    flex-shrink: 0;
    overflow: hidden;
    margin-top: 2px;
    background-size: 180% 180%;
    background-position: center 28%;
    background-repeat: no-repeat;
}

/* Messages */
.sia-msg {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.05px;
    animation: siaFadeIn 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes siaFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.sia-msg-user {
    align-self: flex-end;
    max-width: 82%;
    background: var(--sia-user-msg-bg);
    color: var(--sia-user-msg-text);
    box-shadow: 0 4px 16px rgba(204, 0, 0, 0.12);
    border-bottom-right-radius: 4px;
}

.sia-msg-bot {
    background: var(--sia-bot-msg-bg);
    border: var(--sia-bot-msg-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    color: var(--sia-bot-msg-text);
    border-bottom-left-radius: 4px;
    flex: 1;
}

/* Markdown styling inside bot message */
.sia-msg-bot p { margin: 0 0 10px 0; }
.sia-msg-bot p:last-child { margin-bottom: 0; }
.sia-msg-bot ul, .sia-msg-bot ol { margin: 0 0 10px 0; padding-left: 20px; }
.sia-msg-bot li { margin-bottom: 4px; }
.sia-msg-bot strong { font-weight: 600; }
.sia-msg-bot a { 
    color: var(--sia-accent); 
    text-decoration: none; 
    font-weight: 500;
    border-bottom: 1px dashed var(--sia-accent);
    transition: background 0.2s;
}
.sia-msg-bot a:hover {
    background: rgba(204, 0, 0, 0.07);
}

/* Source Cards */
.sia-source-card {
    display: block;
    margin-top: 10px;
    padding: 11px 14px;
    background: var(--sia-card-bg);
    border: 1px solid var(--sia-card-border);
    border-radius: 10px;
    text-decoration: none !important;
    border-bottom: none !important;
    transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
}

.sia-source-card:hover {
    background-color: var(--sia-card-hover-bg);
    border-color: rgba(204, 0, 0, 0.25);
    transform: translateY(-2px);
}

.sia-source-card-title {
    display: block;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--sia-text-primary);
    margin-bottom: 4px;
}

.sia-source-card-url {
    display: block;
    font-size: 11px;
    color: var(--sia-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Suggested Context Prompts (Outline Pills) */
.sia-prompts-container {
    padding: 0;
    margin: 14px 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.sia-prompts-label {
    display: block;
    width: 100%;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sia-text-secondary);
    margin-bottom: 6px;
    margin-top: 6px;
}

.sia-prompt-btn {
    background: var(--sia-bot-msg-bg);
    border: 1px solid var(--sia-border);
    color: var(--sia-text-primary);
    padding: 11px 15px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.01);
}

.sia-prompt-btn:hover {
    background: var(--sia-accent);
    border-color: var(--sia-accent);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px -4px rgba(204, 0, 0, 0.25), var(--sia-shadow);
}

.sia-prompt-arrow {
    color: var(--sia-accent);
    font-size: 14px;
    font-weight: 600;
    opacity: 0.7;
    transition: transform 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.sia-prompt-btn:hover .sia-prompt-arrow {
    color: #ffffff;
    opacity: 1;
    transform: translateX(3px);
}

/* Input Area capsule */
.sia-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--sia-border);
    display: flex;
    gap: 10px;
    background: var(--sia-surface-opaque);
    align-items: center;
    z-index: 10;
}

.sia-input-wrapper {
    flex: 1;
    position: relative;
}

.sia-input {
    width: 100%;
    background: var(--sia-card-bg);
    border: 1px solid var(--sia-border);
    border-radius: 24px;
    padding: 11px 18px;
    font-size: 14px;
    color: var(--sia-text-primary);
    outline: none;
    transition: all 0.25s ease;
}

.sia-input:focus {
    border-color: rgba(204, 0, 0, 0.4);
    background: var(--sia-surface-opaque);
    box-shadow: 0 0 0 3px rgba(204, 0, 0, 0.08);
}

.sia-input::placeholder {
    color: var(--sia-text-secondary);
    opacity: 0.7;
}

.sia-send-btn {
    background: var(--sia-accent);
    color: #ffffff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(204, 0, 0, 0.2);
    flex-shrink: 0;
}

.sia-send-btn:hover {
    transform: scale(1.08);
    background: var(--sia-accent-hover);
    box-shadow: 0 6px 16px rgba(204, 0, 0, 0.3);
}

.sia-send-btn svg {
    fill: currentColor;
    width: 18px;
    height: 18px;
    transform: translateX(1px);
}

/* Typing Indicator (Custom container next to avatar) */
.sia-typing-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: var(--sia-bot-msg-bg);
    border: var(--sia-bot-msg-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin-left: 36px; /* Offset to align with messages next to avatar */
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    width: fit-content;
}

.sia-dot {
    width: 6px;
    height: 6px;
    background: var(--sia-text-secondary);
    border-radius: 50%;
    animation: siaBounce 1.4s infinite ease-in-out both;
}

.sia-dot:nth-child(1) { animation-delay: -0.32s; }
.sia-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes siaBounce {
    0%, 80%, 100% { transform: scale(0.3); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Callout Message */
.sia-callout {
    position: fixed;
    bottom: 30px;
    right: 96px; 
    max-width: 260px;
    background: var(--sia-surface);
    backdrop-filter: var(--sia-blur);
    -webkit-backdrop-filter: var(--sia-blur);
    border: var(--sia-border);
    border-left: 3.5px solid var(--sia-accent);
    box-shadow: 0 12px 40px 0 rgba(204, 0, 0, 0.08), var(--sia-shadow);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--sia-text-primary);
    cursor: pointer;
    z-index: 9999;
    
    /* Animation / visibility */
    opacity: 0;
    transform: translateX(12px);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.sia-callout-active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

/* Callout Arrow (speech bubble pointer pointing right) */
.sia-callout::after {
    content: '';
    position: absolute;
    right: -6px;
    top: calc(50% - 6px);
    width: 11px;
    height: 11px;
    background: var(--sia-surface-opaque);
    border-top: var(--sia-border);
    border-right: var(--sia-border);
    transform: rotate(45deg);
}

.sia-callout-text {
    pointer-events: none;
    margin-right: 12px;
}

/* Callout Close Button (X in corner) */
.sia-callout-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sia-text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
}

.sia-callout-close-btn:hover {
    background: rgba(125, 125, 125, 0.15);
    color: var(--sia-text-primary);
}

.sia-callout-close-btn svg {
    width: 10px;
    height: 10px;
    fill: currentColor;
}

.sia-callout-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.sia-callout-btn {
    font-size: 11.5px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.sia-callout-btn:active {
    transform: scale(0.96);
}

.sia-callout-btn-primary {
    background: var(--sia-accent);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(204, 0, 0, 0.2);
}

.sia-callout-btn-primary:hover {
    background: var(--sia-accent-hover);
    box-shadow: 0 4px 10px rgba(204, 0, 0, 0.3);
}

.sia-callout-btn-secondary {
    background: var(--sia-card-bg);
    color: var(--sia-text-primary);
    border: 1px solid var(--sia-border);
}

.sia-callout-btn-secondary:hover {
    background: rgba(125, 125, 125, 0.12);
}

/* Mobile Responsiveness */
@media screen and (max-width: 480px) {
    #sia-bubble {
        bottom: 16px;
        right: 16px;
        left: auto;
    }
    
    #sia-widget-window {
        bottom: 16px;
        right: 16px;
        left: auto;
        width: calc(100% - 32px);
        max-width: 380px;
        height: 75vh;
        max-height: 520px;
        border-radius: 16px;
        transform: translateY(16px) scale(0.96);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s;
    }

    #sia-widget-window.sia-open {
        transform: translateY(0) scale(1);
    }

    .sia-header {
        padding: 16px 20px;
    }
    
    .sia-close-btn {
        padding: 8px;
        background: rgba(125, 125, 125, 0.12);
    }

    .sia-callout {
        bottom: 90px;
        right: 16px;
        left: auto;
        max-width: calc(100% - 32px);
        transform: translateY(12px);
    }

    .sia-callout-active {
        transform: translateY(0);
    }

    .sia-callout::after {
        right: 22px;
        left: auto;
        top: auto;
        bottom: -6px;
        border-top: none;
        border-left: none;
        border-bottom: var(--sia-border);
        border-right: var(--sia-border);
        transform: rotate(45deg);
    }
}
