#dc-chat-root,
#dc-chat-root * {
    box-sizing: border-box;
}

/* Design tokens: Nexora Chat Design System */
#dc-chat-root {
    position: relative;
    z-index: 2147483000;
    --nexora-background: #ffffff;
    --nexora-text: #1e293b;
    --nexora-secondary: #64748b;
    --nexora-primary: #2563eb;
    --nexora-primary-hover: #1d4ed8;
    --nexora-bot-bubble: #f0f4f9;
    --nexora-border: #e2e8f0;
    --nexora-separator: #eef2f7;
    --nexora-success: #8bc34a;
    isolation: isolate;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.4;
}

#dc-chat-root button,
#dc-chat-root input {
    font: inherit;
    letter-spacing: normal;
    text-transform: none;
}

#dc-chat-root button {
    -webkit-appearance: none;
    appearance: none;
}

/* Component: external launcher */
.nexora-chat-launcher,
.dc-chat-trigger {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 999998;
    display: flex !important;
    align-items: center !important;
    justify-content: center;
    gap: 11px;
    width: 246px !important;
    min-width: 246px !important;
    height: 60px !important;
    min-height: 60px !important;
    max-height: 60px !important;
    margin: 0 !important;
    padding: 0 20px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: var(--nexora-primary) !important;
    color: #ffffff !important;
    box-shadow: 0 12px 28px rgba(37, 99, 235, .22) !important;
    cursor: pointer;
    font-size: 16px !important;
    font-weight: 600;
    line-height: 1 !important;
    text-align: center !important;
    transition: transform .2s ease, background-color .2s ease, opacity .2s ease;
}

.nexora-chat-launcher:hover,
.nexora-chat-launcher:focus-visible,
.dc-chat-trigger:hover,
.dc-chat-trigger:focus-visible {
    background: var(--nexora-primary-hover) !important;
    color: #ffffff !important;
    transform: translateY(-2px);
}

.nexora-chat-launcher.is-hidden,
.dc-chat-trigger.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(.8);
}

.nexora-chat-launcher svg,
.dc-chat-trigger svg {
    display: block !important;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    margin: 0 !important;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
}

.nexora-chat-launcher > span,
.dc-chat-trigger > span {
    display: block !important;
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    white-space: nowrap;
}

/* Component: widget shell */
.nexora-chat-shell,
.dc-chat-widget {
    position: fixed;
    right: 22px;
    bottom: 94px;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    width: min(410px, calc(100vw - 44px));
    height: min(650px, calc(100vh - 124px));
    min-height: 0;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    background: var(--nexora-background);
    box-shadow: 0 22px 60px rgba(15, 23, 42, .16);
    opacity: 0;
    pointer-events: none;
    transform: translateY(18px) scale(.98);
    transition: opacity .2s ease, transform .2s ease;
}

.nexora-chat-shell.is-open,
.dc-chat-widget.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Component: header and brand */
.nexora-chat-header,
.dc-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    min-height: 72px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--nexora-border);
    background: var(--nexora-background);
    color: var(--nexora-text);
}

.nexora-chat-header-info,
.dc-chat-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1 1 auto;
    gap: 14px;
}

.nexora-chat-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--nexora-primary);
    color: #ffffff;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -.04em;
}

/* DatoCiencia uses its own atom-and-brain mark while keeping the common header scale. */
.dc-chat-brand-mark {
    display: grid;
    flex: 0 0 58px;
    width: 58px;
    height: 48px;
    place-items: center;
    border-radius: 0;
    background: transparent;
}

.dc-chat-logo {
    display: block;
    width: 58px;
    height: 48px;
    overflow: visible;
}

.nexora-chat-header-text {
    min-width: 0;
    overflow: hidden;
}

.nexora-chat-title,
.dc-chat-brand strong {
    display: block;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--nexora-text);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nexora-chat-subtitle,
.dc-chat-brand span {
    display: block;
    margin: 4px 0 0;
    color: var(--nexora-secondary);
    font-size: 13.6px;
    font-weight: 400;
    line-height: 1.2;
    white-space: nowrap;
}

.nexora-chat-subtitle i,
.dc-chat-brand span i {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 5px;
    border-radius: 50%;
    background: var(--nexora-success);
    vertical-align: 1px;
}

