/**
 * RRV3 Contextual Chat & Collaboration - Stylesheet
 * Modern responsive floating chat widget, attachments preview & slide-over collaboration drawer
 */

:root {
    --rrv3-chat-primary: #0284c7;
    --rrv3-chat-primary-hover: #0369a1;
    --rrv3-chat-bg: #ffffff;
    --rrv3-chat-header-bg: #0f172a;
    --rrv3-chat-bubble-self: #0284c7;
    --rrv3-chat-bubble-other: #f1f5f9;
    --rrv3-chat-border: #cbd5e1;
    --rrv3-chat-text: #1e293b;
    --rrv3-chat-text-muted: #64748b;
    --rrv3-chat-shadow: 0 12px 36px -4px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(15, 23, 42, 0.08);
}

/* Base Wrapper */
.rrv3-chat-wrapper,
#rrv3-chat-app {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 2147483647 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    display: block !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}

/* Floating Launcher Trigger */
.rrv3-chat-launcher,
#rrv3-chat-launcher {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 2147483647 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    background: linear-gradient(135deg, #0284c7, #0369a1) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    border-radius: 50px !important;
    padding: 12px 20px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.45) !important;
    transition: transform 0.15s ease, box-shadow 0.15s ease !important;
    outline: none !important;
    text-decoration: none !important;
    pointer-events: auto !important;
}

.rrv3-chat-launcher:hover,
#rrv3-chat-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 26px rgba(2, 132, 199, 0.6) !important;
}

.rrv3-chat-badge,
#rrv3-chat-unread-badge {
    background: #ef4444 !important;
    color: #ffffff !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    border-radius: 20px !important;
    padding: 2px 7px !important;
    margin-left: 2px !important;
    display: inline-block !important;
}

/* Slide-over Drawer */
.rrv3-chat-drawer,
#rrv3-chat-drawer {
    position: fixed !important;
    bottom: 80px !important;
    right: 24px !important;
    width: 400px !important;
    height: 580px !important;
    max-width: calc(100vw - 32px) !important;
    max-height: calc(100vh - 100px) !important;
    background: #ffffff !important;
    border-radius: 16px !important;
    box-shadow: var(--rrv3-chat-shadow) !important;
    display: none;
    flex-direction: column !important;
    overflow: hidden !important;
    border: 1px solid #cbd5e1 !important;
    z-index: 2147483647 !important;
    pointer-events: auto !important;
}

.rrv3-chat-drawer.is-open,
#rrv3-chat-drawer.is-open {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    animation: rrv3ChatPop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes rrv3ChatPop {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Dropzone Overlay */
.rrv3-chat-dropzone-overlay {
    position: absolute;
    inset: 0;
    background: rgba(2, 132, 199, 0.9);
    color: #ffffff;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    backdrop-filter: blur(2px);
}

.rrv3-chat-dropzone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border: 2px dashed #ffffff;
    border-radius: 12px;
    padding: 30px;
}

/* Header */
.rrv3-chat-drawer-head {
    background: #0f172a;
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.rrv3-chat-head-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.rrv3-chat-context-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rrv3-chat-context-sub {
    font-size: 11px;
    color: #94a3b8;
}

.rrv3-chat-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rrv3-chat-head-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.rrv3-chat-head-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* Feed View */
.rrv3-chat-feed-view,
#rrv3-chat-feed-view {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    overflow: hidden !important;
    background: #f8fafc !important;
}

.rrv3-chat-messages-container,
#rrv3-chat-messages-container {
    flex: 1 1 auto !important;
    min-height: 150px !important;
    overflow-y: auto !important;
    padding: 16px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
}

.rrv3-chat-empty-state {
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    margin: auto;
    padding: 20px;
}

/* Message Bubbles */
.rrv3-chat-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.rrv3-chat-msg-row.is-self {
    align-self: flex-end;
    align-items: flex-end;
}

.rrv3-chat-msg-row.is-other {
    align-self: flex-start;
    align-items: flex-start;
}

