/* Advanced Dark Glassmorphism Chatbot UI */
.kb-chatbot-wrap {
    /* One fixed shell height everywhere — not content-sized (avoids “grows when I send a message”) */
    --kb-chat-height: min(660px, 92vh);
    --kb-bg: #1a1b2e;
    --kb-surface: rgba(45, 47, 72, 0.65);
    --kb-border: rgba(148, 163, 184, 0.15);
    --kb-user-bg: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%);
    --kb-input-bg: #ffffff;
    --kb-text: #f1f5f9;
    --kb-text-muted: #94a3b8;
    --kb-accent: #14b8a6;
    --kb-accent-hover: #0d9488;
    --kb-purple: #a78bfa;
    --kb-teal: #2dd4bf;
    --kb-blue: #60a5fa;
    --kb-radius: 16px;
    --kb-input-radius: 20px;
    --kb-recording: #ef4444;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    max-width: 420px;
    margin: 0 auto;
    background: linear-gradient(180deg, #1e1b4b 0%, #1a1b2e 50%, #0f172a 100%);
    border-radius: 20px;
    /* overflow: hidden on both axes — avoid overflow-x-only (can force overflow-y: auto + scrollbar) */
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.4), 0 0 0 1px rgba(148,163,184,0.08);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    height: var(--kb-chat-height);
    max-height: 92vh;
    min-width: 0;
}

.kb-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: rgba(30, 41, 59, 0.5);
    border-bottom: 1px solid var(--kb-border);
    backdrop-filter: blur(8px);
    flex-shrink: 0;
}

.kb-chatbot-header-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.kb-chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    flex-shrink: 0;
    position: relative;
}

.kb-chatbot-avatar-assistant {
    background: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
}

.kb-chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.kb-chatbot-avatar-user {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.kb-chatbot-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #1e293b;
}

.kb-chatbot-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kb-chatbot-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--kb-text);
}

.kb-chatbot-subtitle {
    font-size: 13px;
    color: var(--kb-text-muted);
}

.kb-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kb-chatbot-action-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.15);
    color: var(--kb-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.kb-chatbot-action-btn:hover {
    background: rgba(148, 163, 184, 0.12);
    border-color: var(--kb-accent);
    transform: translateY(-1px);
}
.kb-chatbot-action-btn:active {
    transform: translateY(0);
}
.kb-chatbot-action-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.25);
}
.kb-chatbot-action-btn svg {
    display: block;
}

.kb-chatbot-model-select {
    padding: 6px 12px;
    border: 1px solid var(--kb-border);
    border-radius: 8px;
    background: var(--kb-surface);
    color: var(--kb-text);
    font-size: 13px;
    cursor: pointer;
}

