* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #8b5cf6;
    --accent: #ec4899;
    --bg-dark: #0f172a;
    --bg-light: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ============ АУТЕНТИФИКАЦИЯ ============ */
#auth-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
    animation: fadeIn 0.5s ease;
}

.auth-card {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.5);
    padding: 2.5rem 2rem;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
    background-size: 200% 100%;
    animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 2.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

#auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    background: #f1f5f9;
    padding: 0.35rem;
    border-radius: var(--radius-md);
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}

.tab-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-md);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.input-group {
    position: relative;
    margin-bottom: 1rem;
}

.input-group i {
    position: absolute;
    left: 1.1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    transition: color 0.3s;
    font-size: 0.95rem;
}

.input-group input {
    width: 100%;
    padding: 0.95rem 1rem 0.95rem 2.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #fafbfc;
    font-family: inherit;
    color: var(--text-primary);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.input-group input:focus + i {
    color: var(--primary);
}

.auth-btn {
    width: 100%;
    padding: 0.95rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.auth-btn:active {
    transform: translateY(0);
}

.error-message {
    color: var(--danger);
    margin-top: 1rem;
    font-size: 0.875rem;
    text-align: center;
    padding: 0.75rem;
    background: #fef2f2;
    border-radius: var(--radius-md);
    border: 1px solid #fee2e2;
}

.error-message:empty {
    display: none;
}

/* ============ ОСНОВНОЙ ЧАТ ============ */
#chat-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    background: white;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.3);
    margin: 1rem;
    animation: scaleIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============ БОКОВАЯ ПАНЕЛЬ ============ */
.sidebar {
    width: 360px;
    background: linear-gradient(180deg, #fafbff 0%, #f8fafc 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.avatar {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.3rem;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    position: relative;
    flex-shrink: 0;
}

.avatar::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success);
    border-radius: 50%;
    border: 2px solid white;
}

.avatar.small {
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
}

.avatar.small::after {
    width: 10px;
    height: 10px;
}

.user-info h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.status {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 500;
}

.status.online {
    color: var(--success);
}

.status i {
    font-size: 0.5rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.logout-btn:hover {
    background: var(--danger);
    color: white;
    transform: rotate(90deg);
}

/* ============ ПОИСК ============ */
.search-box {
    padding: 1rem 1.5rem;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    font-size: 0.9rem;
}

.search-box input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.9rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    background: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

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

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.search-results {
    padding: 0.5rem 1.5rem;
    max-height: 220px;
    overflow-y: auto;
}

.search-result-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.4rem;
    background: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid transparent;
    font-weight: 500;
    font-size: 0.9rem;
}

.search-result-item:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.search-result-item:hover .avatar {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

/* ============ СПИСОК ЧАТОВ ============ */
.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1.5rem 1rem;
}

.chats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.chats-header h4 {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
}

.chats-count {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-size: 0.7rem;
    color: white;
    font-weight: 700;
    min-width: 22px;
    text-align: center;
}

.chat-item {
    padding: 0.85rem 1rem;
    margin-bottom: 0.4rem;
    background: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    position: relative;
}

.chat-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.2);
}

.chat-item.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
    transform: translateX(4px);
}

.chat-item.active .last-message,
.chat-item.active .message-time {
    color: rgba(255, 255, 255, 0.85);
}

.chat-item.active .chat-name {
    color: white;
}

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

.chat-name {
    font-weight: 600;
    margin-bottom: 0.2rem;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.last-message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    flex-shrink: 0;
}

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

.empty-chats {
    text-align: center;
    padding: 2.5rem 1rem !important;
    color: var(--text-muted);
}

.empty-chats i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
    display: block;
}

.empty-chats p {
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
}

.empty-chats small {
    font-size: 0.8rem;
}

/* ============ ОБЛАСТЬ ЧАТА ============ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    position: relative;
}

.chat-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.03) 0%, transparent 50%);
    pointer-events: none;
}

.chat-header {
    padding: 1.25rem 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 1;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chat-header-info h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.chat-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* ============ СООБЩЕНИЯ ============ */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
    z-index: 1;
    scroll-behavior: smooth;
}

.welcome-message {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    animation: fadeIn 0.8s ease;
}

.welcome-message i {
    font-size: 4rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-message h3 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 1.3rem;
}

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

