/* Option 4B: Public chat widget — floating, site-wide, guests only */

.aisg-public-chat-widget {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    top: auto !important;
    z-index: 2147483647 !important; /* above theme/plugins (max safe z-index) */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, sans-serif;
    pointer-events: none; /* container doesn't block page; children re-enable */
}

.aisg-public-chat-widget .aisg-public-chat-toggle,
.aisg-public-chat-widget .aisg-public-chat-panel {
    pointer-events: auto;
}

.aisg-public-chat-toggle {
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    border-radius: 50%;
    border: none;
    background: #FFEBDD !important;
    color: #1a1a1a !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.aisg-public-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.aisg-public-chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #1e1e1e;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}

.aisg-public-chat-widget.is-open .aisg-public-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.aisg-public-chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px 12px 0 0;
}

.aisg-public-chat-panel-title {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.aisg-public-chat-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    padding: 0;
}

.aisg-public-chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.aisg-public-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 120px;
}

.aisg-public-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.aisg-public-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.aisg-public-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.aisg-public-chat-welcome {
    color: #9a9a9a;
    font-size: 14px;
    line-height: 1.6;
    margin: 0 0 10px 0;
}

.aisg-public-chat-message {
    margin: 10px 0;
    display: flex;
    animation: aisgPublicChatFadeIn 0.3s ease-in;
}

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

.aisg-public-chat-message--user {
    justify-content: flex-end;
}

.aisg-public-chat-message--assistant {
    justify-content: flex-start;
}

.aisg-public-chat-message-content {
    max-width: 85%;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.aisg-public-chat-message--user .aisg-public-chat-message-content {
    background: rgba(255, 235, 221, 0.25);
    color: #fff;
    border: 1px solid rgba(255, 235, 221, 0.4);
}

.aisg-public-chat-message--assistant .aisg-public-chat-message-content {
    background: rgba(255, 255, 255, 0.08);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.aisg-public-chat-message-content h1,
.aisg-public-chat-message-content h2,
.aisg-public-chat-message-content h3 {
    color: #fff;
    margin: 10px 0 6px 0;
}

.aisg-public-chat-message-content h1 { font-size: 18px; }
.aisg-public-chat-message-content h2 { font-size: 16px; }
.aisg-public-chat-message-content h3 { font-size: 15px; }

.aisg-public-chat-message-content ul,
.aisg-public-chat-message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.aisg-public-chat-message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}

.aisg-public-chat-message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.aisg-public-chat-message-content a {
    color: #FFEBDD;
    text-decoration: underline;
}

.aisg-public-chat-message-content a:hover {
    color: #fff;
}

.aisg-public-chat-typing .aisg-public-chat-message-content {
    opacity: 0.8;
}

.aisg-public-chat-typing-dots span {
    animation: aisgPublicChatTypingDots 1.4s infinite;
    display: inline-block;
}

.aisg-public-chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.aisg-public-chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.aisg-public-chat-input-wrapper {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 0 0 12px 12px;
}

.aisg-public-chat-input {
    flex: 1;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    padding: 0 12px;
    box-sizing: border-box;
}

.aisg-public-chat-input:focus {
    outline: none;
    border-color: rgba(255, 235, 221, 0.6);
}

.aisg-public-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

.aisg-public-chat-send {
    height: 40px;
    padding: 0 18px;
    background: #FFEBDD;
    border: none;
    border-radius: 6px;
    color: #1a1a1a;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.aisg-public-chat-send:hover:not(:disabled) {
    opacity: 0.9;
}

.aisg-public-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .aisg-public-chat-widget {
        bottom: 12px;
        right: 12px;
    }
    .aisg-public-chat-panel {
        width: calc(100vw - 24px);
        right: -6px;
        bottom: 64px;
        height: 420px;
    }
    .aisg-public-chat-message-content {
        max-width: 92%;
    }
}