.kb-chatbot-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.kb-chatbot-body::-webkit-scrollbar,
.kb-chatbot-body::-webkit-scrollbar-button,
.kb-chatbot-body::-webkit-scrollbar-corner {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.kb-chatbot-messages {
    /* flex-basis 0 + min-height 0: scroll inside this pane only; composer stays fully visible */
    flex: 1 1 0%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 16px 18px 28px;
    scroll-padding-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
    /* Hide scrollbar (incl. Windows classic arrows); wheel/touch still scrolls */
    scrollbar-width: none !important;
    scrollbar-color: transparent transparent;
    -ms-overflow-style: none !important;
}

#kb-chatbot-wrap .kb-chatbot-messages::-webkit-scrollbar,
#kb-chatbot-wrap .kb-chatbot-messages::-webkit-scrollbar-track,
#kb-chatbot-wrap .kb-chatbot-messages::-webkit-scrollbar-thumb,
#kb-chatbot-wrap .kb-chatbot-messages::-webkit-scrollbar-button,
#kb-chatbot-wrap .kb-chatbot-messages::-webkit-scrollbar-corner,
.kb-chatbot-messages::-webkit-scrollbar,
.kb-chatbot-messages::-webkit-scrollbar-track,
.kb-chatbot-messages::-webkit-scrollbar-thumb,
.kb-chatbot-messages::-webkit-scrollbar-button,
.kb-chatbot-messages::-webkit-scrollbar-corner {
    width: 0 !important;
    height: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    display: none !important;
    background: transparent !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.kb-chatbot-msg {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.kb-chatbot-msg-user { align-items: flex-end; }
.kb-chatbot-msg-assistant { align-items: flex-start; }

.kb-chatbot-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 90%;
    min-width: 0;
}

.kb-chatbot-msg-assistant .kb-chatbot-msg-row {
    max-width: 100%;
}

.kb-chatbot-msg-user .kb-chatbot-msg-row {
    flex-direction: row-reverse;
}

.kb-chatbot-msg-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    flex: 1;
    min-width: 0;
    max-width: 100%;
}

.kb-chatbot-msg-user .kb-chatbot-msg-content {
    align-items: flex-end;
}

.kb-chatbot-msg-text {
    position: relative;
    padding: 12px 16px;
    border-radius: var(--kb-radius);
    font-size: 16px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.kb-chatbot-msg-user .kb-chatbot-msg-text {
    background: var(--kb-user-bg);
    color: #fff;
    border: none;
}

.kb-chatbot-msg-assistant .kb-chatbot-msg-text {
    background: rgba(51, 65, 85, 0.5);
    color: var(--kb-text);
    border: 1px solid var(--kb-border);
    backdrop-filter: blur(8px);
    max-width: 100%;
}

/* First / welcome message: hug text only — no stretched column or oversized box */
.kb-chatbot-msg-welcome .kb-chatbot-msg-row {
    max-width: 100%;
    width: fit-content;
    align-self: flex-start;
}

.kb-chatbot-msg-welcome .kb-chatbot-msg-content {
    flex: 0 0 auto;
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    gap: 0;
}

/* No extra line under the bubble when timestamp is empty */
.kb-chatbot-msg-welcome .kb-chatbot-msg-time:empty {
    display: none;
}

.kb-chatbot-msg-welcome .kb-chatbot-msg-text {
    width: fit-content;
    max-width: min(100%, 30ch);
    padding: 4px 8px;
    font-size: 15px;
    line-height: 1.32;
    border-radius: 10px;
    box-sizing: border-box;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
}

/* Less dead space next to the speak icon on the welcome line */
.kb-chatbot-msg-welcome .kb-chatbot-msg-body {
    padding-right: 22px;
}

.kb-chatbot-msg-time {
    font-size: 12px;
    color: var(--kb-text-muted);
}

.kb-chatbot-msg-body {
    display: block;
    padding-right: 28px;
    letter-spacing: 0.01em;
}
.kb-chatbot-msg-body .kb-chatbot-bullet {
    display: block;
    padding-left: 1.2em;
    position: relative;
    margin-bottom: 2px;
    line-height: 1.4;
}
.kb-chatbot-msg-body .kb-chatbot-bullet::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--kb-teal);
    font-weight: 700;
}
.kb-chatbot-msg-user .kb-chatbot-msg-body .kb-chatbot-msg-link {
    color: rgba(255,255,255,0.9);
    text-decoration: underline;
}
.kb-chatbot-msg-assistant .kb-chatbot-msg-body .kb-chatbot-msg-link {
    color: var(--kb-teal);
    text-decoration: underline;
    word-break: break-all;
}
.kb-chatbot-msg-assistant .kb-chatbot-msg-body .kb-chatbot-msg-link:hover {
    color: var(--kb-accent-hover);
}

.kb-chatbot-msg-body .kb-chatbot-buy-btn {
    display: inline-block;
    margin: 6px 0;
    padding: 8px 14px;
    background: var(--kb-accent, #19c37d);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9em;
    border: none;
    cursor: pointer;
    transition: background .15s;
}
.kb-chatbot-msg-body .kb-chatbot-buy-btn:hover {
    background: var(--kb-accent-hover, #17a76c);
    color: #fff;
}

.kb-chatbot-msg-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.kb-chatbot-msg-actions:empty { display: none; }
.kb-chatbot-msg-text:has(.kb-chatbot-msg-actions:empty) .kb-chatbot-msg-body { padding-right: 0; }
.kb-chatbot-link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    margin-right: 8px;
    padding: 10px 18px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--kb-teal) 0%, var(--kb-accent) 100%);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform .2s, box-shadow .2s;
    box-shadow: 0 2px 10px rgba(20, 184, 166, 0.35);
}
.kb-chatbot-link-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(20, 184, 166, 0.5);
}