/* Component: close action */
.nexora-chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.nexora-chat-action,
.dc-chat-close {
    display: grid !important;
    flex: 0 0 36px;
    width: 36px !important;
    min-width: 36px !important;
    max-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    place-items: center;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    color: var(--nexora-secondary) !important;
    cursor: pointer;
    font-size: 22px !important;
    font-weight: 400 !important;
    line-height: 1 !important;
}

.nexora-chat-action:hover,
.nexora-chat-action:focus-visible,
.dc-chat-close:hover,
.dc-chat-close:focus-visible {
    background: #f8fafc !important;
    color: var(--nexora-text) !important;
}

/* Component: message list */
.nexora-chat-messages,
.dc-chat-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    background: var(--nexora-background);
    overflow-anchor: none;
    scrollbar-color: #cbd5e1 transparent;
    scrollbar-width: thin;
}

/* Component: message rows and adaptive bubbles */
.nexora-message,
.dc-chat-message {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
    max-width: 100%;
    margin: 0;
    animation: dc-chat-message-in .2s ease both;
}

.nexora-message--user,
.dc-chat-message--user {
    justify-content: flex-end;
}

.nexora-bubble,
.dc-chat-bubble {
    width: fit-content;
    max-width: 75%;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 20px;
    background: var(--nexora-bot-bubble);
    color: var(--nexora-text);
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.nexora-message--bot .nexora-bubble,
.dc-chat-message--bot .dc-chat-bubble {
    border-color: var(--nexora-border);
    border-bottom-left-radius: 4px;
}

.nexora-message--user .nexora-bubble,
.dc-chat-message--user .dc-chat-bubble {
    border-bottom-right-radius: 4px;
    background: var(--nexora-primary);
    color: #ffffff;
}

.nexora-bubble p,
.dc-chat-bubble p {
    margin: 0 0 8px;
}

.nexora-bubble p:last-child,
.dc-chat-bubble p:last-child {
    margin-bottom: 0;
}

/* Component: DatoCiencia source cards */
.dc-chat-source-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
    width: min(100%, 280px);
    margin: 10px 0 12px;
    padding: 10px 11px;
    border: 1px solid #bfdbfe;
    border-left: 3px solid var(--nexora-primary);
    border-radius: 12px;
    background: #ffffff;
}

.dc-chat-source-card strong {
    color: var(--nexora-text);
    font-size: 12px;
    line-height: 1.35;
}

.dc-chat-source-kicker {
    color: var(--nexora-secondary);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .07em;
    line-height: 1.2;
    text-transform: uppercase;
}

.dc-chat-source-link {
    display: inline-flex;
    align-items: center;
    margin-top: 5px;
    padding: 5px 9px;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: #eff6ff;
    color: var(--nexora-primary) !important;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none !important;
    transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

.dc-chat-source-link:hover,
.dc-chat-source-link:focus-visible {
    border-color: var(--nexora-primary);
    background: #dbeafe;
    color: var(--nexora-primary-hover) !important;
}

/* Component: typing state */
.nexora-message.is-typing .nexora-bubble,
.dc-chat-message.is-typing .dc-chat-bubble {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 62px;
    min-height: 36px;
    padding: 8px 10px;
}

.nexora-message.is-typing .nexora-bubble span,
.dc-chat-message.is-typing .dc-chat-bubble span {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--nexora-primary);
    animation: dc-chat-typing 1.2s ease-in-out infinite;
}

.nexora-message.is-typing .nexora-bubble span:nth-child(2),
.dc-chat-message.is-typing .dc-chat-bubble span:nth-child(2) {
    animation-delay: .16s;
}

.nexora-message.is-typing .nexora-bubble span:nth-child(3),
.dc-chat-message.is-typing .dc-chat-bubble span:nth-child(3) {
    animation-delay: .32s;
}

/* Component: input area */
.nexora-chat-input-area,
.dc-chat-form {
    flex: 0 0 auto;
    padding: 12px 15px;
    border-top: 1px solid var(--nexora-separator);
    background: var(--nexora-background);
}

.dc-chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 0;
    border: 0;
    background: transparent;
}

.dc-chat-input-wrap:focus-within {
    border: 0;
    box-shadow: none;
}

