/* =============================================================
   Nexty AI Chat Widget — Nextep Solution
   ============================================================= */

/* ── CSS Variables ── */
:root {
    --nexty-navy:        #0A1628;
    --nexty-orange:      #F97316;
    --nexty-orange-dark: #e85d04;
    --nexty-mint:        #18a558;
    --nexty-mint-dark:   #139047;
    --nexty-white:       #FFFFFF;
    --nexty-bg:          #F8F9FA;
    --nexty-border:      #E5E7EB;
    --nexty-text:        #1F2937;
    --nexty-text-gray:   #6B7280;
    --nexty-shadow:      0 20px 60px rgba(0, 0, 0, 0.18);
    --nexty-radius:      16px;
    --nexty-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --nexty-z:           999999;
}

/* ── Reset scope ── */
#nexty-widget-root *,
#nexty-widget-root *::before,
#nexty-widget-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* =============================================================
   KEYFRAME ANIMATIONS
   ============================================================= */

@keyframes nextyBounce {
    0%   { transform: scale(0) translateY(20px); opacity: 0; }
    60%  { transform: scale(1.15) translateY(-6px); opacity: 1; }
    80%  { transform: scale(0.95) translateY(2px); }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes nextyPulse {
    0%   { transform: scale(1);    opacity: 0.7; }
    100% { transform: scale(1.75); opacity: 0; }
}

@keyframes nextySlideUp {
    0%   { transform: translateY(24px); opacity: 0; }
    100% { transform: translateY(0);    opacity: 1; }
}

@keyframes nextySlideDown {
    0%   { transform: translateY(0);    opacity: 1; }
    100% { transform: translateY(24px); opacity: 0; }
}

@keyframes nextyMsgSlideLeft {
    0%   { transform: translateX(-16px); opacity: 0; }
    100% { transform: translateX(0);     opacity: 1; }
}

@keyframes nextyMsgSlideRight {
    0%   { transform: translateX(16px); opacity: 0; }
    100% { transform: translateX(0);    opacity: 1; }
}

@keyframes nextyTypingDot {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%            { transform: translateY(-6px); opacity: 1;   }
}

@keyframes nextyShimmer {
    0%   { background-position: -200% center; }
    100% { background-position:  200% center; }
}

/* =============================================================
   FLOATING BUBBLE
   ============================================================= */

#nexty-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nexty-orange) 0%, var(--nexty-orange-dark) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--nexty-z);
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;

    /* Bounce in on load */
    animation: nextyBounce 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s both;
}

#nexty-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(249, 115, 22, 0.55);
}

#nexty-bubble:focus-visible {
    outline: 3px solid var(--nexty-orange);
    outline-offset: 3px;
}

#nexty-bubble:active {
    transform: scale(0.95);
}

#nexty-bubble.nexty-active {
    background: linear-gradient(135deg, var(--nexty-navy) 0%, #162340 100%);
    box-shadow: 0 4px 20px rgba(10, 22, 40, 0.45);
}

/* Pulse ring */
.nexty-pulse-ring {
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid var(--nexty-orange);
    animation: nextyPulse 2s ease-out infinite;
    pointer-events: none;
}

/* "N" icon */
.nexty-bubble-icon {
    font-family: var(--nexty-font);
    font-size: 24px;
    font-weight: 800;
    color: var(--nexty-white);
    line-height: 1;
    letter-spacing: -0.5px;
    user-select: none;
    position: relative;
    z-index: 1;
}

/* Tooltip */
.nexty-tooltip {
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--nexty-navy);
    color: var(--nexty-white);
    font-family: var(--nexty-font);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 13px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(-50%) translateX(4px);
}

.nexty-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right: none;
    border-left-color: var(--nexty-navy);
}

#nexty-bubble:hover .nexty-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* =============================================================
   CHAT WINDOW
   ============================================================= */

#nexty-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: var(--nexty-white);
    border-radius: var(--nexty-radius);
    box-shadow: var(--nexty-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: calc(var(--nexty-z) - 1);
    font-family: var(--nexty-font);

    /* Default closed */
    opacity: 0;
    pointer-events: none;
    transform: translateY(24px);
    transition: none;
}

#nexty-chat-window.nexty-open {
    animation: nextySlideUp 0.32s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
    pointer-events: all;
}

#nexty-chat-window.nexty-closing {
    animation: nextySlideDown 0.22s ease-in forwards;
    pointer-events: none;
}

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

.nexty-header {
    background: var(--nexty-navy);
    padding: 0 18px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.nexty-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nexty-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nexty-orange) 0%, var(--nexty-orange-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: var(--nexty-white);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
}

.nexty-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nexty-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--nexty-white);
    line-height: 1.2;
}

.nexty-subtitle {
    font-size: 11px;
    font-weight: 500;
    color: var(--nexty-mint);
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.nexty-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Online status dot */
.nexty-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
    flex-shrink: 0;
}

/* Close button */
#nexty-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--nexty-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.15s ease;
    outline: none;
    flex-shrink: 0;
}

#nexty-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

#nexty-close-btn:focus-visible {
    outline: 2px solid var(--nexty-orange);
    outline-offset: 2px;
}