/* Form inline within chat section */
.kb-chatbot-form-inline {
    padding: 8px 0;
    width: 100%;
}
.kb-chatbot-form-card {
    background: rgba(45, 55, 72, 0.7);
    border: 1px solid rgba(45, 212, 191, 0.25);
    border-radius: 16px;
    padding: 18px 20px;
    max-width: 340px;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    backdrop-filter: blur(8px);
}
.kb-chatbot-form-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 700;
    color: var(--kb-text);
}
.kb-chatbot-form-sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--kb-text-muted);
}
.kb-chatbot-field-group {
    margin-bottom: 10px;
}
.kb-chatbot-field-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--kb-text-muted);
    margin-bottom: 3px;
}
.kb-chatbot-field-group label span {
    color: #f87171;
    margin-left: 2px;
}
.kb-chatbot-field-group input,
.kb-chatbot-field-group textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    font-size: 13px;
    background: rgba(30, 41, 59, 0.6);
    color: var(--kb-text);
    resize: vertical;
}
.kb-chatbot-field-group input::placeholder,
.kb-chatbot-field-group textarea::placeholder {
    color: var(--kb-text-muted);
}
.kb-chatbot-field-group input:focus,
.kb-chatbot-field-group textarea:focus {
    outline: none;
    border-color: var(--kb-teal);
    box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.2);
}
.kb-chatbot-field-group textarea {
    min-height: 72px;
}
.kb-chatbot-two-cols {
    display: flex;
    gap: 10px;
}
.kb-chatbot-two-cols .kb-chatbot-field-group {
    flex: 1;
}
.kb-chatbot-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
.kb-chatbot-form-cancel,
.kb-chatbot-form-submit {
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
}
.kb-chatbot-form-cancel {
    background: rgba(148, 163, 184, 0.2);
    color: var(--kb-text);
}
.kb-chatbot-form-cancel:hover {
    background: rgba(148, 163, 184, 0.3);
}
.kb-chatbot-form-submit {
    background: linear-gradient(135deg, var(--kb-teal) 0%, var(--kb-accent) 100%);
    color: #0f172a;
}
.kb-chatbot-form-submit:hover {
    background: linear-gradient(135deg, var(--kb-accent-hover) 0%, var(--kb-teal) 100%);
}
.kb-chatbot-copy-btn,
.kb-chatbot-speak-btn {
    width: 28px;
    color: var(--kb-text-muted);
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--kb-text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.kb-chatbot-copy-btn:hover,
.kb-chatbot-speak-btn:hover {
    background: var(--kb-border);
    color: var(--kb-text);
}
.kb-chatbot-copy-btn.kb-chatbot-copied { color: var(--kb-accent, #19c37d); }
.kb-chatbot-copy-btn svg,
.kb-chatbot-speak-btn svg { width: 16px; height: 16px; }


.kb-chatbot-msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.kb-chatbot-msg-doc-card {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--kb-text);
    background: rgba(0,0,0,0.05);
    border: 1px solid var(--kb-border);
    border-radius: 8px;
    max-width: 200px;
    min-width: 0;
}

.kb-chatbot-msg-doc-card .kb-chatbot-doc-icon {
    flex-shrink: 0;
    color: var(--kb-text-muted);
}

.kb-chatbot-msg-doc-card .kb-chatbot-msg-doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kb-chatbot-msg-error .kb-chatbot-msg-text {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
}

.kb-chatbot-loading .kb-chatbot-msg-text { padding: 16px 20px; }

.kb-chatbot-loading-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.kb-chatbot-loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kb-teal);
    animation: kb-dot 1.4s ease-in-out infinite both;
}

