/* ─── KD Mobile Chatbot v4 – Premium Assistant UI ──────────────── */

/* ─── Reset ────────────────────────────────────────────────────── */
#kdmc-chatbot-root,
#kdmc-chatbot-root * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

#kdmc-chatbot-root {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE: FULLSCREEN TAKEOVER
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    body.kdmc-mobile-active > *:not(#kdmc-chatbot-root) {
        display: none !important;
    }
    body.kdmc-mobile-active {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
    }
    #kdmc-chatbot-root {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: 999999;
    }
    #kdmc-chat-bubble { display: none !important; }
    #kdmc-chat-window {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        opacity: 1 !important;
        transform: none !important;
        pointer-events: auto !important;
        box-shadow: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   DESKTOP: Floating Chat
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Bubble ───────────────────────────────────────────────────── */
#kdmc-chat-bubble {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 64px;
    height: 64px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 99998;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12), 0 12px 40px rgba(0,0,0,0.08);
}
#kdmc-chat-bubble:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.16), 0 16px 48px rgba(0,0,0,0.12);
}
#kdmc-chat-bubble.kdmc-bubble-hidden {
    transform: scale(0); opacity: 0; pointer-events: none;
}
.kdmc-bubble-dot {
    position: absolute; top: -2px; right: -2px;
    width: 14px; height: 14px; background: #ef4444;
    border-radius: 50%; border: 2.5px solid #fff;
    animation: kdmc-dot-pulse 2s ease-in-out infinite;
}
@keyframes kdmc-dot-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ═══════════════════════════════════════════════════════════════════
   CHAT WINDOW – Background image covers full height here
   ═══════════════════════════════════════════════════════════════════ */
#kdmc-chat-window {
    position: fixed;
    bottom: 28px; right: 28px;
    width: 420px; height: 660px;
    max-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: bottom right;
    border-radius: 24px;
    background-color: var(--kdmc-chat-bg, #f4f5f7);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 24px 80px rgba(0,0,0,0.08);
}
#kdmc-chat-window.kdmc-hidden {
    transform: scale(0.4) translateY(20px); opacity: 0; pointer-events: none;
}
#kdmc-chat-window.kdmc-visible {
    transform: scale(1) translateY(0); opacity: 1;
}

/* Background image – applied to the window, spans full height */
#kdmc-chat-window.kdmc-has-bg {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: scroll;
}
#kdmc-chat-window.kdmc-has-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    border-radius: inherit;
}

/* All direct children sit above the overlay */
#kdmc-chat-window.kdmc-has-bg > * {
    position: relative;
    z-index: 1;
}

/* ─── Header ───────────────────────────────────────────────────── */
#kdmc-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    min-height: 80px;
    flex-shrink: 0;
    z-index: 2;
}
@media (max-width: 768px) {
    #kdmc-chat-header {
        padding: 20px 24px;
        padding-top: calc(20px + env(safe-area-inset-top, 0px));
        min-height: calc(80px + env(safe-area-inset-top, 0px));
    }
}
.kdmc-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.kdmc-header-logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    object-fit: contain;
    background: transparent;
    padding: 0;
    border: none;
    filter: brightness(0) invert(1);
}
.kdmc-header-info {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.kdmc-header-name {
    font-size: 18px;
    font-weight: 650;
    letter-spacing: -0.015em;
    line-height: 1.2;
}
.kdmc-header-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 450;
    margin-top: -2px;
}
.kdmc-status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74,222,128,0.5);
    display: inline-block;
}
.kdmc-header-actions { display: flex; gap: 6px; }
@media (max-width: 768px) { .kdmc-header-actions { display: none; } }
.kdmc-header-actions button {
    background: rgba(255,255,255,0.12);
    border: none; cursor: pointer;
    width: 38px; height: 38px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.kdmc-header-actions button:hover {
    background: rgba(255,255,255,0.25); transform: scale(1.05);
}

/* ═══════════════════════════════════════════════════════════════════
   MESSAGES AREA – transparent so window bg shines through
   ═══════════════════════════════════════════════════════════════════ */
#kdmc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 1;
    background: transparent;
}

#kdmc-chat-messages::-webkit-scrollbar { width: 4px; }
#kdmc-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 4px; }
@media (max-width: 768px) {
    #kdmc-chat-messages::-webkit-scrollbar { width: 0; display: none; }
    #kdmc-chat-messages { padding: 28px 20px 24px; }
}

/* ═══════════════════════════════════════════════════════════════════
   WELCOME SCREEN
   ═══════════════════════════════════════════════════════════════════ */
#kdmc-welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 32px 24px;
    text-align: center;
    animation: kdmc-welcomeFadeIn 0.8s ease;
}
@media (max-width: 768px) {
    #kdmc-welcome-screen { padding: 56px 32px 28px; }
}
.kdmc-welcome-logo {
    width: 100px;
    height: 100px;
    border-radius: 28px;
    object-fit: contain;
    margin-bottom: 24px;
    background: transparent;
    padding: 0;
    border: none;
    animation: kdmc-logoPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}
