/* OpenClaw Chat Widget */

:root {
    --occ-color: #2563eb;
    --occ-color-hover: #1d4ed8;
    --occ-radius: 12px;
    --occ-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --occ-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Wrapper */
#occ-chat-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99998;
    font-family: var(--occ-font);
    font-size: 14px;
    line-height: 1.5;
}

/* Mobile */
@media (max-width: 768px) {
    #occ-chat-wrapper {
        bottom: calc(70px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }

    #occ-chat-window {
        position: fixed !important;
        top: env(safe-area-inset-top, 12px) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: auto !important;
        max-height: none !important;
        box-sizing: border-box !important;
        border-radius: 0 !important;
    }

    /* When keyboard is open on mobile, shrink the chat window */
    #occ-chat-wrapper.occ-keyboard-open #occ-chat-window {
        top: auto !important;
        bottom: 0 !important;
        height: 55vh !important;
    }

    #occ-chat-form {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
}

/* Toggle button */
#occ-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--occ-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--occ-shadow);
    transition: background 0.2s, transform 0.2s;
    position: relative;
}

#occ-chat-toggle:hover {
    background: var(--occ-color-hover);
    transform: scale(1.05);
}

/* Unread badge */
#occ-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat window — slide-up animation */
#occ-chat-window {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    height: 500px;
    max-height: 80vh;
    background: #fff;
    border-radius: var(--occ-radius);
    box-shadow: var(--occ-shadow);
    flex-direction: column;
    overflow: hidden;

    /* Hidden by default */
    display: flex;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#occ-chat-wrapper.occ-open #occ-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#occ-chat-wrapper.occ-open #occ-icon-chat {
    display: none;
}

#occ-chat-wrapper.occ-open #occ-icon-close {
    display: block !important;
}

/* Header */
#occ-chat-header {
    background: var(--occ-color);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#occ-chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
}

#occ-chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

#occ-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#occ-chat-new,
#occ-chat-minimize {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
    border-radius: 4px;
}

#occ-chat-new:hover,
#occ-chat-minimize:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

/* Messages area */
#occ-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

/* Message bubbles */
.occ-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: occ-fade-in 0.2s ease;
}

@keyframes occ-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.occ-msg-bot {
    background: #f1f5f9;
    color: #1e293b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Links in bot messages */
.occ-msg-bot a {
    color: var(--occ-color);
    text-decoration: underline;
    word-break: break-word;
}

.occ-msg-bot a:hover {
    color: var(--occ-color-hover);
}

/* Markdown formatting in bot messages */
.occ-msg-bot strong {
    font-weight: 600;
}

.occ-msg-bot em {
    font-style: italic;
}

.occ-msg-bot ul, .occ-msg-bot ol {
    margin: 4px 0;
    padding-left: 20px;
}

.occ-msg-bot li {
    margin-bottom: 2px;
}

.occ-msg-bot code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
}

/* Yes/No prompt buttons */
.occ-prompt-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.occ-prompt-btn {
    padding: 6px 16px;
    border-radius: 18px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--occ-font);
    font-weight: 500;
    transition: opacity 0.2s, transform 0.1s;
}

.occ-prompt-btn:hover:not(:disabled) {
    transform: scale(1.03);
}

.occ-prompt-btn:disabled {
    cursor: default;
}

.occ-prompt-btn-yes {
    background: var(--occ-color);
    color: #fff;
}

.occ-prompt-btn-no {
    background: #e2e8f0;
    color: #475569;
}

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

/* Typing indicator */
#occ-chat-typing {
    padding: 8px 16px;
    flex-shrink: 0;
}

.occ-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 8px 14px;
    background: #f1f5f9;
    border-radius: 16px;
    width: fit-content;
}

.occ-typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: occ-dot-bounce 1.4s infinite;
}

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

@keyframes occ-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Input form */
#occ-chat-form {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e2e8f0;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

#occ-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: var(--occ-font);
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
}

#occ-chat-input:focus {
    border-color: var(--occ-color);
}

#occ-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--occ-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

#occ-chat-send:hover {
    background: var(--occ-color-hover);
}

#occ-chat-send:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* Scrollbar styling */
#occ-chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

#occ-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Timestamps */
.occ-msg-time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 2px;
    padding: 0 4px;
}

.occ-msg-user + .occ-msg-time {
    text-align: right;
}

/* Retry button */
.occ-retry-btn {
    background: none;
    border: 1px solid #e2e8f0;
    color: #64748b;
    font-size: 12px;
    font-family: var(--occ-font);
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.2s, color 0.2s;
    align-self: flex-end;
}

.occ-retry-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}
