/* KSMA Chat — compact panel melted into the bottom navbar */

.ksma-chatbot {
    position: fixed;
    inset: auto;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    z-index: 10001;
    pointer-events: none;
    font-family: var(--font-primary, 'Space Grotesk', sans-serif);
    overflow: visible;
    background: transparent;
    border: none;
}

.ksma-chat-backdrop[hidden],
.ksma-chat-window[hidden] {
    display: none !important;
}

.ksma-chat-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    z-index: 10000;
}

.ksma-chat-backdrop.is-visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* Same footprint as navbar — flush connected (no gap) */
.ksma-chat-window {
    position: fixed;
    left: 50%;
    bottom: calc(var(--ksma-dock-bottom, 0.65rem) + var(--ksma-dock-h, 3.1rem));
    width: var(--ksma-dock-w, min(720px, calc(100% - 1.5rem)));
    max-width: var(--ksma-dock-w, min(720px, calc(100% - 1.5rem)));
    height: min(420px, calc(100dvh - var(--ksma-dock-bottom, 0.65rem) - var(--ksma-dock-h, 3.1rem) - 1rem));
    z-index: 10040;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    background: rgba(8, 11, 20, 0.92);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    border-radius: 0;
    box-shadow: none;
    outline: none;
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
    transform-origin: 50% 100%;
    transition: opacity 0.28s ease, transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
    isolation: isolate;
    box-sizing: border-box;
}

/* Soft join into navbar — top hairline only */
.ksma-chat-window::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 85, 255, 0.55), transparent);
    pointer-events: none;
    z-index: 2;
}

.ksma-chat-window::after {
    display: none !important;
    content: none !important;
}

.ksma-chat-window.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ksma-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.9rem 0.65rem;
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.ksma-chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.ksma-chat-avatar {
    width: 28px;
    height: 28px;
    border-radius: 0;
    object-fit: contain;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    flex-shrink: 0;
}

.ksma-chat-header strong {
    display: block;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    line-height: 1.2;
}

.ksma-chat-header span {
    display: block;
    color: #0055ff;
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 1;
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 16rem;
}

.ksma-chat-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    width: 2rem;
    height: 2rem;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
}

.ksma-chat-close:hover {
    background: rgba(0, 85, 255, 0.18);
    color: #fff;
    border: none;
}

.ksma-chat-close .ti {
    font-size: 1.05rem;
    line-height: 1;
}

.ksma-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    scroll-behavior: smooth;
    background: transparent;
    position: relative;
    z-index: 1;
}

.ksma-chat-msg {
    max-width: 92%;
    padding: 0.55rem 0.75rem;
    border-radius: 0;
    font-size: 0.82rem;
    line-height: 1.5;
    animation: ksmaMsgIn 0.28s ease both;
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
}

.ksma-chat-msg-icon {
    flex-shrink: 0;
    opacity: 0.85;
    margin-top: 0.1rem;
    color: #0055ff;
}

.ksma-chat-msg-icon .ti {
    font-size: 0.9rem;
    line-height: 1;
}

.ksma-chat-msg-text {
    flex: 1;
    min-width: 0;
}

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

.ksma-chat-msg.bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    color: #e8e8e8;
    border: none;
    border-left: 2px solid #0055ff;
}

.ksma-chat-msg.user {
    align-self: flex-end;
    background: rgba(0, 85, 255, 0.22);
    color: #fff;
    border: none;
}

.ksma-chat-msg.system {
    align-self: center;
    background: transparent;
    color: #888;
    font-size: 0.7rem;
    text-align: center;
    border: none;
    max-width: 95%;
    letter-spacing: 0.02em;
    justify-content: center;
}

.ksma-chat-service-card {
    align-self: stretch;
    background: rgba(255, 255, 255, 0.04);
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0;
    padding: 0.65rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.65rem;
    animation: ksmaMsgIn 0.25s ease;
    transition: background 0.2s ease;
}

.ksma-chat-service-card:hover {
    background: rgba(0, 85, 255, 0.1);
}

.ksma-chat-service-card-info {
    flex: 1;
    min-width: 0;
}

.ksma-chat-service-card-info strong {
    display: block;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ksma-chat-service-card-info span {
    color: #999;
    font-size: 0.68rem;
    letter-spacing: 0.03em;
}

.ksma-chat-service-add {
    position: relative;
    overflow: hidden;
    background: #0055ff;
    color: #fff;
    border: none;
    border-radius: 0;
    padding: 0.45rem 0.75rem;
    font-family: inherit;
    font-size: 0.62rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.ksma-chat-service-add::before {
    display: none;
}

.ksma-chat-service-add .ti {
    position: relative;
    z-index: 1;
    font-size: 0.85rem;
}

.ksma-chat-service-add:hover,
.ksma-chat-service-add.added {
    background: #fff;
    color: #000;
}

.ksma-chat-cart {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 0.55rem 0.85rem;
    background: transparent;
    max-height: 72px;
    overflow-y: auto;
    flex-shrink: 0;
}

.ksma-chat-cart-title {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #0055ff;
    margin-bottom: 0.3rem;
}

.ksma-chat-cart-item {
    font-size: 0.72rem;
    color: #ddd;
    padding: 2px 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.ksma-chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 0.55rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-left: 2px solid #0055ff;
}

.ksma-chat-typing span {
    width: 5px;
    height: 5px;
    background: #0055ff;
    border-radius: 50%;
    animation: ksmaTyping 1.2s infinite;
    opacity: 0.5;
}

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

@keyframes ksmaTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-3px); opacity: 1; }
}

