:root {
    --bg-gradient: linear-gradient(135deg, #051937 0%, #004d7a 100%);
    /* Deep Ocean Teal */
    --glass-bg: rgba(0, 0, 0, 0.4);
    /* Slightly darker for better contrast */
    --glass-border: rgba(64, 224, 208, 0.2);
    /* Turquoise tint border */
    --glass-highlight: rgba(64, 224, 208, 0.1);
    --text-primary: #e0fbfb;
    --text-secondary: #8ec5c5;
    --accent-primary: #00ced1;
    /* Dark Turquoise */
    --accent-hover: #20b2aa;
    /* Light Sea Green */
    --accent-glow: rgba(0, 206, 209, 0.4);
    --msg-me-bg: #008b8b;
    /* Dark Cyan */
    --msg-them-bg: rgba(255, 255, 255, 0.08);
    --danger: #ff6b6b;
    --success: #00fa9a;
    /* Medium Spring Green */
    --font-main: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

body {
    background: var(--bg-gradient);
    height: 100vh;
    color: var(--text-primary);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Utilities */
.hidden {
    display: none !important;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--glass-highlight);
    color: var(--text-primary);
}

.btn-primary {
    background: var(--accent-primary);
    border: none;
    color: #002b36;
    /* Dark text for contrast on bright turquoise */
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
}

.btn-secondary:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Glass Components */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Login Screen */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity 0.5s ease;
}

.login-card {
    width: 400px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeIn 0.8s ease;
}

.logo-area {
    text-align: center;
    margin-bottom: 20px;
}

.logo-area i {
    font-size: 3rem;
    color: var(--accent-primary);
    margin-bottom: 10px;
}

.input-group label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.input-group input,
input[type="text"],
input[type="password"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    border-radius: 12px;
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus,
input[type="text"]:focus {
    border-color: var(--accent-primary);
}

/* Main Interface */
.glass-container {
    width: 95vw;
    height: 90vh;
    background: var(--glass-bg);
    backdrop-filter: blur(40px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    display: flex;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 320px;
    background: rgba(0, 0, 0, 0.2);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
}

.brand-header {
    padding: 20px 20px 0 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-header h2 {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 700;
}

.brand-header i {
    font-size: 1.5rem;
    color: var(--accent-primary);
}

.sidebar-header {
    padding: 15px 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info h3 {
    font-size: 1rem;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.search-bar {
    margin: 0 20px 20px;
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 0 12px;
}

.search-bar i {
    color: var(--text-secondary);
}

.search-bar input {
    background: transparent;
    border: none;
    padding: 12px;
    color: var(--text-primary);
    width: 100%;
}

.search-bar input:focus {
    outline: none;
}

.nav-tabs {
    display: flex;
    padding: 0 20px;
    gap: 20px;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 10px;
}

.nav-tab {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px 0;
    cursor: pointer;
    position: relative;
    font-weight: 500;
}

.nav-tab.active {
    color: var(--accent-primary);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent-primary);
}

.list-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

.list-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    /* Enable truncation */
}

.list-top,
.list-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.list-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.list-status {
    display: flex;
    align-items: center;
    margin-left: 6px;
}

.list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.list-item.active {
    background: rgba(0, 206, 209, 0.15);
    border: 1px solid rgba(0, 206, 209, 0.3);
}

.create-group-btn {
    padding: 12px;
    margin: 0 10px 10px;
    border-radius: 10px;
    background: rgba(0, 206, 209, 0.1);
    color: var(--accent-primary);
    text-align: center;
    cursor: pointer;
    font-size: 0.9em;
    border: 1px dashed var(--glass-border);
}

.avatar-circle {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #203a43, #2c5364);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.1);
    position: relative;
    height: 100%;
}

.chat-area.empty {
    justify-content: center;
    align-items: center;
}

/* FIX: Removed '.active' dependency causing layout break */
.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 10px;
    opacity: 0.5;
    color: var(--accent-primary);
}

.chat-header {
    padding: 15px 25px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    /* Header stays fixed size */
}

.messages-container {
    flex: 1;
    /* Takes remaining space */
    overflow-y: auto;
    /* Enables scroll */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    /* Crucial for nested flex scrolling */
}

.message {
    max-width: 60%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    line-height: 1.4;
    position: relative;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.message-text {
    white-space: pre-wrap;
    /* Preserve newlines */
    word-wrap: break-word;
    /* Ensure long words wrap */
}

.message.me {
    align-self: flex-end;
    background: var(--msg-me-bg);
    border-bottom-right-radius: 4px;
}

.message.them {
    align-self: flex-start;
    background: var(--msg-them-bg);
    border-bottom-left-radius: 4px;
}

.message img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
}

/* Reply Context Inside Message */
.msg-reply-context {
    border-left: 2px solid rgba(255, 255, 255, 0.5);
    padding-left: 8px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Input Area */
.input-area {
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    /* Footer stays fixed size */
}

.input-area input,
.input-area textarea {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    color: white;
    padding: 12px;
    border: none;
    resize: none;
    /* Prevent manual resize */
    font-family: inherit;
    /* Ensure font matches */
    outline: none;
    max-height: 120px;
    /* Optional cap */
}

/* Reply Bar */
.reply-bar {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid var(--accent-primary);
    flex-shrink: 0;
}

.reply-label {
    font-size: 0.75rem;
    color: var(--accent-primary);
    display: block;
}

.reply-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    width: 400px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(64, 224, 208, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(64, 224, 208, 0.4);
}

/* Image Viewer */
.image-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.image-viewer.active {
    opacity: 1;
    pointer-events: auto;
}

.image-viewer img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.image-viewer.active img {
    transform: scale(1);
}

.close-viewer {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.close-viewer:hover {
    background: rgba(255, 255, 255, 0.3);
}

.unread-badge {
    background: var(--accent-primary);
    color: #002b36;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    box-shadow: 0 2px 5px var(--accent-glow);
}

/* Drag and Drop Visual Feedback */
.chat-interface.drag-active {
    border: 2px dashed var(--accent-primary) !important;
    background: rgba(0, 206, 209, 0.1);
    position: relative;
}

.chat-interface.drag-active::after {
    content: 'Перетащите файлы сюда для отправки';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--accent-primary);
    font-size: 1.5rem;
    font-weight: 700;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.chat-interface.drag-active * {
    pointer-events: none;
    /* Prevent child elements from flickering drag events */
    opacity: 0.5;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 80px;
    left: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    width: 250px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.emoji-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 8px;
    transition: background 0.2s;
}

.emoji-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 15px;
    background: var(--msg-them-bg);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    position: absolute;
    bottom: 80px;
    /* Above input area */
    left: 20px;
    pointer-events: none;
    z-index: 50;
}

.typing-indicator.active {
    opacity: 1;
    transform: translateY(0);
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 8px;
    width: 200px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: fadeIn 0.1s ease;
}

.context-item {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 10px 12px;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.context-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.context-item i {
    font-size: 1.1rem;
    color: var(--accent-primary);
}

.context-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 4px 0;
}

.context-reactions {
    display: flex;
    justify-content: space-between;
    padding: 4px;
}

.reaction-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reaction-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}