.message {
    max-width: 65%;
    margin-bottom: 0.4rem;
    animation: messageIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

.message-content {
    padding: 0.75rem 1.1rem;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 0.92rem;
}

.message.sent .message-content {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.message.received .message-content {
    background: white;
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.message-image {
    max-width: 220px;
    max-height: 220px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: block;
    margin-top: 0.3rem;
}

.message-image:hover {
    transform: scale(1.03);
}

.message-time {
    font-size: 0.68rem;
    margin-top: 0.3rem;
    opacity: 0.7;
    text-align: right;
    font-weight: 500;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.85);
}

.message.received .message-time {
    color: var(--text-muted);
}

/* ============ ОБЛАСТЬ ВВОДА ============ */
.message-input-area {
    padding: 1rem 1.5rem 1.25rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 2;
}

.attachment-preview {
    position: relative;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: var(--radius-md);
    display: inline-block;
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease;
}

.attachment-preview img {
    max-width: 140px;
    max-height: 140px;
    border-radius: var(--radius-sm);
    display: block;
}

.remove-attachment {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 26px;
    height: 26px;
    border: 2px solid white;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: transform 0.3s;
    box-shadow: var(--shadow-md);
}

.remove-attachment:hover {
    transform: scale(1.15) rotate(90deg);
}

.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.9rem;
    background: white;
    border-radius: var(--radius-lg);
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    border: 1px solid var(--border);
}

.emoji-picker button {
    width: 42px;
    height: 42px;
    border: none;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.emoji-picker button:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    transform: scale(1.15) rotate(5deg);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.message-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #f8fafc;
    border-radius: var(--radius-xl);
    padding: 0.4rem 0.4rem 0.4rem 1rem;
    border: 1.5px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message-input-wrapper:focus-within {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.7rem 0.3rem;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    color: var(--text-primary);
    line-height: 1.5;
}

#message-input::placeholder {
    color: var(--text-muted);
}

#message-input:focus {
    outline: none;
}

.action-buttons {
    display: flex;
    gap: 0.2rem;
    align-items: center;
}

.action-btn {
    width: 42px;
    height: 42px;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.action-btn:hover {
    background: white;
    color: var(--primary);
    transform: scale(1.1);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.08) rotate(-15deg);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.send-btn:active {
    transform: scale(0.95);
}

/* ============ МОДАЛЬНОЕ ОКНО ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
    animation: fadeIn 0.3s;
}

.modal-content {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: var(--radius-md);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 32px;
    color: white;
    font-size: 36px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.3s;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover {
    color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

/* ============ НЕПРОЧИТАННЫЕ ============ */
.chat-item.has-unread {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    border-left: 3px solid var(--primary);
}

.chat-item.has-unread .chat-name {
    color: var(--primary-dark);
    font-weight: 700;
}

.chat-item.has-unread .last-message {
    color: var(--text-primary);
    font-weight: 500;
}

.unread-badge {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    animation: pulse 2s infinite;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

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

@keyframes newMessageGlow {
    0% { background-color: rgba(99, 102, 241, 0.15); }
    100% { background-color: transparent; }
}

.message.new {
    animation: newMessageGlow 1s ease;
}

/* ============ СКРОЛЛБАР ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

/* ============ АДАПТИВНОСТЬ ============ */
@media (max-width: 768px) {
    #chat-container {
        flex-direction: column;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 45vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .sidebar-header {
        padding: 1rem;
    }
    
    .search-box {
        padding: 0.75rem 1rem;
    }
    
    .chats-list {
        padding: 0 1rem 1rem;
    }
    
    .message {
        max-width: 80%;
    }
    
    .message-image {
        max-width: 180px;
    }
    
    .messages {
        padding: 1rem;
    }
    
    .message-input-area {
        padding: 0.75rem 1rem 1rem;
    }
    
    .chat-header {
        padding: 1rem;
    }
}

/* ============ АНИМАЦИИ ============ */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error-message:not(:empty) {
    animation: shake 0.4s ease;
}
/* ============================================
   D2PANEL — ДОПОЛНИТЕЛЬНЫЕ СТИЛИ
   ============================================ */

/* Фикс — фиксированный размер сообщений */
.message {
    max-width: 65% !important;
    width: fit-content;
    margin-bottom: 0.5rem;
    animation: messageIn 0.3s ease;
}

.message-content {
    padding: 0.7rem 1rem;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.45;
    font-size: 0.9rem;
}

.message.sent .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.25);
}

