/**
 * NaN Booking Pro - Chatbot v3.0
 * تصميم احترافي مستوحى من Intercom + WhatsApp
 */

/* ========== Reset & Base ========== */
#nbp-chatbot,
#nbp-chatbot * {
    box-sizing: border-box !important;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Tajawal', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#nbp-chatbot {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    direction: rtl;
    font-size: 14px;
    line-height: 1.5;
}

#nbp-chatbot.pos-right { right: 20px; }
#nbp-chatbot.pos-left { left: 20px; }

/* ========== Floating Bubble ========== */
.nbp-bubble {
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--nbp-color, #6366f1);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4), 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    position: relative;
    overflow: hidden;
}

.nbp-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
    pointer-events: none;
}

.nbp-bubble:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 28px rgba(99, 102, 241, 0.5), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nbp-bubble:active {
    transform: translateY(-1px) scale(0.98);
}

.nbp-bubble i {
    font-size: 30px;
    line-height: 1;
    color: #fff;
    transition: transform 0.3s;
}

.nbp-bubble .ti-x {
    display: none;
    font-size: 26px !important;
}

#nbp-chatbot.open .nbp-bubble .ti-message-circle-2 { display: none; }
#nbp-chatbot.open .nbp-bubble .ti-x { display: block; }

/* Pulsing dot */
.nbp-pulse-dot {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 2;
}

.nbp-pulse-dot::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    background: #ef4444;
    animation: nbp-pulse-anim 2s infinite;
    opacity: 0;
}

@keyframes nbp-pulse-anim {
    0% { opacity: 0.6; transform: scale(1); }
    100% { opacity: 0; transform: scale(2.2); }
}

#nbp-chatbot.open .nbp-pulse-dot { display: none; }

/* ========== Window ========== */
.nbp-window {
    position: absolute;
    bottom: 80px;
    width: 400px;
    height: 640px;
    max-height: calc(100vh - 110px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18), 0 8px 24px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: none;
    flex-direction: column;
    transform-origin: bottom right;
}

#nbp-chatbot.pos-left .nbp-window {
    left: 0;
    transform-origin: bottom left;
}

#nbp-chatbot.pos-right .nbp-window { right: 0; }

#nbp-chatbot.open .nbp-window {
    display: flex;
    animation: nbp-window-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes nbp-window-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========== Header ========== */
.nbp-header {
    position: relative;
    background: linear-gradient(135deg, var(--nbp-color, #6366f1) 0%, var(--nbp-color-2, #8b5cf6) 100%);
    color: #fff;
    padding: 22px 20px 18px;
    flex-shrink: 0;
    overflow: hidden;
}

.nbp-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    pointer-events: none;
}

.nbp-header-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 1;
}

.nbp-header-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.nbp-header-avatar i {
    font-size: 24px;
    color: #fff;
}

.nbp-header-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #4ade80;
    border-radius: 50%;
    border: 2.5px solid #fff;
}

.nbp-header-info {
    flex: 1;
    min-width: 0;
}

.nbp-header-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin: 0 0 3px 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nbp-header-subtitle {
    font-size: 12.5px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 4px;
}

.nbp-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.nbp-icon-btn {
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.nbp-icon-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.05);
}

.nbp-icon-btn:active {
    transform: scale(0.95);
}

.nbp-icon-btn i {
    font-size: 16px;
    color: #fff;
}

