* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(180deg, #f5f7fa 0%, #c3cfe2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chat-container {
    width: 100%;
    max-width: 480px;
    height: 90vh;
    max-height: 700px; /* Максимальная высота */
    min-height: 500px; /* Минимальная высота */
    margin: 20px auto;
    background: #ffffff;
    border-radius: 22px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1.5px solid #e0e0e0;
}

.chat-header {
    padding: 18px 24px;
    background: linear-gradient(180deg, #46637f 0%, #5a7b9a 100%);
    color: #e0e0e0;
    font-size: 1.2em;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: relative;
    z-index: 2;
    transition: box-shadow 0.2s;
}
.chat-header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWK4dzAAAAD0lEQVQIW2NkYGD4/38AAwABAAMBsIgSAAAAAABJRU5ErkJggg==');
    opacity: 0.15;
    z-index: -1;
}
.chat-header:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.chat-header .chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    border: 2.5px solid rgba(255,255,255,0.8);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    background: #f7f9fa;
    transition: box-shadow 0.2s;
}
.chat-header .chat-header-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.chat-header .chat-title {
    font-size: 1em;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: fadeIn 0.5s;
    color: #e0e0e0;
}
.chat-header .chat-users-count {
    font-size: 0.8em;
    opacity: 0.9;
    margin-top: 2px;
    color: rgba(224,224,224,0.7);
    font-weight: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f7f9fa;
    position: relative;
    /* Убираем max-height - пусть flex сам управляет */
    min-height: 200px; /* Минимальная высота */
}

.message {
    max-width: 82%;
    padding: 14px 20px;
    border-radius: 20px;
    position: relative;
    word-break: break-word;
    font-size: 1.04em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    margin-bottom: 2px;
    transition: box-shadow 0.2s, background 0.2s;
    opacity: 1;
    background: #f0f4f8;
    border: 1px solid #e0e0e0;
    animation: fadeInMsg 0.4s;
}
@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
.message.received {
    align-self: flex-start;
    background-color: #f0f4f8; /* Very light blue */
    border-radius: 12px 12px 12px 4px;
}
.message.sent {
    align-self: flex-end;
    background-color: #e8f0f7; /* Slightly more saturated light blue */
    border-radius: 12px 12px 4px 12px;
}
.message:hover {
    background-color: #e0eaf5; /* Slightly darker on hover */
}
.message .user-info {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    gap: 8px;
}
.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 8px;
    border: 1.5px solid #cfd8dc;
    background: #fff;
    object-fit: cover;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.message .username {
    font-weight: 600;
    color: #46637f;
    font-size: 1em;
}
.message .timestamp {
    font-size: 0.78em;
    color: #b0b0b0;
    margin-top: 6px;
    text-align: right;
    letter-spacing: 0.2px;
}
.message-text a {
    color: #5a7b9a;
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s;
}
.message-text a:hover {
    color: #5a7b9a;
}
.message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.typing-indicator {
    padding: 10px 20px;
    color: #666;
    font-style: italic;
    background: #f0f2f5;
    border-radius: 12px;
    width: fit-content;
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 80px; /* Над полем ввода */
    width: calc(100% - 32px);
    text-align: left;
    pointer-events: none;
    z-index: 10;
    background: rgba(240, 242, 245, 0.95);
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 0;
    transition: opacity 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.typing-indicator.visible {
    opacity: 1;
}
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.typing-dots::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #666;
    border-radius: 50%;
    animation: typingDot1 1.4s infinite ease-in-out;
}
.typing-dots::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #666;
    border-radius: 50%;
    margin-right: 4px;
    animation: typingDot2 1.4s infinite ease-in-out;
}