.message.received .message-content {
    background: white;
    color: #1e293b;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
}

.message-image {
    max-width: 100%;
    max-height: 320px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
    margin-top: 4px;
    transition: transform 0.3s;
}

.message-image:hover {
    transform: scale(1.02);
}

/* Сообщения — контейнер */
.messages {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

/* Строка сообщения не растягивается */
.messages > * {
    flex-shrink: 0;
}

/* ============================================
   САЙДБАР — заголовки разделов и элементы
   ============================================ */

#app {
    display: flex;
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin: 1rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 0.6rem 0.5rem;
    margin: 0.75rem 0 0.4rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.section-header:hover {
    background: #f1f5f9;
}

.section-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-header .toggle-icon {
    font-size: 0.7rem;
    color: #94a3b8;
    transition: transform 0.2s;
    display: inline-block;
}

.section-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.section-header .add-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    transition: transform 0.2s;
}

.section-header .add-btn:hover {
    transform: scale(1.1);
}

.section-content {
    overflow: hidden;
    max-height: 2000px;
    transition: max-height 0.35s ease-out;
}

.section-content.collapsed {
    max-height: 0 !important;
}

/* ============================================
   КАНАЛЫ — карточки
   ============================================ */

#channels-list .chat-item {
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.35rem;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s;
    border: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

#channels-list .chat-item:hover {
    transform: translateX(3px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

#channels-list .chat-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

#channels-list .chat-item.active .chat-name {
    color: white;
}

#channels-list .chat-info {
    flex: 1;
    min-width: 0;
}

#channels-list .chat-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Кнопка удаления */
.delete-btn {
    background: #fee2e2;
    color: #dc2626;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.2s;
    flex-shrink: 0;
}

.delete-btn:hover {
    background: #dc2626;
    color: white;
    transform: scale(1.15);
}

/* ============================================
   БОТЫ — карточки
   ============================================ */

.bot-card {
    background: white;
    padding: 0.6rem 0.75rem;
    margin: 0.35rem 0;
    border-radius: 10px;
    border-left: 3px solid #667eea;
    font-size: 0.8rem;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #667eea;
}

.bot-card .bot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.bot-card .bot-header b {
    font-size: 0.85rem;
    color: #1e293b;
}

.bot-card .token-text {
    font-family: 'Courier New', monospace;
    color: #64748b;
    word-break: break-all;
    font-size: 0.7rem;
    background: #f1f5f9;
    padding: 0.3rem 0.5rem;
    border-radius: 5px;
    margin: 0.3rem 0;
    line-height: 1.3;
}

.bot-card button:not(.delete-btn) {
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 0.2rem;
    transition: transform 0.2s;
}

.bot-card button:not(.delete-btn):hover {
    transform: scale(1.05);
}

/* ============================================
   ГРУППЫ БОТОВ
   ============================================ */

.bot-group-card {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    padding: 0.65rem 0.8rem;
    margin: 0.4rem 0;
    border-radius: 10px;
    border-left: 3px solid #f59e0b;
    font-size: 0.8rem;
}

.bot-group-card .bot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.bot-group-card .bot-header b {
    font-size: 0.85rem;
    color: #78350f;
}

.bot-group-members {
    color: #92400e;
    font-size: 0.72rem;
    margin: 0.3rem 0;
    line-height: 1.35;
    word-break: break-word;
}

.group-btn {
    background: #f59e0b;
    color: white;
    padding: 0.25rem 0.6rem;
    font-size: 0.7rem;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    margin-right: 0.3rem;
    margin-top: 0.2rem;
    transition: all 0.2s;
}

.group-btn:hover {
    background: #d97706;
    transform: scale(1.05);
}

/* ============================================
   ПОИСК
   ============================================ */

.search-result-item {
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.3rem;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid #e2e8f0;
    font-size: 0.85rem;
    font-weight: 500;
    color: #1e293b;
}

.search-result-item:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: translateX(3px);
}

.search-result-item .avatar.small {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
}

/* ============================================
   СКРОЛЛБАР В САЙДБАРЕ — потоньше
   ============================================ */

.chats-list::-webkit-scrollbar,
#search-results::-webkit-scrollbar,
.messages::-webkit-scrollbar {
    width: 6px;
}

