/**
 * AlertOwl - Message Detail Panel Styles
 * Slide-out panel for viewing message details
 * 
 * Add to dashboard.css or include separately
 */

/* ===========================================
   OVERLAY
   =========================================== */
.message-detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.message-detail-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* ===========================================
   PANEL
   =========================================== */
.message-detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 520px;
    max-width: 100%;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.3);
}

.message-detail-panel.open {
    transform: translateX(0);
}

/* ===========================================
   HEADER
   =========================================== */
.message-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.message-detail-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.message-detail-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.message-detail-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ===========================================
   BODY (Scrollable)
   =========================================== */
.message-detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.message-detail-body::-webkit-scrollbar {
    width: 6px;
}

.message-detail-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.message-detail-body::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===========================================
   PRIORITY BANNER
   =========================================== */
.detail-priority-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    margin: 0;
}

.detail-priority-icon {
    font-size: 18px;
}

.detail-priority-text {
    font-weight: 600;
    font-size: 15px;
}

.detail-confidence {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
}

/* ===========================================
   SECTIONS
   =========================================== */
.detail-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.detail-section-title svg {
    color: var(--accent-teal);
}

/* ===========================================
   META GRID
   =========================================== */
.detail-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-meta-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-meta-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-meta-value {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-word;
}

.detail-source {
    display: flex;
    align-items: center;
    gap: 6px;
}

.detail-status {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.detail-status.unread {
    background: rgba(20, 184, 166, 0.15);
    color: var(--accent-teal);
}

.detail-status.read {
    background: rgba(113, 113, 122, 0.15);
    color: var(--text-muted);
}

/* ===========================================
   SUBJECT & LABELS
   =========================================== */
.detail-subject {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    margin: 0 0 12px 0;
}

.detail-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.detail-label {
    display: inline-block;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ===========================================
   AI ANALYSIS
   =========================================== */
.detail-ai-section {
    background: rgba(20, 184, 166, 0.03);
}

.detail-ai-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-ai-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.detail-ai-item.full-width {
    grid-column: 1 / -1;
}

.detail-ai-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-ai-value {
    font-size: 14px;
    color: var(--text-primary);
}

.detail-ai-reasoning {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--accent-teal);
}

.detail-signals {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.detail-signal {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(234, 179, 8, 0.15);
    border: 1px solid rgba(234, 179, 8, 0.3);
    border-radius: 4px;
    font-size: 12px;
    color: #eab308;
}

/* Category badge */
.detail-ai-value.category-badge {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border-radius: 20px;
    font-weight: 500;
    font-size: 13px;
}

/* Action badge */
.detail-ai-value.action-badge {
    display: inline-block;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

/* ===========================================
   MESSAGE CONTENT
   =========================================== */
.detail-content-wrapper {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.detail-content {
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.detail-content p {
    margin: 0 0 12px 0;
}

.detail-content p:last-child {
    margin-bottom: 0;
}

.detail-content a {
    color: var(--accent-teal);
}

.detail-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.detail-content table {
    width: 100%;
    border-collapse: collapse;
}

.detail-content td, .detail-content th {
    padding: 8px;
    border: 1px solid var(--border);
}

/* ===========================================
   ACTIONS
   =========================================== */
.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.detail-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 13px;
}

.detail-action-btn svg {
    flex-shrink: 0;
}

/* Reviewed state button */
.detail-action-btn.reviewed {
    color: var(--accent-teal);
    border-color: rgba(20, 184, 166, 0.3);
}

/* ===========================================
   TOOLTIPS
   =========================================== */
.detail-action-btn.has-tooltip {
    position: relative;
}

.detail-action-btn.has-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: normal;
    width: max-content;
    max-width: 220px;
    text-align: center;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.detail-action-btn.has-tooltip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 101;
}

.detail-action-btn.has-tooltip:hover::after,
.detail-action-btn.has-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

/* ===========================================
   MOBILE STYLES
   =========================================== */
@media (max-width: 768px) {
    .message-detail-panel {
        width: 100%;
        border-left: none;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        height: 95vh;
        top: auto;
        bottom: 0;
    }
    
    .message-detail-panel.open {
        transform: translateY(0);
    }
    
    .message-detail-header {
        padding: 12px 16px;
        border-radius: 16px 16px 0 0;
    }
    
    /* Add drag handle for mobile */
    .message-detail-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
    }
    
    .message-detail-header h2 {
        margin-left: auto;
        margin-right: auto;
    }
    
    .detail-section {
        padding: 16px;
    }
    
    .detail-meta-grid {
        gap: 12px;
    }
    
    .detail-ai-grid {
        grid-template-columns: 1fr;
    }
    
    .detail-subject {
        font-size: 16px;
    }
    
    .detail-content-wrapper {
        max-height: 200px;
    }
    
    .detail-actions {
        padding: 16px;
        gap: 8px;
    }
    
    .detail-action-btn {
        flex: 1;
        justify-content: center;
        min-width: calc(50% - 4px);
    }
}

/* ===========================================
   TABLE ROW CLICKABLE
   =========================================== */
.messages-table tbody tr {
    cursor: pointer;
    transition: background 0.15s ease;
}

.messages-table tbody tr:hover {
    background: var(--bg-hover);
}

.messages-table tbody tr:active {
    background: var(--bg-tertiary);
}

/* ===========================================
   SORTABLE COLUMNS
   =========================================== */
.messages-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
}

.messages-table th.sortable:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.messages-table th.sortable.sorted {
    color: var(--accent-teal);
    background: rgba(20, 184, 166, 0.1);
}

/* Sort indicator styling */
.messages-table th.sortable::after {
    content: '';
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
}

.messages-table th.sortable:hover::after {
    opacity: 0.6;
}

.messages-table th.sortable.sorted::after {
    opacity: 1;
}

/* ===========================================
   REAL-TIME NEW ROW ANIMATION
   =========================================== */
@keyframes newRowHighlight {
    0% { background: rgba(20, 184, 166, 0.3); }
    100% { background: transparent; }
}

.messages-table tbody tr.new-row {
    animation: newRowHighlight 2s ease-out;
}

/* Real-time connection indicator (optional) */
.realtime-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.realtime-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-teal);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.realtime-indicator.disconnected::before {
    background: #ef4444;
    animation: none;
}