.kb-chatbot-loading-dots span:nth-child(1) { animation-delay: 0s; }
.kb-chatbot-loading-dots span:nth-child(2) { animation-delay: .2s; }
.kb-chatbot-loading-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes kb-dot {
    0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
    40% { transform: scale(1); opacity: 1; }
}


/* Composer: fixed footprint — does not grow with empty thread or steal space from messages */
.kb-chatbot-composer {
    flex: 0 0 auto;
    padding: 14px 18px 18px;
    background: rgba(30, 41, 59, 0.5);
    border-top: 1px solid var(--kb-border);
    backdrop-filter: blur(8px);
    min-width: 0;
    /* overflow-x-only makes overflow-y: auto per CSS → ugly outer scrollbar */
    overflow: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.kb-chatbot-composer::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.kb-chatbot-branding {
    text-align: center;
    font-size: 11px;
    color: var(--kb-text-muted);
    margin: 10px 0 0;
}

.kb-chatbot-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    min-height: 0;
}

.kb-chatbot-attachments:empty { display: none; }

.kb-chatbot-attach-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--kb-bg);
    border: 1px solid var(--kb-border);
    border-radius: 12px;
    font-size: 13px;
    color: var(--kb-text);
    max-width: 180px;
}

.kb-chatbot-attach-pill.kb-chatbot-uploading {
    opacity: 0.6;
    animation: kb-pulse 1.5s ease-in-out infinite;
}

@keyframes kb-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.kb-chatbot-attach-pill span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kb-chatbot-attach-pill .kb-chatbot-pill-remove {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--kb-text-muted);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}

.kb-chatbot-attach-pill .kb-chatbot-pill-remove:hover {
    background: var(--kb-border);
    color: var(--kb-text);
}

.kb-chatbot-ocr-notice {
    margin-top: 6px;
    padding: 8px 10px;
    font-size: 12px;
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    line-height: 1.4;
}

/* Voice transcript display */
.kb-chatbot-voice-transcript {
    padding: 10px 14px;
    margin-bottom: 10px;
    background: rgba(25, 195, 125, 0.1);
    border: 1px solid var(--kb-accent);
    border-radius: 12px;
    font-size: 15px;
    color: var(--kb-text);
    line-height: 1.45;
    overflow-wrap: anywhere;
    max-height: 100px;
    overflow: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    animation: kb-fade-in 0.2s ease-in;
}

.kb-chatbot-voice-transcript::-webkit-scrollbar,
.kb-chatbot-voice-transcript::-webkit-scrollbar-button {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

@keyframes kb-fade-in {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Message type bar (mic + field + send) — stable min height in default vs busy chat */
.kb-chatbot-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 14px 16px;
    min-height: 58px;
    min-width: 0;
    box-sizing: border-box;
    overflow: visible;
    background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: var(--kb-input-radius);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06), inset 0 1px 0 rgba(255,255,255,0.8);
    transition: border-color .25s, box-shadow .25s;
}

.kb-chatbot-input-row:has(.kb-chatbot-voice-recording) {
    padding-top: 16px;
    padding-bottom: 20px;
}

.kb-chatbot-input-row:focus-within {
    border-color: rgba(45, 212, 191, 0.5);
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.15), 0 4px 20px rgba(20, 184, 166, 0.12);
}

.kb-chatbot-icon-btn {
    flex-shrink: 0;
    width: 40px;
    height: 38px;
    border: none;
    background: linear-gradient(145deg, #6366f1 0%, #7c3aed 100%);
    border-radius: 12px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s, opacity .2s;
    user-select: none;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.kb-chatbot-icon-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.4);
    opacity: 0.95;
}

.kb-chatbot-icon-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Recording state */
.kb-chatbot-voice-recording {
    background: var(--kb-recording) !important;
    color: #fff !important;
    animation: kb-recording-pulse 1.5s ease-in-out infinite;
}

.kb-chatbot-stop-speech-btn {
    background: linear-gradient(145deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}

.kb-chatbot-stop-speech-btn:hover {
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.45);
}

