/* ═══════════════════════════════════════════════════════════════════════════
   Chat Widget — SimSD 2026 (estilo Intercom / Fin, tema escuro)
   Carregado em todas as páginas via header.php.
   O widget só fica visível após o consentimento de cookies (classe .consented).
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --chat-brand: #8c0a25;
    --chat-brand-2: #680218;
    --chat-panel: #1c1c20;
    --chat-panel-2: #232329;
    --chat-bot-bubble: #2c2c33;
    --chat-user-bubble: #7a0a20;
    --chat-text: #f3f3f5;
    --chat-muted: #9a9aa3;
    --chat-border: rgba(255, 255, 255, .08);
    --chat-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}

/* Oculto por padrão; revelado apenas após consentimento de cookies. */
.simsd-chat-root {
    display: none;
}

.simsd-chat-root.consented {
    display: block;
}

/* ───────── Launcher (botão flutuante) ───────── */
.simsd-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--chat-brand), var(--chat-brand-2));
    color: #fff;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483000;
    transition: transform .18s ease, box-shadow .18s ease;
}

.simsd-chat-launcher:hover {
    transform: scale(1.06);
}

.simsd-chat-launcher:focus-visible {
    outline: 3px solid rgba(140, 10, 37, .45);
    outline-offset: 3px;
}

.simsd-chat-launcher svg {
    width: 28px;
    height: 28px;
    transition: opacity .15s ease, transform .15s ease;
}

.simsd-chat-launcher .icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(.6);
}

.simsd-chat-root.open .simsd-chat-launcher .icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(.6);
}

.simsd-chat-root.open .simsd-chat-launcher .icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* ───────── Janela do chat ───────── */
.simsd-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 140px);
    background: var(--chat-panel);
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 2147483000;
    opacity: 0;
    transform: translateY(16px) scale(.98);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    font-family: 'Raleway', system-ui, -apple-system, sans-serif;
    color: var(--chat-text);
}

.simsd-chat-root.open .simsd-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ───────── Header ───────── */
.simsd-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    flex-shrink: 0;
    background: var(--chat-panel);
}

.simsd-chat-heading-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    flex: 1;
}

.simsd-chat-heading h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
}

.simsd-chat-heading p {
    margin: 2px 0 0;
    font-size: .8rem;
    color: var(--chat-muted);
}

.simsd-chat-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.simsd-chat-close,
.simsd-chat-reset {
    background: transparent;
    border: none;
    color: var(--chat-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background .15s ease, color .15s ease;
}

.simsd-chat-close svg,
.simsd-chat-reset svg {
    width: 20px;
    height: 20px;
}

.simsd-chat-close:hover,
.simsd-chat-reset:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

/* ───────── Lista de mensagens ───────── */
.simsd-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--chat-panel);
}

.simsd-chat-messages::-webkit-scrollbar {
    width: 8px;
}

.simsd-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .12);
    border-radius: 8px;
}

.simsd-chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: .95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.simsd-chat-msg.bot {
    align-self: flex-start;
    background: var(--chat-bot-bubble);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
}

