/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --secondary-color: #6B7280;
    --background: #F9FAFB;
    --surface: #FFFFFF;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --success: #10B981;
    --error: #EF4444;
    --message-user: #4F46E5;
    --message-other: #F3F4F6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --input-bg: #FFFFFF;
    --sidebar-bg: #FFFFFF;
    --modal-bg: #FFFFFF;
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --primary-color: #6366F1;
    --primary-hover: #818CF8;
    --secondary-color: #9CA3AF;
    --background: #111827;
    --surface: #1F2937;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --border: #374151;
    --success: #34D399;
    --error: #F87171;
    --message-user: #6366F1;
    --message-other: #374151;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --input-bg: #374151;
    --sidebar-bg: #1F2937;
    --modal-bg: #1F2937;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
}

#app {
    height: 100vh;
    overflow: hidden;
}

.screen {
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
}

.logo {
    text-align: center;
    margin-bottom: 2rem;
    color: white;
}

.logo h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.logo p {
    font-size: 1rem;
    opacity: 0.9;
}

#login-form,
.oauth-login-container {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
}

.btn-oauth {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 2rem;
    font-size: 1rem;
}

.login-footer {
    margin-top: 1.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: var(--surface);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
}

.btn-text:hover {
    color: var(--text-primary);
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--primary-hover);
}

/* Chat Container */
.chat-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--background);
}

.conversation-item.active {
    background: rgba(79, 70, 229, 0.1);
    border-left: 3px solid var(--primary-color);
}

/* Empty state */
.no-conversations {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.no-conversations p {
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.no-conversations small {
    font-size: 0.75rem;
}

/* Conversation item layout */
.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.25rem;
}

.conversation-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-item h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 0.5rem;
}

.conversation-item p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin: 0;
}

.conversation-item .time {
    font-size: 0.625rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* Message count badge */
.message-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--primary-color);
    color: white;
    border-radius: 9px;
    font-size: 0.625rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* Has unread styling */
.conversation-item.has-unread {
    background: rgba(79, 70, 229, 0.05);
}

.conversation-item.has-unread h4 {
    font-weight: 600;
}

.conversation-item.has-unread p {
    color: var(--text-primary);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.admin-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, #7C3AED 100%);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.admin-link:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    opacity: 0.95;
}

.admin-link svg {
    flex-shrink: 0;
}

.user-info {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.welcome-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
}

.welcome-panel h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.welcome-panel p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.welcome-panel .btn-primary {
    width: auto;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.9375rem;
}

.message.user {
    align-self: flex-end;
    background: var(--message-user);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.other {
    align-self: flex-start;
    background: var(--message-other);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: linear-gradient(135deg, #7C3AED 0%, #4F46E5 100%);
    color: white;
    border-bottom-left-radius: 4px;
}

.message .sender {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.message .time {
    font-size: 0.625rem;
    opacity: 0.7;
    margin-top: 0.25rem;
    text-align: right;
}

/* Message Footer with Read Receipt */
.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.message-footer .time {
    margin-top: 0;
}

.message-footer .read-check {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
}

.message.user .read-check {
    color: rgba(255, 255, 255, 0.9);
}

.read-indicator {
    font-size: 0.625rem;
    opacity: 0.7;
    text-align: right;
    margin-top: 0.25rem;
    font-style: italic;
}

/* Markdown Styles */
.message .content code {
    background: rgba(0, 0, 0, 0.15);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85em;
}

.message.user .content code {
    background: rgba(255, 255, 255, 0.2);
}

.message .content pre {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message.user .content pre {
    background: rgba(255, 255, 255, 0.15);
}

.message .content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1.4;
}

.message .content strong {
    font-weight: 600;
}

.message .content em {
    font-style: italic;
}

.message .content a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.9;
}

.message .content a:hover {
    opacity: 1;
}

.message.ai .content a {
    color: #A5D6FF;
}

/* Message Input */
.message-input-container {
    padding: 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

#message-form {
    display: flex;
    gap: 0.75rem;
}

#message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 0.9375rem;
    transition: border-color 0.2s;
}

#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-send {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-send:hover {
    background: var(--primary-hover);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-content.modal-small {
    max-width: 400px;
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    padding: 1rem;
}

.ai-response {
    background: var(--background);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

#ai-form {
    display: flex;
    gap: 0.75rem;
}

#ai-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9375rem;
}

#ai-form .btn-primary {
    width: auto;
}

/* Loading States */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--message-other);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    max-width: 200px;
    align-self: flex-start;
}

.typing-indicator.hidden {
    display: none !important;
}

