/* Crystal Tech AI chat widget — floating bottom-left, self-contained.
   Uses the ct-chat- prefix so it never collides with site styles. */

.ct-chat-launcher {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9998;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #6e56cf, #2563eb);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.ct-chat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 36px rgba(37, 99, 235, 0.55);
}
.ct-chat-launcher svg {
    width: 30px;
    height: 30px;
}
.ct-chat-launcher__dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    display: none;
}
.ct-chat-launcher.has-unread .ct-chat-launcher__dot {
    display: block;
}

.ct-chat-panel {
    position: fixed;
    bottom: 100px;
    left: 24px;
    z-index: 9999;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 140px);
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #0f172a;
}
.ct-chat-panel.is-open {
    display: flex;
    animation: ctChatPop 0.18s ease;
}
@keyframes ctChatPop {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
}

.ct-chat-panel__header {
    background: linear-gradient(135deg, #6e56cf, #2563eb);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.ct-chat-panel__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}
.ct-chat-panel__title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.ct-chat-panel__subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.ct-chat-panel__actions { margin-left: auto; display: flex; gap: 8px; }
.ct-chat-panel__btn {
    background: rgba(255,255,255,0.12);
    border: 0;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.ct-chat-panel__btn:hover { background: rgba(255,255,255,0.22); }
.ct-chat-panel__btn svg { width: 16px; height: 16px; }

.ct-chat-panel__status {
    background: #fef3c7;
    color: #92400e;
    padding: 8px 14px;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid #fde68a;
    display: none;
}
.ct-chat-panel__status.is-visible { display: block; }
.ct-chat-panel__status.is-success { background: #dcfce7; color: #166534; border-bottom-color: #bbf7d0; }

.ct-chat-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ct-chat-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    line-height: 1.45;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.ct-chat-msg--bot,
.ct-chat-msg--agent {
    align-self: flex-start;
    background: #fff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}
.ct-chat-msg--agent { border-color: #c7d2fe; background: #eef2ff; }
.ct-chat-msg--client {
    align-self: flex-end;
    background: linear-gradient(135deg, #6e56cf, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ct-chat-msg--system {
    align-self: center;
    background: transparent;
    color: #64748b;
    font-size: 12px;
    font-style: italic;
    max-width: 100%;
    text-align: center;
    padding: 4px 8px;
}
.ct-chat-msg__sender {
    font-size: 11px;
    opacity: 0.7;
    margin-bottom: 2px;
    font-weight: 600;
}
.ct-chat-msg--client .ct-chat-msg__sender { display: none; }

.ct-chat-typing {
    align-self: flex-start;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: none;
}
.ct-chat-typing.is-visible { display: flex; gap: 4px; }
.ct-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: ctChatBlink 1.1s infinite;
}
.ct-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ct-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ctChatBlink {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.ct-chat-panel__composer {
    border-top: 1px solid #e2e8f0;
    background: #fff;
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ct-chat-panel__composer textarea {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    background: #f8fafc;
    color: #0f172a;
}
.ct-chat-panel__composer textarea:focus {
    outline: none;
    border-color: #6e56cf;
    background: #fff;
}
.ct-chat-panel__send {
    background: linear-gradient(135deg, #6e56cf, #2563eb);
    color: #fff;
    border: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.12s ease;
}
.ct-chat-panel__send:hover { transform: scale(1.05); }
.ct-chat-panel__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ct-chat-panel__send svg { width: 18px; height: 18px; }

.ct-chat-panel__footer {
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    padding: 6px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
}

@media (max-width: 540px) {
    .ct-chat-launcher { bottom: 16px; left: 16px; width: 56px; height: 56px; }
    .ct-chat-panel {
        bottom: 16px;
        left: 16px;
        right: 16px;
        width: auto;
        height: calc(100vh - 32px);
        max-height: none;
        border-radius: 14px;
    }
}
