/* Chat Styles */

.chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    background-color: rgba(var(--surface-color-rgb), 0.9);
    border: 1px solid var(--primary-color-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 990;
    transition: height var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
    overflow: hidden;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    resize: both;
    min-width: 250px;
    min-height: 50px;
    max-width: 80vw;
    max-height: 80vh;
}

/* Dragging state */
.chat-container.dragging {
    opacity: 0.9;
    box-shadow: var(--shadow-xl);
    transition: none; /* Disable transitions during drag for better performance */
    cursor: move;
}

/* Special handling for fullscreen mode */
:fullscreen .chat-container,
:-webkit-full-screen .chat-container,
:-moz-full-screen .chat-container,
:-ms-fullscreen .chat-container {
    position: absolute;
    z-index: 990;
}

/* When document has fullscreen class */
html.is-fullscreen .chat-container {
    position: fixed;
    z-index: 990;
}

.chat-container.collapsed {
    height: 50px;
    resize: none;
}

.chat-container.expanded {
    height: 300px;
    resize: both;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background-color: var(--primary-color);
    cursor: move; /* Indicate draggable */
    position: relative;
    transition: background-color var(--transition-fast) ease;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    user-select: none; /* Prevent text selection during drag */
}

.chat-header:hover {
    background-color: var(--primary-color-light);
}

/* Remove the chat-header arrow since we're using the toggle button now */
.chat-header::after {
    display: none;
}

.latest-message {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Chat toggle and notification */
.chat-controls {
    display: flex;
    align-items: center;
    position: relative;
}

.chat-toggle {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-circle);
    background-color: var(--secondary-color);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background-color var(--transition-fast) ease;
}

.chat-toggle:hover {
    background-color: var(--accent-color);
}

/* Add up/down arrow to chat toggle */
.chat-toggle::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 8px solid var(--text-primary);
    transition: transform var(--transition-fast) ease;
}

.chat-container.expanded .chat-toggle::before {
    transform: rotate(180deg);
}

/* Separate unread badge */
.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    background-color: var(--error-color);
    color: white;
    border-radius: 8px;
    font-size: 10px;
    font-weight: bold;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    z-index: 9999; /* Ensure it's on top of everything */
    line-height: 1;
    box-sizing: border-box;
    pointer-events: none;
}

/* Show badge when has-unread is present */
.chat-container.has-unread .chat-unread-badge {
    display: flex;
}

/* Remove the old pseudo-element badge */
.chat-toggle.has-unread::after {
    display: none;
}

.chat-body {
    display: flex;
    flex-direction: column;
    height: calc(100% - 50px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    background-color: rgba(0, 0, 0, 0.2);
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color-light) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--primary-color-light);
    border-radius: var(--radius-lg);
}

.chat-message {
    margin-bottom: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    background-color: var(--primary-color);
    word-break: break-word;
    box-shadow: var(--shadow-sm);
    animation: message-fade-in var(--transition-normal) ease;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
}

.chat-user {
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 3px;
    width: 100%;
}

.chat-text {
    color: var(--text-primary);
    font-size: 0.95rem;
    flex-grow: 1;
    margin-right: var(--space-sm);
}

.chat-time {
    color: var(--text-tertiary);
    font-size: 0.7rem;
    margin-left: var(--space-md);
    white-space: nowrap;
}

.chat-notification {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    margin: var(--space-md) 0;
    font-style: italic;
}

/* Local system messages (only visible to the current user) */
.chat-local-system {
    text-align: center;
    color: var(--accent-color);
    font-size: 0.85rem;
    margin: var(--space-md) 0;
    font-style: italic;
    background-color: rgba(var(--accent-color-rgb), 0.1);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-color);
}

/* Command links in chat messages */
.command-link {
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast) ease;
    display: inline-block;
    margin: 2px 0;
}

.command-link:hover {
    background-color: rgba(var(--accent-color-rgb), 0.2);
    text-decoration: none;
}

.command-link:active {
    background-color: rgba(var(--accent-color-rgb), 0.3);
    transform: translateY(1px);
}

/* Command Popup Styles */
.command-popup {
    position: fixed;
    background-color: rgba(var(--surface-color-rgb), 0.95);
    border: 1px solid var(--primary-color-light);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    width: 90%;
    max-width: 300px;
    z-index: 980;
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    transition: opacity var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1), 
                transform var(--transition-normal) cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    user-select: none;
    transform: translateY(10px);
    bottom: 60px;
    left: 10px;
    will-change: transform, opacity;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.command-popup.dragging {
    opacity: 0.9;
    box-shadow: var(--shadow-xl);
    transition: none; /* Disable transitions during drag for better performance */
    cursor: move;
}

.command-popup-header {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.command-popup-header span:last-child {
    cursor: pointer;
    padding: 0 var(--space-sm);
    color: var(--text-tertiary);
    font-size: 1rem;
    transition: color var(--transition-fast) ease;
}

.command-popup-header span:last-child:hover {
    color: var(--text-primary);
}

.command-popup-list {
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: var(--space-sm);
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color-light) transparent;
}

.command-popup-list::-webkit-scrollbar {
    width: 6px;
}

.command-popup-list::-webkit-scrollbar-track {
    background: transparent;
}

.command-popup-list::-webkit-scrollbar-thumb {
    background-color: var(--primary-color-light);
    border-radius: var(--radius-lg);
}

.command-popup-list .no-results {
    padding: var(--space-sm);
    color: var(--text-tertiary);
    text-align: center;
    font-style: italic;
}

.command-popup-list > div {
    padding: var(--space-sm);
    cursor: pointer;
    border-radius: var(--radius-md);
    margin: 2px 0;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-fast) ease;
}

.command-popup-list > div:hover {
    background-color: var(--primary-color);
}

.command-popup-list > div > div:first-child {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.command-popup-list > div > div:last-child {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.chat-form {
    display: flex;
    padding: var(--space-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background-color: var(--primary-color-dark);
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast) ease, box-shadow var(--transition-fast) ease;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(var(--accent-color-rgb), 0.2);
    background-color: rgba(0, 0, 0, 0.3);
}

.chat-send {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-circle);
    background-color: var(--secondary-color);
    border: none;
    margin-left: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color var(--transition-fast) ease;
    position: relative;
}

/* Add right arrow to send button */
.chat-send::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid var(--text-primary);
}

.chat-send:hover {
    background-color: var(--accent-color);
}
