/* ==========================================
   NEXCORE CHAT — PREMIUM
   ========================================== */

.nxc {
    --c: var(--nxc-color, #667eea);
    --c-light: color-mix(in srgb, var(--c) 12%, transparent);
    --radius: var(--nxc-radius, 20px);
    --btn-size: var(--nxc-btn-size, 60px);
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.nxc[data-position="right"] { right: 24px; }
.nxc[data-position="left"] { left: 24px; }

/* ==========================================
   TOGGLE — Botão flutuante
   ========================================== */

.nxc__toggle {
    width: var(--btn-size);
    height: var(--btn-size);
    border-radius: 50%;
    border: none;
    background: var(--c);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    box-shadow:
        0 4px 14px rgba(0, 0, 0, 0.15),
        0 0 0 0 var(--c);
    opacity: 0;
    transform: scale(0.6) translateY(20px);
    transition: opacity 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.nxc__toggle--visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.nxc__toggle:hover {
    background: var(--nxc-hover, var(--c));
    box-shadow:
        0 6px 24px rgba(0, 0, 0, 0.2),
        0 0 0 4px var(--c-light);
    transform: scale(1.05);
}

.nxc__toggle:active {
    transform: scale(0.95);
}

/* Ícones */
.nxc__icon-x { display: none; }
.nxc__toggle--active .nxc__icon-chat { display: none; }
.nxc__toggle--active .nxc__icon-x { display: block; }

/* Pulse ring */
.nxc__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--c);
    opacity: 0;
    animation: nxc-pulse 2.5s ease-out infinite;
    pointer-events: none;
}

.nxc__toggle--active .nxc__pulse { display: none; }

@keyframes nxc-pulse {
    0% { transform: scale(0.95); opacity: 0.7; }
    70% { transform: scale(1.3); opacity: 0; }
    100% { transform: scale(1.3); opacity: 0; }
}

/* ==========================================
   WINDOW — Janela do chat
   ========================================== */

.nxc__window {
    position: absolute;
    bottom: calc(var(--btn-size) + 16px);
    width: 400px;
    max-height: min(560px, calc(100vh - 120px));
    background: #fff;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(24px) scale(0.92);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.12),
        0 4px 16px rgba(0, 0, 0, 0.06),
        0 0 0 1px rgba(0, 0, 0, 0.04);
}

.nxc[data-position="right"] .nxc__window { right: 0; }
.nxc[data-position="left"] .nxc__window { left: 0; }

.nxc__window--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ==========================================
   HEADER
   ========================================== */

.nxc__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--c);
    color: #fff;
    flex-shrink: 0;
}

.nxc__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.nxc__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}

