/* ==========================================
   MESSAGING.CSS — Centro de Mensajes Premium
   Project Pilder OS v1.0 Enterprise
   Patrón: Panel lateral deslizable (como Advisor/ViewerNotes)
   ========================================== */

/* ── Panel Overlay (backdrop) ── */
.msg-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9998;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
    opacity: 0;
}
.msg-overlay.open {
    display: block;
    opacity: 1;
}

/* ── Panel Principal ── */
.msg-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 430px;
    height: 100vh;
    background: linear-gradient(180deg, #1a1d23 0%, #12141a 100%);
    color: #e8eaed;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}
.msg-panel.open {
    transform: translateX(0);
}

/* ── Header ── */
.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}
.msg-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.msg-header-icon {
    font-size: 1.3rem;
}
.msg-header-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.msg-header-badge {
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: 6px;
}
.msg-header-badge:empty,
.msg-header-badge[data-count="0"] {
    display: none;
}
.msg-header-close {
    background: none;
    border: none;
    color: #9aa0a6;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
}
.msg-header-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ── Section Filter Bar ── */
.msg-filter-bar {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    scrollbar-width: none;
}
.msg-filter-bar::-webkit-scrollbar {
    display: none;
}
.msg-filter-chip {
    padding: 4px 12px;
    border-radius: 14px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: #9aa0a6;
    transition: all 0.2s;
    user-select: none;
}
.msg-filter-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e8eaed;
}
.msg-filter-chip.active {
    background: var(--brand, #6366f1);
    color: white;
    border-color: var(--brand, #6366f1);
}

/* ── Chat Area ── */
.msg-chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}
.msg-chat-area::-webkit-scrollbar {
    width: 4px;
}
.msg-chat-area::-webkit-scrollbar-track {
    background: transparent;
}
.msg-chat-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

/* ── Empty State ── */
.msg-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
}
.msg-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}
.msg-empty-title {
    font-size: 1rem;
    font-weight: 700;
    color: #9aa0a6;
    margin-bottom: 6px;
}
.msg-empty-sub {
    font-size: 0.8rem;
    color: #6b7280;
    line-height: 1.5;
}

/* ── Message Bubble ── */
.msg-bubble {
    display: flex;
    gap: 10px;
    animation: msgFadeIn 0.3s ease;
    max-width: 100%;
}
@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Own messages */
.msg-bubble.own {
    flex-direction: row-reverse;
}
.msg-bubble.own .msg-content {
    background: rgba(99, 102, 241, 0.18);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 16px 4px 16px 16px;
}
.msg-bubble.own .msg-meta {
    text-align: right;
}

/* Others' messages */
.msg-bubble:not(.own) .msg-content {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px 16px 16px 16px;
}

/* Avatar */
.msg-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
    margin-top: 2px;
}
.msg-bubble.own .msg-avatar {
    background: linear-gradient(135deg, #6366f1, #818cf8);
}
.msg-bubble:not(.own) .msg-avatar {
    background: linear-gradient(135deg, #059669, #34d399);
}

/* Content */
.msg-content {
    padding: 10px 14px;
    max-width: 330px;
    word-break: break-word;
}
.msg-sender {
    font-size: 0.72rem;
    font-weight: 700;
    color: #a5b4fc;
    margin-bottom: 4px;
}
.msg-bubble:not(.own) .msg-sender {
    color: #6ee7b7;
}
.msg-text {
    font-size: 0.85rem;
    line-height: 1.5;
    color: #e8eaed;
}
.msg-text .msg-mention {
    color: #fbbf24;
    font-weight: 700;
    cursor: pointer;
}
.msg-text .msg-mention:hover {
    text-decoration: underline;
}

/* Section Badge (deep-link) */
.msg-section-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 3px 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 600;
    color: #93c5fd;
    cursor: pointer;
    transition: all 0.2s;
}
.msg-section-badge:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #bfdbfe;
    border-color: rgba(99, 102, 241, 0.4);
}