.simsd-chat-msg.user {
    align-self: flex-end;
    background: var(--chat-user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.simsd-chat-msg a {
    color: #fff;
    text-decoration: underline;
}

.simsd-chat-msg.bot a {
    color: #ff9db0;
}

.simsd-chat-rich {
    --chat-flow-gap: 10px;
    --chat-flow-gap-tight: 8px;
    white-space: normal;
    line-height: 1.45;
}

.simsd-chat-rich :where(
    h3,
    h4,
    .chat-title,
    p,
    ul,
    ol,
    blockquote,
    pre,
    .chat-card,
    .chat-section,
    .chat-note,
    .chat-warning,
    .chat-alert,
    .chat-success,
    .chat-actions,
    .chat-chip-row,
    .chat-grid,
    .chat-divider
) {
    margin: 0;
}

.simsd-chat-rich > * + * {
    margin-top: var(--chat-flow-gap);
}

.simsd-chat-rich :where(div:not(.chat-actions):not(.chat-chip-row):not(.chat-grid), blockquote, .chat-quote) > * + * {
    margin-top: var(--chat-flow-gap-tight);
}

.simsd-chat-rich > :where(strong, em, span, small, code),
.simsd-chat-rich :where(div:not(.chat-actions):not(.chat-chip-row):not(.chat-grid), blockquote, .chat-quote) > :where(strong, em, span, small, code) {
    display: block;
}

.simsd-chat-rich h3,
.simsd-chat-rich h4,
.simsd-chat-rich .chat-title {
    color: #fff;
    font-size: .98rem;
    font-weight: 800;
    line-height: 1.25;
}

.simsd-chat-rich h4 {
    font-size: .9rem;
}

.simsd-chat-rich ul,
.simsd-chat-rich ol {
    padding-left: 18px;
}

.simsd-chat-rich li {
    margin: 0 0 6px;
}

.simsd-chat-rich code,
.simsd-chat-rich .chat-code {
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(255, 255, 255, .09);
    color: #fff;
    font-family: Consolas, Monaco, monospace;
    font-size: .85em;
}

.simsd-chat-rich pre {
    padding: 10px;
    overflow-x: auto;
    border-radius: 8px;
    background: rgba(0, 0, 0, .24);
}

.simsd-chat-rich pre code {
    padding: 0;
    background: transparent;
}

.simsd-chat-rich blockquote,
.simsd-chat-rich .chat-quote {
    padding: 8px 10px;
    border-left: 3px solid #ff9db0;
    border-radius: 0 8px 8px 0;
    background: rgba(255, 255, 255, .06);
    color: rgba(255, 255, 255, .9);
}

.simsd-chat-rich .chat-lead {
    color: #fff;
    font-weight: 650;
}

.simsd-chat-rich .chat-muted {
    color: var(--chat-muted);
}

.simsd-chat-rich .chat-small,
.simsd-chat-rich small {
    font-size: .78rem;
    color: var(--chat-muted);
}

.simsd-chat-rich .chat-kicker {
    display: block;
    color: #ff9db0;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.simsd-chat-rich .chat-card,
.simsd-chat-rich .chat-section {
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 10px;
    background: rgba(255, 255, 255, .045);
}

.simsd-chat-rich .chat-note,
.simsd-chat-rich .chat-warning,
.simsd-chat-rich .chat-alert,
.simsd-chat-rich .chat-success {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .1);
}

.simsd-chat-rich .chat-note {
    background: rgba(255, 255, 255, .055);
}

.simsd-chat-rich .chat-warning {
    background: rgba(255, 193, 7, .12);
    border-color: rgba(255, 193, 7, .28);
}

.simsd-chat-rich .chat-alert {
    background: rgba(227, 6, 19, .14);
    border-color: rgba(255, 157, 176, .3);
}

.simsd-chat-rich .chat-success {
    background: rgba(46, 160, 67, .14);
    border-color: rgba(86, 211, 100, .28);
}

.simsd-chat-rich .chat-highlight {
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(255, 157, 176, .16);
    color: #fff;
    font-weight: 700;
}

.simsd-chat-rich .chat-list {
    list-style: disc;
}

.simsd-chat-rich .chat-steps {
    list-style: decimal;
}

.simsd-chat-rich .chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.simsd-chat-rich a.chat-button,
.simsd-chat-rich a.chat-button-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: .82rem;
    font-weight: 800;
    line-height: 1.1;
    text-decoration: none;
}

.simsd-chat-rich a.chat-button {
    background: #ff9db0;
    color: #31010c;
}

.simsd-chat-rich a.chat-button-outline {
    border: 1px solid rgba(255, 157, 176, .55);
    color: #ffd4dc;
}

.simsd-chat-retry-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 7px 12px;
    border: 1px solid rgba(255, 157, 176, .55);
    border-radius: 8px;
    background: rgba(255, 157, 176, .14);
    color: #ffd4dc;
    font-family: inherit;
    font-size: .82rem;
    font-weight: 800;
    line-height: 1.1;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.simsd-chat-retry-button:hover:not(:disabled) {
    border-color: rgba(255, 157, 176, .75);
    background: rgba(255, 157, 176, .24);
    color: #fff;
}

.simsd-chat-retry-button:disabled {
    cursor: default;
    opacity: .65;
}

.simsd-chat-rich .chat-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.simsd-chat-rich .chat-chip,
.simsd-chat-rich .chat-pill,
.simsd-chat-rich .chat-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    color: rgba(255, 255, 255, .92);
    font-size: .76rem;
    font-weight: 750;
}

.simsd-chat-rich .chat-badge {
    border-radius: 6px;
    color: #ffd4dc;
}

.simsd-chat-rich .chat-grid {
    display: grid;
    gap: 8px;
}

.simsd-chat-rich .chat-divider {
    height: 1px;
    background: rgba(255, 255, 255, .1);
}

/* linha de metadados sob a saudação (ex.: "Assistente SimSD • Agora") */
.simsd-chat-meta {
    align-self: flex-start;
    font-size: .7rem;
    color: var(--chat-muted);
    margin: -2px 0 6px 4px;
}

/* indicador de digitando */
.simsd-chat-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.simsd-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-muted);
    opacity: .5;
    animation: simsd-typing 1.2s infinite ease-in-out;
}

.simsd-chat-typing span:nth-child(2) {
    animation-delay: .15s;
}

.simsd-chat-typing span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes simsd-typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: .35;
    }

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

/* ───────── Composer ───────── */
.simsd-chat-form {
    padding: 0 16px 12px;
    background: var(--chat-panel);
    flex-shrink: 0;
}

.simsd-chat-input-wrapper {
    background: var(--chat-bot-bubble);
    border-radius: 16px;
    border: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    padding: 12px;
}

.simsd-chat-input {
    width: 100%;
    resize: none;
    border: none;
    background: transparent;
    color: var(--chat-text);
    font-family: inherit;
    font-size: .95rem;
    line-height: 1.4;
    max-height: 120px;
    outline: none;
    padding: 0;
    margin-bottom: 8px;
    border-radius: 1px;
}

.simsd-chat-input::placeholder {
    color: var(--chat-muted);
}

.simsd-chat-input-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.simsd-chat-input-actions {
    display: none;
}

.simsd-chat-send {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: var(--chat-brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease;
}

.simsd-chat-send:hover {
    background: var(--chat-brand-2);
    color: #fff;
}

.simsd-chat-send svg {
    width: 16px;
    height: 16px;
}

.simsd-chat-footer-note {
    font-size: .75rem;
    color: var(--chat-muted);
    text-align: center;
    padding: 0 16px 16px;
    background: var(--chat-panel);
}

.simsd-chat-footer-note a {
    color: var(--chat-muted);
    text-decoration: underline;
}

/* ───────── Mobile ───────── */
@media (max-width: 480px) {
    .simsd-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .simsd-chat-launcher {
        bottom: 18px;
        right: 18px;
    }
}
