/* ==========================================================================
   Kamilla AI B2B Sales Consultant & Lead Widget Styles
   fprom.kz - ТОО «Fortune PROM» (Казахстан, Алматы)
   Enterprise Modern UI/UX v2.0
   ========================================================================== */

:root {
    --km-navy-dark: #07132b;
    --km-navy-primary: #0b224e;
    --km-navy-light: #163a7d;
    --km-blue-accent: #0284c7;
    --km-blue-glow: #38bdf8;
    --km-orange-cta: #f97316;
    --km-orange-hover: #ea580c;
    --km-whatsapp: #25D366;
    --km-whatsapp-hover: #128c7e;
    --km-emerald: #10b981;
    --km-emerald-soft: #ecfdf5;
    
    --km-surface-main: #ffffff;
    --km-surface-bg: #f8fafc;
    --km-surface-card: #f0f7ff;
    --km-border-light: #e2e8f0;
    --km-border-focus: #0284c7;
    
    --km-text-heading: #0f172a;
    --km-text-body: #1e293b;
    --km-text-muted: #64748b;
    --km-text-subtle: #94a3b8;
    
    --km-shadow-floating: 0 20px 50px -10px rgba(11, 34, 78, 0.28), 0 0 0 1px rgba(11, 34, 78, 0.08);
    --km-shadow-card: 0 8px 24px rgba(2, 132, 199, 0.08);
    --km-radius-window: 24px;
    --km-radius-bubble: 18px;
}

/* Floating Launcher Button */
.km-widget-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.km-launcher {
    position: relative;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0b224e 0%, #0284c7 100%);
    box-shadow: 0 8px 30px rgba(11, 34, 78, 0.4), 0 2px 8px rgba(2, 132, 199, 0.3);
    cursor: pointer;
    border: 3.5px solid #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease, box-shadow 0.25s ease;
    user-select: none;
    outline: none;
}

.km-launcher:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 35px rgba(11, 34, 78, 0.5), 0 4px 12px rgba(2, 132, 199, 0.4);
}

.km-launcher:active {
    transform: scale(0.96);
}

/* Launcher completely hidden when chat is open (prevents overlap) */
.km-launcher--hidden {
    transform: scale(0) !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.km-launcher__avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Pulse Ring Animation */
.km-launcher__pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid #22c55e;
    animation: km-pulse 2.2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
    pointer-events: none;
}

@keyframes km-pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.18);
        opacity: 0.4;
    }
    100% {
        transform: scale(1.35);
        opacity: 0;
    }
}

/* Status Dot */
.km-launcher__status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 15px;
    height: 15px;
    background-color: #22c55e;
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Unread Badge */
.km-launcher__badge {
    position: absolute;
    top: -4px;
    left: -4px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: km-bounce 1.5s infinite;
}

@keyframes km-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Proactive Speech Cloud (Balloon) */
.km-cloud {
    position: absolute;
    bottom: 12px;
    right: 80px;
    width: 320px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 14px 40px rgba(11, 34, 78, 0.2), 0 2px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--km-border-light);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: km-cloud-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    cursor: pointer;
    transform-origin: bottom right;
}

@keyframes km-cloud-in {
    from {
        opacity: 0;
        transform: scale(0.85) translateX(15px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateX(0);
    }
}

.km-cloud::after {
    content: "";
    position: absolute;
    bottom: 24px;
    right: -9px;
    width: 0;
    height: 0;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-left: 10px solid #ffffff;
    filter: drop-shadow(2px 0 2px rgba(0, 0, 0, 0.04));
}

.km-cloud__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.km-cloud__meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.km-cloud__name {
    font-size: 13px;
    font-weight: 700;
    color: var(--km-navy-primary);
}

.km-cloud__dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
}

.km-cloud__close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--km-text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
}

.km-cloud__close:hover {
    color: #ef4444;
    background: #fee2e2;
}

.km-cloud__text {
    font-size: 13.5px;
    line-height: 1.48;
    color: var(--km-text-heading);
    margin: 0;
}

