/* ===== AI Chat Widget - Exact copy from textiles-factory.com ===== */
/* Colors adapted to our brand: #0f2b5c(primary), #1a56db(primary-light), #c41e3a(accent), #a01830(accent-dark) */

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-toggle {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, #c41e3a, #a01830);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.75rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transition: all 0.25s ease;
    cursor: pointer;
}

/* Stage 1: Waiting bubble */
.chat-waiting {
    width: 48px; height: 48px;
    background: #e5e7eb;
    border-radius: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: all 0.25s ease;
    cursor: default;
}
.chat-waiting .waiting-container { background: transparent; border-radius:0; padding:0; box-shadow:none; }
.chat-waiting .waiting-icon { display:none; }
.chat-waiting .waiting-dots { display: flex; gap: 3px; align-items: center; }
.chat-waiting .waiting-dots span {
    width: 5px; height: 5px;
    background: #9ca3af;
    border-radius: 50%;
    animation: waitingPulse 1.4s infinite ease-in-out both;
}
.chat-waiting .waiting-dots span:nth-child(1) { animation-delay: 0s; }
.chat-waiting .waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-waiting .waiting-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes waitingPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Stage 2: Found you group */
.chat-found-group {
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    cursor: pointer;
    max-width: min(300px, calc(100vw - 40px));
}
.chat-found-group.visible {
    display: flex;
    animation: foundGroupAppear 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.chat-found-bounce-wrap { min-width: 200px; max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    animation: cornerBounce 1.5s ease-in-out infinite;
}
@keyframes cornerBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
@keyframes foundGroupAppear {
    from { opacity: 0; transform: scale(0.5) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Mini preview bubble */
.chat-mini-preview { min-width: 200px;
    position: relative;
    background: #fff;
    color: #1f2937;
    padding: 12px 14px 10px;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 0 0 1px rgba(26,26,46,0.06);
    text-align: left;
    width: 100%;
    max-width: 280px;
}
.chat-mini-preview::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 28px;
    width: 12px; height: 12px;
    background: #fff;
    border-right: 1px solid rgba(26,26,46,0.06);
    border-bottom: 1px solid rgba(26,26,46,0.06);
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0,0,0,0.04);
}
.chat-mini-preview-text {
    font-size: 0.875rem;
    line-height: 1.55;
    margin: 0 0 6px;
    font-family: 'Inter', sans-serif;
}
.chat-mini-preview-hint {
    display: block;
    font-size: 0.6875rem;
    color: #a01830;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.chat-found-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 0;
}
.chat-found-group--compact .chat-mini-preview { min-width: 200px; display: none; }
.chat-found-group--compact.chat-found-group--show-new-msg .chat-mini-preview { min-width: 200px;
    display: block;
    max-width: 240px;
    padding: 10px 12px 8px;
    animation: foundGroupAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.chat-found-group--show-new-msg .chat-mini-preview-hint { display: none; }

/* Avatar */
.chat-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    display: inline-block;
    line-height: 0;
}
.chat-avatar-found {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, #c41e3a, #a01830);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 4px 16px rgba(15,43,92,0.35);
    cursor: pointer;
    overflow: hidden;
    position: relative;
}
.chat-avatar-found:hover { transform: scale(1.08); }
.chat-avatar-placeholder-icon {
    width: 100%; height: 100%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.6);
    position: absolute; inset: 0; z-index: 0;
}
.chat-avatar-placeholder-icon.is-hidden { display: none; }
.avatar-icon {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    line-height: 1;
    position: relative;
    z-index: 1;
}
.avatar-icon.is-hidden { display: none; }
.chat-avatar-img {
    display: none;
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: absolute;
    inset: 0;
    z-index: 2;
}
.chat-avatar-img.is-visible { display: block; }
.chat-avatar-img--found, .chat-avatar-img--header {}

/* Badge */
.chat-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #c41e3a;
    color: #fff;
    min-width: 20px; height: 20px;
    border-radius: 10px;
    font-size: 11px; font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    animation: badgePop 0.3s ease;
    z-index: 3;
}
@keyframes badgePop {
    from { transform: scale(0); }
    50% { transform: scale(1.3); }
    to { transform: scale(1); }
}

/* Chat Box */
.chat-box {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    height: 500px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.25s ease;
}
.chat-box.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #0f2b5c, #1a56db);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.chat-avatar-header {
    width: 42px; height: 42px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}
.chat-avatar-header-text {
    width: 100%; height: 100%;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
}
.chat-avatar-header-text.is-hidden { display: none; }
.chat-avatar-header-placeholder-icon {
    width: 100%; height: 100%;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-avatar-header-placeholder-icon.is-hidden { display: none; }
.chat-info { flex: 1; }
.chat-info h4 {
    color: #fff;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    margin: 0;
}
.chat-info span {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.75);
}
.chat-close {
    color: rgba(255,255,255,0.7);
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
    background: none; border: none;
    transition: opacity 0.15s ease;
    margin-left: auto;
}
.chat-close:hover { opacity: 1; }

/* Messages */
.chat-messages {
    flex: 1;
    padding: 12px 14px;
    overflow-y: auto;
    background: #f7f8fc;
}
.message {
    margin-bottom: 6px;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}
@keyframes messageIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.message.ai { margin-right: auto; }
.message.user {
    margin-left: auto;
    background: #c41e3a;
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}
.message-content {
    padding: 8px 12px;
    line-height: 1.45;
}
.message.ai .message-content {
    background: #fff;
    color: #374151;
    border-radius: 14px 14px 14px 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.message-time {
    font-size: 0.625rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* Chat Input */
.chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
    background: #f9fafb;
    transition: border-color 0.2s;
}
.chat-input:focus {
    border-color: #1a56db;
    box-shadow: 0 0 0 3px rgba(15,43,92,0.1);
    background: #fff;
}
.chat-send {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f2b5c, #1a56db);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    flex-shrink: 0;
}
.chat-send:hover { transform: scale(1.1); }
.chat-image-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: #f0f1f6;
    color: #5a6270;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-image-btn:hover { background: #e2e5ed; }

/* Utility */
.is-hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
    .chat-box {
        width: calc(100vw - 32px);
        right: -4px;
        bottom: 68px;
        height: 450px;
    }
}
