/* Chat-related styles extracted from site_style.css */

.btn-chat {
    border-color: #1267CB;
    background-color: #1267CB;
}

.btn-chat-parent[disabled] {
    opacity: 0.65;
}

.btn-chat-parent[disabled] .btn-chat {
    border-color: #cecece;
    background-color: #cecece;
}

/* AI Chat Styles */
.ai-chat-container {
    position: fixed;
    top: 90px;
    right: 20px;
    left: auto;
    bottom: auto;
    width: 400px;
    height: 600px;
    z-index: 1000;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.ai-chat-container.ai-chat-container--user-positioned {
    right: auto;
    left: var(--ai-chat-left, 20px);
    top: var(--ai-chat-top, 90px);
}

.ai-chat-drag-handle {
    cursor: grab;
    user-select: none;
}

.ai-chat-drag-handle:active {
    cursor: grabbing;
}

.ai-chat-drag-handle .btn,
.ai-chat-drag-handle a {
    cursor: pointer;
}

body.ai-chat-dragging {
    user-select: none;
}

.ai-chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    background: white;
}

.ai-chat-header {
    padding: 15px;
    flex-shrink: 0;
}

/* Keep action buttons on one row: center column must shrink (min-width:0), actions must not */
.ai-chat-header > .d-flex {
    min-width: 0;
}

.ai-chat-header .flex-grow-1 {
    min-width: 0;
}

.ai-header-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    flex-shrink: 0;
}

.ai-header-actions .btn {
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
}

.ai-chat-tabs {
    flex-shrink: 0;
}

.ai-chat-tabs .nav-tabs {
    border-bottom: 1px solid #dee2e6;
    padding: 0 15px;
}

.ai-chat-tabs .nav-link {
    border: none;
    padding: 10px 15px;
    font-size: 14px;
}

.ai-chat-tabs .nav-link.active {
    border-bottom: 2px solid #007bff;
    background: transparent;
}

.ai-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

#aiChatContainer .tab-pane {
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

/* Outer: watermark fixed in pane; inner .ai-messages-container scrolls */
.ai-messages-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #fff;
}

.ai-messages-wrap::before {
    content: "";
    position: absolute;
    inset: 0;
    background: url("/static/assets/images/iflows-watermark.png") center / 58% no-repeat;
    opacity: 0.1;
    pointer-events: none;
    z-index: 0;
}

.ai-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: transparent;
    position: relative;
    z-index: 1;
}

#aiChatContainer .tab-content>.active {
    display: flex;
}

.ai-messages {
    min-height: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ai-messages-container .message {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.3s ease-in;
}

/* Floating AI chat: same left/right logic as main chat (chat.css .chat-message); no bubble colors */
#aiChatContainer .ai-messages-container .message {
    display: flex;
    flex-direction: column;
}

#aiChatContainer .ai-messages-container .message.user {
    align-self: flex-end;
    align-items: flex-end;
    background: transparent;
    color: #212529;
}

#aiChatContainer .ai-messages-container .message.ai,
#aiChatContainer .ai-messages-container .message.operator,
#aiChatContainer .ai-messages-container .message.system {
    align-self: flex-start;
    align-items: flex-start;
    background: transparent;
    color: #212529;
}

#aiChatContainer .ai-messages-container .message.user .message-header {
    justify-content: flex-end;
    width: 100%;
}

#aiChatContainer .ai-messages-container .message.ai .message-header,
#aiChatContainer .ai-messages-container .message.operator .message-header,
#aiChatContainer .ai-messages-container .message.system .message-header {
    justify-content: flex-start;
    width: 100%;
}

#aiChatContainer .ai-messages-container .message .message-text {
    background: transparent;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    text-align: left;
}

#aiChatContainer .ai-messages-container .message.user .message-time {
    text-align: right;
    width: 100%;
}

#aiChatContainer .ai-messages-container .message.ai .message-time,
#aiChatContainer .ai-messages-container .message.operator .message-time,
#aiChatContainer .ai-messages-container .message.system .message-time {
    text-align: left;
    width: 100%;
}

/* Long text / filenames must stay inside the fixed-width popup (flex min-width fix). */
#aiChatContainer .ai-messages-container {
    overflow-x: hidden;
}

#aiChatContainer .ai-messages-container .message {
    min-width: 0;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: break-word;
}

#aiChatContainer .ai-messages-container .message .message-text {
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

#aiChatContainer .ai-messages-container .message.chat-feedback-prompt .message-text {
    background: #e7f1ff;
    padding: 8px 12px;
    border-radius: 8px;
}

