/**
 * AI Chat Widget Styles for ai-work.at
 * Brand-aligned design with accessibility support
 *
 * Colors from Brand Kit:
 * - Primary: #2B8CA3 (Teal)
 * - Text: #0F223D (Deep Oxford Blue)
 * - Background: #F9FAFC (Off-White Pearl)
 * - Cards: #FFFFFF with shadow
 */

/* ============================================
   Widget Container
   ============================================ */

.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Chat Bubble Button
   ============================================ */

.ai-chat-bubble {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2B8CA3 0%, #1E6B7D 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 4px 12px rgba(43, 140, 163, 0.35),
        0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow:
        0 6px 20px rgba(43, 140, 163, 0.45),
        0 3px 6px rgba(0, 0, 0, 0.15);
}

.ai-chat-bubble:focus {
    outline: none;
    box-shadow:
        0 0 0 3px rgba(43, 140, 163, 0.4),
        0 4px 12px rgba(43, 140, 163, 0.35);
}

.ai-chat-bubble:active {
    transform: scale(0.98);
}

.ai-chat-bubble svg {
    width: 26px;
    height: 26px;
}

.ai-chat-bubble-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(43, 140, 163, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.2);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* ============================================
   Chat Window
   ============================================ */

.ai-chat-window {
    display: none;
    flex-direction: column;
    width: 380px;
    height: 560px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow:
        0 12px 40px rgba(15, 34, 61, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-chat-widget.is-open .ai-chat-window {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ============================================
   Chat Header
   ============================================ */

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #2B8CA3 0%, #1E6B7D 100%);
    color: white;
}

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

.ai-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-header-avatar svg {
    color: white;
}

.ai-chat-header-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
}

.ai-chat-header-subtitle {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.85;
    color: rgba(255, 255, 255, 0.9);
}

.ai-chat-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ai-chat-close:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

/* ============================================
   Chat Messages
   ============================================ */

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #F9FAFC;
    scroll-behavior: smooth;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(43, 140, 163, 0.3);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(43, 140, 163, 0.5);
}

/* ============================================
   Message Bubbles
   ============================================ */

.ai-chat-message {
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
}

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

.ai-chat-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* User Messages */
.ai-chat-message--user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.ai-chat-message--user .ai-chat-message-content {
    background: linear-gradient(135deg, #2B8CA3 0%, #1E6B7D 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Assistant Messages */
.ai-chat-message--assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.ai-chat-message--assistant .ai-chat-message-content {
    background: #ffffff;
    color: #0F223D;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Message Time */
.ai-chat-message-time {
    font-size: 11px;
    color: #8896A6;
    margin-top: 4px;
    padding: 0 4px;
}

/* Links in Messages */
.ai-chat-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chat-message--user .ai-chat-link {
    color: white;
}

.ai-chat-message--assistant .ai-chat-link {
    color: #2B8CA3;
}

.ai-chat-link:hover {
    text-decoration-thickness: 2px;
}

/* Lists in Messages */
.ai-chat-message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chat-message-content li {
    margin-bottom: 4px;
}

/* Strong/Bold */
.ai-chat-message-content strong {
    font-weight: 600;
}

/* ============================================
   Typing Indicator
   ============================================ */

.ai-chat-typing .ai-chat-message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
}

.ai-chat-typing-dots {
    display: flex;
    gap: 4px;
}

.ai-chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: #2B8CA3;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.ai-chat-typing-text {
    font-size: 12px;
    color: #8896A6;
    font-style: italic;
}

/* ============================================
   Error Message
   ============================================ */

.ai-chat-error {
    display: none;
    padding: 12px 16px;
    margin: 0 16px 12px;
    background: #FEE2E2;
    color: #991B1B;
    border-radius: 8px;
    font-size: 13px;
    animation: messageSlideIn 0.3s ease;
}

.ai-chat-error.is-visible {
    display: block;
}

/* ============================================
   Input Area
   ============================================ */

.ai-chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 16px;
    background: #ffffff;
    border-top: 1px solid #E5E7EB;
}

