/* === CHAT FAB BUTTON === */
#chat-fab {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent-green), #059669);
    color: white;
    font-size: 20px;
    cursor: pointer;
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1;
}

#chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(16, 185, 129, 0.5);
}

#chat-fab:active {
    transform: scale(0.95);
}

/* Badge on FAB */
#chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    animation: badgePop 0.3s ease;
    pointer-events: none;
}

/* Hide FAB when chat is open */
#chat-panel:not(.chat-hidden)~#chat-fab,
body.chat-open #chat-fab {
    display: none;
}

/* === CHAT PANEL === */
#chat-panel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 320px;
    z-index: 500;
    border-radius: 14px;
    background: rgba(12, 12, 20, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(16px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.5);
    transform-origin: bottom right;
}

/* Hidden state */
#chat-panel.chat-hidden {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
    visibility: hidden;
}

#chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    user-select: none;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

#chat-header span:first-child {
    flex: 1;
}

#chat-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
}

#chat-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

#chat-body {
    display: flex;
    flex-direction: column;
    height: 300px;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* ---- Message Styles ---- */
.chat-msg {
    padding: 6px 10px;
    border-radius: 8px;
    animation: msgSlide 0.25s ease;
    line-height: 1.5;
}

.chat-msg:hover {
    background: rgba(255, 255, 255, 0.03);
}

.chat-msg .msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.chat-msg .chat-name {
    font-weight: 700;
    font-size: 12px;
    color: var(--accent-green);
}

.chat-msg .chat-time {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.6;
}

.chat-msg .chat-text {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-word;
    line-height: 1.4;
}

/* System messages */
.chat-msg.system {
    padding: 4px 10px;
    text-align: center;
}

.chat-msg.system .chat-text {
    color: var(--text-muted);
    font-size: 11px;
    font-style: italic;
}

.chat-msg.system .chat-name {
    color: var(--accent-amber);
    font-size: 11px;
}

/* ---- Chat Input ---- */
#chat-form {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 14px 14px;
}

#chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: all 0.2s;
}

#chat-input:focus {
    border-color: var(--accent-green);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}

#chat-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

#chat-form button {
    background: linear-gradient(135deg, var(--accent-green), #059669);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

#chat-form button:hover {
    transform: scale(1.03);
    box-shadow: 0 2px 12px rgba(16, 185, 129, 0.3);
}

#chat-form button:active {
    transform: scale(0.97);
}

/* Animations */
@keyframes msgSlide {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes badgePop {
    0% {
        transform: scale(0.5);
    }

    70% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

/* Mobile */
@media (max-width: 768px) {
    #chat-fab {
        width: 44px;
        height: 44px;
        font-size: 18px;
        bottom: 12px;
        right: 12px;
    }

    #chat-panel {
        width: 280px;
        right: 12px;
        bottom: 12px;
    }

    #chat-body {
        height: 220px;
    }

    #chat-header {
        padding: 8px 12px;
        font-size: 12px;
    }

    .chat-msg .chat-text {
        font-size: 12px;
    }

    .chat-msg .chat-name {
        font-size: 11px;
    }

    #chat-input {
        font-size: 12px;
        padding: 6px 10px;
    }

    #chat-form button {
        padding: 6px 12px;
        font-size: 11px;
    }

    #chat-form {
        padding: 8px 10px;
    }
}

@media (max-width: 420px) {
    #chat-panel {
        width: calc(100vw - 24px);
        right: 12px;
    }

    #chat-body {
        height: 180px;
    }
}