/* Opacity-only — no transform, so the bar stays inside composer overflow without clipping */
@keyframes kb-recording-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.82; }
}

.kb-chatbot-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    min-width: 0;
    padding: 8px 4px;
    border: none;
    background: transparent;
    font-size: 16px;
    line-height: 1.5;
    resize: none;
    font-family: inherit;
    color: #1e293b;
    overflow-y: auto;
    scrollbar-width: none !important;
    scrollbar-color: transparent transparent;
    -ms-overflow-style: none !important;
}

#kb-chatbot-wrap .kb-chatbot-input::-webkit-scrollbar,
#kb-chatbot-wrap .kb-chatbot-input::-webkit-scrollbar-track,
#kb-chatbot-wrap .kb-chatbot-input::-webkit-scrollbar-thumb,
#kb-chatbot-wrap .kb-chatbot-input::-webkit-scrollbar-button,
.kb-chatbot-input::-webkit-scrollbar,
.kb-chatbot-input::-webkit-scrollbar-track,
.kb-chatbot-input::-webkit-scrollbar-thumb,
.kb-chatbot-input::-webkit-scrollbar-button {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.kb-chatbot-input-row .kb-chatbot-input::placeholder { color: #64748b; }
.kb-chatbot-input:focus { outline: none; }

.kb-chatbot-send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 38px;
    border: none;
    background: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
    color: #fff;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(20, 184, 166, 0.4);
    transition: transform .2s, box-shadow .2s, opacity .2s;
}

.kb-chatbot-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(20, 184, 166, 0.5);
}

.kb-chatbot-send-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Connect with human – overlay and form */
.kb-chatbot-contact-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
}
.kb-chatbot-contact-overlay.kb-chatbot-contact-open {
    display: flex;
}
.kb-chatbot-contact-modal {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--kb-border);
    border-radius: 16px;
    padding: 24px;
    max-width: 360px;
    width: calc(100% - 24px);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.5);
    backdrop-filter: blur(12px);
}
.kb-chatbot-contact-title {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--kb-text);
}
.kb-chatbot-contact-form label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--kb-text-muted);
}
.kb-chatbot-contact-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 12px;
    box-sizing: border-box;
    background: rgba(15, 23, 42, 0.6);
    color: var(--kb-text);
}
.kb-chatbot-contact-input:focus {
    outline: none;
    border-color: var(--kb-teal);
}
.kb-chatbot-contact-feedback {
    font-size: 13px;
    margin-bottom: 12px;
    padding: 8px;
    border-radius: 8px;
}
.kb-chatbot-contact-feedback.kb-chatbot-contact-success {
    background: rgba(25, 195, 125, 0.15);
    color: var(--kb-accent);
}
.kb-chatbot-contact-feedback.kb-chatbot-contact-error {
    background: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}
.kb-chatbot-contact-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin: 0;
}
.kb-chatbot-contact-cancel,
.kb-chatbot-contact-submit {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid var(--kb-border);
    background: var(--kb-surface);
    color: var(--kb-text);
}
.kb-chatbot-contact-cancel:hover {
    background: var(--kb-bg);
}
.kb-chatbot-contact-submit {
    background: linear-gradient(135deg, var(--kb-teal) 0%, var(--kb-accent) 100%);
    color: #0f172a;
    border: none;
}
.kb-chatbot-contact-submit:hover:not(:disabled) {
    opacity: 0.9;
    filter: brightness(1.1);
}
.kb-chatbot-contact-submit:disabled {
    opacity: .7;
    cursor: not-allowed;
}

/* Floating widget (bottom-right button + panel) */
.kb-chatbot-float-wrap {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 999998;
    font-family: inherit;
    max-width: 100vw;
    overflow: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.kb-chatbot-float-wrap::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.kb-chatbot-float-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.9);
    background: linear-gradient(145deg, #ffffff 0%, #f0fdfa 50%, #ccfbf1 100%);
    color: #0d9488;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(20, 184, 166, 0.45), 0 0 0 0 rgba(20, 184, 166, 0.3);
    transition: transform .25s, box-shadow .25s;
}