.rrv3-chat-msg-meta {
    font-size: 11px;
    color: var(--rrv3-chat-text-muted);
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rrv3-chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.rrv3-chat-msg-row.is-self .rrv3-chat-msg-bubble {
    background: #0284c7;
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.rrv3-chat-msg-row.is-other .rrv3-chat-msg-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 3px;
}

.rrv3-chat-msg-time {
    font-size: 10px;
    margin-top: 3px;
    color: #94a3b8;
}

/* Attachments in Message Bubble */
.rrv3-chat-msg-attachments {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.rrv3-chat-img-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rrv3-chat-img-thumb {
    width: 140px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    cursor: zoom-in;
    transition: transform 0.15s;
}

.rrv3-chat-img-thumb:hover {
    transform: scale(1.02);
}

.rrv3-chat-doc-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    text-decoration: none;
    color: inherit;
    border: 1px solid rgba(0,0,0,0.08);
    transition: background 0.15s;
}

.rrv3-chat-msg-row.is-self .rrv3-chat-doc-card {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
}

.rrv3-chat-doc-card:hover {
    background: rgba(0, 0, 0, 0.1);
}

.rrv3-chat-msg-row.is-self .rrv3-chat-doc-card:hover {
    background: rgba(255, 255, 255, 0.28);
}

.rrv3-chat-doc-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.rrv3-chat-doc-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.rrv3-chat-doc-size {
    font-size: 10px;
    opacity: 0.75;
}

/* Input Area & Pending Attachments */
.rrv3-chat-input-area {
    background: #ffffff;
    border-top: 1px solid var(--rrv3-chat-border);
    padding: 12px;
    position: relative;
    flex-shrink: 0;
}

.rrv3-chat-pending-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #e2e8f0;
}

.rrv3-chat-pending-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11.5px;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.rrv3-chat-pending-del {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
    line-height: 1;
}

.rrv3-chat-pending-del:hover {
    font-weight: bold;
}

.rrv3-chat-form-inner {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.rrv3-chat-attach-btn {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.rrv3-chat-attach-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.rrv3-chat-textarea {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 90px;
    box-sizing: border-box;
}

.rrv3-chat-textarea:focus {
    border-color: #0284c7;
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

.rrv3-chat-send-btn {
    background: #0284c7;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.rrv3-chat-send-btn:hover {
    background: #0369a1;
}

.rrv3-chat-tools-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 11px;
    color: #94a3b8;
}

/* Mention Autocomplete Popup */
.rrv3-chat-mention-popup {
    position: absolute;
    bottom: 100%;
    left: 12px;
    right: 12px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    max-height: 180px;
    overflow-y: auto;
    box-shadow: var(--rrv3-chat-shadow);
    z-index: 100;
}

.rrv3-chat-mention-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
}

.rrv3-chat-mention-item:hover {
    background: #f0f9ff;
    color: #0284c7;
}

.rrv3-chat-mention-tag {
    background: rgba(2, 132, 199, 0.15);
    color: #0284c7;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 600;
}

.rrv3-chat-msg-row.is-self .rrv3-chat-mention-tag {
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}

/* Recent Conversations List */
.rrv3-chat-recent-view,
#rrv3-chat-recent-view {
    flex: 1 1 auto !important;
    display: none;
    flex-direction: column !important;
    background: #ffffff !important;
    overflow: hidden !important;
}

.rrv3-chat-recent-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.rrv3-chat-recent-head h4 {
    margin: 0;
    font-size: 14px;
    color: #1e293b;
}

.rrv3-chat-recent-list {
    flex: 1;
    overflow-y: auto;
}

.rrv3-chat-recent-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.15s;
}

.rrv3-chat-recent-item:hover {
    background: #f8fafc;
}

.rrv3-chat-recent-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.rrv3-chat-recent-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

.rrv3-chat-recent-snippet {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fullscreen Lightbox */
.rrv3-chat-lightbox,
#rrv3-chat-lightbox-modal {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.92) !important;
    z-index: 2147483647 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.rrv3-chat-lightbox img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.rrv3-chat-lightbox-close {
    position: absolute;
    top: 24px;
    right: 24px;
    color: #ffffff;
    font-size: 28px;
    cursor: pointer;
    opacity: 0.8;
}

.rrv3-chat-lightbox-close:hover {
    opacity: 1;
}

.rrv3-chat-lightbox-caption {
    color: #cbd5e1;
    font-size: 13px;
    margin-top: 12px;
}