.ai-chat-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    color: #0F223D;
    background: #F9FAFC;
    resize: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input::placeholder {
    color: #8896A6;
}

.ai-chat-input:focus {
    outline: none;
    border-color: #2B8CA3;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(43, 140, 163, 0.15);
}

.ai-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-chat-send {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #2B8CA3 0%, #1E6B7D 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.ai-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
}

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

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-send:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(43, 140, 163, 0.3);
}

/* ============================================
   Footer
   ============================================ */

.ai-chat-footer {
    padding: 8px 16px;
    text-align: center;
    font-size: 11px;
    color: #8896A6;
    background: #ffffff;
    border-top: 1px solid #E5E7EB;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 480px) {
    .ai-chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
    }

    .ai-chat-bubble {
        position: fixed;
        bottom: 16px;
        right: 16px;
    }

    .ai-chat-widget.is-open .ai-chat-bubble {
        display: none;
    }

    .ai-chat-window {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .ai-chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .ai-chat-messages {
        padding: 16px;
    }

    .ai-chat-input-container {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

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

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .ai-chat-bubble-pulse {
        animation: none;
    }

    .ai-chat-window {
        transition: opacity 0.15s ease;
        transform: none;
    }

    .ai-chat-message {
        animation: none;
    }

    .ai-chat-typing-dots span {
        animation: none;
        opacity: 0.7;
    }

    .ai-chat-bubble:hover,
    .ai-chat-send:hover:not(:disabled) {
        transform: none;
    }
}

/* ============================================
   Dark Mode Support
   ============================================ */

@media (prefers-color-scheme: dark) {
    .ai-chat-window {
        background: #1a1a2e;
    }

    .ai-chat-messages {
        background: #16162a;
    }

    .ai-chat-message--assistant .ai-chat-message-content {
        background: #252540;
        color: #E5E7EB;
    }

    .ai-chat-message-time {
        color: #6B7280;
    }

    .ai-chat-input-container {
        background: #1a1a2e;
        border-top-color: #374151;
    }

    .ai-chat-input {
        background: #252540;
        border-color: #374151;
        color: #E5E7EB;
    }

    .ai-chat-input::placeholder {
        color: #6B7280;
    }

    .ai-chat-input:focus {
        background: #252540;
        border-color: #2B8CA3;
    }

    .ai-chat-footer {
        background: #1a1a2e;
        border-top-color: #374151;
        color: #6B7280;
    }

    .ai-chat-error {
        background: #450a0a;
        color: #fecaca;
    }

    .ai-chat-message--assistant .ai-chat-link {
        color: #5BBFD0;
    }

    .ai-chat-messages::-webkit-scrollbar-thumb {
        background: rgba(91, 191, 208, 0.3);
    }

    .ai-chat-messages::-webkit-scrollbar-thumb:hover {
        background: rgba(91, 191, 208, 0.5);
    }
}

/* Dark mode class-based override (for site dark mode toggle) */
.dark .ai-chat-window,
[data-theme="dark"] .ai-chat-window {
    background: #1a1a2e;
}

.dark .ai-chat-messages,
[data-theme="dark"] .ai-chat-messages {
    background: #16162a;
}

.dark .ai-chat-message--assistant .ai-chat-message-content,
[data-theme="dark"] .ai-chat-message--assistant .ai-chat-message-content {
    background: #252540;
    color: #E5E7EB;
}

.dark .ai-chat-input-container,
[data-theme="dark"] .ai-chat-input-container {
    background: #1a1a2e;
    border-top-color: #374151;
}

.dark .ai-chat-input,
[data-theme="dark"] .ai-chat-input {
    background: #252540;
    border-color: #374151;
    color: #E5E7EB;
}

.dark .ai-chat-footer,
[data-theme="dark"] .ai-chat-footer {
    background: #1a1a2e;
    border-top-color: #374151;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .ai-chat-widget {
        display: none !important;
    }
}
