/* ========================================
   Local AI Chat - Frontend Styles (CMX)
   ======================================== */

:root {
    --lac-primary: #1e5aa8;
    --lac-primary-hover: #164a8a;
    --lac-bg: #ffffff;
    --lac-msg-user: #1e5aa8;
    --lac-msg-bot: #f1f5f9;
    --lac-text: #1e293b;
    --lac-text-light: #64748b;
    --lac-border: #e2e8f0;
    --lac-radius: 16px;
    --lac-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

/* ===== Floating button & popup ===== */
#lac-floating-container {
    display: block !important;
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 2147483647 !important;
    visibility: visible !important;
    opacity: 1 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

#lac-toggle-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--lac-primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 10px 20px 10px 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(30, 90, 168, 0.45);
    transition: all 0.25s ease;
}

#lac-toggle-btn:hover {
    background: var(--lac-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(30, 90, 168, 0.55);
}

#lac-toggle-btn .lac-btn-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    flex-shrink: 0;
    display: block;
}

#lac-chat-popup {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: min(380px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    box-shadow: var(--lac-shadow);
    border-radius: var(--lac-radius);
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-sizing: border-box;
}

#lac-chat-popup.lac-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px) scale(0.96);
}

/* ===== Chat wrapper ===== */
.lac-chat-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--lac-bg);
    border-radius: var(--lac-radius);
    overflow: hidden;
    border: 1px solid var(--lac-border);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    height: var(--lac-height, 450px);
}

.lac-chat-wrapper.lac-popup {
    height: 480px;
    border: none;
}

.lac-chat-wrapper.lac-embedded {
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Header */
.lac-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    background: var(--lac-primary);
    color: #fff;
}

.lac-header-info {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 12px;
}

.lac-avatar-img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    flex-shrink: 0;
    display: block;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.lac-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
}

.lac-status {
    font-size: 12px;
    opacity: 0.85;
}

.lac-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: clamp(40px, 11vw, 44px);
    min-width: 40px;
    height: clamp(40px, 11vw, 44px);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    line-height: 1;
}

.lac-close-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Messages area */
.lac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lac-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    animation: lacFadeIn 0.25s ease;
}

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

.lac-msg-bot {
    align-self: flex-start;
    background: var(--lac-msg-bot);
    color: var(--lac-text);
    border-bottom-left-radius: 4px;
}

.lac-msg-user {
    align-self: flex-end;
    background: var(--lac-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.lac-msg-typing {
    align-self: flex-start;
    background: var(--lac-msg-bot);
    color: var(--lac-text-light);
    font-style: italic;
    font-size: 13px;
    padding: 10px 16px;
}

.lac-msg-typing span {
    display: inline-block;
    animation: lacDots 1.2s infinite;
}

.lac-msg-typing span:nth-child(2) { animation-delay: 0.2s; }
.lac-msg-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lacDots {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

/* Input area */
.lac-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px clamp(10px, 3vw, 14px);
    border-top: 1px solid var(--lac-border);
    background: #fff;
    min-width: 0;
}

.lac-input {
    flex: 1;
    min-width: 0;
    width: 0;
    border: 1px solid var(--lac-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    color: var(--lac-text);
    box-sizing: border-box;
}

.lac-input:focus {
    border-color: var(--lac-primary);
}

.lac-send-btn {
    width: clamp(44px, 12vw, 48px);
    min-width: 44px;
    height: clamp(44px, 12vw, 48px);
    border-radius: 50%;
    border: none;
    background: var(--lac-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex: 0 0 auto;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
}

.lac-send-btn svg {
    display: block;
    width: clamp(20px, 5vw, 22px);
    height: clamp(20px, 5vw, 22px);
    flex: 0 0 auto;
}

.lac-send-btn:hover {
    background: var(--lac-primary-hover);
}

.lac-send-btn:active {
    transform: scale(0.94);
}

.lac-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 480px) {
    #lac-floating-container {
        bottom: 16px !important;
        right: 16px !important;
    }

    #lac-toggle-btn .lac-btn-text {
        display: none;
    }

    #lac-toggle-btn {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        padding: 0;
        justify-content: center;
    }

    #lac-toggle-btn .lac-btn-logo {
        width: 40px;
        height: 40px;
    }

    #lac-chat-popup {
        width: min(380px, calc(100vw - 24px));
        right: -4px;
        bottom: 72px;
    }

    .lac-chat-wrapper.lac-popup {
        height: min(70vh, 560px);
        height: min(70dvh, 560px);
        min-height: 320px;
        max-height: calc(100dvh - 104px);
    }

    .lac-chat-header {
        padding: 10px 12px;
    }

    .lac-header-info {
        gap: 8px;
    }

    .lac-avatar-img {
        width: 38px;
        height: 38px;
    }

    .lac-input {
        padding: 10px 14px;
    }
}

@media (max-width: 340px) {
    #lac-chat-popup {
        right: -8px;
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
    }

    .lac-input-area {
        gap: 6px;
        padding-right: 8px;
        padding-left: 8px;
    }

    .lac-input {
        padding-right: 10px;
        padding-left: 10px;
    }
}
