/* Общие стили */
:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    color: var(--text);
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-container {
    display: flex;
    height: 100vh;
    gap: 1px;
}

/* --- Левая колонка (сайдбар) --- */
.sidebar {
    width: 340px;
    min-width: 340px;
    max-width: 340px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    margin: 12px 0 12px 12px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border-light);
    background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
}

.sidebar-header h2 {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.025em;
}

.bot-filter {
    margin-top: 16px;
}

.bot-select {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 16px 16px;
    padding-right: 40px;
}

.bot-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.logout-btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: #fef2f2;
}

.filter-btn {
    padding: 6px 12px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    border-radius: 15px;
    cursor: pointer;
    margin-right: 6px;
    font-size: 12px;
}

.filter-btn.active {
    background-color: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}

.dialog-list {
    overflow-y: auto;
    scrollbar-gutter: stable both-edges;
    flex-grow: 1;
    padding: 8px 0;
}

.dialog-item {
    padding: 16px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.2s ease;
    position: relative;
}

.dialog-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: var(--border-light);
}

.dialog-item:last-child::after {
    display: none;
}

.dialog-item.active {
    background: linear-gradient(90deg, var(--primary-light) 0%, rgba(59, 130, 246, 0.1) 100%);
    border-left: 3px solid var(--primary);
}

.dialog-item:hover:not(.active) {
    background: var(--border-light);
}

/* Аватарка пользователя */
.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: var(--primary);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.dialog-item .details {
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.dialog-item .top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.dialog-item .user-display {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-item .last-time {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 500;
}

.dialog-item .bot-id {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.dialog-item .middle-row {
    display: flex;
    align-items: center;
    margin: 6px 0 4px 0;
}

.dialog-item .client-message-preview {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.dialog-item .bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.direction-badge {
    font-size: 10px;
    font-weight: 600;
    border-radius: 12px;
    padding: 3px 8px;
    letter-spacing: 0.025em;
    text-transform: uppercase;
}
.direction-badge.in { 
    background: #f0fdf4; 
    color: #15803d; 
}
.direction-badge.out { 
    background: #eff6ff; 
    color: var(--primary); 
}


/* --- Правая колонка (окно чата) --- */
.chat-window {
    flex: 1;
    min-width: 0;
    width: calc(100vw - 340px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-lg);
    margin: 12px 12px 12px 0;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
    position: sticky;
    top: 0;
    z-index: 10;
}

.message-list {
    flex-grow: 1;
    overflow-y: auto;
    scrollbar-gutter: stable both-edges;
    padding: 24px;
    background: #fafbfc;
}

.message {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message .bubble {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
}

.message .meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    font-weight: 500;
}

/* Сообщение от пользователя */
.message.in {
    align-items: flex-start;
}
.message.in .bubble {
    background: #f3f4f6;
    color: var(--text);
    border-bottom-left-radius: 6px;
}
.message.in .meta {
    align-self: flex-start;
    margin-left: 4px;
}

/* Сообщение от бота */
.message.out {
    align-items: flex-end;
}
.message.out .bubble {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    border-bottom-right-radius: 6px;
}
.message.out .meta {
    align-self: flex-end;
    margin-right: 4px;
}

/* --- Новые стили --- */

/* Статус подключения */
.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    background: var(--border-light);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--warning);
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background-color: var(--success);
    animation: none;
}

.status-indicator.disconnected {
    background-color: var(--danger);
    animation: pulse 1s infinite;
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

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

/* Обновленный заголовок чата */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

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

.header-stats {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Модальное окно для уведомлений */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: none;
    border-radius: 8px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
}

/* Кастомные скроллбары */
.dialog-list::-webkit-scrollbar,
.message-list::-webkit-scrollbar {
    width: 6px;
}

.dialog-list::-webkit-scrollbar-track,
.message-list::-webkit-scrollbar-track {
    background: transparent;
}

.dialog-list::-webkit-scrollbar-thumb,
.message-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.dialog-list::-webkit-scrollbar-thumb:hover,
.message-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Улучшения для мобильных устройств */
@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
        gap: 0;
        padding: 0;
    }
    
    .sidebar {
        width: 100%;
        height: 200px;
        margin: 0;
        border-radius: 0;
    }
    
    .chat-window {
        height: calc(100vh - 200px);
        margin: 0;
        border-radius: 0;
    }
}
