/**
 * FDA chatbot reskin — overrides the generic dify-chatbot styles.
 *
 * Scoped under #dify-widget-{state_key} and its sibling launcher/close buttons.
 * No font-family is set on purpose: the widget inherits the host site's stack.
 */

:root {
    --fda-brand: hsl(234 89% 60%);
    --fda-brand-hover: hsl(234 89% 54%);
    --fda-brand-fg: #fff;
    --fda-brand-soft: hsl(234 100% 97%);
    --fda-brand-navy: hsl(230 45% 18%);
    --fda-fg: hsl(234 60% 14%);
    --fda-muted: hsl(220 20% 96%);
    --fda-muted-fg: hsl(234 15% 40%);
    --fda-border: hsl(220 20% 90%);
    --fda-card: #fff;
    --fda-shadow-soft: 0 10px 40px -15px hsl(234 89% 60% / .25);
    --fda-shadow-card: 0 4px 20px -8px hsl(234 40% 30% / .12);
    --fda-radius-lg: 24px;
    --fda-radius-md: 16px;
    --fda-radius-sm: 3px;
}

/* -------------------------------------------------------------------------
 * Launcher (closed state)
 * ------------------------------------------------------------------------- */

.dify-open-button[aria-expanded="false"]{
    box-shadow: none;
}

.dify-open-button.fda-launcher {
    position: fixed;
    right: 45px;
    bottom: 85px;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: transform .2s ease;
}

.dify-open-button.fda-launcher:hover {
    transform: scale(1.04);
}

.dify-open-button.fda-launcher:active {
    transform: scale(.97);
}

.fda-launcher__bubble {
    position: relative;
    margin-right: 16px;
    padding: 8px 16px;
    background: #fff;
    color: var(--fda-fg);
    border: 1px solid var(--fda-border);
    border-radius: var(--fda-radius-md);
    border-bottom-right-radius: 4px;
    box-shadow: var(--fda-shadow-card);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.fda-launcher__bubble::after {
    content: "";
    position: absolute;
    right: 16px;
    bottom: -6px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 1px solid var(--fda-border);
    border-bottom: 1px solid var(--fda-border);
    transform: rotate(45deg);
}

.fda-launcher__avatar {
    display: block;
    width: auto;
    height: 112px;
    filter: drop-shadow(0 12px 24px rgb(0 0 0 / .25));
}

@media (min-width: 768px) {
    .fda-launcher__avatar {
        height: 128px;
    }
}

/* Hide the original .bubble-icon SVG that ships with the vanilla widget. */
.dify-open-button.fda-launcher .bubble-icon,
.dify-open-button.fda-launcher .notification-badge {
    display: none !important;
}

/* -------------------------------------------------------------------------
 * Close button (visible only when dialog is open)
 * ------------------------------------------------------------------------- */

.dify-close-button.fda-close {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    background: var(--fda-brand);
    color: var(--fda-brand-fg);
    border: 0;
    border-radius: 999px;
    box-shadow: var(--fda-shadow-soft);
    cursor: pointer;
    transition: transform .2s ease;
}

.dify-close-button.fda-close:hover {
    background: var(--fda-brand-hover);
    transform: scale(1.04);
}

.dify-close-button.fda-close .bubble-icon svg {
    width: 20px;
    height: 20px;
}

/* -------------------------------------------------------------------------
 * Dialog (open state)
 * ------------------------------------------------------------------------- */

.dify-chatbot.fda-dialog {
    position: fixed;
    right: 24px;
    bottom: 88px;
    z-index: 9997;
    display: flex;
    flex-direction: column;
    width: 416px;
    max-width: calc(100vw - 48px);
    height: 512px;
    max-height: calc(100vh - 120px);
    overflow: hidden;
    background: var(--fda-card);
    border: 1px solid var(--fda-border);
    border-radius: var(--fda-radius-lg);
    box-shadow: var(--fda-shadow-soft);
    color: var(--fda-fg);
}

/* Hide structural pieces inherited from the generic widget that FDA doesn't use. */
.dify-chatbot.fda-dialog .resize-handle,
.dify-chatbot.fda-dialog .new-conversation-button,
.dify-chatbot.fda-dialog .minimize-button {
    display: none !important;
}

/* Header — partner logos + civic-exam badge. */
.dify-chatbot.fda-dialog .dify-widget-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid var(--fda-border);
}

.fda-header__logos {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fda-header__logo {
    display: block;
    width: auto;
}

.fda-header__logo--tef {
    height: 12px;
}

.fda-header__logo--dfp {
    height: 14px;
}

.fda-header__logo--rf {
    height: 36px;
}

.fda-header__divider {
    width: 1px;
    height: 12px;
    background: var(--fda-border);
}

.fda-header__divider--tall {
    height: 24px;
    margin: 0 4px;
}

.fda-header__badge {
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--fda-fg);
}

/* Hide the inherited dify-widget-title (kept in markup for a11y label). */
.dify-chatbot.fda-dialog .dify-widget-title {
    position: absolute;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    width: 1px;
    height: 1px;
}

/* Body — message stream. */
.dify-chatbot.fda-dialog .dify-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--fda-brand-soft);
}

