/* ══════════════════════════════════════════════════════════════════════════════
   Keymus Chat Panel — Styles
   Floating chat widget + inline chat panel
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Floating Button ──────────────────────────────────────────────────────── */
.keymus-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.keymus-chat-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff 0%, #0056d2 100%);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 123, 255, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.keymus-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 123, 255, 0.5);
}

.keymus-chat-btn:active {
    transform: scale(0.95);
}

.keymus-chat-btn .close-icon {
    display: none;
}

.keymus-chat-widget.open .keymus-chat-btn .chat-icon {
    display: none;
}

.keymus-chat-widget.open .keymus-chat-btn .close-icon {
    display: block;
}

/* Badge */
.keymus-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: #ff3b30;
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid white;
    line-height: 1;
}

.keymus-chat-badge.visible {
    display: flex;
    animation: badgePop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes badgePop {
    0%   { transform: scale(0); opacity: 0; }
    80%  { transform: scale(1.15); }
    100% { transform: scale(1);   opacity: 1; }
}

/* Pulsing glow on the chat button when there are unread messages (panel closed) */
.keymus-chat-widget.has-unread:not(.open) .keymus-chat-btn {
    animation: chatBtnPulse 2s ease-in-out infinite;
}

@keyframes chatBtnPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0, 123, 255, 0.4); }
    50%       { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0.18),
                            0 4px 20px rgba(255, 59, 48, 0.4); }
}

/* ── Chat Panel ───────────────────────────────────────────────────────────── */
.keymus-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 540px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99998;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.keymus-chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Panel Header ─────────────────────────────────────────────────────────── */
.keymus-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #007bff 0%, #0056d2 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

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

.keymus-chat-header-info {
    flex: 1;
    min-width: 0;
}

.keymus-chat-header-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.keymus-chat-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin: 0;
    line-height: 1.3;
}

/* ── Connection Status Bar ────────────────────────────────────────────────── */
.keymus-chat-status {
    padding: 6px 16px;
    font-size: 11px;
    text-align: center;
    font-weight: 500;
    display: none;
    flex-shrink: 0;
}

.keymus-chat-status.connected {
    background: #d4edda;
    color: #155724;
    display: block;
    animation: fadeOut 2s ease-in-out 2s forwards;
}

.keymus-chat-status.disconnected {
    background: #f8d7da;
    color: #721c24;
    display: block;
}

.keymus-chat-status.polling {
    background: #fff3cd;
    color: #856404;
    display: block;
}

.keymus-chat-status.error {
    background: #f8d7da;
    color: #721c24;
    display: block;
}

@keyframes fadeOut {
    to { opacity: 0; height: 0; padding: 0; overflow: hidden; }
}

/* ── Messages Area ────────────────────────────────────────────────────────── */
.keymus-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

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

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

.keymus-chat-messages::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 3px;
}

/* Welcome state */
.keymus-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 20px;
    color: #6c757d;
}

.keymus-chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.keymus-chat-welcome h4 {
    margin: 0 0 8px;
    font-size: 16px;
    color: #343a40;
    font-weight: 600;
}

.keymus-chat-welcome p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* Loading state */
.keymus-chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 6px;
}

.keymus-chat-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #007bff;
    animation: chatBounce 1.4s ease-in-out infinite both;
}

.keymus-chat-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.keymus-chat-loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ── Message Bubble ───────────────────────────────────────────────────────── */
.keymus-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}

.keymus-msg-sent {
    align-self: flex-end;
    background: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.keymus-msg-received {
    align-self: flex-start;
    background: white;
    color: #212529;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.keymus-msg-system {
    align-self: center;
    background: transparent;
    color: #6c757d;
    font-size: 12px;
    font-style: italic;
    padding: 6px 12px;
    max-width: 90%;
    text-align: center;
}

.keymus-msg-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #007bff;
}

.keymus-msg-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.6;
    text-align: right;
}

.keymus-msg-sent .keymus-msg-time {
    color: rgba(255, 255, 255, 0.7);
}

/* Typing indicator */
.keymus-typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 10px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    gap: 4px;
    align-items: center;
}

.keymus-typing-indicator.visible {
    display: flex;
}

.keymus-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #adb5bd;
    animation: typingPulse 1.4s ease-in-out infinite;
}

.keymus-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.keymus-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Input Area ───────────────────────────────────────────────────────────── */
.keymus-chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.keymus-chat-input {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
}

.keymus-chat-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.keymus-chat-input::placeholder {
    color: #adb5bd;
}

.keymus-chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #007bff;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.keymus-chat-send-btn:hover {
    background: #0056d2;
}

.keymus-chat-send-btn:disabled {
    background: #adb5bd;
    cursor: not-allowed;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .keymus-chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 100px);
        max-height: none;
        bottom: 70px;
        right: 8px;
        border-radius: 12px;
    }

    .keymus-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .keymus-chat-btn {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }

    .keymus-chat-input-area {
        padding: 12px 12px;
        gap: 6px;
    }

    .keymus-chat-input {
        min-height: 36px;
        padding: 8px 12px;
        font-size: 14px;
    }

    .keymus-chat-send-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
}

/* ── Reduced Motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .keymus-chat-panel {
        transition: opacity 0.15s ease;
        transform: none !important;
    }

    .keymus-chat-loading-dot,
    .keymus-typing-dot {
        animation: none;
    }
}