.typing-indicator .typing-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* AI Typing Indicator - special styling */
.typing-indicator.ai-typing {
    background: linear-gradient(135deg, #7C3AED 0%, #4F46E5 100%);
}

.typing-indicator.ai-typing .typing-name {
    color: rgba(255, 255, 255, 0.8);
}

.typing-indicator.ai-typing .typing-dots span {
    background: white;
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 500;
    z-index: 100;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.connection-status.show {
    transform: translateY(0);
}

.connection-status.connected {
    background: var(--success);
    color: white;
}

.connection-status.disconnected {
    background: var(--error);
    color: white;
}

.connection-status.reconnecting {
    background: #F59E0B;
    color: white;
}

/* Online Indicator */
.online-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary-color);
    margin-left: 6px;
    vertical-align: middle;
    transition: background 0.3s ease;
}

.online-indicator.online {
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.online-count {
    font-size: 0.75rem;
    color: var(--success);
    font-weight: 500;
}

/* User info with online status */
.user-info {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Load More Button */
.load-more-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.btn-load-more {
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--primary-color);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-load-more:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-load-more:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Search Functionality */
.search-container {
    display: flex;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.search-container input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease;
}

.search-container input:focus {
    border-color: var(--primary-color);
}

.search-container input::placeholder {
    color: var(--text-secondary);
}

.btn-search {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.btn-search:hover {
    background: var(--primary-hover);
}

.search-results {
    max-height: 300px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border);
}

.search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.search-loading,
.search-error,
.search-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-error {
    color: var(--error);
}

.search-results-list {
    display: flex;
    flex-direction: column;
}

.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.search-result-item:hover {
    background: var(--surface);
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.search-result-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.search-result-sender.ai {
    color: var(--primary-color);
}

.search-result-time {
    font-size: 0.625rem;
    color: var(--text-secondary);
}

.search-result-content {
    font-size: 0.8125rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.search-result-content mark {
    background: #FEF08A;
    color: inherit;
    padding: 0.1rem 0.2rem;
    border-radius: 2px;
}

.search-result-conv {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Message highlight when navigating from search */
.message.highlight {
    animation: highlightPulse 2s ease-out;
}

@keyframes highlightPulse {
    0% {
        box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.4);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
    }
}

/* File Attachments */
.btn-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-attach:hover {
    background: var(--background);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-attach:disabled,
.btn-attach.uploading {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-attach.uploading svg {
    animation: spin 1s linear infinite;
}

#message-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Message Attachments */
.message-attachments {
    margin-top: 0.5rem;
}

.attachment {
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.attachment:last-child {
    margin-bottom: 0;
}

.attachment-image {
    max-width: 300px;
}

.attachment-image img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.attachment-image img:hover {
    opacity: 0.9;
}

.attachment-info {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.7;
}

.attachment-file {
    background: var(--background);
    border: 1px solid var(--border);
}

.message.user .attachment-file {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.attachment-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: inherit;
}

.attachment-link:hover {
    background: rgba(0, 0, 0, 0.05);
}

.message.user .attachment-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.attachment-icon {
    font-size: 1.5rem;
}

.attachment-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.attachment-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-size {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Message Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    background: var(--message-other);
    border: 1px solid var(--border);
    border-radius: 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.reaction-btn:hover {
    background: var(--border);
    border-color: var(--primary-color);
}

.reaction-btn.user-reacted {
    background: rgba(79, 70, 229, 0.1);
    border-color: var(--primary-color);
}

.reaction-emoji {
    font-size: 1rem;
}

.reaction-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-react {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0;
    transition: all 0.2s;
    margin-left: 0.5rem;
}

.message:hover .btn-react {
    opacity: 1;
}

.btn-react:hover {
    background: var(--border);
    color: var(--primary-color);
}

.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: fadeIn 0.15s ease-out;
}

.message.user .reaction-picker {
    left: auto;
    right: 0;
}

.reaction-picker-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.15s;
}

.reaction-picker-btn:hover {
    background: var(--message-other);
    transform: scale(1.2);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(0.5rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Message Edit/Delete */
.content-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
}

.message-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.message:hover .message-actions {
    opacity: 1;
}

.btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.btn-action:hover {
    background: var(--border);
}

.btn-edit:hover {
    color: var(--primary-color);
}

.btn-delete:hover {
    color: #ef4444;
}

.edited-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-left: 0.5rem;
}

.message.deleted .message-content {
    color: var(--text-secondary);
    font-style: italic;
}

.message.deleted .message-actions {
    display: none;
}

/* Inline Edit Form */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.edit-textarea {
    width: 100%;
    min-height: 3rem;
    padding: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    resize: vertical;
    background: var(--surface);
    color: var(--text);
}

.edit-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.edit-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.btn-cancel,
.btn-save {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: var(--border);
    color: var(--text);
}

.btn-save {
    background: var(--primary-color);
    border: none;
    color: white;
}

.btn-save:hover {
    background: var(--primary-dark);
}

/* Notification Toggle */
.notification-toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.toggle-label svg {
    opacity: 0.7;
}

.toggle-checkbox {
    position: relative;
    width: 2.5rem;
    height: 1.25rem;
    appearance: none;
    background: var(--border);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-checkbox:checked {
    background: var(--primary-color);
}

.toggle-checkbox::before {
    content: '';
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1rem;
    height: 1rem;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-checkbox:checked::before {
    transform: translateX(1.25rem);
}

.toggle-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Theme Toggle */
.theme-toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* Export Modal */
.export-description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9375rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.export-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.export-option:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.export-option:hover svg {
    stroke: white;
}

.export-option svg {
    flex-shrink: 0;
    stroke: var(--text-secondary);
}

.export-label {
    font-weight: 600;
    font-size: 1rem;
}

.export-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.export-option:hover .export-desc {
    color: rgba(255, 255, 255, 0.8);
}

/* Export button styling */
#export-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#export-btn svg {
    stroke: currentColor;
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 5;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.2s;
}

.mobile-menu-btn:hover {
    background: var(--bg-tertiary);
}

.mobile-menu-btn svg {
    display: block;
}

/* Mobile overlay when sidebar is open */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}

.sidebar-overlay.active {
    display: block;
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .chat-actions {
        gap: 0.5rem;
    }

    .btn-secondary {
        padding: 0.4rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .chat-container {
        position: relative;
    }

    .sidebar {
        width: 85%;
        max-width: 320px;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-header {
        padding: 1rem;
    }

    .sidebar-header h2 {
        font-size: 1.1rem;
    }

    .sidebar-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 1rem;
    }

    .sidebar-footer .user-info {
        text-align: center;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid var(--border-color);
    }

    .notification-toggle-container,
    .theme-toggle-container {
        justify-content: space-between;
    }

    .sidebar-footer #logout-btn {
        width: 100%;
        text-align: center;
        padding: 0.75rem;
        margin-top: 0.5rem;
        background: var(--bg-tertiary);
        border-radius: 6px;
    }

    .chat-main {
        width: 100%;
    }

    .welcome-panel {
        padding: 2rem 1rem;
        padding-top: 4rem;
    }

    .welcome-panel h2 {
        font-size: 1.5rem;
    }

    .chat-panel {
        padding-top: 0;
    }

    .chat-header {
        padding: 0.75rem 1rem;
        padding-left: 3.5rem;
    }

    .chat-header h3 {
        font-size: 1rem;
    }

    .chat-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .chat-actions .btn-secondary {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    #export-btn span,
    #export-btn svg + span {
        display: none;
    }

    #export-btn {
        padding: 0.5rem;
    }

    .messages-container {
        padding: 1rem;
    }

    .message {
        max-width: 90%;
    }

    .message-input-container {
        padding: 0.75rem;
    }

    .message-input-container form {
        gap: 0.5rem;
    }

    #message-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .btn-send {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .btn-attach {
        padding: 0.5rem;
    }

    /* Modal responsive */
    .modal-content {
        width: 95%;
        max-width: 400px;
        margin: 1rem;
        max-height: 90vh;
    }

    .modal-content.modal-small {
        width: 90%;
    }

    .export-options {
        flex-direction: column;
        gap: 0.75rem;
    }

    .export-option {
        padding: 1rem;
    }

    /* Search results */
    .search-results {
        max-height: 40vh;
    }

    /* Conversation items */
    .conversation-item {
        padding: 0.75rem;
    }

    .conversation-item h4 {
        font-size: 0.9rem;
    }

    .conversation-item p {
        font-size: 0.8rem;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        max-width: none;
    }

    .chat-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding-left: 3.5rem;
    }

    .chat-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .welcome-panel h2 {
        font-size: 1.25rem;
    }

    .welcome-panel p {
        font-size: 0.9rem;
    }

    .login-container {
        padding: 1.5rem;
    }

    .logo h1 {
        font-size: 2rem;
    }
}

/* ====================================
   NEW FEATURE STYLES (Phase 15)
   - Channel Selector
   - Notification Center
   - Participants Modal
   - Invite via Channel Modal
   ==================================== */

/* Chat Header Layout */
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.chat-header-left h3 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Channel Selector */
.channel-selector {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.75rem;
}

.channel-selector:hover {
    border-color: var(--primary-color);
}

.channel-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

[data-theme="dark"] .channel-selector {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* Sidebar Action Buttons */
.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-notification,
.btn-participants {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-notification:hover,
.btn-participants:hover {
    background: var(--background);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-notification svg,
.btn-participants svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--error);
    color: white;
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: 9px;
    animation: badgePulse 2s ease-in-out infinite;
}

.notification-badge.hidden {
    display: none;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Notification Center Modal */
.notification-center .modal-content {
    max-width: 450px;
}

.notification-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
}

.notification-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.notification-tab:hover {
    color: var(--text-primary);
}

.notification-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.notification-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.btn-mark-all {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-mark-all:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-mark-all svg {
    width: 14px;
    height: 14px;
}

.notification-list {
    max-height: 400px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s ease;
}

.notification-item:hover {
    background: var(--background);
}

.notification-item.unread {
    background: rgba(79, 70, 229, 0.05);
}

.notification-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.notification-icon.message {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

.notification-icon.mention {
    background: rgba(245, 158, 11, 0.1);
    color: #F59E0B;
}

.notification-icon.system {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.notification-icon.alert {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.notification-body {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-time {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.notification-item.unread .notification-title {
    font-weight: 600;
}

.notification-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: var(--primary-color);
    border-radius: 0 2px 2px 0;
}

.notification-item {
    position: relative;
}

.notification-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    text-align: center;
}

.notification-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.notification-empty p {
    font-size: 0.9375rem;
    font-weight: 500;
}

.notification-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Participants Modal */
.participants-modal .modal-content {
    max-width: 500px;
}

.participants-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.participants-search input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.participants-search input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.participants-search input::placeholder {
    color: var(--text-secondary);
}

.participants-list {
    max-height: 350px;
    overflow-y: auto;
}

.participant-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s ease;
}

.participant-item:hover {
    background: var(--background);
}

.participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #7C3AED 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.participant-info {
    flex: 1;
    min-width: 0;
}

.participant-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.participant-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.participant-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary-color);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.status-dot.away {
    background: #F59E0B;
}

.status-dot.offline {
    background: var(--secondary-color);
}

.btn-add-participant {
    padding: 0.375rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-add-participant:hover {
    background: var(--primary-hover);
}

.participants-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.invite-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.btn-invite-channel {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-invite-channel:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-invite-channel svg {
    width: 14px;
    height: 14px;
}

.participants-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    text-align: center;
}

.participants-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Invite Modal */
.invite-modal .modal-content {
    max-width: 400px;
}

.invite-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group.invite-field {
    margin-bottom: 0;
}

.invite-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.invite-field input,
.invite-field textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-family: inherit;
}

.invite-field input:focus,
.invite-field textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.invite-field textarea {
    min-height: 100px;
    resize: vertical;
}

.invite-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.invite-actions .btn-secondary {
    flex: 1;
}

.invite-actions .btn-primary {
    flex: 2;
}

.channel-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--background);
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.channel-badge svg {
    width: 16px;
    height: 16px;
}

.channel-badge.sms {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.channel-badge.email {
    background: rgba(59, 130, 246, 0.1);
    color: #3B82F6;
}

.channel-badge.whatsapp {
    background: rgba(37, 211, 102, 0.1);
    color: #25D366;
}

.channel-badge.telegram {
    background: rgba(0, 136, 204, 0.1);
    color: #0088CC;
}

/* Responsive for new components */
@media (max-width: 768px) {
    .chat-header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .channel-selector {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
        padding-right: 1.5rem;
    }

    .sidebar-actions {
        gap: 0.25rem;
    }

    .btn-notification,
    .btn-participants {
        width: 32px;
        height: 32px;
    }

    .btn-notification svg,
    .btn-participants svg {
        width: 16px;
        height: 16px;
    }

    .notification-center .modal-content,
    .participants-modal .modal-content,
    .invite-modal .modal-content {
        width: 95%;
        max-height: 85vh;
    }

    .notification-tabs {
        flex-wrap: wrap;
    }

    .notification-tab {
        flex: 1 1 33%;
        padding: 0.5rem;
        font-size: 0.75rem;
        text-align: center;
    }

    .notification-list,
    .participants-list {
        max-height: 50vh;
    }

    .notification-item {
        padding: 0.75rem;
    }

    .notification-icon {
        width: 32px;
        height: 32px;
    }

    .participant-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.75rem;
    }

    .invite-options {
        flex-direction: column;
    }

    .btn-invite-channel {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .sidebar-actions {
        margin-top: 0.5rem;
    }

    .notification-badge {
        min-width: 16px;
        height: 16px;
        font-size: 0.625rem;
    }

    .notification-title {
        font-size: 0.8125rem;
    }

    .notification-body {
        font-size: 0.75rem;
    }

    .participant-name {
        font-size: 0.8125rem;
    }

    .participant-role {
        font-size: 0.6875rem;
    }
}
