/* ================================================
   NUMERIS Chatbot Widget — Modern Floating Chat
   ================================================ */

/* ─── Bubble Button ─── */
.nrs-chat-bubble {
    position: fixed;
    bottom: 90px;
    right: 25px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2B3A67, #3d4f80);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(43,58,103,0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: nrs-pulse 2s infinite;
}
.nrs-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(43,58,103,0.5);
}
.nrs-chat-bubble i {
    font-size: 20px;
    transition: transform 0.3s;
}
.nrs-chat-bubble.active i {
    transform: rotate(90deg);
}
.nrs-chat-bubble .nrs-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #FF9933;
    color: #fff;
    font-size: 11px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

@keyframes nrs-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(43,58,103,0.4); }
    50% { box-shadow: 0 4px 30px rgba(255,153,51,0.4); }
}

/* ─── Chat Panel ─── */
.nrs-chat-panel {
    position: fixed;
    bottom: 155px;
    right: 25px;
    width: 380px;
    max-height: min(550px, calc(100vh - 170px));
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
}
.nrs-chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ─── Header ─── */
.nrs-chat-header {
    background: linear-gradient(135deg, #2B3A67, #3d4f80);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.nrs-chat-header .nrs-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.nrs-chat-header .nrs-info {
    flex: 1;
    min-width: 0;
}
.nrs-chat-header .nrs-info h6 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.nrs-chat-header .nrs-info small {
    color: rgba(255,255,255,0.7);
    font-size: 11px;
}
.nrs-chat-header .nrs-status {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}
.nrs-chat-actions {
    display: flex;
    gap: 4px;
}
.nrs-chat-actions button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.nrs-chat-actions button:hover {
    background: rgba(255,255,255,0.25);
}

/* ─── Conversation List ─── */
.nrs-conv-list {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.nrs-conv-list.active {
    display: flex;
}
.nrs-conv-list-header {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 600;
    color: #2B3A67;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.nrs-conv-list-body {
    flex: 1;
    overflow-y: auto;
}
.nrs-conv-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f5f5f5;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}
.nrs-conv-item:hover {
    background: #f8f9fa;
}
.nrs-conv-item .nrs-conv-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #eef1f7;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2B3A67;
    font-size: 14px;
    flex-shrink: 0;
}
.nrs-conv-item .nrs-conv-info {
    flex: 1;
    min-width: 0;
}
.nrs-conv-item .nrs-conv-title {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nrs-conv-item .nrs-conv-date {
    font-size: 11px;
    color: #999;
}
.nrs-conv-item .nrs-conv-delete {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
}
.nrs-conv-item .nrs-conv-delete:hover {
    color: #e74c3c;
    background: #fee;
}
.nrs-conv-empty {
    padding: 40px 20px;
    text-align: center;
    color: #999;
    font-size: 13px;
}
.nrs-conv-empty i {
    font-size: 40px;
    color: #ddd;
    display: block;
    margin-bottom: 10px;
}

/* ─── Chat View ─── */
.nrs-chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.nrs-chat-view.hidden {
    display: none;
}

/* ─── Messages ─── */
.nrs-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.nrs-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}
.nrs-msg.user {
    align-self: flex-end;
    background: #2B3A67;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.nrs-msg.assistant {
    align-self: flex-start;
    background: #f0f2f5;
    color: #333;
    border-bottom-left-radius: 4px;
}
.nrs-msg.assistant strong {
    color: #2B3A67;
}
.nrs-msg.assistant a {
    color: #FF9933;
    text-decoration: underline;
}
.nrs-msg.system {
    align-self: center;
    background: #fff8ec;
    border: 1px solid #FF9933;
    color: #7a5500;
    font-size: 12px;
    border-radius: 20px;
    padding: 6px 14px;
    text-align: center;
    max-width: 92%;
}
.nrs-msg.system a {
    color: #FF9933;
    font-weight: 600;
    text-decoration: none;
}
.nrs-msg.system a:hover {
    text-decoration: underline;
}
.nrs-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 3px;
    text-align: right;
}
.nrs-msg.assistant .nrs-msg-time {
    text-align: left;
}