#aiChatContainer .ai-messages-container .message .chat-message-attachments {
    max-width: 100%;
    min-width: 0;
}

#aiChatContainer .ai-messages-container .chat-attachment-file {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

#aiChatContainer .ai-messages-container .chat-attachment-meta {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#aiChatContainer .ai-messages-container .chat-attachment-thumb-wrap {
    max-width: 100%;
}

#aiChatContainer .ai-messages-container .chat-attachment-thumb {
    max-width: 100%;
    height: auto;
}

#aiChatContainer .ai-input-container {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

#aiChatContainer .chat-attach-preview,
#aiChatContainer .chat-pending-attachments-list {
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: break-word;
}

#aiChatContainer .message-header {
    max-width: 100%;
    min-width: 0;
    flex-wrap: wrap;
}

#aiChatContainer .message.ai .message-header .flowy-ai-avatar-img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    align-self: flex-end;
    background: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-support {
    align-self: flex-start;
    background: #f8f9fa;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message-header {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    font-size: 12px;
    opacity: 0.8;
}

.message-avatar {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    background: #fff;
    color: #007bff;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
    text-align: right;
}

.ai-input-container {
    padding: 15px;
    border-top: 1px solid #dee2e6;
    flex-shrink: 0;
    background: white;
    margin-top: 10px;
}

.ai-chat-input-group {
    --ai-chat-input-line-height: 1.5;
    --ai-chat-input-vpad: 0.375rem;
    --ai-chat-input-inner-height: calc(
        var(--ai-chat-input-line-height) * 1em + 2 * var(--ai-chat-input-vpad)
    );
    --ai-chat-input-outer-height: calc(var(--ai-chat-input-inner-height) + 2px);

    width: 100%;
    max-width: 100%;
    align-items: stretch;
}

.ai-chat-input-group .input-group-prepend,
.ai-chat-input-group .input-group-append {
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
}

.ai-chat-input-group .input-group-prepend .btn,
.ai-chat-input-group .input-group-append .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: var(--ai-chat-input-outer-height);
    padding: var(--ai-chat-input-vpad) 1rem;
    line-height: 1;
}

.ai-chat-input-group > .form-control {
    flex: 1 1 auto;
    min-width: 0;
    width: 1%;
    box-sizing: border-box;
    min-height: var(--ai-chat-input-outer-height);
    line-height: var(--ai-chat-input-line-height);
    padding: var(--ai-chat-input-vpad) 0.75rem;
}

.ai-history-container {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.ai-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    position: relative;
    padding: 12px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.history-item:hover {
    background: var(--light-blue);
    border-color: var(--primary-blue);
}

.history-actions {
    position: relative;
}

.history-menu-btn {
    background: transparent;
    border: none;
    color: #6c757d;
    padding: 4px 8px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.3s ease;
}

.history-item:hover .history-menu-btn {
    opacity: 1;
}

.history-menu-btn:hover {
    background: #e9ecef;
    color: var(--primary-blue);
}

.history-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    min-width: 180px;
}

.history-dropdown-menu.show {
    display: block;
}

.history-dropdown-menu .dropdown-item {
    padding: 8px 12px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 14px;
    color: #495057;
    transition: background 0.2s ease;
}

.history-dropdown-menu .dropdown-item:hover {
    background: #f8f9fa;
    color: var(--primary-blue);
}

.history-dropdown-menu .dropdown-item i {
    width: 16px;
    text-align: center;
}

.history-title {
    font-weight: 600;
    margin-bottom: 5px;
}

.history-preview {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 11px;
    color: #999;
}

@media (max-width: 768px) {
    .ai-chat-container:not(.ai-chat-container--user-positioned) {
        width: 100%;
        height: 80%;
        bottom: 0;
        right: 0;
        left: auto;
        top: auto;
        border-radius: 0;
    }

    .ai-chat-container.ai-chat-container--user-positioned {
        width: 100%;
        height: 80%;
        bottom: auto;
        right: auto;
        left: var(--ai-chat-left, 0px);
        top: var(--ai-chat-top, 90px);
        border-radius: 0;
    }
}

#newChatBtn,
#closeChatBtn,
#transferToOperator {
    background: transparent !important;
    color: #FFF !important;
    font-size: 18px;
}

#transferToOperator {
    display: none;
}

#chatToggle:focus {
    outline: none !important;
    box-shadow: none !important;
}

#chatToggle {
    /* Icon uses .notification-bell-size (25px) like the notifications bell */
    min-width: 25px;
    overflow: visible !important;
    position: relative;
    z-index: 1;
}