/* ========== Messages Area ========== */
.nbp-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 16px 12px;
    background: linear-gradient(180deg, #f9fafb 0%, #f1f5f9 100%);
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.nbp-messages::-webkit-scrollbar {
    width: 6px;
}

.nbp-messages::-webkit-scrollbar-track {
    background: transparent;
}

.nbp-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.nbp-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ========== Message ========== */
.nbp-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    margin-bottom: 8px;
    animation: nbp-msg-pop 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes nbp-msg-pop {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.nbp-msg.bot {
    align-self: flex-start;
}

.nbp-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    margin-top: 3px;
}

.nbp-msg.bot .nbp-msg-avatar {
    background: linear-gradient(135deg, var(--nbp-color, #6366f1) 0%, var(--nbp-color-2, #8b5cf6) 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.nbp-msg.user .nbp-msg-avatar {
    background: #e2e8f0;
    color: #64748b;
}

.nbp-msg-avatar i {
    font-size: 14px;
    line-height: 1;
}

.nbp-msg-wrapper {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    max-width: 100%;
}

.nbp-msg-bubble {
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.nbp-msg.bot .nbp-msg-bubble {
    background: #fff;
    color: #1e293b;
    border-top-right-radius: 4px;
}

.nbp-msg.user .nbp-msg-bubble {
    background: linear-gradient(135deg, var(--nbp-color, #6366f1) 0%, var(--nbp-color-2, #8b5cf6) 100%);
    color: #fff;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* Markdown formatting */
.nbp-msg-bubble strong, .nbp-msg-bubble b {
    font-weight: 700;
}

.nbp-msg-bubble em, .nbp-msg-bubble i {
    font-style: italic;
}

.nbp-msg-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 12.5px;
}

.nbp-msg.user .nbp-msg-bubble code {
    background: rgba(255, 255, 255, 0.25);
}

.nbp-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.nbp-msg-bubble ol, .nbp-msg-bubble ul {
    margin: 8px 0 4px;
    padding-right: 22px;
}

.nbp-msg-bubble li {
    margin: 4px 0;
    line-height: 1.6;
}

.nbp-msg-bubble p {
    margin: 0 0 8px;
}

.nbp-msg-bubble p:last-child {
    margin-bottom: 0;
}

.nbp-msg-bubble hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin: 10px 0;
}

.nbp-msg.user .nbp-msg-bubble hr {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.nbp-msg-time {
    font-size: 10.5px;
    color: #94a3b8;
    padding: 0 8px;
    line-height: 1.3;
}

.nbp-msg.user .nbp-msg-time {
    text-align: end;
}

/* ========== Typing Indicator ========== */
.nbp-typing {
    background: #fff;
    border-radius: 18px;
    border-top-right-radius: 4px;
    padding: 13px 16px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.nbp-typing-dot {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: nbp-typing-anim 1.4s infinite ease-in-out;
}

.nbp-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.nbp-typing-dot:nth-child(3) { animation-delay: 0.3s; }

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

/* ========== Suggestions ========== */
.nbp-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0 8px 38px;
    padding-right: 4px;
}

.nbp-chip {
    background: #fff;
    border: 1.5px solid var(--nbp-color, #6366f1);
    color: var(--nbp-color, #6366f1);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.3;
    font-family: inherit;
    white-space: nowrap;
}

.nbp-chip:hover {
    background: var(--nbp-color, #6366f1);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

/* ========== Booking Card ========== */
.nbp-booking-card {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 1.5px solid #6ee7b7;
    border-radius: 14px;
    padding: 14px 16px;
    margin: 4px 0;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
}

.nbp-booking-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: #047857;
    font-weight: 700;
    font-size: 14px;
    padding-bottom: 10px;
    border-bottom: 1px dashed rgba(16, 185, 129, 0.25);
}

.nbp-booking-card-header i {
    font-size: 20px;
    background: #10b981;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nbp-booking-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 13px;
}

.nbp-booking-label {
    color: #065f46;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nbp-booking-label i {
    font-size: 14px;
    opacity: 0.7;
}

.nbp-booking-value {
    color: #064e3b;
    font-weight: 700;
}

/* ========== Handoff Bar ========== */
.nbp-handoff {
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.nbp-handoff-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.25);
}

.nbp-handoff-btn:hover {
    background: #1da851;
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.35);
}

.nbp-handoff-btn i {
    font-size: 18px;
    line-height: 1;
}

/* ========== Input Area ========== */
.nbp-input-area {
    padding: 12px 16px 14px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.nbp-input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #f1f5f9;
    border-radius: 24px;
    padding: 5px 5px 5px 14px;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.nbp-input-wrap:focus-within {
    background: #fff;
    border-color: var(--nbp-color, #6366f1);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.nbp-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 4px;
    font-size: 14px;
    font-family: inherit;
    color: #1e293b;
    resize: none;
    max-height: 100px;
    min-height: 24px;
    outline: none;
    line-height: 1.4;
    width: 100%;
}

.nbp-input::placeholder {
    color: #94a3b8;
}

.nbp-send-btn {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--nbp-color, #6366f1) 0%, var(--nbp-color-2, #8b5cf6) 100%);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.nbp-send-btn:hover:not(:disabled) {
    transform: scale(1.08) rotate(-10deg);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.nbp-send-btn:active {
    transform: scale(0.95);
}

.nbp-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.nbp-send-btn i {
    font-size: 16px;
    color: #fff;
    line-height: 1;
    transform: scaleX(-1);
}

/* ========== Footer Branding ========== */
.nbp-footer {
    text-align: center;
    padding: 6px;
    background: #fff;
    font-size: 10.5px;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
}

.nbp-footer a {
    color: var(--nbp-color, #6366f1);
    text-decoration: none;
    font-weight: 600;
}

/* ========== Mobile ========== */
@media (max-width: 480px) {
    #nbp-chatbot {
        bottom: 16px;
    }

    #nbp-chatbot.pos-right { right: 16px; }
    #nbp-chatbot.pos-left { left: 16px; }

    .nbp-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 110px);
        right: -8px !important;
        left: -8px !important;
        margin: 0 auto;
        bottom: 78px;
    }

    #nbp-chatbot.pos-left .nbp-window {
        left: -8px;
        right: auto !important;
    }

    .nbp-bubble {
        width: 58px;
        height: 58px;
    }

    .nbp-bubble i {
        font-size: 26px;
    }
}

/* ========== RTL fixes ========== */
[dir="rtl"] .nbp-input {
    text-align: right;
}