.dify-chatbot.fda-dialog .dify-welcome-message,
.dify-chatbot.fda-dialog .message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
}

.dify-chatbot.fda-dialog .message.user-message {
    flex-direction: row-reverse;
}

.dify-chatbot.fda-dialog .message-avatar {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    object-fit: cover;
    background: transparent;
}

.dify-chatbot.fda-dialog .message-avatar.bot-avatar {
    width: 44px;
    height: 44px;
}

/* User avatar fallback: keep a discreet circle when the engine emits the
 * default emoji template (👤). */
.dify-chatbot.fda-dialog span.message-avatar.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--fda-brand);
    color: var(--fda-brand-fg);
    font-size: 18px;
}

.dify-chatbot.fda-dialog .message-body {
    max-width: 80%;
}

.dify-chatbot.fda-dialog .message-content {
    padding: 10px 16px;
    background: #fff;
    border: 1px solid var(--fda-border);
    border-radius: var(--fda-radius-md);
    border-bottom-left-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgb(0 0 0 / .04);
    white-space: pre-line;
}

.dify-chatbot.fda-dialog .message.user-message .message-content {
    background: var(--fda-brand);
    color: var(--fda-brand-fg);
    border-color: var(--fda-brand);
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: var(--fda-radius-md);
}

.dify-chatbot.fda-dialog .message.user-message .message-content a {
    color: inherit;
    text-decoration: underline;
}

/* Markdown helpers inside bot bubbles. */
.dify-chatbot.fda-dialog .markdown-body p {
    margin: 0 0 8px;
}

.dify-chatbot.fda-dialog .markdown-body p:last-child {
    margin-bottom: 0;
}

.dify-chatbot.fda-dialog .markdown-body a {
    color: var(--fda-brand);
}

.dify-chatbot.fda-dialog .markdown-body ul,
.dify-chatbot.fda-dialog .markdown-body ol {
    margin: 0 0 8px;
    padding-left: 20px;
}

.dify-chatbot.fda-dialog .markdown-body code {
    padding: 1px 4px;
    background: var(--fda-muted);
    border-radius: 4px;
    font-size: .9em;
}

/* Typing indicator (three dots). */
.dify-chatbot.fda-dialog .typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 6px 0;
}

.dify-chatbot.fda-dialog .typing-indicator > span {
    width: 6px;
    height: 6px;
    background: var(--fda-muted-fg);
    border-radius: 999px;
    animation: fda-typing 1.2s infinite ease-in-out;
}

.dify-chatbot.fda-dialog .typing-indicator > span:nth-child(2) {
    animation-delay: .15s;
}

.dify-chatbot.fda-dialog .typing-indicator > span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes fda-typing {
    0%, 80%, 100% {
        opacity: .3;
        transform: scale(.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Input zone. */
.dify-chatbot.fda-dialog .dify-widget-input {
    padding: 12px;
    background: var(--fda-card);
    border-top: 1px solid var(--fda-border);
}

.dify-chatbot.fda-dialog .dify-input-form .input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dify-chatbot.fda-dialog .message-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--fda-border);
    border-radius: var(--fda-radius-sm);
    font: inherit;
    font-size: 14px;
    color: var(--fda-fg);
    resize: none;
    line-height: 1.4;
}

.dify-chatbot.fda-dialog .message-input:focus {
    outline: 2px solid var(--fda-brand);
    outline-offset: 1px;
    border-color: var(--fda-brand);
}

.dify-chatbot.fda-dialog .send-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    transition: transform .15s ease;
}

.dify-chatbot.fda-dialog .send-button:hover:not([disabled]) {
    transform: scale(1.05);
}

.dify-chatbot.fda-dialog .send-button:active:not([disabled]) {
    transform: scale(.95);
}

.dify-chatbot.fda-dialog .send-button[disabled] {
    opacity: .5;
    cursor: not-allowed;
}

.dify-chatbot.fda-dialog .send-button .send-icon-paper {
    display: block;
    width: 40px;
    height: 40px;
}

/* Hide the default arrow/spinner SVG that ships with the engine. */
.dify-chatbot.fda-dialog .send-button .send-icon,
.dify-chatbot.fda-dialog .send-button .loading-spinner {
    display: none;
}

/* Suggestions panel below messages. */
.dify-chatbot.fda-dialog .suggestions-content {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.dify-chatbot.fda-dialog .suggestion-button {
    padding: 6px 12px;
    background: #fff;
    color: var(--fda-brand);
    border: 1px solid var(--fda-brand);
    border-radius: 999px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.dify-chatbot.fda-dialog .suggestion-button:hover {
    background: var(--fda-brand);
    color: var(--fda-brand-fg);
}

/* Feedback buttons (thumbs up/down) under bot messages. */
.dify-chatbot.fda-dialog .message-feedback {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.dify-chatbot.fda-dialog .feedback-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--fda-muted-fg);
    font-size: 14px;
    cursor: pointer;
    opacity: .6;
    transition: opacity .15s ease;
}

.dify-chatbot.fda-dialog .feedback-btn:hover,
.dify-chatbot.fda-dialog .feedback-btn.active {
    opacity: 1;
    color: var(--fda-brand);
}
