/**
 * AI Chat Widget - 樣式
 * 
 * @package Ez2_AI_Business_Suite
 * @subpackage SkyEye
 * @since 2.55.0
 */

/* CSS Variables */
.ez2-chat-widget {
    --ez2-chat-primary: #2271b1;
    --ez2-chat-primary-dark: #1a5a8c;
    --ez2-chat-bg: #ffffff;
    --ez2-chat-text: #1e1e1e;
    --ez2-chat-text-light: #666666;
    --ez2-chat-border: #e0e0e0;
    --ez2-chat-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    --ez2-chat-radius: 16px;
    --ez2-chat-radius-sm: 8px;
    --ez2-chat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Container */
.ez2-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: var(--ez2-chat-font);
    font-size: 14px;
    line-height: 1.5;
}

.ez2-chat-widget[data-position="right"] {
    right: 20px;
}

.ez2-chat-widget[data-position="left"] {
    left: 20px;
}

/* Toggle Button */
.ez2-chat-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ez2-chat-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: var(--ez2-chat-shadow);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ez2-chat-toggle:hover {
    background: var(--ez2-chat-primary-dark);
    transform: scale(1.05);
}

.ez2-chat-toggle.is-open {
    transform: rotate(180deg);
}

.ez2-chat-toggle-icon {
    font-size: 24px;
}

.ez2-chat-toggle-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #dc3545;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat Window */
.ez2-chat-window {
    position: absolute;
    bottom: 70px;
    width: 360px;
    max-height: 520px;
    background: var(--ez2-chat-bg);
    border-radius: var(--ez2-chat-radius);
    box-shadow: var(--ez2-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ez2-chat-widget[data-position="right"] .ez2-chat-window {
    right: 0;
}

.ez2-chat-widget[data-position="left"] .ez2-chat-window {
    left: 0;
}

/* Header */
.ez2-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--ez2-chat-primary);
    color: #ffffff;
}

.ez2-chat-header-info {
    flex: 1;
}

.ez2-chat-header-title {
    font-size: 16px;
    font-weight: 600;
}

.ez2-chat-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}

.ez2-chat-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

/* Body */
.ez2-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    max-height: 360px;
}

/* Messages */
.ez2-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ez2-chat-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}

.ez2-chat-message.is-user {
    align-self: flex-end;
    align-items: flex-end;
}

.ez2-chat-message.is-system {
    align-self: center;
    max-width: 90%;
}

.ez2-chat-message-bubble {
    padding: 10px 14px;
    border-radius: var(--ez2-chat-radius-sm);
    background: var(--ez2-chat-bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ez2-chat-message.is-user .ez2-chat-message-bubble {
    background: var(--ez2-chat-primary);
    color: #fff;
}

.ez2-chat-message.is-system .ez2-chat-message-bubble {
    background: #e9ecef;
    color: var(--ez2-chat-text-light);
    font-size: 13px;
    text-align: center;
}

.ez2-chat-message-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ez2-chat-message-content a {
    color: inherit;
    text-decoration: underline;
}

.ez2-chat-message-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 13px;
}

.ez2-chat-message.is-user .ez2-chat-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.ez2-chat-message-time {
    font-size: 11px;
    color: var(--ez2-chat-text-light);
    margin-top: 4px;
}

.ez2-chat-message.is-user .ez2-chat-message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Typing Indicator */
.ez2-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ez2-chat-bg);
    border-radius: var(--ez2-chat-radius-sm);
    width: fit-content;
    margin-top: 12px;
}

.ez2-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ez2-chat-text-light);
    border-radius: 50%;
    animation: ez2-chat-typing 1.4s infinite ease-in-out both;
}

.ez2-chat-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ez2-chat-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Form */
.ez2-chat-form {
    padding: 12px 16px;
    background: var(--ez2-chat-bg);
    border-top: 1px solid var(--ez2-chat-border);
}

.ez2-chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8f9fa;
    border: 1px solid var(--ez2-chat-border);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ez2-chat-input-wrap:focus-within {
    border-color: var(--ez2-chat-primary);
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1);
}

.ez2-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--ez2-chat-text);
    outline: none;
}

.ez2-chat-input::placeholder {
    color: var(--ez2-chat-text-light);
}

.ez2-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ez2-chat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s;
}

.ez2-chat-send:hover:not(:disabled) {
    background: var(--ez2-chat-primary-dark);
}

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

/* Scrollbar */
.ez2-chat-body::-webkit-scrollbar {
    width: 6px;
}

.ez2-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.ez2-chat-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.ez2-chat-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mobile */
@media (max-width: 480px) {
    .ez2-chat-widget {
        bottom: 10px;
    }
    
    .ez2-chat-widget[data-position="right"] {
        right: 10px;
    }
    
    .ez2-chat-widget[data-position="left"] {
        left: 10px;
    }
    
    .ez2-chat-window {
        width: calc(100vw - 20px);
        max-width: 360px;
        max-height: calc(100vh - 100px);
    }
    
    .ez2-chat-body {
        max-height: calc(100vh - 250px);
    }
}

/* Animation */
.ez2-chat-window {
    animation: ez2-chat-slide-up 0.3s ease-out;
}

@keyframes ez2-chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .ez2-chat-widget {
        --ez2-chat-bg: #2d2d2d;
        --ez2-chat-text: #e0e0e0;
        --ez2-chat-text-light: #a0a0a0;
        --ez2-chat-border: #404040;
    }
    
    .ez2-chat-body {
        background: #1e1e1e;
    }
    
    .ez2-chat-input-wrap {
        background: #363636;
        border-color: #404040;
    }
    
    .ez2-chat-message.is-system .ez2-chat-message-bubble {
        background: #363636;
    }
}
