.patient-chatbot-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1054;
    background: transparent;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0s linear 0.28s;
}

.patient-chatbot-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0s;
}

.patient-chatbot-root {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 1055;
    pointer-events: none;
}

.patient-chatbot-teaser {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    width: max-content;
    max-width: min(320px, calc(100vw - 48px));
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    font-size: 0.88rem;
    font-weight: 500;
    color: #334155;
    line-height: 1.45;
    pointer-events: auto;
    cursor: pointer;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition:
        opacity 0.35s ease,
        transform 0.35s ease,
        visibility 0s;
    white-space: nowrap;
    box-sizing: border-box;
}

.patient-chatbot-teaser::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 23px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    transform: rotate(45deg);
    pointer-events: none;
}

.patient-chatbot-teaser.is-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    pointer-events: none;
    transition:
        opacity 0.35s ease,
        transform 0.35s ease,
        visibility 0s linear 0.35s;
}

.patient-chatbot-fab {
    width: 58px;
    height: 58px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a6b3c 0%, #15603a 100%);
    color: #fff;
    box-shadow: 0 8px 24px rgba(26, 107, 60, 0.35);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition:
        transform 0.28s cubic-bezier(0.34, 1.2, 0.64, 1),
        box-shadow 0.2s ease,
        background 0.2s ease;
    flex-shrink: 0;
}

.patient-chatbot-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(26, 107, 60, 0.42);
}

.patient-chatbot-fab:focus,
.patient-chatbot-fab:focus-visible,
.patient-chatbot-fab:active {
    outline: none;
    box-shadow: 0 8px 24px rgba(26, 107, 60, 0.35);
    -webkit-tap-highlight-color: transparent;
}

.patient-chatbot-fab.is-active {
    box-shadow: 0 6px 18px rgba(26, 107, 60, 0.28);
}

.patient-chatbot-fab i {
    font-size: 1.45rem;
    transition: transform 0.28s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.patient-chatbot-popup {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    width: min(380px, calc(100vw - 32px));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(14px) scale(0.94);
    transform-origin: bottom right;
    transition:
        opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1),
        visibility 0s linear 0.32s;
}

.patient-chatbot-popup.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition:
        opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1),
        visibility 0s;
}

.patient-chatbot-popup-arrow {
    position: absolute;
    bottom: -6px;
    right: 23px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    transform: rotate(45deg);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease 0.08s;
}

.patient-chatbot-popup.is-open .patient-chatbot-popup-arrow {
    opacity: 1;
}

.patient-chatbot-popup-panel {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: min(72vh, 560px);
    max-height: min(72vh, 560px);
    border: 1px solid #e2e8f0;
}

.patient-chatbot-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
    color: #1a1a2e;
    font-family: 'Inter', sans-serif;
    flex-shrink: 0;
}

.patient-chatbot-popup-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #1a1a2e;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.patient-chatbot-popup-header h2 i {
    color: #1a6b3c;
}

.patient-chatbot-popup-close {
    font-size: 1.5rem;
    font-weight: 700;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
    border: none;
    background: none;
    padding: 0;
}

.patient-chatbot-popup-close:hover {
    color: #dc2626;
}

.patient-chatbot-popup-close:focus,
.patient-chatbot-popup-close:focus-visible,
.patient-chatbot-popup-close:active {
    outline: none;
    box-shadow: none;
    border: none;
    -webkit-tap-highlight-color: transparent;
}

.patient-chatbot-popup-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px 18px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

.patient-chatbot-popup-footer {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
}

.patient-chatbot-popup-loading,
.patient-chatbot-popup-empty {
    text-align: center;
    color: #64748b;
    font-size: 0.86rem;
    padding: 28px 12px;
}

.patient-chatbot-bubble-row {
    display: flex;
    margin-bottom: 10px;
}

.patient-chatbot-bubble-row.is-user {
    justify-content: flex-end;
}

