/* ========== Chat Widget ========== */
.chat-fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(61, 40, 23, 0.3);
    z-index: 9998;
    transition: all 0.3s ease;
}

.chat-fab:hover {
    transform: scale(1.08);
    background: var(--color-accent);
}

.chat-fab svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    display: none;
}

.chat-fab-badge.visible {
    display: flex;
}

/* Chat Panel */
.chat-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    max-width: calc(100vw - 60px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--color-white);
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(61, 40, 23, 0.2);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideIn 0.3s ease;
}

.chat-panel.open {
    display: flex;
}

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

.chat-header {
    background: var(--color-primary);
    color: var(--color-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-header-text h3 {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.chat-header-text .chat-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
}

.chat-status-dot.offline {
    background: #f87171;
}

.chat-close {
    background: none;
    border: none;
    color: var(--color-white);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.chat-close:hover {
    opacity: 1;
}

/* Nickname Screen */
.chat-nickname-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
}

.chat-nickname-screen .chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.chat-nickname-screen h2 {
    font-family: var(--font-serif);
    font-size: 22px;
    color: var(--color-primary);
    margin-bottom: 8px;
    font-weight: 500;
}

.chat-nickname-screen p {
    font-size: 14px;
    color: var(--color-text-light);
    margin-bottom: 24px;
    line-height: 1.6;
}

.chat-nickname-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}

.chat-nickname-input:focus {
    border-color: var(--color-accent);
}

.chat-nickname-btn {
    width: 100%;
    padding: 12px;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background 0.2s;
    letter-spacing: 1px;
}

.chat-nickname-btn:hover {
    background: var(--color-accent);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--color-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.chat-message {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    animation: msgFadeIn 0.3s ease;
}

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

.chat-message.visitor {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-message.cs {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.visitor .chat-message-bubble {
    background: var(--color-primary);
    color: var(--color-white);
    border-bottom-right-radius: 4px;
}

.chat-message.cs .chat-message-bubble {
    background: var(--color-white);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.chat-message-time {
    font-size: 10px;
    color: var(--color-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message-sender {
    font-size: 11px;
    color: var(--color-text-light);
    margin-bottom: 2px;
    padding: 0 4px;
    font-weight: 500;
}

/* System messages */
.chat-system-message {
    text-align: center;
    font-size: 12px;
    color: var(--color-text-light);
    padding: 8px;
    background: var(--color-cream);
    border-radius: 8px;
    align-self: center;
    max-width: 90%;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: none;
}

.chat-typing.visible {
    display: flex;
    gap: 4px;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-text-light);
    animation: typingBounce 1.4s infinite;
}

.chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input Area */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--color-white);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--color-accent);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: var(--color-accent);
}

.chat-send-btn:disabled {
    background: var(--color-border);
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Chat disabled state */
.chat-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-disconnected {
    text-align: center;
    padding: 8px;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    flex-shrink: 0;
}

/* ========== Button Group for Product Pages ========== */
.product-buttons {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.buy-button {
    flex: 0 0 auto;
}

.live-chat-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 16px 36px;
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    font-size: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: var(--transition);
    cursor: pointer;
    font-family: var(--font-sans);
}

.live-chat-button:hover {
    background: var(--color-primary);
    color: var(--color-white);
}

.live-chat-button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .chat-fab {
        bottom: 20px;
        right: 20px;
        width: 52px;
        height: 52px;
    }

    .chat-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .live-chat-button {
        padding: 14px 24px;
        font-size: 13px;
    }
}
