/**
 * ATM Chatbot Frontend Styles
 * Author: Jo Garcia
 */

/* CSS Variables (can be overridden via inline styles) */
:root {
    --atmchat-primary: #6366f1;
    --atmchat-secondary: #4f46e5;
    --atmchat-text: #ffffff;
    --atmchat-bg: #f8fafc;
    --atmchat-user-msg: #6366f1;
    --atmchat-bot-msg: #e2e8f0;
    --atmchat-button-size: 60px;
    --atmchat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --atmchat-shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Reset */
.atmchat-widget *,
.atmchat-widget *::before,
.atmchat-widget *::after,
.atmchat-button *,
.atmchat-button *::before,
.atmchat-button *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Chat Button */
.atmchat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--atmchat-button-size);
    height: var(--atmchat-button-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--atmchat-primary) 0%, var(--atmchat-secondary) 100%);
    border: none;
    cursor: pointer;
    box-shadow: var(--atmchat-shadow);
    z-index: 999998;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.atmchat-button:hover {
    transform: scale(1.08);
    box-shadow: 0 14px 50px rgba(99, 102, 241, 0.4);
}

.atmchat-button:active {
    transform: scale(0.96);
}

.atmchat-button-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--atmchat-text);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.atmchat-button-icon.chat-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.atmchat-button-icon.close-icon {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

.atmchat-button.active .chat-icon {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

.atmchat-button.active .close-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Unread Badge */
.atmchat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Widget */
.atmchat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--atmchat-shadow);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.atmchat-widget.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.atmchat-header {
    background: linear-gradient(135deg, var(--atmchat-primary) 0%, var(--atmchat-secondary) 100%);
    padding: 20px;
    flex-shrink: 0;
}

.atmchat-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.atmchat-header-info {
    flex: 1;
}

.atmchat-title {
    color: var(--atmchat-text);
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 4px 0;
    letter-spacing: -0.02em;
}

.atmchat-subtitle {
    color: var(--atmchat-text);
    opacity: 0.85;
    font-size: 13px;
    margin: 0;
    font-weight: 400;
}

.atmchat-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--atmchat-text);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.atmchat-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

/* Messages Area */
.atmchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--atmchat-bg);
    scroll-behavior: smooth;
}

.atmchat-messages::-webkit-scrollbar {
    width: 6px;
}

.atmchat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.atmchat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.atmchat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Message Bubbles */
.atmchat-message {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.atmchat-message.visitor {
    align-items: flex-end;
}

.atmchat-message.admin,
.atmchat-message.bot {
    align-items: flex-start;
}

.atmchat-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}

.atmchat-message.visitor .atmchat-message-content {
    background: var(--atmchat-user-msg);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.atmchat-message.admin .atmchat-message-content,
.atmchat-message.bot .atmchat-message-content {
    background: var(--atmchat-bot-msg);
    color: #1e293b;
    border-bottom-left-radius: 6px;
}

.atmchat-message-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
    padding: 0 4px;
}

/* Message Attachments */
.atmchat-message-attachment {
    margin-top: 8px;
}

.atmchat-message-attachment img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.atmchat-message-attachment img:hover {
    transform: scale(1.02);
}

.atmchat-message-attachment .file-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s ease;
}

.atmchat-message-attachment .file-link:hover {
    background: rgba(0, 0, 0, 0.12);
}

.atmchat-message-attachment .file-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Typing Indicator */
.atmchat-typing {
    padding: 0 20px 12px;
    background: var(--atmchat-bg);
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--atmchat-bot-msg);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Input Area */
.atmchat-input-area {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 16px;
    position: relative;
}

.atmchat-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.atmchat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 8px 12px;
    transition: all 0.2s ease;
}

.atmchat-input-wrapper:focus-within {
    background: #e2e8f0;
    box-shadow: 0 0 0 2px var(--atmchat-primary);
}

.atmchat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 4px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    color: #1e293b;
}

.atmchat-input:focus {
    outline: none;
}

.atmchat-input::placeholder {
    color: #94a3b8;
}

/* Input Buttons */
.atmchat-emoji-btn,
.atmchat-attach-btn,
.atmchat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.atmchat-emoji-btn,
.atmchat-attach-btn {
    background: transparent;
    color: #64748b;
}

.atmchat-emoji-btn:hover,
.atmchat-attach-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #1e293b;
}

.atmchat-send-btn {
    background: var(--atmchat-primary);
    color: #fff;
}

.atmchat-send-btn:hover {
    background: var(--atmchat-secondary);
    transform: scale(1.05);
}

.atmchat-send-btn:active {
    transform: scale(0.95);
}

.atmchat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

/* Emoji Picker */
.atmchat-emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--atmchat-shadow);
    padding: 12px;
    margin-bottom: 8px;
    max-height: 280px;
    overflow-y: auto;
    animation: fadeInUp 0.2s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}

.emoji-item {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    border-radius: 8px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-item:hover {
    background: #f1f5f9;
    transform: scale(1.2);
}

/* File Preview */
.atmchat-file-preview {
    background: #f1f5f9;
    border-radius: 12px;
    padding: 10px 14px;
}

.file-preview-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.file-preview-name {
    font-size: 13px;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.file-preview-remove {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.file-preview-remove:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Welcome Message */
.atmchat-welcome {
    text-align: center;
    padding: 30px 20px;
}

.atmchat-welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--atmchat-primary) 0%, var(--atmchat-secondary) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: #fff;
}

.atmchat-welcome h4 {
    font-size: 16px;
    color: #1e293b;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.atmchat-welcome p {
    font-size: 14px;
    color: #64748b;
    margin: 0;
}

/* Date Separator */
.atmchat-date-separator {
    display: flex;
    align-items: center;
    margin: 20px 0;
    gap: 12px;
}

.atmchat-date-separator::before,
.atmchat-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

.atmchat-date-separator span {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 500;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .atmchat-widget {
        bottom: 90px;
        right: 10%;
        left: auto;
        width: 80%;
        max-width: 80%;
        height: auto;
        max-height: 70vh;
        border-radius: 20px;
    }
    
    .atmchat-widget.active {
        border-radius: 20px;
    }
    
    .atmchat-button {
        bottom: 16px;
        right: 16px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    
    .atmchat-header {
        padding: 16px;
    }
    
    .atmchat-input-area {
        padding: 16px;
    }
    
    .atmchat-messages {
        max-height: calc(70vh - 150px);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .atmchat-widget,
    .atmchat-button,
    .atmchat-message,
    .atmchat-emoji-picker,
    .typing-dots span {
        animation: none;
        transition: none;
    }
}