.nxc__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nxc__avatar--default {
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.nxc__title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nxc__subtitle {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nxc__close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    flex-shrink: 0;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nxc__close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ==========================================
   RGPD CONSENT
   ========================================== */

.nxc__gdpr {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    overflow-y: auto;
}

.nxc__gdpr-inner {
    text-align: center;
}

.nxc__gdpr-icon {
    color: var(--c);
    margin-bottom: 16px;
}

.nxc__gdpr-text {
    font-size: 13px;
    line-height: 1.6;
    color: #50575e;
    margin: 0 0 20px;
}

.nxc__gdpr-link {
    color: var(--c);
    text-decoration: none;
    font-weight: 500;
}

.nxc__gdpr-link:hover {
    text-decoration: underline;
}

.nxc__gdpr-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nxc__gdpr-accept {
    padding: 12px 24px;
    background: var(--c);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.nxc__gdpr-accept:hover { opacity: 0.9; }
.nxc__gdpr-accept:active { transform: scale(0.97); }

.nxc__gdpr-reject {
    padding: 10px;
    background: none;
    border: none;
    color: #999;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s;
}

.nxc__gdpr-reject:hover { color: #666; }

/* ==========================================
   LEAD FORM
   ========================================== */

.nxc__lead-form {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    overflow-y: auto;
}

.nxc__lf-inner {
    text-align: center;
    width: 100%;
}

.nxc__lf-icon {
    color: var(--c);
    margin-bottom: 12px;
}

.nxc__lf-title {
    font-size: 14px;
    color: #50575e;
    margin: 0 0 20px;
    line-height: 1.5;
}

.nxc__lf-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.nxc__lf-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nxc__lf-field input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.nxc__lf-field input:focus {
    border-color: var(--c);
    box-shadow: 0 0 0 2px var(--c-light);
}

.nxc__lf-submit {
    width: 100%;
    padding: 12px;
    background: var(--c);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    margin-top: 4px;
    -webkit-tap-highlight-color: transparent;
}

.nxc__lf-submit:hover { opacity: 0.9; }
.nxc__lf-submit:active { transform: scale(0.97); }
.nxc__lf-submit:disabled { opacity: 0.6; cursor: wait; }

/* ==========================================
   MESSAGES
   ========================================== */

.nxc__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 200px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Scrollbar */
.nxc__messages::-webkit-scrollbar { width: 4px; }
.nxc__messages::-webkit-scrollbar-track { background: transparent; }
.nxc__messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* Message wrapper */
.nxc__msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: nxc-msg-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.nxc__msg--assistant {
    align-self: flex-start;
}

.nxc__msg--system {
    align-self: center;
    max-width: 90%;
}

@keyframes nxc-msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Avatar in messages */
.nxc__msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--c);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-top: 2px;
}

.nxc__msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Bubbles */
.nxc__bubble {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.nxc__msg--user .nxc__bubble {
    background: var(--c);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.nxc__msg--assistant .nxc__bubble {
    background: var(--nxc-bot-bg, #f0f2f5);
    color: #1d2327;
    border-bottom-left-radius: 4px;
}

.nxc__msg--system .nxc__bubble {
    background: #fff8e1;
    color: #7c6b2d;
    font-size: 13px;
    text-align: center;
    border-radius: 10px;
}

/* Meta (timestamp + copy) */
.nxc__msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0 0 36px;
}

.nxc__msg-meta--right {
    justify-content: flex-end;
    padding: 3px 0 0 0;
}

.nxc__time {
    font-size: 11px;
    color: #aaa;
}

.nxc__copy {
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    padding: 2px;
    display: flex;
    border-radius: 4px;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nxc__copy:hover {
    color: #666;
}

/* ==========================================
   MARKDOWN ELEMENTS
   ========================================== */

.nxc__bubble strong { font-weight: 600; }
.nxc__bubble em { font-style: italic; }

.nxc__bubble a {
    color: var(--c);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.nxc__msg--user .nxc__bubble a {
    color: rgba(255,255,255,0.9);
}

.nxc__code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12.5px;
}

.nxc__msg--user .nxc__code {
    background: rgba(255, 255, 255, 0.15);
}

.nxc__code-block {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 12px 14px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    overflow-x: auto;
    margin: 6px 0;
    line-height: 1.5;
    white-space: pre;
}

.nxc__list {
    margin: 4px 0;
    padding-left: 18px;
}

.nxc__list li {
    margin: 2px 0;
}

.nxc__h2 {
    display: block;
    font-size: 15px;
    margin: 6px 0 2px;
}

.nxc__h3 {
    display: block;
    font-size: 14px;
    margin: 4px 0 2px;
}

/* ==========================================
   THINKING INDICATOR — Futuristic
   ========================================== */

.nxc__thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
}

.nxc__think-orb {
    position: relative;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

/* Core pulsante */
.nxc__think-core {
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    background: var(--c);
    animation: nxc-core-pulse 1.8s ease-in-out infinite;
    box-shadow:
        0 0 12px var(--c),
        0 0 24px color-mix(in srgb, var(--c) 40%, transparent);
}

@keyframes nxc-core-pulse {
    0%, 100% { transform: scale(0.8); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* Anéis orbitais */
.nxc__think-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--c);
    border-right-color: color-mix(in srgb, var(--c) 40%, transparent);
    animation: nxc-ring-spin 1.5s linear infinite;
}

.nxc__think-ring--2 {
    inset: 3px;
    border-top-color: color-mix(in srgb, var(--c) 60%, transparent);
    border-right-color: transparent;
    border-left-color: color-mix(in srgb, var(--c) 30%, transparent);
    animation-duration: 2s;
    animation-direction: reverse;
}

@keyframes nxc-ring-spin {
    to { transform: rotate(360deg); }
}

/* Texto "A pensar" com shimmer */
.nxc__think-text {
    font-size: 13px;
    color: #999;
    background: linear-gradient(
        90deg,
        #999 0%,
        #bbb 40%,
        var(--c) 50%,
        #bbb 60%,
        #999 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: nxc-shimmer 2s ease-in-out infinite;
}

@keyframes nxc-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ==========================================
   FORM
   ========================================== */

.nxc__form {
    padding: 12px 14px 10px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    background: #fff;
}

.nxc__input-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #f5f6f8;
    border-radius: 12px;
    padding: 4px 4px 4px 14px;
    transition: box-shadow 0.2s;
}

.nxc__input-wrap:focus-within {
    box-shadow: 0 0 0 2px var(--c-light);
}

.nxc__input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    outline: none;
    padding: 8px 0;
    font-family: inherit;
    color: #1d2327;
    min-width: 0;
    -webkit-appearance: none;
}

.nxc__input::placeholder {
    color: #999;
}

.nxc__send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--c);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.nxc__send:hover { opacity: 0.85; }
.nxc__send:active { transform: scale(0.9); }

.nxc__powered {
    text-align: center;
    font-size: 11px;
    color: #ccc;
    margin-top: 8px;
    letter-spacing: 0.3px;
}

.nxc__powered a {
    color: #bbb;
    text-decoration: none;
    transition: color 0.2s;
}

.nxc__powered a:hover {
    color: #888;
}

/* ==========================================
   MOBILE — Full sheet
   ========================================== */

@media (max-width: 768px) {
    .nxc {
        bottom: 16px;
    }

    .nxc[data-position="right"] { right: 16px; }
    .nxc[data-position="left"] { left: 16px; }

    /* Janela: bottom sheet fullscreen */
    .nxc__window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        /* iPhone safe area */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .nxc[data-position="right"] .nxc__window,
    .nxc[data-position="left"] .nxc__window {
        right: 0;
        left: 0;
    }

    /* Animação mobile: slide up */
    .nxc__window {
        transform: translateY(100%);
        opacity: 1;
    }

    .nxc__window--open {
        transform: translateY(0);
    }

    /* Header mobile */
    .nxc__header {
        padding: 14px 16px;
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    /* Messages ocupam o espaço disponível */
    .nxc__messages {
        min-height: 0;
        flex: 1;
        padding: 14px 12px;
    }

    .nxc__msg {
        max-width: 92%;
    }

    /* Form mobile */
    .nxc__form {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .nxc__input {
        font-size: 16px; /* Previne zoom no iOS */
    }

    /* RGPD e Lead form scrolláveis */
    .nxc__gdpr,
    .nxc__lead-form {
        padding: 20px 16px;
    }

    /* Esconde toggle quando chat está aberto */
    .nxc__toggle--active {
        opacity: 0;
        pointer-events: none;
    }

    /* Code blocks não excedem a janela */
    .nxc__code-block {
        max-width: calc(100vw - 100px);
    }
}

/* Tablets — janela mais larga */
@media (min-width: 769px) and (max-width: 1024px) {
    .nxc__window {
        width: 380px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .nxc__toggle,
    .nxc__window,
    .nxc__msg,
    .nxc__dots span {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }

    .nxc__pulse {
        display: none;
    }
}