/* Meta (timestamp + read status) */
.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 0.62rem;
    color: #6b7280;
}
.msg-read-indicator {
    color: #34d399;
    font-size: 0.7rem;
}

/* ── Input Area ── */
.msg-input-area {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

/* Section selector (above input) */
.msg-section-selector {
    display: none;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    font-size: 0.75rem;
    color: #a5b4fc;
}
.msg-section-selector.active {
    display: flex;
}
.msg-section-selector-label {
    font-weight: 600;
    white-space: nowrap;
}
.msg-section-selector select {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e8eaed;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
    outline: none;
}
.msg-section-selector select option {
    background: #1a1d23;
    color: #e8eaed;
}
.msg-section-clear {
    background: none;
    border: none;
    color: #9aa0a6;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px;
    line-height: 1;
}
.msg-section-clear:hover {
    color: #ef4444;
}

/* Input row */
.msg-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.msg-input-row textarea {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 14px;
    color: #e8eaed;
    font-size: 0.85rem;
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.4;
}
.msg-input-row textarea::placeholder {
    color: #6b7280;
}
.msg-input-row textarea:focus {
    border-color: var(--brand, #6366f1);
}
.msg-section-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #9aa0a6;
    width: 38px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
    flex-shrink: 0;
}
.msg-section-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border-color: rgba(99, 102, 241, 0.3);
}
.msg-section-btn.active {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.4);
}
.msg-send-btn {
    background: var(--brand, #6366f1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    flex-shrink: 0;
}
.msg-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}
.msg-send-btn:disabled {
    opacity: 0.4;
    transform: none;
    cursor: not-allowed;
    box-shadow: none;
}

/* ── @Mentions Popup ── */
.msg-mention-popup {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    max-height: 200px;
    overflow-y: auto;
    background: #1e2028;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
    z-index: 10000;
    padding: 6px;
}
.msg-mention-popup.open {
    display: block;
}
.msg-mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.msg-mention-item:hover,
.msg-mention-item.selected {
    background: rgba(99, 102, 241, 0.15);
}
.msg-mention-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
    color: white;
    background: linear-gradient(135deg, #059669, #34d399);
}
.msg-mention-info {
    flex: 1;
    min-width: 0;
}
.msg-mention-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #e8eaed;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-mention-role {
    font-size: 0.65rem;
    color: #6b7280;
}

/* ── Floating Trigger Button (in header) ── */
.msg-trigger-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 20px;
    color: #a5b4fc;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
    white-space: nowrap;
}
.msg-trigger-btn:hover {
    background: rgba(99, 102, 241, 0.22);
    color: #c7d2fe;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}
.msg-trigger-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 0.6rem;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    animation: msgBadgePulse 2s ease-in-out infinite;
}
.msg-trigger-badge:empty,
.msg-trigger-badge[data-count="0"] {
    display: none;
}
@keyframes msgBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ── Date Separator ── */
.msg-date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}
.msg-date-separator::before,
.msg-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
}
.msg-date-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #6b7280;
    white-space: nowrap;
    padding: 2px 10px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
}

/* ── Typing Indicator ── */
.msg-typing {
    display: none;
    padding: 4px 16px;
    font-size: 0.72rem;
    color: #6b7280;
    font-style: italic;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .msg-panel {
        width: 100%;
    }
    .msg-content {
        max-width: calc(100vw - 100px);
    }
    .msg-trigger-btn span.msg-trigger-label {
        display: none;
    }
    .msg-trigger-btn {
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .msg-header {
        padding: 12px 14px;
    }
    .msg-input-area {
        padding: 10px 12px;
    }
    .msg-chat-area {
        padding: 12px 10px 6px;
    }
}

/* ── Viewer Mode Compatibility ── */
body.viewer-mode .msg-trigger-btn {
    /* Viewers CAN use messaging — keep visible */
    display: inline-flex;
}