.chats-list::-webkit-scrollbar-thumb,
#search-results::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chats-list::-webkit-scrollbar-thumb:hover,
#search-results::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ============================================
   АДАПТИВ
   ============================================ */

@media (max-width: 768px) {
    #app {
        flex-direction: column;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .message {
        max-width: 80% !important;
    }
}
/* ============================================
   ФОН ЧАТА — КАРТИНКА fon.jpeg
   ============================================ */

.chat-area {
    background: url('/fon.jpeg') center/cover no-repeat fixed !important;
    position: relative;
}

.chat-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(2px);
    pointer-events: none;
    z-index: 0;
}

.chat-area > * {
    position: relative;
    z-index: 1;
}

.chat-header {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(15px);
}

.messages {
    background: transparent !important;
}

.message-input-area {
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(15px);
}

/* Если хотите чтобы фон был ярче — уменьшите прозрачность */
/* .chat-area::before { background: rgba(255, 255, 255, 0.4); } */

/* ============================================
   КАСТОМНЫЕ МОДАЛЬНЫЕ ОКНА
   ============================================ */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.custom-modal {
    background: white;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.custom-modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.custom-modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.custom-modal-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg);
}

.custom-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.custom-modal-body label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 0.5rem;
}

.custom-modal-body input[type="text"],
.custom-modal-body input[type="password"],
.custom-modal-body textarea {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #1e293b;
    background: #fafbfc;
    transition: all 0.2s;
    outline: none;
    margin-bottom: 1rem;
}

.custom-modal-body input:focus,
.custom-modal-body textarea:focus {
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.custom-modal-body textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

/* Список ботов для выбора */
.bot-select-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 320px;
    overflow-y: auto;
    padding: 0.25rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #fafbfc;
}

.bot-select-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1.5px solid transparent;
    user-select: none;
}

.bot-select-item:hover {
    background: #f1f5f9;
}

.bot-select-item.selected {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    border-color: #667eea;
}

.bot-select-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #667eea;
    margin: 0;
}

.bot-select-item .bot-select-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}

.bot-select-item .bot-select-id {
    font-size: 0.72rem;
    color: #94a3b8;
    font-family: monospace;
}

.custom-modal-footer {
    padding: 1rem 1.5rem 1.25rem;
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    border-top: 1px solid #e2e8f0;
    background: #fafbfc;
}

.btn-secondary {
    padding: 0.7rem 1.3rem;
    background: white;
    color: #475569;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.btn-primary {
    padding: 0.7rem 1.4rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
/* ============================================
   КАСТОМНЫЕ УВЕДОМЛЕНИЯ (confirm / alert)
   ============================================ */

.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    border-radius: 12px;
    padding: 0.9rem 1.1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 280px;
    max-width: 420px;
    animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
    font-size: 0.9rem;
    font-weight: 500;
    color: #1e293b;
    border-left: 4px solid #6366f1;
}

.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #ef4444; }
.toast.info { border-left-color: #6366f1; }

.toast i {
    font-size: 1.15rem;
}
.toast.success i { color: #10b981; }
.toast.error i { color: #ef4444; }
.toast.info i { color: #6366f1; }

.toast.hide {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Кастомный confirm */
.confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    z-index: 2500;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: white;
    border-radius: 18px;
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.confirm-box-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.confirm-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.confirm-icon.danger {
    background: #fee2e2;
    color: #dc2626;
}

.confirm-icon.warning {
    background: #fef3c7;
    color: #d97706;
}

.confirm-icon.info {
    background: #e0e7ff;
    color: #4f46e5;
}

.confirm-box h4 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
}

.confirm-box p {
    margin: 0 0 1.25rem;
    color: #64748b;
    font-size: 0.9rem;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
}

.btn-danger {
    padding: 0.7rem 1.3rem;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Кастомный prompt */
.prompt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    z-index: 2500;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.prompt-overlay.active {
    display: flex;
}

.prompt-box {
    background: white;
    border-radius: 18px;
    padding: 1.5rem;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.prompt-box h4 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
}

.prompt-box input {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fafbfc;
    outline: none;
    margin-bottom: 1.25rem;
    color: #1e293b;
    transition: all 0.2s;
}

.prompt-box input:focus {
    border-color: #6366f1;
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}