.kdmc-welcome-logo-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 28px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    animation: kdmc-logoPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}
.kdmc-welcome-name {
    font-size: 26px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.025em;
    margin-bottom: 10px;
    animation: kdmc-welcomeFadeIn 0.6s ease 0.4s both;
}
.kdmc-welcome-text {
    font-size: 16px;
    color: #64748b;
    font-weight: 400;
    line-height: 1.6;
    max-width: 340px;
    animation: kdmc-welcomeFadeIn 0.6s ease 0.6s both;
}
.kdmc-voice-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    margin-top: 20px;
    opacity: 0;
    transition: opacity 0.3s;
}
.kdmc-voice-wave.kdmc-wave-active { opacity: 1; }
.kdmc-voice-wave span {
    width: 4px; border-radius: 4px;
    animation: kdmc-wave 1.2s ease-in-out infinite;
}
.kdmc-voice-wave span:nth-child(1) { height: 10px; animation-delay: 0s; }
.kdmc-voice-wave span:nth-child(2) { height: 18px; animation-delay: 0.1s; }
.kdmc-voice-wave span:nth-child(3) { height: 26px; animation-delay: 0.2s; }
.kdmc-voice-wave span:nth-child(4) { height: 18px; animation-delay: 0.3s; }
.kdmc-voice-wave span:nth-child(5) { height: 10px; animation-delay: 0.4s; }
@keyframes kdmc-wave {
    0%, 100% { transform: scaleY(0.4); opacity: 0.3; }
    50% { transform: scaleY(1); opacity: 1; }
}
@keyframes kdmc-logoPop {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes kdmc-welcomeFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Suggestion Chips ─────────────────────────────────────────── */
.kdmc-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 20px 24px 8px;
    animation: kdmc-welcomeFadeIn 0.6s ease 0.8s both;
}
.kdmc-suggestion-chip {
    background: #ffffff;
    border: 1.5px solid rgba(0,0,0,0.07);
    border-radius: 16px;
    padding: 12px 20px;
    font-size: 14px;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 480;
    font-family: inherit;
    line-height: 1.3;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.kdmc-suggestion-chip:hover {
    border-color: var(--kdmc-primary, #0066FF);
    color: var(--kdmc-primary, #0066FF);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.kdmc-suggestion-chip:active { transform: scale(0.96); }

/* ═══════════════════════════════════════════════════════════════════
   MESSAGE BUBBLES – customizable via CSS vars
   ═══════════════════════════════════════════════════════════════════ */
.kdmc-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: kdmc-msgFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.kdmc-message-bot { align-self: flex-start; }
.kdmc-message-user { align-self: flex-end; flex-direction: row-reverse; }

.kdmc-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    object-fit: contain;
    flex-shrink: 0;
    margin-top: 2px;
    background: transparent;
    padding: 0;
    border: none;
}
.kdmc-avatar-default {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
}
.kdmc-msg-bubble { position: relative; }
.kdmc-msg-content {
    padding: 14px 20px;
    font-size: var(--kdmc-font-size, 15px);
    line-height: 1.65;
    word-break: break-word;
    letter-spacing: -0.008em;
}
.kdmc-message-bot .kdmc-msg-content {
    background: var(--kdmc-bot-bg, #FFFFFF);
    color: var(--kdmc-bot-text, #1e293b);
    border-radius: var(--kdmc-bot-radius, 20px);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);padding: 1em !important;
}
.kdmc-message-user .kdmc-msg-content {
    background: var(--kdmc-user-bg, #0066FF);
    color: var(--kdmc-user-text, #FFFFFF);
    border-radius: var(--kdmc-user-radius, 20px);
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);padding: 1em !important;
}
.kdmc-msg-content strong { font-weight: 650; }
.kdmc-msg-content em { font-style: italic; }
.kdmc-msg-content code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.87em;
}
.kdmc-msg-content pre {
    background: #1e293b; color: #e2e8f0;
    padding: 14px 16px; border-radius: 12px;
    margin: 10px 0; overflow-x: auto;
    font-size: 13px; line-height: 1.5;
}
.kdmc-msg-content pre code { background: none; padding: 0; color: inherit; }
.kdmc-msg-content a { color: #2563eb; text-decoration: underline; text-underline-offset: 2px; }
.kdmc-message-user .kdmc-msg-content a { color: rgba(255,255,255,0.9); }

/* ─── TTS Button ───────────────────────────────────────────────── */
.kdmc-msg-actions {
    display: flex; gap: 4px;
    margin-top: 8px; padding-left: 4px;
}
.kdmc-tts-btn {
    background: none;
    border: 1px solid rgba(0,0,0,0.06);
    cursor: pointer;
    padding: 6px 12px;
    color: #94a3b8;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: inherit;padding: 1em !important;
}
.kdmc-tts-btn:hover { color: #475569; background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.1); }
.kdmc-tts-btn.kdmc-tts-playing {
    color: var(--kdmc-primary, #0066FF);
    border-color: var(--kdmc-primary, #0066FF);
    background: rgba(0,102,255,0.04);
}
.kdmc-tts-btn.kdmc-tts-playing svg { animation: kdmc-tts-pulse 1s ease-in-out infinite; }
.kdmc-tts-btn.kdmc-tts-loading { opacity: 0.5; pointer-events: none; }
@keyframes kdmc-tts-pulse {
    0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

/* ─── Typing Indicator ─────────────────────────────────────────── */
#kdmc-typing-indicator { display: none; padding: 0 24px 4px; }
#kdmc-typing-indicator.kdmc-active { display: block; }
.kdmc-typing-wrapper { display: flex; align-items: center; gap: 12px; }
.kdmc-typing-avatar {
    width: 36px; height: 36px;
    border-radius: 12px;
    object-fit: contain;
    flex-shrink: 0;
    background: transparent;
    border: none;
}
.kdmc-typing-avatar-default {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; color: #475569;
}
.kdmc-typing-bubble {
    display: inline-flex; gap: 5px;
    padding: 16px 20px;
    background: var(--kdmc-bot-bg, #fff);
    border-radius: var(--kdmc-bot-radius, 20px);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.kdmc-typing-bubble span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #cbd5e1;
    animation: kdmc-typing 1.4s ease-in-out infinite;
}
.kdmc-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.kdmc-typing-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes kdmc-typing {
    0%, 60%, 100% { transform: translateY(0); background: #cbd5e1; }
    30% { transform: translateY(-8px); background: #94a3b8; }
}

/* ═══════════════════════════════════════════════════════════════════
   ACTION BUTTONS
   ═══════════════════════════════════════════════════════════════════ */
.kdmc-action-buttons {
    display: flex;
    gap: 10px;
    padding: 8px 24px 4px;
    flex-shrink: 0;
    z-index: 2;margin: 0 28px !important;
}
.kdmc-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 8px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 580;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    border: 1.5px solid rgba(0,0,0,0.06);
    background: #374151 !important;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    white-space: nowrap;
}
.kdmc-action-btn:hover {
    background: #f8fafc;
    border-color: var(--kdmc-primary, #0066FF);
    color: var(--kdmc-primary, #0066FF);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.06);
}
.kdmc-action-btn:active { transform: scale(0.97); }
.kdmc-action-btn svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

/* Mobile: Compact dark buttons, pulled up tight */
@media (max-width: 768px) {
    .kdmc-action-buttons {
        padding: 0 20px 6px;
        gap: 8px;
        margin-top: -16px;
    }
    .kdmc-action-btn {
        padding: 10px 6px !important;
        font-size: 0.8em;
        border-radius: 12px;
        background: #19272e;
        color: #ffffff !important;
        border-color: rgba(255,255,255,0.08);
        box-shadow: none;
        text-decoration: none !important;margin:0 27px !important;
    }
    .kdmc-action-btn:hover {
        background: #243338;
        color: #ffffff;
        border-color: rgba(255,255,255,0.15);
    }
}

/* ═══════════════════════════════════════════════════════════════════
   INPUT AREA – transparent so bg shines through
   ═══════════════════════════════════════════════════════════════════ */
#kdmc-chat-input-area {
    padding: 12px 24px 16px;
    flex-shrink: 0;
    z-index: 2;
    background: transparent;
}
@media (max-width: 768px) {
    #kdmc-chat-input-area {
        padding: 12px 20px 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}
.kdmc-input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #ffffff;
    border: 1.5px solid rgba(0,0,0,0.07);
    border-radius: 20px;
    padding: 0 0 0 16px;
    transition: all 0.25s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}
.kdmc-input-container:focus-within {
    border-color: var(--kdmc-primary, #0066FF);
    box-shadow: 0 0 0 3px rgba(0,102,255,0.06), 0 2px 8px rgba(0,0,0,0.05);
}
#kdmc-chat-input {
    flex: 1;
    border: none;
    padding: 10px !important;
    font-size: 15px;
    line-height: 1.45;
    resize: none;
    outline: none;
    max-height: 120px;
    background: transparent;
    color: #1e293b;
    font-family: inherit;
    letter-spacing: -0.008em;
}
#kdmc-chat-input::placeholder { color: #94a3b8; }
#kdmc-send-btn {
    width: 44px; height: 44px; min-width: 44px;
    border-radius: 14px; border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
}
#kdmc-send-btn:disabled { opacity: 0.3; cursor: default; transform: scale(0.9); }
#kdmc-send-btn:not(:disabled):hover { transform: scale(1.08); filter: brightness(1.1); }
#kdmc-send-btn:not(:disabled):active { transform: scale(0.92); }

.kdmc-powered-by {
    text-align: center;
    font-size: 11px;
    color: #b0b8c4;
    margin-top: 10px;
    font-weight: 400;
    letter-spacing: 0.01em;
}

/* ─── Animations ───────────────────────────────────────────────── */
@keyframes kdmc-msgFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