.kb-chatbot-float-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 32px rgba(20, 184, 166, 0.55), 0 0 40px 4px rgba(20, 184, 166, 0.2);
}

.kb-chatbot-float-panel {
    display: none;
    position: fixed;
    bottom: 84px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    /* Must set height + max-height (not max-height alone) or panel shrinks with short threads and grows when messages arrive */
    height: min(660px, calc(100vh - 100px));
    max-height: min(660px, calc(100vh - 100px));
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
    z-index: 999997;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.kb-chatbot-float-panel::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.kb-chatbot-float-panel.kb-chatbot-float-panel-open {
    display: block;
}

.kb-chatbot-float-panel .kb-chatbot-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    /* Inherit fixed panel height so inner layout matches embedded shortcode */
    --kb-chat-height: 100%;
}

/* Light theme overrides */
.kb-chatbot-wrap.kb-chatbot-theme-light {
    --kb-bg: #f8fafc;
    --kb-surface: rgba(255, 255, 255, 0.9);
    --kb-border: rgba(15, 23, 42, 0.12);
    --kb-text: #1e293b;
    --kb-text-muted: #64748b;
    --kb-accent: #0d9488;
    --kb-accent-hover: #0f766e;
    background: linear-gradient(180deg, #f1f5f9 0%, #f8fafc 50%, #e2e8f0 100%);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.15), 0 0 0 1px rgba(15,23,42,0.06);
}

.kb-chatbot-theme-light .kb-chatbot-header {
    background: rgba(255, 255, 255, 0.7);
    border-bottom-color: rgba(15, 23, 42, 0.1);
}

.kb-chatbot-theme-light .kb-chatbot-online-dot {
    border-color: #f8fafc;
}

.kb-chatbot-theme-light .kb-chatbot-action-btn {
    border-color: rgba(15, 23, 42, 0.2);
    color: var(--kb-text);
}

.kb-chatbot-theme-light .kb-chatbot-action-btn:hover {
    background: rgba(15, 23, 42, 0.05);
    border-color: var(--kb-accent);
}

.kb-chatbot-theme-light .kb-chatbot-msg-assistant .kb-chatbot-msg-text {
    background: rgba(255, 255, 255, 0.95);
    color: var(--kb-text);
    border-color: rgba(15, 23, 42, 0.1);
}

.kb-chatbot-theme-light .kb-chatbot-msg-body .kb-chatbot-bullet::before {
    color: var(--kb-accent);
}

.kb-chatbot-theme-light .kb-chatbot-composer {
    background: rgba(248, 250, 252, 0.9);
    border-top-color: rgba(15, 23, 42, 0.1);
}

.kb-chatbot-theme-light .kb-chatbot-contact-overlay {
    background: rgba(248, 250, 252, 0.9);
}

.kb-chatbot-theme-light .kb-chatbot-contact-modal {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(15, 23, 42, 0.12);
}

.kb-chatbot-theme-light .kb-chatbot-form-card {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(13, 148, 136, 0.2);
}

.kb-chatbot-theme-light .kb-chatbot-msg-doc-card {
    background: rgba(15, 23, 42, 0.05);
    border-color: rgba(15, 23, 42, 0.12);
}

.kb-chatbot-theme-light .kb-chatbot-msg-error .kb-chatbot-msg-text {
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.2);
}

.kb-chatbot-theme-light .kb-chatbot-loading-dots span {
    background: var(--kb-accent);
}

/* Mobile responsiveness */
@media (max-width: 640px) {
    .kb-chatbot-wrap {
        --kb-chat-height: min(660px, 92vh);
    }
    
    .kb-chatbot-msg-user .kb-chatbot-msg-text {
        max-width: 90%;
    }

    .kb-chatbot-float-panel {
        right: 10px;
        bottom: 76px;
        width: calc(100vw - 20px);
        height: min(660px, calc(100vh - 96px));
        max-height: min(660px, calc(100vh - 96px));
    }

    .kb-chatbot-float-btn {
        bottom: 16px;
        right: 16px;
    }
}