.patient-chatbot-bubble-row.is-bot,
.patient-chatbot-bubble-row.is-system {
    justify-content: flex-start;
}

.patient-chatbot-bubble {
    max-width: 86%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 0.84rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.patient-chatbot-bubble.is-user {
    background: #1a6b3c;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.patient-chatbot-bubble.is-bot {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.patient-chatbot-bubble.is-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    min-width: 54px;
}

.patient-chatbot-bubble.is-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    opacity: 0.35;
    animation: patientChatbotTypingDot 1.15s infinite ease-in-out;
}

.patient-chatbot-bubble.is-typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.patient-chatbot-bubble.is-typing span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes patientChatbotTypingDot {
    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.35;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.patient-chatbot-bubble.is-system {
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
    border-radius: 999px;
    font-size: 0.76rem;
    padding: 8px 12px;
}

.patient-chatbot-popup-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px 0;
    background: #fff;
}

.patient-chatbot-quick {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.patient-chatbot-quick:hover {
    background: #f1f5f9;
}

.patient-chatbot-quick:focus,
.patient-chatbot-quick:focus-visible,
.patient-chatbot-quick:active {
    outline: none;
    box-shadow: none;
    border-color: #e2e8f0;
}

.patient-chatbot-popup-compose {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
}

.patient-chatbot-popup-compose input {
    flex: 1;
    box-sizing: border-box;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 0.82rem;
    line-height: 38px;
    outline: none;
    background: #f8fafc;
    -webkit-appearance: none;
    appearance: none;
}

.patient-chatbot-popup-compose input:focus {
    border-color: #1a6b3c;
    background: #fff;
   
}

.patient-chatbot-popup-compose button {
    box-sizing: border-box;
    width: 40px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    border: none;
    border-radius: 12px;
    background: #1a6b3c;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.patient-chatbot-popup-compose button:focus,
.patient-chatbot-popup-compose button:focus-visible,
.patient-chatbot-popup-compose button:active {
    outline: none;
    box-shadow: none;
}

.patient-chatbot-popup-compose button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.patient-chatbot-popup-foot {
    padding: 0 14px 12px;
    font-size: 0.72rem;
    color: #64748b;
    background: #fff;
}

@media (prefers-reduced-motion: reduce) {
    .patient-chatbot-fab,
    .patient-chatbot-fab i,
    .patient-chatbot-popup,
    .patient-chatbot-popup-arrow,
    .patient-chatbot-backdrop,
    .patient-chatbot-teaser {
        transition: none;
    }

    .patient-chatbot-bubble.is-typing span {
        animation: none;
        opacity: 0.6;
    }
}

@media (max-width: 991.98px) {
    .patient-chatbot-root {
        right: 16px;
        bottom: 88px;
    }

    .patient-chatbot-fab {
        width: 54px;
        height: 54px;
    }

    .patient-chatbot-popup-arrow {
        right: 21px;
    }

    .patient-chatbot-popup-header {
        padding: 1rem 1.25rem;
    }
}

@media (max-width: 767.98px) {
    .patient-chatbot-backdrop.is-open {
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    .patient-chatbot-root.is-chat-open {
        inset: 0;
        right: 0;
        left: 0;
        bottom: 0;
        top: 0;
        width: auto;
        height: auto;
        pointer-events: none;
    }

    .patient-chatbot-root.is-chat-open .patient-chatbot-fab,
    .patient-chatbot-root.is-chat-open .patient-chatbot-teaser {
        display: none;
    }

    .patient-chatbot-root.is-chat-open .patient-chatbot-popup {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--patient-chatbot-keyboard-offset, 0px);
        top: auto;
        width: 100%;
        max-width: none;
        transform: translateY(100%);
        transform-origin: bottom center;
    }

    .patient-chatbot-root.is-chat-open .patient-chatbot-popup.is-open {
        transform: translateY(0);
    }

    .patient-chatbot-root.is-chat-open .patient-chatbot-popup-arrow {
        display: none;
    }

    .patient-chatbot-root.is-chat-open .patient-chatbot-popup-panel {
        width: 100%;
        height: min(
            88dvh,
            calc(100dvh - env(safe-area-inset-top, 0px) - 12px)
        );
        max-height: min(
            88dvh,
            calc(100dvh - env(safe-area-inset-top, 0px) - 12px)
        );
        border-radius: 18px 18px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.18);
    }

    .patient-chatbot-popup-foot {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 767.98px) {
    .patient-chatbot-root:not(.is-chat-open) .patient-chatbot-popup {
        width: min(380px, calc(100vw - 32px));
    }

    .patient-chatbot-root:not(.is-chat-open) .patient-chatbot-popup-panel {
        height: min(72vh, 580px);
        max-height: min(72vh, 580px);
    }
}

/* Dark mode — loaded after light styles; widget CSS is included at end of body */
html[data-theme="dark"] .patient-chatbot-popup-panel {
    background: var(--dm-surface, #242428) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-arrow {
    background: var(--dm-surface, #242428) !important;
    border-right-color: var(--dm-border, #3a3a3f) !important;
    border-bottom-color: var(--dm-border, #3a3a3f) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-header {
    background: var(--dm-surface, #242428) !important;
    border-bottom-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-header h2 {
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-header h2 i {
    color: #4ade80 !important;
}

html[data-theme="dark"] .patient-chatbot-popup-close {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-close:hover {
    color: #f87171 !important;
}

html[data-theme="dark"] .patient-chatbot-popup-messages {
    background: var(--dm-bg, #1c1c1e) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-footer,
html[data-theme="dark"] .patient-chatbot-popup-quick,
html[data-theme="dark"] .patient-chatbot-popup-compose,
html[data-theme="dark"] .patient-chatbot-popup-foot {
    background: var(--dm-surface, #242428) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-footer {
    border-top-color: var(--dm-border, #3a3a3f) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-loading,
html[data-theme="dark"] .patient-chatbot-popup-empty {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-bubble.is-bot {
    background: var(--dm-surface-raised, #2c2c30) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .patient-chatbot-bubble.is-user {
    background: var(--dm-primary, #1a6b3c) !important;
    color: #fff !important;
}

html[data-theme="dark"] .patient-chatbot-bubble.is-system {
    background: rgba(234, 88, 12, 0.15) !important;
    border-color: rgba(251, 146, 60, 0.35) !important;
    color: #fdba74 !important;
}

html[data-theme="dark"] .patient-chatbot-bubble.is-typing span {
    background: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-quick {
    background: var(--dm-bg, #1c1c1e) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-quick:hover {
    background: var(--dm-primary-subtle, rgba(26, 107, 60, 0.18)) !important;
    border-color: var(--dm-primary, #1a6b3c) !important;
    color: #4ade80 !important;
}

html[data-theme="dark"] .patient-chatbot-quick:focus,
html[data-theme="dark"] .patient-chatbot-quick:focus-visible,
html[data-theme="dark"] .patient-chatbot-quick:active {
    border-color: var(--dm-border, #3a3a3f) !important;
    box-shadow: none !important;
    outline: none !important;
}

html[data-theme="dark"] .patient-chatbot-popup-compose input {
    background: var(--dm-bg, #1c1c1e) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-compose input::placeholder {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-compose input:focus {
    border-color: var(--dm-primary, #1a6b3c) !important;
    background: var(--dm-bg, #1c1c1e) !important;
    box-shadow: 0 0 0 3px rgba(26, 107, 60, 0.25) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-foot {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .patient-chatbot-popup-foot strong {
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .patient-chatbot-teaser {
    background: var(--dm-surface, #242428) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text, #f5f5f5) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
}

html[data-theme="dark"] .patient-chatbot-teaser::after {
    background: var(--dm-surface, #242428) !important;
    border-right-color: var(--dm-border, #3a3a3f) !important;
    border-bottom-color: var(--dm-border, #3a3a3f) !important;
}
