/* ============================================
   MSFG Dashboard - Chat Styles
   Company chat interface with tag system
   ============================================ */

/* ========================================
   CHAT CONTAINER
======================================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 500px;
}

/* ========================================
   TAG FILTER BAR (top of chat)
======================================== */
.chat-tag-filter-bar {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    overflow-x: auto;
    flex-shrink: 0;
}

.chat-tag-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.chat-tag-btn:hover {
    border-color: var(--tag-color, var(--green-bright));
    color: var(--tag-color, var(--green-bright));
}

.chat-tag-btn.active {
    background: var(--tag-color, var(--green-bright));
    color: white;
    border-color: var(--tag-color, var(--green-bright));
}

.chat-tag-all {
    --tag-color: var(--green-forest);
}

.chat-tag-create {
    border-style: dashed;
    color: var(--text-muted);
}

.chat-tag-create:hover {
    border-color: var(--green-bright);
    color: var(--green-bright);
    background: var(--bg-tertiary);
}

/* ========================================
   CHAT MESSAGES AREA
======================================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: var(--spacing-sm);
}

.chat-empty i {
    font-size: 2rem;
    opacity: 0.4;
}

.chat-empty p {
    font-size: 0.85rem;
}

/* ========================================
   CHAT MESSAGE
======================================== */
.chat-message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
}

.chat-message.own {
    flex-direction: row-reverse;
    margin-left: auto;
}

/* Chat Avatar */
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-brand);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Chat Bubble */
.chat-bubble {
    background: var(--bg-tertiary);
    padding: 0.75rem var(--spacing-md);
    border-radius: var(--radius-xl);
    border-top-left-radius: var(--radius-sm);
    position: relative;
}

.chat-message.own .chat-bubble {
    background: var(--green-bright);
    color: white;
    border-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-sm);
}

/* Chat Sender Name */
.chat-sender {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.chat-message.own .chat-sender {
    color: rgba(255,255,255,0.8);
}

/* Chat Text */
.chat-text {
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

/* Chat Meta (time + edited label) */
.chat-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: 0.25rem;
}

.chat-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.chat-message.own .chat-time {
    color: rgba(255,255,255,0.7);
}

.chat-edited {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-style: italic;
}

.chat-message.own .chat-edited {
    color: rgba(255,255,255,0.6);
}

/* ========================================
   MESSAGE ACTION BUTTONS (hover toolbar)
======================================== */
.chat-msg-actions {
    position: absolute;
    top: -10px;
    right: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 2px;
    box-shadow: var(--shadow-sm);
    z-index: 5;
}

.chat-message.own .chat-msg-actions {
    right: auto;
    left: 4px;
}

.chat-message:hover .chat-msg-actions {
    opacity: 1;
    pointer-events: auto;
}

.chat-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    line-height: 1;
}

.chat-action-btn:hover {
    color: var(--green-bright);
    background: var(--bg-tertiary);
}

.chat-delete-btn:hover {
    color: var(--status-danger);
}

/* ========================================
   EDIT INDICATOR BAR
======================================== */
.chat-edit-bar {
    display: none;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0.35rem var(--spacing-md);
    background: var(--bg-tertiary);
    border-top: 2px solid var(--green-bright);
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-edit-bar i {
    color: var(--green-bright);
}

.chat-edit-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chat-edit-cancel:hover {
    color: var(--status-danger);
    background: var(--bg-primary);
}

/* ========================================
   FILE ATTACHMENTS (in messages)
======================================== */
.chat-attachments {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-top: 0.5rem;
}

.chat-attachment-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    background: rgba(0,0,0,0.08);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    max-width: 260px;
}

.chat-message.own .chat-attachment-card {
    background: rgba(255,255,255,0.15);
}