@keyframes typingDot1 {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes typingDot2 {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    20% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes typingDots {
    0%, 80%, 100% {
        content: '';
    }
    20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60% {
        content: '...';
    }
}

.chat-input {
    padding: 16px;
    background: #f0f2f5;
    display: flex;
    gap: 12px;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
    flex-shrink: 0; /* Предотвращаем сжатие поля ввода */
    position: relative; /* Убираем sticky если был */
    bottom: 0;
    width: 100%;
}
.chat-input input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid #cfd8dc;
    border-radius: 22px;
    outline: none;
    font-size: 1.04em;
    background: #fff;
    transition: border 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.chat-input input:focus {
    border: 1px solid #5a7b9a;
    box-shadow: 0 2px 8px rgba(90,123,154,0.2);
}
.chat-input button {
    padding: 12px 24px;
    background: linear-gradient(180deg, #5a7b9a 0%, #46637f 100%);
    color: #fff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.04em;
    transition: background 0.3s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(70,99,127,0.2);
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.chat-input button::after {
    content: '\27A4';
    font-size: 1.1em;
}
.chat-input button:hover {
    background: linear-gradient(180deg, #46637f 0%, #5a7b9a 100%);
    box-shadow: 0 4px 12px rgba(70,99,127,0.3);
}

/* --- Модальные окна и страницы --- */
.chat-main-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%; /* Заполняем всю доступную высоту */
    min-height: 0; /* Важно для правильной работы flex */
}

.chat-info-view {
    flex: 1;
    background: #f7f9fa;
    overflow-y: auto;
    position: relative;
    width: 100%;
    display: none; /* По умолчанию скрыто */
    height: 100%; /* Заполняем всю доступную высоту */
}

/* Убеждаемся что одновременно показывается только один вид */
.chat-main-view.hidden {
    display: none !important;
}

.chat-info-view.visible {
    display: flex !important;
    flex-direction: column;
}

.chat-info-content, .chat-users-content {
    padding: 20px;
    max-width: 100%;
    height: 100%;
    overflow-y: auto;
}

.chat-info-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: #5a7b9a;
    font-size: 1em;
    cursor: pointer;
    padding: 8px 0;
    margin-bottom: 20px;
    transition: color 0.2s ease;
    font-weight: 500;
    text-decoration: none;
}

.chat-info-back:hover {
    color: #46637f;
}

.chat-info-main {
    text-align: center;
    padding: 20px 0;
}

.chat-info-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin: 0 auto 20px auto;
    display: block;
    border: 4px solid #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    object-fit: cover;
}

.chat-info-title {
    margin: 0 0 16px 0;
    font-size: 1.8em;
    color: #46637f;
    font-weight: 700;
}

.chat-info-description {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
    font-size: 1em;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.chat-info-link {
    margin-bottom: 30px;
    padding: 12px;
    background: #e8f4fd;
    border-radius: 12px;
    border: 1px solid #d0e7ff;
}

.chat-info-link a {
    color: #5a7b9a;
    text-decoration: underline;
    word-break: break-all;
    font-size: 1em;
    font-weight: 500;
}

.chat-info-members-title {
    font-weight: 600;
    margin: 30px 0 20px 0;
    color: #46637f;
    text-align: left;
    font-size: 1.2em;
    border-bottom: 1px solid #e8eef5;
    padding-bottom: 10px;
}

.chat-info-users-list {
    text-align: left;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chat-info-user {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #f0f4f8;
    transition: background-color 0.2s;
}

.chat-info-user:last-child {
    border-bottom: none;
}

.chat-info-user:hover {
    background-color: #f8f9fa;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    margin-right: 16px;
    border: 2px solid #fff;
    background: #fff;
    object-fit: cover;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.user-name {
    font-weight: 500;
    color: #46637f;
    font-size: 1.1em;
}

.show-all-users-btn {
    display: inline-block;
    margin: 20px auto;
    padding: 12px 24px;
    background: linear-gradient(180deg, #5a7b9a 0%, #46637f 100%);
    color: #fff;
    text-decoration: none;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    font-weight: 500;
    box-shadow: 0 3px 12px rgba(90,123,154,0.3);
}

.show-all-users-btn:hover {
    background: linear-gradient(180deg, #46637f 0%, #5a7b9a 100%);
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(90,123,154,0.4);
}

.chat-users-title {
    margin: 0 0 24px 0;
    font-size: 1.6em;
    color: #46637f;
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid #5a7b9a;
    padding-bottom: 12px;
}

.chat-users-list {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .chat-container {
        height: 100vh;
        max-height: 100vh;
        min-height: 100vh;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }
    body {
        align-items: flex-start;
        background: #fff; /* White background on mobile */
    }
    .chat-header {
        padding: 16px 18px;
    }
    .chat-messages {
        padding: 16px 12px;
        min-height: 0; /* На мобильных убираем минимальную высоту */
    }
    .chat-input {
        padding: 10px;
        gap: 6px; /* Reduced gap */
    }
    .chat-input button {
        padding: 8px 12px; /* Further reduced padding */
        font-size: 0.9em; /* Further reduced font size */
    }
    .chat-input input {
        padding: 8px 10px; /* Further reduced padding */
        font-size: 0.9em; /* Further reduced font size */
    }
    .chat-header .chat-avatar {
         width: 40px;
         height: 40px;
         margin-right: 8px;
    }
    .typing-indicator {
        bottom: 60px; /* Меньше на мобильных */
        left: 12px;
        right: 12px;
        width: calc(100% - 24px);
    }
    .chat-info-content, .chat-users-content {
        padding: 16px;
    }
     .chat-info-users-list {
         margin-top: 16px;
     }
    .chat-info-user {
        padding: 8px 0;
    }
    .chat-info-user img {
        width: 28px;
        height: 28px;
        margin-right: 10px;
    }
}

.message.new-since-last-visit {
    animation: newMessageHighlight 2s ease-out;
    background-color: #e8f0f7;
    border: 1px solid #5a7b9a;
}

@keyframes newMessageHighlight {
    0% {
        background-color: #e8f0f7;
        transform: translateY(10px);
    }
    50% {
        background-color: #d4e4f7;
    }
    100% {
        background-color: #e8f0f7;
        transform: translateY(0);
    }
}

/* Состояния отправки сообщений пользователя */
.message.sending {
    opacity: 0.7;
    background: #e8f0f7;
    border: 1px solid #b3d4fc;
}

.message.send-error {
    background: #ffebee;
    border: 1px solid #ffcdd2;
    animation: errorShake 0.5s ease-in-out;
}

.message-status {
    font-size: 0.75em;
    color: #999;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
}

.message-status.error {
    color: #f44336;
}

.message-status.sending {
    color: #1976d2;
}

/* Индикатор загрузки */
.loading-indicator {
    width: 14px;
    height: 14px;
    border: 2px solid #e3f2fd;
    border-top: 2px solid #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Иконка ошибки */
.error-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #f44336;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    flex-shrink: 0;
}

.error-icon::before {
    content: '!';
}

/* Анимация ошибки */
@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
} 