/* ============================================================
   NISSEI Chatbot Widget - Beautiful & Modern Style
   Version: 1.0
   Namespace: .nsbot-* (không đụng chạm với CSS web hiện tại)
   ============================================================ */

/* Reset chỉ trong scope widget */
.nsbot-wrapper,
.nsbot-wrapper * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
}

.nsbot-wrapper {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2147483000; /* rất cao để luôn nằm trên cùng */
    line-height: 1.5;
}

/* ============================================================
   FLOATING TOGGLE BUTTON
   ============================================================ */
.nsbot-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 60%, #06b6d4 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(30, 64, 175, 0.45), 0 4px 10px rgba(6, 182, 212, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    animation: nsbot-float 3s ease-in-out infinite;
}
.nsbot-toggle:hover {
    transform: scale(1.1) rotate(-8deg);
    box-shadow: 0 14px 40px rgba(30, 64, 175, 0.6);
}
.nsbot-toggle:active {
    transform: scale(0.95);
}

/* Pulse effect */
.nsbot-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    opacity: 0.4;
    z-index: -1;
    animation: nsbot-pulse 2s ease-in-out infinite;
}

@keyframes nsbot-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
@keyframes nsbot-pulse {
    0%   { transform: scale(1);   opacity: 0.5; }
    100% { transform: scale(1.35); opacity: 0;   }
}

/* Badge chấm đỏ báo mới */
.nsbot-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: nsbot-blink 1.5s ease-in-out infinite;
}
@keyframes nsbot-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* ============================================================
   CHAT BOX
   ============================================================ */
.nsbot-box {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.22), 0 10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: nsbot-slide-up 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes nsbot-slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.9); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ============================================================
   HEADER
   ============================================================ */
.nsbot-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #3b82f6 100%);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}
/* Decorative circles */
.nsbot-header::before {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}
.nsbot-header::after {
    content: '';
    position: absolute;
    bottom: -40px;
    left: 40%;
    width: 80px;
    height: 80px;
    background: rgba(6, 182, 212, 0.15);
    border-radius: 50%;
}
.nsbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}
.nsbot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
}
/* Online dot */
.nsbot-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid #1e40af;
}
.nsbot-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
}
.nsbot-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nsbot-subtitle .nsbot-dot {
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}
.nsbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}
.nsbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ============================================================
   BODY - Conversation area
   ============================================================ */
.nsbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #eff6ff 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Message bubbles */
.nsbot-msg {
    max-width: 85%;
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: nsbot-msg-in 0.3s ease-out;
    position: relative;
}
@keyframes nsbot-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.nsbot-msg-bot {
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.nsbot-msg-user {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}
.nsbot-msg a {
    color: #2563eb;
    text-decoration: underline;
    font-weight: 500;
}
.nsbot-msg-user a {
    color: #fff;
}
.nsbot-msg b, .nsbot-msg strong {
    font-weight: 600;
}
.nsbot-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
}

/* Typing indicator */
.nsbot-typing {
    display: inline-flex;
    gap: 5px;
    padding: 14px 18px !important;
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
}
.nsbot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: nsbot-bounce 1.2s infinite ease-in-out;
}
.nsbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.nsbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes nsbot-bounce {
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1;   }
}

/* Welcome card */
.nsbot-welcome {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    padding: 14px;
    text-align: center;
    margin-bottom: 4px;
}
.nsbot-welcome-icon {
    font-size: 32px;
    margin-bottom: 6px;
}
.nsbot-welcome-title {
    font-size: 14px;
    font-weight: 600;
    color: #1e40af;
    margin-bottom: 4px;
}
.nsbot-welcome-text {
    font-size: 12px;
    color: #475569;
}

/* ============================================================
   FOOTER - Search & Question List
   ============================================================ */
.nsbot-footer {
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nsbot-search-wrap {
    position: relative;
}
.nsbot-search {
    width: 100%;
    padding: 10px 44px 10px 38px;
    border: 1.5px solid #e5e7eb;
    border-radius: 22px;
    font-size: 13px;
    outline: none;
    transition: all 0.2s;
    background: #f9fafb;
}
.nsbot-search:focus {
    border-color: #3b82f6;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.nsbot-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

.nsbot-send {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}
.nsbot-send:hover {
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    transform: translateY(-50%) scale(1.08);
}
.nsbot-send:active {
    transform: translateY(-50%) scale(0.95);
}

.nsbot-questions-label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 4px;
}

.nsbot-questions {
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
}
.nsbot-question-btn {
    text-align: left;
    padding: 10px 14px;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}
.nsbot-question-btn::before {
    content: '💬';
    font-size: 14px;
    flex-shrink: 0;
}
.nsbot-question-btn:hover {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #93c5fd;
    color: #1e40af;
    transform: translateX(3px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}
.nsbot-question-btn:active {
    transform: translateX(3px) scale(0.98);
}

.nsbot-empty {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    padding: 16px;
    background: #f9fafb;
    border-radius: 10px;
}

/* Powered by */
.nsbot-powered {
    text-align: center;
    font-size: 10px;
    color: #9ca3af;
    padding: 4px 0;
    background: #fff;
}
.nsbot-powered strong {
    color: #1e40af;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
.nsbot-body::-webkit-scrollbar,
.nsbot-questions::-webkit-scrollbar {
    width: 6px;
}
.nsbot-body::-webkit-scrollbar-track,
.nsbot-questions::-webkit-scrollbar-track {
    background: transparent;
}
.nsbot-body::-webkit-scrollbar-thumb,
.nsbot-questions::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.nsbot-body::-webkit-scrollbar-thumb:hover,
.nsbot-questions::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================================
   RESPONSIVE MOBILE
   ============================================================ */
@media (max-width: 480px) {
    .nsbot-wrapper {
        right: 12px;
        bottom: 12px;
    }
    .nsbot-toggle {
        width: 56px;
        height: 56px;
    }
    .nsbot-box {
        width: calc(100vw - 24px);
        height: calc(100vh - 90px);
        max-height: calc(100vh - 90px);
        border-radius: 16px;
    }
}

/* ============================================================
   HIDE/SHOW STATES
   ============================================================ */
.nsbot-hidden {
    display: none !important;
}