/* Markdown dans les bulles */
.nrs-msg.assistant h5.nrs-md-h,
.nrs-msg.assistant h6.nrs-md-h {
    font-size: 13px;
    font-weight: 700;
    color: #2B3A67;
    margin: 8px 0 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid rgba(43,58,103,0.15);
}
.nrs-msg.assistant ul.nrs-md-list {
    margin: 4px 0 6px 0;
    padding-left: 18px;
}
.nrs-msg.assistant ul.nrs-md-list li {
    font-size: 13px;
    margin-bottom: 3px;
    line-height: 1.5;
}
.nrs-msg.assistant p {
    margin: 0 0 6px;
}
.nrs-msg.assistant p:last-of-type {
    margin-bottom: 0;
}

/* Typing indicator */
.nrs-typing {
    align-self: flex-start;
    background: #f0f2f5;
    padding: 12px 18px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: none;
    gap: 4px;
}
.nrs-typing.show {
    display: flex;
}
.nrs-typing span {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: nrs-bounce 1.4s infinite ease-in-out both;
}
.nrs-typing span:nth-child(1) { animation-delay: -0.32s; }
.nrs-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes nrs-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Welcome message */
.nrs-welcome {
    text-align: center;
    padding: 20px 16px;
}
.nrs-welcome .nrs-welcome-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2B3A67, #3d4f80);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 0 auto 12px;
}
.nrs-welcome h5 {
    color: #2B3A67;
    font-size: 15px;
    margin-bottom: 6px;
}
.nrs-welcome p {
    color: #666;
    font-size: 12px;
    margin-bottom: 14px;
}
.nrs-quick-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}
.nrs-quick-btn {
    background: #eef1f7;
    border: 1px solid #dde1ea;
    color: #2B3A67;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.nrs-quick-btn:hover {
    background: #2B3A67;
    color: #fff;
    border-color: #2B3A67;
}

/* ─── Input Area ─── */
.nrs-chat-input {
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 6px;
    align-items: end;
    flex-shrink: 0;
}
.nrs-chat-input textarea {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 13px;
    resize: none;
    outline: none;
    max-height: 80px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color 0.2s;
    min-width: 0;
}
.nrs-chat-input textarea:focus {
    border-color: #2B3A67;
}
.nrs-chat-input textarea::placeholder {
    color: #aaa;
}
.nrs-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #2B3A67;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.nrs-send-btn:hover {
    background: #FF9933;
}
.nrs-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Input Buttons (image, voice) ─── */
.nrs-input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f0f2f5;
    color: #666;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.nrs-input-btn:hover {
    background: #e0e3e8;
    color: #2B3A67;
}

/* Voice recording active state */
.nrs-voice-btn.recording {
    background: #e74c3c !important;
    color: #fff !important;
    animation: nrs-record-pulse 1s infinite;
}
@keyframes nrs-record-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

/* TTS toggle active state */
#nrsTtsToggle.active {
    background: rgba(255,153,51,0.3) !important;
    color: #FF9933 !important;
}

/* ─── Image Preview ─── */
.nrs-image-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-top: 1px solid #f0f0f0;
    background: #f8f9fa;
}
.nrs-image-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #2B3A67;
}
.nrs-image-preview button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e74c3c;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.nrs-image-preview button:hover {
    background: #c0392b;
}

/* ─── Message with image ─── */
.nrs-msg-image {
    margin-bottom: 6px;
}
.nrs-msg-image img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
    .nrs-chat-panel {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: calc(158px + env(safe-area-inset-bottom, 0px));
        max-height: calc(100vh - 170px);
        border-radius: 12px;
    }
    .nrs-chat-bubble {
        right: 15px;
        bottom: calc(90px + env(safe-area-inset-bottom, 0px));
        width: 46px;
        height: 46px;
    }
    .back-to-top {
        right: 15px !important;
        bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ─── Scrollbar ─── */
.nrs-chat-messages::-webkit-scrollbar,
.nrs-conv-list-body::-webkit-scrollbar {
    width: 4px;
}
.nrs-chat-messages::-webkit-scrollbar-thumb,
.nrs-conv-list-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* ─── Markdown in messages ─── */
.nrs-msg.assistant ul, .nrs-msg.assistant ol {
    margin: 6px 0;
    padding-left: 18px;
}
.nrs-msg.assistant li {
    margin-bottom: 3px;
}
.nrs-msg.assistant p {
    margin: 0 0 6px;
}
.nrs-msg.assistant p:last-child {
    margin-bottom: 0;
}