#nexty-close-btn:active {
    transform: scale(0.9);
}

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

#nexty-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--nexty-bg);
    scroll-behavior: smooth;
}

/* Scrollbar styling */
#nexty-messages-area::-webkit-scrollbar {
    width: 4px;
}
#nexty-messages-area::-webkit-scrollbar-track {
    background: transparent;
}
#nexty-messages-area::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
#nexty-messages-area::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ── Message row ── */
.nexty-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
}

/* Bot: left-aligned */
.nexty-message.bot {
    align-self: flex-start;
    animation: nextyMsgSlideLeft 0.28s ease-out both;
}

/* User: right-aligned */
.nexty-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    animation: nextyMsgSlideRight 0.28s ease-out both;
}

/* Mini avatar on bot messages */
.nexty-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--nexty-orange) 0%, var(--nexty-orange-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: var(--nexty-white);
    flex-shrink: 0;
    margin-bottom: 2px;
}

/* Message content wrapper */
.nexty-msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 78%;
}

.nexty-message.user .nexty-msg-content {
    align-items: flex-end;
}

/* Bubble */
.nexty-bubble {
    padding: 11px 15px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

/* Bot bubble */
.nexty-message.bot .nexty-bubble {
    background: var(--nexty-white);
    color: var(--nexty-text);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* User bubble */
.nexty-message.user .nexty-bubble {
    background: linear-gradient(135deg, var(--nexty-orange) 0%, var(--nexty-orange-dark) 100%);
    color: var(--nexty-white);
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3);
}

/* Timestamp */
.nexty-timestamp {
    font-size: 10px;
    color: var(--nexty-text-gray);
    padding: 0 4px;
}

/* ── Redirect / CTA button ── */
.nexty-redirect-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 8px 16px;
    background: var(--nexty-mint);
    color: var(--nexty-white);
    border: none;
    border-radius: 100px;
    font-family: var(--nexty-font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 8px rgba(24, 165, 88, 0.3);
    outline: none;
}

.nexty-redirect-btn:hover {
    background: var(--nexty-mint-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(24, 165, 88, 0.4);
}

.nexty-redirect-btn:focus-visible {
    outline: 2px solid var(--nexty-mint);
    outline-offset: 2px;
}

.nexty-redirect-btn:active {
    transform: translateY(0);
}

.nexty-redirect-btn .nexty-btn-arrow {
    font-size: 15px;
    transition: transform 0.2s ease;
}

.nexty-redirect-btn:hover .nexty-btn-arrow {
    transform: translateX(3px);
}

/* =============================================================
   TYPING INDICATOR
   ============================================================= */

.nexty-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 8px;
    background: var(--nexty-bg);
    flex-shrink: 0;
}

.nexty-typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--nexty-white);
    padding: 10px 14px;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.nexty-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--nexty-orange);
    animation: nextyTypingDot 1.4s ease-in-out infinite;
}

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

/* =============================================================
   INPUT AREA
   ============================================================= */

.nexty-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--nexty-white);
    border-top: 1px solid var(--nexty-border);
    flex-shrink: 0;
}

#nexty-input {
    flex: 1;
    height: 42px;
    padding: 0 14px;
    border: 1.5px solid var(--nexty-border);
    border-radius: 100px;
    font-family: var(--nexty-font);
    font-size: 14px;
    color: var(--nexty-text);
    background: var(--nexty-bg);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}

#nexty-input::placeholder {
    color: var(--nexty-text-gray);
}

#nexty-input:focus {
    border-color: var(--nexty-orange);
    background: var(--nexty-white);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12);
}

#nexty-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#nexty-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--nexty-orange) 0%, var(--nexty-orange-dark) 100%);
    color: var(--nexty-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
    outline: none;
}

#nexty-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.5);
}

#nexty-send-btn:focus-visible {
    outline: 2px solid var(--nexty-orange);
    outline-offset: 3px;
}

#nexty-send-btn:active {
    transform: scale(0.9);
}

#nexty-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* =============================================================
   UTILITY
   ============================================================= */

.nexty-hidden {
    display: none !important;
}

/* =============================================================
   MOBILE — screens < 480px
   ============================================================= */

@media (max-width: 479px) {
    #nexty-chat-window {
        right: 12px;
        left: 12px;
        width: auto;
        height: 70vh;
        bottom: 90px;
        border-radius: 14px;
    }

    #nexty-bubble {
        bottom: 20px;
        right: 20px;
        width: 54px;
        height: 54px;
    }

    .nexty-bubble-icon {
        font-size: 21px;
    }

    .nexty-tooltip {
        display: none;
    }

    .nexty-name {
        font-size: 15px;
    }
}

/* =============================================================
   REDUCED MOTION
   ============================================================= */

@media (prefers-reduced-motion: reduce) {
    #nexty-bubble,
    .nexty-pulse-ring,
    #nexty-chat-window.nexty-open,
    #nexty-chat-window.nexty-closing,
    .nexty-message,
    .nexty-typing-dots span {
        animation: none !important;
        transition: none !important;
    }
    #nexty-chat-window {
        transform: none;
        opacity: 1;
    }
    #nexty-chat-window.nexty-open {
        opacity: 1;
        pointer-events: all;
    }
}
