/* ============================================================
   My AI Chat - Frontend Styles
   ============================================================ */

/* --- Reset & Base --- */
#ai-chat-plugin-container *,
#ai-chat-plugin-container *::before,
#ai-chat-plugin-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- Container --- */
#ai-chat-plugin-container {
    position: relative;
    z-index: 999999;
}

/* JS will set display:block after applying config */
#ai-chat-plugin-container.mac-initialized {
    display: block !important;
}

/* --- Floating Button --- */
#ai-chat-plugin-btn {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: #FFFFFF;
    padding: 0;
}

#ai-chat-plugin-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

#ai-chat-plugin-btn:active {
    transform: scale(0.95);
}

#ai-chat-plugin-btn-icon svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
}

/* Position: right (default) */
#ai-chat-plugin-container.mac-position-right #ai-chat-plugin-btn {
    right: 24px;
}

/* Position: left */
#ai-chat-plugin-container.mac-position-left #ai-chat-plugin-btn {
    left: 24px;
}

/* --- Overlay (mobile) --- */
#mac-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999998;
}

#mac-overlay.mac-active {
    display: block;
}

/* --- Invitation Bubble --- */
#mac-invitation-bubble {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 15px;
    background: #FFFFFF;
    color: #1F2937;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    line-height: 1.4;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 999998;
    cursor: pointer;
}

#mac-invitation-bubble.mac-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#mac-invitation-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 20px;
    border: 8px solid transparent;
    border-top-color: #FFFFFF;
}

.mac-position-left #mac-invitation-bubble {
    right: auto;
    left: 0;
}

.mac-position-left #mac-invitation-bubble::after {
    right: auto;
    left: 20px;
}

/* --- Chat Window --- */
#ai-chat-plugin-window {
    position: fixed;
    bottom: 90px;
    z-index: 999999;
    width: 380px;
    height: 500px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: #FFFFFF;
    opacity: 0;
    transform: scale(0.9) translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

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

/* Popup: above (default) */
#ai-chat-plugin-container.mac-position-right.mac-popup-above #ai-chat-plugin-window {
    right: 24px;
}

#ai-chat-plugin-container.mac-position-left.mac-popup-above #ai-chat-plugin-window {
    left: 24px;
}

/* Popup: right side slide */
#ai-chat-plugin-container.mac-position-right.mac-popup-right #ai-chat-plugin-window {
    right: 90px;
}

#ai-chat-plugin-container.mac-position-left.mac-popup-right #ai-chat-plugin-window {
    left: 90px;
}

/* Popup: bottom slide */
#ai-chat-plugin-container.mac-popup-bottom #ai-chat-plugin-window {
    bottom: 0;
    right: 0;
    border-radius: 12px 12px 0 0;
}

/* --- Chat Header --- */
#ai-chat-plugin-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    flex-shrink: 0;
}

#mac-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

#mac-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

#ai-chat-plugin-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ai-chat-plugin-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}

#ai-chat-plugin-close:hover {
    opacity: 1;
}

/* --- Messages Area --- */
#ai-chat-plugin-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: #F9FAFB;
}

#ai-chat-plugin-messages::-webkit-scrollbar {
    width: 5px;
}

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

#ai-chat-plugin-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 4px;
}

/* --- Message Bubbles --- */
.mac-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.mac-message-user {
    align-self: flex-end;
    background: #2563EB;
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.mac-message-ai {
    align-self: flex-start;
    background: #F0F0F0;
    color: #1F2937;
    border-bottom-left-radius: 4px;
}

.mac-message-ai a {
    color: #2563EB;
    text-decoration: underline;
}

/* Markdown content inside AI messages */
.mac-message-ai pre {
    background: #1E293B;
    color: #E2E8F0;
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

.mac-message-ai code {
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
    font-size: 13px;
}

.mac-message-ai :not(pre) > code {
    background: #E5E7EB;
    padding: 1px 5px;
    border-radius: 3px;
}

.mac-message-ai ul,
.mac-message-ai ol {
    padding-left: 20px;
    margin: 4px 0;
}

.mac-message-ai p {
    margin: 4px 0;
}

.mac-message-ai p:first-child {
    margin-top: 0;
}

.mac-message-ai p:last-child {
    margin-bottom: 0;
}

/* --- Typing Indicator --- */
.mac-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: #F0F0F0;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.mac-typing-dot {
    width: 7px;
    height: 7px;
    background: #9CA3AF;
    border-radius: 50%;
    animation: mac-typing-bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes mac-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- Scroll to Bottom Button --- */
#mac-scroll-bottom {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    color: #6B7280;
    transition: background 0.15s;
}

#mac-scroll-bottom:hover {
    background: #F3F4F6;
}

#mac-scroll-bottom.mac-visible {
    display: flex;
}

/* --- Input Area --- */
#ai-chat-plugin-input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid #E5E7EB;
    background: #FFFFFF;
    flex-shrink: 0;
    gap: 8px;
}

#ai-chat-plugin-input {
    flex: 1;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
    color: #1F2937;
    background: #F9FAFB;
}

#ai-chat-plugin-input:focus {
    border-color: #2563EB;
    background: #FFFFFF;
}

#ai-chat-plugin-input::placeholder {
    color: #9CA3AF;
}

#ai-chat-plugin-send {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2563EB;
    color: #FFFFFF;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

#ai-chat-plugin-send:hover {
    background: #1D4ED8;
}

#ai-chat-plugin-send:active {
    transform: scale(0.92);
}

#ai-chat-plugin-send:disabled {
    background: #9CA3AF;
    cursor: not-allowed;
}

/* --- Character Count --- */
#mac-char-count {
    padding: 2px 16px 6px;
    font-size: 12px;
    color: #9CA3AF;
    text-align: right;
    background: #FFFFFF;
}

#mac-char-count.mac-over {
    color: #EF4444;
}

/* --- Error Message in Chat --- */
.mac-message-error {
    align-self: center;
    background: #FEF2F2;
    color: #B91C1C;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    border: 1px solid #FECACA;
    max-width: 90%;
    text-align: center;
}

/* ============================================================
   Mobile Responsive (screen width <= 768px)
   ============================================================ */
@media screen and (max-width: 768px) {
    #ai-chat-plugin-btn {
        bottom: 16px;
    }

    #ai-chat-plugin-container.mac-position-right #ai-chat-plugin-btn {
        right: 16px;
    }

    #ai-chat-plugin-container.mac-position-left #ai-chat-plugin-btn {
        left: 16px;
    }

    #ai-chat-plugin-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    #mac-scroll-bottom {
        bottom: 76px;
    }
}