.ksma-chat-input-area {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 0.65rem 0.85rem 0.75rem;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

/* Real buttons — stacked, filled, interactive */
.ksma-chat-quick-replies {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.55rem;
    max-height: none;
    overflow: visible;
}

.ksma-chat-quick-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.55rem;
    width: 100%;
    background: #111;
    border: none;
    border-left: 3px solid #0055ff;
    color: #fff;
    padding: 0.72rem 0.9rem;
    border-radius: 0;
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    line-height: 1.3;
    text-align: left;
    letter-spacing: 0.03em;
    animation: ksmaQuickIn 0.35s ease both;
}

.ksma-chat-quick-btn .ti {
    font-size: 0.95rem;
    color: #0055ff;
    margin-right: 0;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.ksma-chat-quick-btn:hover {
    background: #0055ff;
    color: #fff;
    transform: translateX(2px);
}

.ksma-chat-quick-btn:hover .ti {
    color: #fff;
}

.ksma-chat-quick-btn:active {
    transform: translateX(0);
}

.ksma-chat-quick-btn.primary {
    background: #0055ff;
    border-left-color: #fff;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.7rem;
}

.ksma-chat-quick-btn.primary .ti {
    color: #fff;
}

.ksma-chat-quick-btn.primary:hover {
    background: #fff;
    color: #000;
    border-left-color: #0055ff;
}

.ksma-chat-quick-btn.primary:hover .ti {
    color: #0055ff;
}

@keyframes ksmaQuickIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

.ksma-chat-form {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

.ksma-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 0;
    padding: 0.55rem 0.15rem;
    color: #fff;
    font-family: inherit;
    font-size: 0.84rem;
    outline: none;
    transition: border-color 0.2s ease;
    min-height: 2.4rem;
}

.ksma-chat-input:focus {
    border-bottom-color: #0055ff;
}

.ksma-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.ksma-chat-send {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0;
    border: none;
    background: #0055ff;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease;
    position: relative;
    overflow: hidden;
}

.ksma-chat-send::before {
    display: none;
}

.ksma-chat-send .ti {
    position: relative;
    z-index: 1;
    font-size: 0.95rem;
    line-height: 1;
    color: #fff;
}

.ksma-chat-send:hover {
    background: #fff;
    color: #000;
    border: none;
}

.ksma-chat-send:hover .ti {
    color: #000;
}

.ksma-chat-success {
    text-align: center;
    padding: 1.5rem 1rem;
}

.ksma-chat-success-icon {
    margin-bottom: 0.65rem;
}

.ksma-chat-success-icon .ti {
    font-size: 2rem;
    color: #0055ff;
}

.ksma-chat-success h3 {
    color: #fff;
    margin: 0 0 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ksma-chat-success p {
    color: #aaa;
    font-size: 0.8rem;
    line-height: 1.55;
    margin: 0 0 0.85rem;
}

.ksma-chat-restart-btn {
    margin-top: 0.35rem;
    padding: 0.65rem 1.1rem;
    background: #0055ff;
    border: none;
    border-radius: 0;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.ksma-chat-restart-btn:hover {
    background: #fff;
    color: #000;
}

/* When chat is open, navbar feels attached */
body.ksma-chat-open .bottom-nav-container {
    border-top-color: transparent !important;
    background: rgba(8, 11, 20, 0.92) !important;
}

@media (max-width: 768px) {
    .ksma-chat-window {
        bottom: calc(var(--ksma-dock-bottom, 0.55rem) + var(--ksma-dock-h, 3rem) + env(safe-area-inset-bottom, 0px));
        width: var(--ksma-dock-w, calc(100% - 1.25rem));
        max-width: var(--ksma-dock-w, calc(100% - 1.25rem));
        height: min(58dvh, 360px);
        transform: translateX(-50%) translateY(16px);
    }

    .ksma-chat-window.is-visible {
        transform: translateX(-50%) translateY(0);
    }

    .ksma-chat-header {
        padding: 0.65rem 0.8rem;
    }

    .ksma-chat-messages {
        padding: 0.65rem 0.75rem;
    }

    .ksma-chat-input-area {
        padding: 0.55rem 0.75rem 0.7rem;
    }

    .ksma-chat-header span {
        max-width: 11rem;
    }
}

@media (max-width: 480px) {
    .ksma-chat-window {
        height: min(54dvh, 340px);
    }

    .ksma-chat-header strong {
        font-size: 0.72rem;
    }

    .ksma-chat-header span {
        font-size: 0.58rem;
        max-width: 9.5rem;
    }

    .ksma-chat-quick-btn {
        padding: 0.65rem 0.8rem;
        font-size: 0.7rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ksma-chat-window,
    .ksma-chat-msg,
    .ksma-chat-quick-btn,
    .ksma-chat-backdrop {
        transition: none !important;
        animation: none !important;
    }
}