.chat-attach-icon {
    font-size: 1rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-message.own .chat-attach-icon {
    color: rgba(255,255,255,0.8);
}

.chat-attach-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-attach-name {
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attach-size {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.chat-message.own .chat-attach-size {
    color: rgba(255,255,255,0.6);
}

.chat-attach-download,
.chat-attach-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 3px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-attach-download:hover {
    color: var(--green-bright);
}

.chat-attach-delete:hover {
    color: var(--status-danger);
}

.chat-message.own .chat-attach-download,
.chat-message.own .chat-attach-delete {
    color: rgba(255,255,255,0.5);
}

.chat-message.own .chat-attach-download:hover {
    color: white;
}

.chat-message.own .chat-attach-delete:hover {
    color: #ff6b6b;
}

/* ========================================
   PENDING FILES (below input)
======================================== */
.chat-pending-files {
    display: none;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.375rem var(--spacing-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-pending-file {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-pending-file i:first-child {
    color: var(--green-bright);
    font-size: 0.7rem;
}

.chat-pending-file span {
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-pending-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.65rem;
    padding: 1px 2px;
    line-height: 1;
}

.chat-pending-remove:hover {
    color: var(--status-danger);
}

/* ========================================
   ATTACH BUTTON
======================================== */
.chat-attach-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    align-self: center;
}

.chat-attach-btn:hover {
    border-color: var(--green-bright);
    color: var(--green-bright);
    background: var(--bg-tertiary);
}

/* Message Tags */
.chat-msg-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.375rem;
}

.chat-msg-tag {
    display: inline-block;
    padding: 1px 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 600;
    background: var(--tag-color, var(--green-bright));
    color: white;
    opacity: 0.9;
}

/* ========================================
   TAG PICKER (above input)
======================================== */
.chat-tag-picker-bar {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: var(--spacing-xs) var(--spacing-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
    overflow-x: auto;
}

.chat-tag-picker-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chat-tag-picker-label i {
    font-size: 0.65rem;
}

.chat-tag-picker {
    display: flex;
    gap: 0.25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.chat-tag-picker-empty {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

.chat-tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 0.5rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--tag-color, var(--green-bright));
    background: transparent;
    color: var(--tag-color, var(--green-bright));
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.chat-tag-pill:hover {
    background: var(--tag-color, var(--green-bright));
    color: white;
}

.chat-tag-pill.selected {
    background: var(--tag-color, var(--green-bright));
    color: white;
}

/* ========================================
   TAG EDIT POPOVER
======================================== */
.chat-tag-popover {
    position: absolute;
    bottom: 100%;
    left: 0;
    z-index: 100;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}

.chat-tag-popover-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--spacing-xs);
}

.chat-tag-popover-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 180px;
    overflow-y: auto;
}

.chat-tag-popover-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
}

.chat-tag-popover-item:hover {
    background: var(--bg-tertiary);
}

.chat-tag-popover-item input[type="checkbox"] {
    accent-color: var(--green-bright);
}

.chat-tag-popover-empty {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: var(--spacing-xs);
}

.chat-tag-popover-actions {
    display: flex;
    gap: var(--spacing-xs);
    justify-content: flex-end;
    margin-top: var(--spacing-xs);
    padding-top: var(--spacing-xs);
    border-top: 1px solid var(--border-color);
}

/* ========================================
   CHAT INPUT AREA
======================================== */
.chat-input-row {
    display: flex;
    gap: 0.75rem;
    padding: var(--spacing-sm) var(--spacing-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 0.6rem var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.chat-input:focus {
    border-color: var(--green-bright);
    box-shadow: 0 0 0 3px rgba(140, 198, 62, 0.2);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

/* Send Button */
.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(140, 198, 62, 0.4);
}

/* ========================================
   CHAT TYPING INDICATOR (Future)
======================================== */
.chat-typing {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ========================================
   TAG FILTER HINT (empty state)
======================================== */
.chat-tag-filter-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0;
}

.chat-tag-filter-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

/* ========================================
   MANAGE TAGS MODAL
======================================== */
.manage-tags-create {
    margin-bottom: var(--spacing-md);
}

.manage-tags-create-row {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.manage-tags-create-row .form-input {
    flex: 1;
}

.manage-tags-color-input {
    width: 40px !important;
    height: 36px;
    padding: 2px !important;
    border-radius: var(--radius-sm) !important;
    cursor: pointer;
    flex: 0 0 40px !important;
}

.manage-tags-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.manage-tags-empty i {
    font-size: 2rem;
    opacity: 0.3;
    margin-bottom: var(--spacing-sm);
    display: block;
}

.manage-tags-empty p {
    font-size: 0.85rem;
}

.manage-tags-table {
    width: 100%;
    border-collapse: collapse;
}

.manage-tags-row {
    border-bottom: 1px solid var(--border-color);
}

.manage-tags-row td {
    padding: 0.5rem 0.25rem;
    vertical-align: middle;
}

.manage-tags-actions-cell {
    text-align: right;
    width: 50px;
}

/* ========================================
   RESPONSIVE
======================================== */
@media (max-width: 768px) {
    .chat-container {
        height: 400px;
    }

    .chat-message {
        max-width: 92%;
    }

    .chat-tag-popover {
        min-width: 170px;
    }
}

/* ========================================
   FLOATING CHAT FAB
======================================== */
.chat-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(140, 198, 62, 0.4);
    transition: all var(--transition-fast);
    z-index: 998;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(140, 198, 62, 0.5);
}

.chat-fab.is-open {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    box-shadow: var(--shadow-md);
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--status-danger);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-secondary);
}

/* ========================================
   FLOATING CHAT PANEL
======================================== */
.chat-float-panel {
    position: fixed;
    bottom: 5rem;
    right: 1.5rem;
    width: 400px;
    height: 520px;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all var(--transition-normal);
    overflow: hidden;
}

.chat-float-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-float-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-float-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.chat-float-title i {
    color: var(--green-bright);
}

.chat-float-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.chat-float-close {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-float-close:hover {
    background: var(--status-danger);
    color: white;
    border-color: var(--status-danger);
}

/* Override chat-container height inside floating panel */
.chat-float-panel .chat-container {
    flex: 1;
    height: auto;
    min-height: 0;
}

@media (max-width: 480px) {
    .chat-float-panel {
        width: calc(100vw - 2rem);
        right: 1rem;
        bottom: 4.5rem;
        height: 60vh;
    }
}
