/* SmartChat AI - Modern Clean Interface */

/* CSS Variables - defaults, overridden by inline styles */
:root {
    --smartchat-primary: #4F46E5;
    --smartchat-secondary: #6366F1;
    --smartchat-link-color: #2563EB;
    --smartchat-font-size: 14px;
    --smartchat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --smartchat-bubble-size: 60px;
    --smartchat-text: #1a1a1a;
    --smartchat-text-muted: #71717a;
    --smartchat-bg: #FFFFFF;
    --smartchat-bg-chat: #FAFAFA;
    --smartchat-border: #e4e4e7;
    --smartchat-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    --smartchat-radius: 16px;
}

/* Reset */
.smartchat-widget,
.smartchat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Widget Container */
.smartchat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--smartchat-font);
    font-size: var(--smartchat-font-size);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==================== Toggle Button ==================== */
.smartchat-toggle {
    width: var(--smartchat-bubble-size);
    height: var(--smartchat-bubble-size);
    border-radius: 50%;
    background: var(--smartchat-primary);
    border: none;
    box-shadow: var(--smartchat-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.smartchat-toggle:hover {
    transform: scale(1.05);
}

.smartchat-toggle:active {
    transform: scale(0.95);
}

.smartchat-toggle svg {
    width: calc(var(--smartchat-bubble-size) * 0.45);
    height: calc(var(--smartchat-bubble-size) * 0.45);
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: absolute;
}

.smartchat-toggle .chat-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.smartchat-toggle .close-icon {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

/* When open - toggle becomes close button */
.smartchat-widget.open .smartchat-toggle .chat-icon {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.smartchat-widget.open .smartchat-toggle .close-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.smartchat-widget.open .smartchat-toggle {
    background: #374151;
}

/* Notification Dot */
.notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
    display: none;
}

.notification-dot.active {
    display: block;
}

/* ==================== Chat Window ==================== */
.smartchat-window {
    position: absolute;
    bottom: calc(var(--smartchat-bubble-size) + 16px);
    right: 0;
    width: 340px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--smartchat-bg);
    border-radius: var(--smartchat-radius);
    box-shadow: var(--smartchat-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
}

.smartchat-widget.open .smartchat-window {
    display: flex;
    animation: windowSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Header ==================== */
.smartchat-header {
    background: var(--smartchat-primary);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.bot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.bot-avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-avatar-placeholder svg {
    width: 20px;
    height: 20px;
    color: white;
    opacity: 0.9;
}

.header-info {
    flex: 1;
    min-width: 0;
}

.header-info h3 {
    font-size: calc(var(--smartchat-font-size) + 1px);
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.header-btn svg {
    width: 16px;
    height: 16px;
}

/* ==================== Messages Container ==================== */
.smartchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--smartchat-bg);
    overscroll-behavior: contain;
}

/* Thin scrollbar */
.smartchat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.smartchat-messages::-webkit-scrollbar-thumb {
    background: #d4d4d8;
    border-radius: 2px;
}

/* ==================== Messages ==================== */
.message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: messageIn 0.25s ease-out;
}

.user-message {
    align-items: flex-end;
}

.bot-message {
    align-items: flex-start;
}

.message-content {
    max-width: 82%;
    padding: 10px 14px;
    font-size: var(--smartchat-font-size);
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.user-message .message-content {
    background: var(--smartchat-primary);
    color: white;
    border-radius: 16px 16px 4px 16px;
}

.bot-message .message-content {
    background: #f1f5f9;
    color: var(--smartchat-text);
    border-radius: 16px 16px 16px 4px;
}

.message-content p {
    margin: 0;
}

.message-content p + p {
    margin-top: 8px;
}

/* Links */
.bot-message .message-content a.smartchat-link {
    color: var(--smartchat-link-color, #2563EB);
    text-decoration: none;
    font-weight: 500;
}

.bot-message .message-content a.smartchat-link:hover {
    text-decoration: underline;
}

.bot-message .message-content strong {
    font-weight: 600;
}

.message-time {
    font-size: calc(var(--smartchat-font-size) - 3px);
    color: var(--smartchat-text-muted);
    padding: 0 4px;
}

/* ==================== Typing Indicator ==================== */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: 16px 16px 16px 4px;
    width: fit-content;
    margin: 0 16px 14px 16px;
}

.typing-indicator.visible {
    display: flex;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #a1a1aa;
    border-radius: 50%;
    animation: typingPulse 1.4s ease-in-out infinite;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ==================== Input Area ==================== */
.smartchat-input-area {
    background: var(--smartchat-bg);
    padding: 12px 16px 16px;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--smartchat-bg);
    border: 1px solid var(--smartchat-border);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--smartchat-primary);
}

.message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    font-size: var(--smartchat-font-size);
    resize: none;
    max-height: 100px;
    min-height: 20px;
    font-family: var(--smartchat-font);
    line-height: 1.5;
    color: var(--smartchat-text);
}

.message-input:focus {
    outline: none;
}

.message-input::placeholder {
    color: var(--smartchat-text-muted);
}

.send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--smartchat-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: var(--smartchat-secondary);
}

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

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

.send-button svg {
    width: 16px;
    height: 16px;
}

/* ==================== Mobile Responsive ==================== */
@media (max-width: 480px) {
    .smartchat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .smartchat-widget.open {
        bottom: 0;
        right: 0;
        left: 0;
    }
    
    .smartchat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform-origin: bottom center;
    }
    
    .smartchat-header {
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top));
    }
    
    .bot-avatar,
    .bot-avatar-placeholder {
        width: 32px;
        height: 32px;
    }
    
    .smartchat-messages {
        padding: 16px 14px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .typing-indicator {
        margin: 0 14px 12px 14px;
    }
    
    .smartchat-input-area {
        padding: 10px 14px 14px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
    
    .message-input {
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (max-width: 900px) {
    .smartchat-header {
        padding: 10px 14px;
    }
    
    .bot-avatar,
    .bot-avatar-placeholder {
        width: 28px;
        height: 28px;
    }
    
    .smartchat-messages {
        padding: 12px 14px;
        gap: 10px;
    }
    
    .smartchat-input-area {
        padding: 8px 12px 10px;
    }
}

/* ==================== Animations ==================== */
@keyframes windowSlideUp {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.15);
        opacity: 1;
    }
}

/* ==================== Reduced Motion ==================== */
@media (prefers-reduced-motion: reduce) {
    .smartchat-widget,
    .smartchat-widget * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== Focus States ==================== */
.smartchat-toggle:focus-visible,
.header-btn:focus-visible,
.send-button:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}