.km-cloud__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.km-cloud__chip {
    font-size: 12px;
    background: #f0f7ff;
    color: #0b224e;
    border: 1px solid #bfdbfe;
    border-radius: 20px;
    padding: 4px 10px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.km-cloud__chip:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

/* ==========================================================================
   Chat Modal Window (Desktop & Docked)
   ========================================================================== */
.km-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 388px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 48px);
    background: #ffffff;
    border-radius: var(--km-radius-window);
    box-shadow: var(--km-shadow-floating);
    border: 1px solid rgba(226, 232, 240, 0.9);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: km-chat-spring 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform-origin: bottom right;
    z-index: 1000000;
}

@keyframes km-chat-spring {
    from {
        opacity: 0;
        transform: scale(0.88) translateY(24px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Chat Header */
.km-chat__header {
    background: linear-gradient(135deg, #07132b 0%, #0b224e 50%, #163a7d 100%);
    color: #ffffff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 4px 16px rgba(7, 19, 43, 0.2);
    position: relative;
    z-index: 2;
}

.km-chat__profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.km-chat__avatar-wrap {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.km-chat__avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #ffffff;
    object-fit: cover;
    display: block;
}

.km-chat__avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #10b981;
    border: 2.5px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.km-chat__profile-info {
    display: flex;
    flex-direction: column;
}

.km-chat__title-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.km-chat__title {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.2px;
    margin: 0;
}

.km-chat__verified {
    color: #38bdf8;
    filter: drop-shadow(0 1px 2px rgba(56, 189, 248, 0.4));
}

.km-chat__subtitle {
    font-size: 11px;
    font-weight: 500;
    color: #cbd5e1;
    margin: 2px 0 3px 0;
    letter-spacing: 0.1px;
}

.km-chat__status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(16, 185, 129, 0.16);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #34d399;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    width: fit-content;
}

.km-chat__status-pill-dot {
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 6px #10b981;
    animation: km-dot-pulse 1.8s infinite;
}

@keyframes km-dot-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

.km-chat__controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.km-chat__btn-control {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.km-chat__btn-control:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.06);
}

/* Chat Body / Messages Stream */
.km-chat__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.km-chat__body::-webkit-scrollbar {
    width: 5px;
}

.km-chat__body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Message Rows */
.km-msg {
    display: flex;
    gap: 8px;
    max-width: 92%;
    animation: km-msg-in 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes km-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.km-msg--bot {
    align-self: flex-start;
    align-items: flex-start;
}

.km-msg--user {
    align-self: flex-end;
    justify-content: flex-end;
}

/* Bot Mini Avatar Column */
.km-msg__avatar-col {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin-top: 4px;
}

.km-msg__mini-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid #ffffff;
    box-shadow: 0 2px 6px rgba(11, 34, 78, 0.15);
    display: block;
}

.km-msg__content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* Message Bubbles */
.km-msg__bubble {
    padding: 12px 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.km-msg--bot .km-msg__bubble {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.km-msg--bot .km-msg__bubble strong {
    color: #0b224e;
    font-weight: 700;
}

.km-msg--user .km-msg__bubble {
    background: linear-gradient(135deg, #0284c7 0%, #0b224e 100%);
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 4px 14px rgba(11, 34, 78, 0.22);
}

.km-msg__time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 1px;
}

.km-msg--bot .km-msg__time {
    margin-left: 4px;
    align-self: flex-start;
}

.km-msg--user .km-msg__time {
    margin-right: 4px;
    align-self: flex-end;
}

/* Typing Indicator */
.km-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    padding: 10px 14px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.km-typing__dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.km-typing__dot {
    width: 6px;
    height: 6px;
    background: #0284c7;
    border-radius: 50%;
    animation: km-typing-bounce 1.3s infinite ease-in-out;
}

.km-typing__dot:nth-child(1) { animation-delay: 0s; }
.km-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.km-typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes km-typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

.km-typing__label {
    font-size: 11.5px;
    color: #64748b;
    font-style: italic;
}

/* Interactive Quick Reply Chips */
.km-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.km-chip-btn {
    background: #ffffff;
    color: #0b224e;
    border: 1.5px solid #dbeafe;
    padding: 7px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 1px 4px rgba(11, 34, 78, 0.04);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.km-chip-btn:hover {
    background: linear-gradient(135deg, #0284c7 0%, #0b224e 100%);
    color: #ffffff;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.km-chip-btn:active {
    transform: translateY(0);
}

/* Quick Lead Card in Dialogue */
.km-lead-box {
    background: linear-gradient(180deg, #ffffff 0%, #f0f7ff 100%);
    border: 1.5px solid #bae6fd;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(2, 132, 199, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 6px;
    animation: km-fade-up 0.3s ease;
}

@keyframes km-fade-up {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.km-lead-box__top {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.km-lead-box__badge {
    background: #e0f2fe;
    color: #0369a1;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 3px 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
}

.km-lead-box__heading {
    font-size: 13.5px;
    font-weight: 700;
    color: #07132b;
    margin: 2px 0 0 0;
    line-height: 1.35;
}

.km-lead-box__sub {
    font-size: 11.5px;
    color: #475569;
    margin: 0;
    line-height: 1.4;
}

.km-lead-box__form {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.km-lead-box__field {
    flex: 1;
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    padding: 0 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.km-lead-box__field:focus-within {
    border-color: #0284c7;
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

.km-lead-box__flag {
    font-size: 15px;
    margin-right: 4px;
    user-select: none;
}

.km-lead-box__input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 13.5px;
    font-weight: 600;
    color: #0f172a;
    padding: 9px 0;
    background: transparent;
}

.km-lead-box__btn {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    padding: 0 14px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(249, 115, 22, 0.35);
}

.km-lead-box__btn:hover {
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(249, 115, 22, 0.45);
}

.km-lead-box__btn:active {
    transform: translateY(0);
}

.km-lead-box__wa {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #ffffff !important;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 12.5px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(34, 197, 94, 0.28);
}

.km-lead-box__wa:hover {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(34, 197, 94, 0.38);
    color: #ffffff !important;
}

.km-lead-box__trust {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 10.5px;
    color: #64748b;
    margin-top: 2px;
}

.km-lead-box__success {
    text-align: center;
    padding: 16px 8px;
}

.km-lead-box__success-icon {
    width: 44px;
    height: 44px;
    background: #dcfce7;
    color: #16a34a;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: bold;
    margin: 0 auto 8px;
}

/* Chat Footer / Input Form */
.km-chat__footer {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid #f1f5f9;
    box-shadow: 0 -4px 14px rgba(15, 23, 42, 0.03);
}

.km-chat__form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 28px;
    padding: 4px 5px 4px 16px;
    transition: all 0.2s ease;
}

.km-chat__form:focus-within {
    background: #ffffff;
    border-color: #0284c7;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.km-chat__input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13.5px;
    outline: none;
    color: #0f172a;
    line-height: 1.4;
}

.km-chat__input::placeholder {
    color: #94a3b8;
}

.km-chat__send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0284c7 0%, #0b224e 100%);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

.km-chat__send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.45);
}

.km-chat__send-btn:active {
    transform: scale(0.95);
}

/* Mobile Responsiveness */
@media (max-width: 560px) {
    .km-widget-root {
        bottom: 16px;
        right: 16px;
    }

    .km-launcher {
        width: 58px;
        height: 58px;
    }

    .km-cloud {
        right: 0;
        bottom: 74px;
        width: calc(100vw - 32px);
    }

    .km-cloud::after {
        display: none;
    }

    .km-chat {
        position: fixed;
        inset: auto 0 0 0;
        width: 100vw;
        max-width: 100vw;
        height: 86vh;
        max-height: 86vh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        bottom: 0;
        right: 0;
    }
}