/* KMD AI chatbot widget. All selectors are prefixed with .kmdc- to avoid clashing with the site CSS. */
#kmd-chatbot {
    --kmdc-primary: #004aad;
    --kmdc-navy: #01246c;
    --kmdc-light: #e3eaf5;
    --kmdc-bg: #ffffff;
    --kmdc-text: #1f2937;
    --kmdc-muted: #6b7280;
    --kmdc-border: #e5e7eb;
    --kmdc-user: #004aad;
    --kmdc-bot: #f1f4f9;
    --kmdc-font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", "Pyidaungsu", sans-serif;
    --kmdc-font-my: "Noto Sans Myanmar", "Pyidaungsu", "Myanmar Text", sans-serif;
    font-family: var(--kmdc-font);
    color: var(--kmdc-text);
}

#kmd-chatbot *,
#kmd-chatbot *::before,
#kmd-chatbot *::after { box-sizing: border-box; }

/* Floating bubble */
.kmdc-bubble {
    position: fixed; left: 30px; bottom: var(--kmdc-bubble-bottom, 30px); z-index: 2147483000;
    width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--kmdc-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(1, 36, 108, .35);
    transition: transform .15s ease, background .15s ease;
}
.kmdc-bubble:hover { background: var(--kmdc-navy); transform: translateY(-2px); }
.kmdc-bubble:focus-visible { outline: 3px solid #facc15; outline-offset: 3px; }
.kmdc-bubble svg { width: 26px; height: 26px; }

/* Panel: opens just above the bubble, which stays visible as the open/close toggle */
.kmdc-panel {
    position: fixed; left: 30px; bottom: calc(var(--kmdc-bubble-bottom, 30px) + 72px); z-index: 2147483001;
    width: 340px; height: min(520px, calc(100dvh - var(--kmdc-bubble-bottom, 30px) - 92px));
    display: none; flex-direction: column;
    background: var(--kmdc-bg); border-radius: 16px; overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
}
.kmdc-open .kmdc-panel { display: flex; animation: kmdc-pop .18s ease-out; }
@keyframes kmdc-pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .kmdc-open .kmdc-panel { animation: none; } }

.kmdc-header {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 10px 10px 14px; background: var(--kmdc-primary); color: #fff;
}
.kmdc-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    background: #fff; color: var(--kmdc-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 10.5px; letter-spacing: .2px;
}
.kmdc-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kmdc-title small { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 400; opacity: .85; margin-top: 2px; }
.kmdc-title small::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
.kmdc-icon-btn {
    background: none; border: 0; color: #fff; cursor: pointer;
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; padding: 0;
    display: flex; align-items: center; justify-content: center; opacity: .9;
}
.kmdc-icon-btn:hover { background: rgba(255, 255, 255, .18); opacity: 1; }
.kmdc-icon-btn svg { width: 18px; height: 18px; }
.kmdc-icon-btn:focus-visible { outline: 2px solid #facc15; outline-offset: 2px; }

/* Thin scrollbars */
.kmdc-log, .kmdc-input { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.kmdc-log::-webkit-scrollbar, .kmdc-input::-webkit-scrollbar { width: 6px; }
.kmdc-log::-webkit-scrollbar-thumb, .kmdc-input::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.kmdc-log::-webkit-scrollbar-button, .kmdc-input::-webkit-scrollbar-button { display: none; }

/* Messages */
.kmdc-log {
    flex: 1; overflow-y: auto; overscroll-behavior: contain;
    padding: 14px; display: flex; flex-direction: column; gap: 10px;
    background: #fafbfd;
}
.kmdc-msg {
    max-width: 86%; padding: 9px 13px; border-radius: 14px;
    font-size: 13px; line-height: 1.5;
    /* Long Burmese lines have no spaces: allow breaking anywhere so nothing overflows at 375px. */
    overflow-wrap: anywhere; word-break: break-word; white-space: normal;
}
.kmdc-msg.kmdc-user { align-self: flex-end; background: var(--kmdc-user); color: #fff; border-bottom-right-radius: 4px; }
.kmdc-msg.kmdc-bot { align-self: flex-start; background: var(--kmdc-bot); color: var(--kmdc-text); border-bottom-left-radius: 4px; }
.kmdc-msg.kmdc-error { background: #fef2f2; color: #991b1b; }
.kmdc-msg p { margin: 0; }
.kmdc-msg p + p { margin-top: 6px; }
.kmdc-msg ul { margin: 4px 0; padding-left: 18px; }
.kmdc-msg li { margin: 2px 0; }
.kmdc-msg strong { font-weight: 700; }

/* Burmese text: own font, larger size and taller lines (stacked characters need room). */
#kmd-chatbot [lang="my"] {
    font-family: var(--kmdc-font-my);
    font-size: 13px;
    line-height: 1.75;
}
.kmdc-msg [lang="en"] { font-size: 13px; line-height: 1.5; }

.kmdc-debug { font-size: 10.5px; color: var(--kmdc-muted); margin-top: -4px; align-self: flex-start; padding-left: 4px; }

/* Typing indicator */
.kmdc-typing { align-self: flex-start; background: var(--kmdc-bot); border-radius: 14px; padding: 12px 14px; display: flex; gap: 4px; }
.kmdc-typing i { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; display: block; animation: kmdc-blink 1.2s infinite ease-in-out; }
.kmdc-typing i:nth-child(2) { animation-delay: .15s; }
.kmdc-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes kmdc-blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .kmdc-typing i { animation: none; opacity: .6; } }

/* Input */
.kmdc-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--kmdc-border); background: var(--kmdc-bg); }
.kmdc-input {
    flex: 1; min-width: 0; resize: none; max-height: 120px; min-height: 42px; overflow-y: hidden;
    padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 12px;
    font-family: var(--kmdc-font); font-size: 14px;
    line-height: 1.5; color: var(--kmdc-text); background: #fff;
}
.kmdc-input:focus { outline: none; border-color: var(--kmdc-primary); box-shadow: 0 0 0 3px rgba(0, 74, 173, .15); }
.kmdc-input::placeholder { color: #9ca3af; font-family: var(--kmdc-font); font-size: 13px; }
.kmdc-send {
    width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 12px; cursor: pointer;
    background: var(--kmdc-primary); color: #fff; display: flex; align-items: center; justify-content: center;
}
.kmdc-send:hover:not(:disabled) { background: var(--kmdc-navy); }
.kmdc-send:disabled { background: #9ca3af; cursor: not-allowed; }
.kmdc-send:focus-visible { outline: 3px solid #facc15; outline-offset: 2px; }
.kmdc-send svg { width: 20px; height: 20px; }
.kmdc-counter { font-size: 11px; color: var(--kmdc-muted); text-align: right; padding: 0 12px 6px; background: var(--kmdc-bg); display: none; }
.kmdc-counter.kmdc-show { display: block; }

.kmdc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Small screens: full-screen chat */
@media (max-width: 480px) {
    /* Full screen; the header's ✕ closes it (the panel covers the bubble here). */
    .kmdc-panel { left: 0; bottom: 0; width: 100vw; height: 100dvh; border-radius: 0; z-index: 2147483002; }
    .kmdc-bubble { left: 30px; bottom: var(--kmdc-bubble-bottom, 30px); } /* same margins as the back-to-top button */
    .kmdc-msg { max-width: 90%; }
    .kmdc-input { font-size: 16px; } /* below 16px, iOS zooms the page when the box is focused */
}