#chatToggle.chat-toggle-loading:disabled,
#chatToggle.chat-toggle-loading[disabled] {
    cursor: wait;
    opacity: 0.85;
}

/*
 * Bootstrap .badge (and .btn .badge) sets position/top/vertical-align that breaks
 * corner placement; force same geometry as #all_notifications .notification-count.
 */
#chatToggle .chat-header-notification-count.badge.notification-count,
#chatToggle .chat-header-icon-anchor .notification-count {
    position: absolute !important;
    top: -8px !important;
    right: -8px !important;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
    vertical-align: top !important;
    z-index: 2;
    float: none !important;
    /* Keep .notification-count look vs default .badge */
    padding: 0.1rem 0.3rem !important;
    font-size: 0.6rem !important;
    font-weight: 600 !important;
    line-height: 1.5 !important;
    border-radius: 50% !important;
    background-color: #fb665e !important;
    color: #ffffff !important;
    border: none !important;
    min-width: 16px;
    text-align: center;
    white-space: nowrap;
}

/* .btn-sm font-size would shrink the glyph vs the bell (inside <a>, not btn-sm) */
/* Color matches .text-link-color on the notifications bell (style.css) */
#chatToggle .chat-header-icon-anchor .notification-bell-size {
    font-size: 25px !important;
    width: 25px !important;
    height: 25px !important;
    line-height: 25px !important;
    vertical-align: middle;
    color: #8a98ac !important;
}

#chatToggle:hover .chat-header-icon-anchor .notification-bell-size,
#chatToggle:focus .chat-header-icon-anchor .notification-bell-size {
    color: #8a98ac !important;
}

.chat-header-toggle-btn {
    padding: 0;
}

/* Same anchor as bell: badge positions vs icon box, not full toolbar button */
.chat-header-icon-anchor {
    line-height: 0;
    vertical-align: middle;
    overflow: visible;
}

.ai-history-unread-badge {
    background-color: #fb665e;
    color: #ffffff;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 600;
    min-width: 16px;
    min-height: 16px;
    text-align: center;
    line-height: 1.5;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 0.1rem 0.25rem;
}

/* Scoped to AI chat popup only; avoids affecting other <a disabled> (e.g. technical page). */
#aiChatContainer a[disabled] {
    pointer-events: none;
    color: gray;
    text-decoration: none;
    cursor: not-allowed;
}

/* Notification permission floating popup (global — chat page + operator transfer) */
#notif-permission-popup {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 340px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
    z-index: 9999;
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    overflow: hidden;
}

#notif-permission-popup.notif-popup-visible {
    transform: translateY(0);
    opacity: 1;
}

#notif-permission-popup.notif-popup-hiding {
    transform: translateY(120%);
    opacity: 0;
}

.notif-popup-header {
    display: flex;
    align-items: flex-start;
    padding: 16px 16px 12px 16px;
    gap: 12px;
}

.notif-popup-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
}

.notif-popup-icon.notif-popup-icon-blocked {
    background: linear-gradient(135deg, #f6c23e 0%, #e0a800 100%);
}

.notif-popup-text {
    flex: 1;
    min-width: 0;
}

.notif-popup-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.notif-popup-desc {
    font-size: 12px;
    color: #718096;
    margin: 0;
    line-height: 1.4;
}

.notif-popup-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.15s;
}

.notif-popup-close:hover {
    color: #4a5568;
}

.notif-popup-actions {
    padding: 0 16px 16px 16px;
    display: flex;
    gap: 8px;
}

.notif-popup-actions .btn {
    font-size: 13px;
    border-radius: 8px;
    padding: 6px 16px;
}

.notif-popup-steps {
    padding: 0 16px 16px 16px;
    border-top: 1px solid #f0f0f0;
    margin-top: 0;
}

.notif-popup-steps-title {
    font-size: 11px;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 12px 0 8px 0;
}

.notif-popup-steps ol {
    margin: 0;
    padding-left: 18px;
}

.notif-popup-steps ol li {
    font-size: 12px;
    color: #4a5568;
    line-height: 1.5;
    margin-bottom: 2px;
}

.notif-popup-steps ol li strong {
    color: #2d3748;
}

.notif-popup-browser-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    background: #edf2f7;
    color: #4a5568;
    border-radius: 20px;
    padding: 2px 8px;
    margin-bottom: 8px;
}

@media (max-width: 480px) {
    #notif-permission-popup {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 16px;
    }
}