/* ============================================================
   DigiDr Chatbot Widget
   ============================================================ */

@property --chatbot-border-angle {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

/* ── Floating Action Button ── */
.chatbot-fab-wrap {
    position: fixed;
    bottom: 40px;
    right: 28px;
    z-index: 9999;
}

.chatbot-fab {
    width: auto;
    min-width: 94px;
    height: 46px;
    padding: 7px 14px 7px 9px;
    box-sizing: border-box;
    border-radius: 999px;
    background:
        linear-gradient(#ffffff, #ffffff) padding-box,
        conic-gradient(
            from var(--chatbot-border-angle),
            #0E65D7 0deg,
            #22C7E8 120deg,
            #FF8A00 240deg,
            #0E65D7 360deg
        ) border-box;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    box-shadow: 0 6px 24px rgba(14, 101, 215, 0.18), 0 2px 8px rgba(0, 0, 0, 0.10);
    transition:
        transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.25s ease,
        opacity 0.22s ease,
        visibility 0.22s ease;
    animation: chatbot-border-spin 3s linear infinite;
    position: absolute;
    bottom: 0;
    right: 0;
    overflow: visible;
    isolation: isolate;
}

.chatbot-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 32px rgba(14, 101, 215, 0.24), 0 4px 12px rgba(0, 0, 0, 0.12);
}

.chatbot-fab:active {
    transform: scale(0.96);
}

.chatbot-fab img {
    width: 30px;
    height: 30px;
    object-fit: contain;
    border-radius: 50%;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.chatbot-fab-text {
    color: #0E65D7;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.01em;
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.chatbot-fab-wrap.is-open .chatbot-fab {
    display: none;
}

@keyframes chatbot-border-spin {
    to { --chatbot-border-angle: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-fab {
        animation: none;
    }
}

/* Hide FAB on mobile while index hero is in view (see chatbot.js) */
@media (max-width: 768px) {
    .chatbot-fab-wrap.chatbot-fab-wrap--hero-hidden:not(.is-open) .chatbot-fab {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(20px) scale(0.92);
    }
}

@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
    .chatbot-fab-wrap .chatbot-fab {
        transition: opacity 0.28s ease, visibility 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
            box-shadow 0.25s ease;
    }
}

/* ── Notification Badge ── */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    z-index: 2;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FF4757;
    border: 2px solid #fff;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.chatbot-fab-wrap.is-open .chatbot-badge {
    display: none;
}

/* Mobile backdrop (blur when chat is open) */
.chatbot-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .chatbot-backdrop {
        position: fixed;
        inset: 0;
        z-index: 0;
        background: rgba(15, 23, 42, 0.35);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
    }

    .chatbot-fab-wrap.is-open .chatbot-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    .chatbot-backdrop {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(15, 23, 42, 0.5);
    }
}

/* ── Chat Window ── */
.chatbot-window {
    position: relative;
    z-index: 1;
    width: 400px;
    max-width: calc(100vw - 24px);
    max-height: min(620px, calc(100dvh - 110px));
    height: min(580px, calc(100dvh - 110px));
    background: #ffffff;
    border-radius: 24px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 24px 48px -12px rgba(14, 101, 215, 0.15),
        0 12px 24px -8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: chatbot-open 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
    border: none;
    isolation: isolate;
}

@keyframes chatbot-open {
    from { opacity: 0; transform: scale(0.92) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.chatbot-window.is-closing {
    animation: chatbot-close 0.2s cubic-bezier(0.4, 0, 1, 1) both;
}

@keyframes chatbot-close {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to   { opacity: 0; transform: scale(0.96) translateY(8px); }
}

/* Fallback for browsers without dvh */
@supports not (height: 1dvh) {
    .chatbot-window {
        max-height: min(600px, calc(100vh - 110px));
        height: min(560px, calc(100vh - 110px));
    }
}

/* ── Header ── */
.chatbot-header {
    background: #ffffff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.chatbot-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: var(--gradient-blue-orange, linear-gradient(90deg, #346BFA 0%, #D0901A 100%));
    opacity: 0.9;
}

.chatbot-header-avatar {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid rgba(14, 101, 215, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(14, 101, 215, 0.08);
}

.chatbot-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.chatbot-header-name {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

.chatbot-header-close {
    margin-left: auto;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    color: #374151;
    transition: background 0.15s ease, color 0.15s ease;
}

.chatbot-header-close:hover {
    background: rgba(14, 101, 215, 0.1);
    color: #0E65D7;
}

.chatbot-header-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(14, 101, 215, 0.25);
}

.chatbot-header-close .material-symbols-outlined {
    font-size: 22px;
}

/* ── Suggested Quick Replies ── */
.chatbot-suggestions {
    padding: 12px 16px 0;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    background: var(--background-primary, #F6F4FF);
    border-top: 1px solid rgba(14, 101, 215, 0.1);
}

.chatbot-suggestions::-webkit-scrollbar { display: none; }

.chatbot-suggestion-chip {
    white-space: nowrap;
    padding: 8px 14px;
    border-radius: 9999px;
    border: 1px solid rgba(14, 101, 215, 0.22);
    background: #ffffff;
    color: #0E65D7;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    font-family: var(--font-family-primary, 'DM Sans', sans-serif);
    margin-bottom: 12px;
    flex-shrink: 0;
}

.chatbot-suggestion-chip:hover {
    background: #0E65D7;
    color: #ffffff;
    border-color: #0E65D7;
}

/* ── Messages Area ── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background-color: var(--background-primary, #F6F4FF);
    background-image: radial-gradient(rgba(14, 101, 215, 0.12) 1px, transparent 1px);
    background-size: 14px 14px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(14, 101, 215, 0.20);
    border-radius: 4px;
}

/* ── Message Bubble ── */
.chatbot-msg {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 90%;
    animation: chatbot-msg-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes chatbot-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chatbot-msg.bot {
    align-self: flex-start;
}

.chatbot-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chatbot-msg-avatar {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid rgba(14, 101, 215, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.chatbot-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chatbot-msg-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.5;
    font-family: var(--font-family-primary, 'DM Sans', sans-serif);
    word-break: break-word;
    letter-spacing: -0.01em;
}

.chatbot-msg.bot .chatbot-msg-bubble {
    background: #ffffff;
    color: #1f2937;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.chatbot-msg.user .chatbot-msg-bubble {
    background: #0E65D7;
    color: #ffffff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(14, 101, 215, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.chatbot-msg-time {
    font-size: 10.5px;
    color: #9ca3af;
    margin-top: 5px;
    text-align: right;
    padding: 0 2px;
    font-weight: 500;
}

.chatbot-msg.bot .chatbot-msg-time {
    text-align: left;
    /* padding-left: 46px; */
}

/* ── Typing Indicator ── */
.chatbot-typing {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    align-self: flex-start;
}

.chatbot-typing-dots {
    background: #ffffff;
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    border: none;
}

.chatbot-typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: chatbot-bounce 1.2s ease-in-out infinite;
}

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

@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
    40%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Divider ── */
.chatbot-divider {
    align-self: center;
    font-size: 11px;
    color: #6b7280;
    font-weight: 500;
    margin: 2px 0 6px;
    flex-shrink: 0;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 9999px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ── Input Area ── */
.chatbot-input-area {
    padding: 4px 16px 14px;
    background: var(--background-primary, #F6F4FF);
    border-top: none;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.chatbot-input-wrap {
    flex: 1;
    border: 2px solid transparent;
    border-radius: 16px;
    display: flex;
    align-items: flex-end;
    padding: 10px 16px;
    background:
        linear-gradient(#ffffff, #ffffff) padding-box,
        var(--gradient-blue-orange) border-box;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 48px;
}

.chatbot-input-wrap:focus-within {
    background:
        linear-gradient(#ffffff, #ffffff) padding-box,
        var(--gradient-blue-orange) border-box;
    border-color: transparent;
    box-shadow: 0 0 0 3px rgba(14, 101, 215, 0.1);
}

.chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: #111827;
    font-family: var(--font-family-primary, 'DM Sans', sans-serif);
    resize: none;
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 0;
    min-height: 22px;
}

.chatbot-input::placeholder {
    color: #9ca3af;
}

.chatbot-input::-webkit-scrollbar { display: none; }

.chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: #0E65D7;
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.chatbot-send-btn:hover:not(:disabled) {
    background: #0a52b5;
    transform: scale(1.04);
}

.chatbot-send-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.chatbot-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: #d1d5db;
}

.chatbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

/* ── Footer ── */
.chatbot-footer {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 0 0 12px;
    background: #ffffff;
    flex-shrink: 0;
    letter-spacing: 0.01em;
}

.chatbot-footer a {
    color: #0E65D7;
    text-decoration: none;
    font-weight: 500;
}

.chatbot-footer a:hover {
    text-decoration: underline;
}

/* Desktop: nudge FAB slightly left */
@media (min-width: 769px) {
    .chatbot-fab-wrap {
        right: 44px;
    }
}

/* ── Mobile Responsive ── */
@media (max-width: 480px) {
    .chatbot-fab-wrap {
        left: 16px;
        right: 16px;
        bottom: 28px;
    }

    .chatbot-fab {
        min-width: 88px;
        height: 44px;
        padding: 7px 13px 7px 9px;
    }

    .chatbot-fab img {
        width: 28px;
        height: 28px;
    }

    .chatbot-fab-text {
        font-size: 13px;
    }

    .chatbot-window {
        width: 100%;
        max-width: 100%;
        height: calc(100dvh - 96px);
        max-height: calc(100dvh - 96px);
        border-radius: 20px 20px 8px 8px;
        transform-origin: bottom center;
    }

    /* Fallback for browsers without dvh */
    @supports not (height: 1dvh) {
        .chatbot-window {
            height: calc(100vh - 96px);
            max-height: calc(100vh - 96px);
        }
    }
}

/* Landscape on phones: shorten height to avoid overflow */
@media (max-height: 500px) and (max-width: 480px) {
    .chatbot-window {
        height: calc(100dvh - 84px);
        max-height: calc(100dvh - 84px);
    }

    @supports not (height: 1dvh) {
        .chatbot-window {
            height: calc(100vh - 84px);
            max-height: calc(100vh - 84px);
        }
    }

    .chatbot-header {
        padding: 10px 16px;
    }

    .chatbot-header-avatar {
        width: 40px;
        height: 40px;
    }
}