/* ===========================================
   CARD HEADER (for consistent styling)
   =========================================== */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header .card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===========================================
   FILTERS BAR
   =========================================== */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-select {
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    min-width: 150px;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-teal);
}

.filter-checkbox {
    display: flex;
    align-items: flex-end;
}

.checkbox-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.checkbox-filter:hover {
    border-color: var(--border-light);
}

.checkbox-filter input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-teal);
    cursor: pointer;
}

.checkbox-filter input[type="checkbox"]:checked + span {
    color: var(--text-primary);
}

/* Filter count badges */
.filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--accent-teal);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    margin-left: 8px;
}

@media (max-width: 768px) {
    .filters-bar {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-select {
        width: 100%;
        min-width: unset;
    }
    
    .checkbox-filter {
        width: 100%;
        justify-content: center;
    }
}

/* ===========================================
   CLASSIFICATION FEEDBACK
   =========================================== */

.detail-feedback-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.detail-feedback-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.detail-feedback-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-feedback-buttons {
    display: flex;
    gap: 8px;
}

.feedback-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-btn:hover:not(:disabled) {
    border-color: var(--accent-teal);
    color: var(--accent-teal);
}

.feedback-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.feedback-btn.feedback-up.active {
    background: rgba(34, 197, 94, 0.15);
    border-color: #22c55e;
    color: #22c55e;
}

.feedback-btn.feedback-down.active {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #ef4444;
}

.detail-feedback-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 8px;
    font-size: 13px;
    color: #22c55e;
}

.detail-feedback-status svg {
    flex-shrink: 0;
}

.feedback-correction {
    padding: 2px 10px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    color: #818cf8;
}

.feedback-edit-btn {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-edit-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
}

.feedback-edit-btn svg {
    flex-shrink: 0;
}

/* ===========================================
   FEEDBACK CORRECTION MODAL
   =========================================== */

.feedback-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.feedback-modal-overlay.open {
    opacity: 1;
}

.feedback-modal-overlay.closing {
    opacity: 0;
}

.feedback-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: 420px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.feedback-modal-overlay.open .feedback-modal {
    transform: scale(1);
}

.feedback-modal h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.feedback-modal p {
    margin: 0 0 24px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.feedback-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.feedback-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.feedback-form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.feedback-form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.feedback-form-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.feedback-form-select:focus {
    outline: none;
    border-color: var(--accent-teal);
}

.feedback-form-textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease;
}

.feedback-form-textarea:focus {
    outline: none;
    border-color: var(--accent-teal);
}

.feedback-form-textarea::placeholder {
    color: var(--text-muted);
}

.feedback-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Responsive */
@media (max-width: 480px) {
    .detail-feedback-prompt {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .feedback-modal {
        padding: 20px;
    }
    
    .feedback-modal-actions {
        flex-direction: column;
    }
    
    .feedback-modal-actions .btn {
        width: 100%;
    }
}
