:root {
    --bg-dark: #0f0f1a;
    --bg-panel: #1a1a2e;
    --bg-panel-light: #24243e;
    --bg-input: #2a2a42;
    --text-primary: #ffffff;
    --text-secondary: #b0b0cc;
    --accent: #6c3dfd;
    --accent-hover: #5a2de0;
    --accent-light: rgba(108, 61, 253, 0.15);
    --border: #2e2e4a;
    --online: #4ade80;
    --offline: #6b7280;
    --unread-badge: #6c3dfd;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    height: 100vh;
    overflow: hidden;
    background: var(--bg-dark);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(108, 61, 253, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(108, 61, 253, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(108, 61, 253, 0.06) 0%, transparent 50%);
    color: var(--text-primary);
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ============ ЛЕВАЯ ПАНЕЛЬ (SIDEBAR) ============ */
.sidebar {
    width: 320px;
    min-width: 280px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 10;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel-light);
    border-bottom: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 0 0 2px rgba(108, 61, 253, 0.4);
}

.avatar.online::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: var(--online);
    border: 2px solid var(--bg-panel-light);
    border-radius: 50%;
}

.avatar.group {
    background: #8b5cf6;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.btn-icon:hover {
    background: var(--accent-hover);
}

.search-bar {
    padding: 12px 16px;
    position: relative;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.search-bar input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    font-size: 14px;
    outline: none;
    transition: all var(--transition);
    color: var(--text-primary);
}

.search-bar input::placeholder {
    color: #8a8aa0;
}

.search-bar input:focus {
    border-color: var(--accent);
    background: var(--bg-panel-light);
    box-shadow: 0 0 0 4px rgba(108, 61, 253, 0.1);
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 16px;
    pointer-events: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-panel);
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.chat-item:hover {
    background: var(--bg-panel-light);
}

.chat-item.active {
    background: var(--accent-light);
}

.chat-item .avatar {
    width: 46px;
    height: 46px;
    font-size: 20px;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-name {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-item-name .online-dot {
    width: 8px;
    height: 8px;
    background: var(--online);
    border-radius: 50%;
    display: inline-block;
}

.chat-item-last-message {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.unread-badge {
    background: var(--unread-badge);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 6px rgba(108, 61, 253, 0.4);
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h2 {
    color: var(--text-primary);
    font-size: 20px;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

/* ============ ПРАВАЯ ПАНЕЛЬ (CHAT AREA) ============ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    transition: transform 0.3s ease;
    min-width: 0;
}

.chat-header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 5;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px;
    margin-right: 4px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.chat-header-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-header-status.online {
    color: var(--online);
    font-weight: 500;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.message-own {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-other {
    align-self: flex-start;
    background: var(--bg-panel-light);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    text-align: right;
    margin-top: 4px;
}

.message-other .message-time {
    color: var(--text-secondary);
}

.typing-indicator {
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    border-top: 1px solid var(--border);
}

.message-input-container {
    padding: 12px 16px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.message-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 40px;
    line-height: 1.4;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: all var(--transition);
}

.message-input::placeholder {
    color: #8a8aa0;
}

.message-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(108, 61, 253, 0.1);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:disabled {
    background: #3a3a5c;
    cursor: not-allowed;
}

/* ============ МОДАЛЬНЫЕ ОКНА ============ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayAppear 0.2s ease;
}

@keyframes overlayAppear {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-panel);
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: 420px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalAppear 0.3s ease;
}

@keyframes modalAppear {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-panel-light);
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-content {
    display: none;
    padding: 20px;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

.field-group {
    margin-bottom: 16px;
}

.field-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.input-wrapper {
    width: 100%;
}

.input-wrapper input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all var(--transition);
}

.input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 61, 253, 0.1);
}

.input-wrapper input::placeholder {
    color: #8a8aa0;
}

.search-results {
    margin-top: 8px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
}

.empty-result {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.user-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.user-result-item:hover {
    background: var(--bg-panel-light);
}

.user-result-item .avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
}

.user-result-info {
    flex: 1;
    min-width: 0;
}

.user-result-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.user-result-username {
    font-size: 12px;
    color: var(--text-secondary);
}

.selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    min-height: 30px;
}

.selected-user-tag {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-light);
    color: var(--accent);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

.selected-user-tag .remove-user {
    cursor: pointer;
    font-size: 14px;
    transition: color var(--transition);
}

.selected-user-tag .remove-user:hover {
    color: var(--error);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: #3a3a5c;
    cursor: not-allowed;
}

/* ============ АДАПТИВНОСТЬ ============ */
@media (max-width: 767px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        transform: translateX(0);
        z-index: 20;
    }

    .chat-area {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        transform: translateX(100%);
        z-index: 30;
    }

    .app-container.show-chat .sidebar {
        transform: translateX(-100%);
    }

    .app-container.show-chat .chat-area {
        transform: translateX(0);
    }

    .back-btn {
        display: block;
    }
}
/* ============ СООБЩЕНИЯ (дополнено) ============ */
.message {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.message-own {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-other {
    align-self: flex-start;
    background: var(--bg-panel-light);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}

.message-text {
    word-wrap: break-word;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    text-align: right;
    margin-top: 4px;
}

.message-other .message-time {
    color: var(--text-secondary);
}

/* ============ РЕЗУЛЬТАТЫ ПОИСКА (дополнено) ============ */
.user-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.user-result:hover {
    background: var(--bg-panel-light);
}

.user-result .avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
}

.user-result span {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
}

/* Кнопки внутри результатов */
.btn-small,
.btn-select,
.btn-add {
    padding: 4px 10px;
    border-radius: 6px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: white;
    transition: background var(--transition);
}

.btn-small:hover,
.btn-select:hover,
.btn-add:hover {
    background: var(--accent-hover);
}

/* ============ ВЫБРАННЫЕ ПОЛЬЗОВАТЕЛИ (дополнено) ============ */
.selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    min-height: 30px;
}

.selected-user-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-light);
    color: var(--accent);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.selected-user-chip:hover {
    background: rgba(108, 61, 253, 0.25);
}

/* ============ ПРОЧИЕ УТОЧНЕНИЯ ============ */
.chat-avatar {
    /* Можно использовать вместо .avatar, если нужно */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}
@media (min-width: 768px) {
    .back-btn {
        display: none;
    }
}