.nexora-chat-input,
#dc-chat-input {
    min-width: 0;
    min-height: 48px;
    flex: 1 1 auto;
    width: 100%;
    padding: 10px 16px !important;
    border: 1px solid var(--nexora-primary) !important;
    border-radius: 999px !important;
    outline: 0;
    background: var(--nexora-background) !important;
    color: var(--nexora-text);
    font-size: 14px;
    line-height: 1.4;
}

#dc-chat-input:focus {
    border-color: var(--nexora-primary) !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.nexora-chat-input::placeholder,
#dc-chat-input::placeholder {
    color: #64748b;
    opacity: 1;
}

/* Component: send button */
.nexora-chat-send,
.dc-chat-send {
    display: grid !important;
    place-items: center;
    flex: 0 0 48px;
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    height: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: var(--nexora-primary) !important;
    color: #ffffff !important;
    cursor: pointer;
    line-height: 1 !important;
    transition: background-color .2s ease, transform .2s ease, opacity .2s ease;
}

.nexora-chat-send:hover,
.nexora-chat-send:focus-visible,
.dc-chat-send:hover,
.dc-chat-send:focus-visible {
    background: var(--nexora-primary-hover) !important;
    color: #ffffff !important;
    transform: translateY(-1px);
}

.nexora-chat-send:disabled,
.dc-chat-send:disabled {
    cursor: wait;
    opacity: .65;
}

.nexora-chat-send svg,
.dc-chat-send svg {
    width: 19px;
    height: 19px;
}

/* Component: Synaptix branding footer */
.nexora-chat-branding,
.aechat-branding-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 7px;
    flex: 0 0 auto;
    min-height: 52px;
    padding: 12px 18px;
    border-top: 1px solid var(--nexora-border);
    background: var(--nexora-background);
    color: #334155;
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
}

.nexora-chat-branding a,
.aechat-branding-footer a {
    color: var(--nexora-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.nexora-chat-branding a:hover,
.nexora-chat-branding a:focus-visible,
.aechat-branding-footer a:hover,
.aechat-branding-footer a:focus-visible {
    color: var(--nexora-primary-hover);
}

.aechat-branding-footer-icon,
.aechat-branding-footer-external {
    display: block;
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    color: var(--nexora-secondary);
}

.aechat-branding-footer-external {
    width: 12px;
    height: 12px;
    margin-left: -2px;
}

.screen-reader-text {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes dc-chat-message-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes dc-chat-typing {
    0%, 60%, 100% { opacity: .35; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

@media (max-width: 640px) {
    .nexora-chat-shell,
    .dc-chat-widget {
        top: 10px;
        right: 10px;
        bottom: 10px;
        left: 10px;
        width: auto;
        height: calc(100vh - 20px);
        height: calc(100dvh - 20px);
        border-radius: 20px;
    }

    .nexora-chat-launcher,
    .dc-chat-trigger {
        right: 16px;
        bottom: 16px;
    }
}

@media (max-width: 480px) {
    .nexora-chat-launcher,
    .dc-chat-trigger {
        width: 56px !important;
        min-width: 56px !important;
        height: 56px !important;
        min-height: 56px !important;
        max-height: 56px !important;
        padding: 0 !important;
    }

    .nexora-chat-launcher > span,
    .dc-chat-trigger > span {
        display: none !important;
    }

    .nexora-chat-header,
    .dc-chat-header {
        padding-inline: 12px;
    }

    .nexora-chat-header-info,
    .dc-chat-brand {
        gap: 10px;
    }

    .dc-chat-brand-mark {
        flex-basis: 52px;
        width: 52px;
        height: 44px;
    }

    .dc-chat-logo {
        width: 52px;
        height: 44px;
    }

    .nexora-chat-messages,
    .dc-chat-messages {
        padding: 16px 12px;
    }

    .nexora-chat-input-area,
    .dc-chat-form {
        padding-inline: 12px;
    }

    .nexora-chat-branding,
    .aechat-branding-footer {
        padding-inline: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nexora-chat-launcher,
    .dc-chat-trigger,
    .nexora-chat-shell,
    .dc-chat-widget,
    .nexora-message,
    .dc-chat-message,
    .nexora-chat-send,
    .dc-chat-send {
        transition: none;
        animation: none;
    }
}
