/* Основные стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: #ebedf0;
    color: #000;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: #fff;
    min-height: 100vh;
}

/* Заголовок */
.header {
    background-color: #5181b8;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 20px;
    font-weight: 500;
}

.stats {
    font-size: 14px;
    opacity: 0.9;
}

/* Список диалогов */
.dialogs-list {
    background-color: #fff;
}

.dialog-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #e7e8ec;
    text-decoration: none;
    color: inherit;
    position: relative;
    transition: background-color 0.2s;
}

.dialog-item:hover {
    background-color: #f5f7fa;
}

.dialog-item.unanswered {
    background-color: #f0f2f5;
}

.dialog-avatar {
    margin-right: 12px;
}

.avatar-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #5181b8;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 500;
}

.dialog-content {
    flex: 1;
    min-width: 0;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.dialog-name {
    font-weight: 500;
    color: #2a5885;
}

.dialog-time {
    font-size: 13px;
    color: #939393;
}

.dialog-preview {
    font-size: 14px;
    color: #656565;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-author {
    color: #939393;
}

.unread-indicator {
    width: 8px;
    height: 8px;
    background-color: #5181b8;
    border-radius: 50%;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* Страница чата */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

.chat-header {
    background-color: #5181b8;
    color: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.back-button {
    color: white;
    text-decoration: none;
    font-size: 16px;
    margin-right: 20px;
}

.back-button:hover {
    opacity: 0.8;
}

.chat-user-info {
    margin-right: auto;
}

.chat-user-info h2 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 2px;
}

.user-id {
    font-size: 13px;
    opacity: 0.8;
}

.vk-link {
    color: white;
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    transition: all 0.2s;
}

.vk-link:hover {
    background-color: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

.client-card-button {
    color: white;
    background-color: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 15px;
}

.client-card-button:hover {
    background-color: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

.reminders-button {
    color: white;
    background-color: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 15px;
}

.reminders-button:hover {
    background-color: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

/* Контейнер сообщений */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #fff;
}

.message {
    margin-bottom: 15px;
    display: flex;
}

.message.user {
    justify-content: flex-start;
}

.message.bot,
.message.operator,
.message.newsletter {
    justify-content: flex-end;
}

.message-content {
    max-width: 85%;
    position: relative;
}

.message-text {
    padding: 8px 12px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-text {
    background-color: #ebedf0;
    color: #000;
}

.message.bot .message-text {
    background-color: #4a76a8;
    color: white;
}

.message.operator .message-text {
    background-color: #28a745;
    color: white;
}

.message.newsletter .message-text {
    background-color: #e85959;
    color: white;
}

.message-time {
    font-size: 12px;
    color: #939393;
    margin-top: 4px;
    padding: 0 12px;
}

.message.bot .message-time,
.message.operator .message-time,
.message.newsletter .message-time {
    text-align: right;
}

/* Поле ввода */
.input-container {
    border-top: 1px solid #e7e8ec;
    padding: 15px 20px;
    background-color: #fafbfc;
    display: flex;
    gap: 5px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #d3d9de;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 70vh;
    overflow-y: hidden; /* Изменено с auto на hidden, чтобы JS управлял появлением */
    transition: height 0.1s ease-out;
}

#messageInput:focus {
    border-color: #5181b8;
}

#sendButton {
    padding: 10px 20px;
    background-color: #5181b8;
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

#sendButton:hover:not(:disabled) {
    background-color: #4a76a8;
}

#sendButton:disabled {
    background-color: #d1d5db;
    border-color: #d1d5db;
    cursor: not-allowed;
}

#emoji-picker-button {
    background: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    color: #828282;
    transition: color 0.2s;
}

#emoji-picker-button:hover {
    color: #5181b8;
}

/* Emoji Picker Styles */
emoji-picker {
    position: absolute;
    bottom: 85px; /* Position it above the input bar */
    right: 20px;
    z-index: 100;
    --num-columns: 8;
    --emoji-size: 24px;
    --border-radius: 12px;
    --category-font-size: 14px;
    --background: #fff;
    --box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    /* Hide the preview section */
    --preview-height: 0px;
    --preview-padding: 0px;
    /* Ensure scrollbar is visible if content overflows */
    max-height: 300px;
    overflow-y: auto;
}


/* Общие мобильные стили (все ориентации) */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chat-header {
        padding: 8px 12px;
        flex-wrap: nowrap;
        gap: 8px;
    }
    
    .chat-user-info h2 {
        font-size: 16px;
    }
    
    .chat-user-info {
        margin-right: 8px;
        flex: 1;
        min-width: 0;
    }
    
    /* Скрываем ID пользователя на мобильной версии */
    .user-id {
        display: none;
    }
    
    /* Полностью отключаем тултипы для всех устройств */
    .client-card-button::after,
    .reminders-button::after,
    .vk-link::after,
    .back-button::after,
    .client-card-button:hover::after,
    .reminders-button:hover::after,
    .vk-link:hover::after,
    .back-button:hover::after {
        display: none !important;
        content: none !important;
    }
}

/* Портретная ориентация (вертикальный экран) - только иконки */
@media (max-width: 768px) and (orientation: portrait) {
    /* Стили для кнопок-иконок в портретной ориентации */
    .back-button {
        margin-right: 8px;
        padding: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: rgba(255,255,255,0.1);
        border: 1px solid rgba(255,255,255,0.2);
        font-size: 16px;
    }
    
    .client-card-button {
        margin-right: 4px;
        padding: 0;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0;
        position: relative;
    }
    
    .client-card-button::before {
        content: "👤";
        font-size: 16px;
    }
    
    .reminders-button {
        margin-right: 4px;
        padding: 0;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0;
        position: relative;
    }
    
    .reminders-button::before {
        content: "🔔";
        font-size: 16px;
    }
    
    .vk-link {
        padding: 0;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0;
        position: relative;
    }
    
    .vk-link::before {
        content: "↗";
        font-size: 16px;
        font-weight: bold;
    }
}

/* Альбомная ориентация (горизонтальный экран) - иконки + текст */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-header {
        padding: 6px 10px;
        gap: 6px;
    }
    
    .back-button {
        margin-right: 8px;
        padding: 4px 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 32px;
        border-radius: 16px;
        background: rgba(255,255,255,0.1);
        border: 1px solid rgba(255,255,255,0.2);
        font-size: 14px;
        white-space: nowrap;
    }
    
    .client-card-button,
    .reminders-button {
        margin-right: 4px;
        padding: 4px 8px;
        height: 32px;
        border-radius: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        position: relative;
        white-space: nowrap;
    }
    
    .client-card-button::before {
        content: "👤 ";
        font-size: 12px;
        margin-right: 2px;
    }
    
    .reminders-button::before {
        content: "🔔 ";
        font-size: 12px;
        margin-right: 2px;
    }
    
    .vk-link {
        padding: 4px 8px;
        height: 32px;
        border-radius: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        position: relative;
        white-space: nowrap;
    }
    
    .vk-link::before {
        content: "↗ ";
        font-size: 12px;
        font-weight: bold;
        margin-right: 2px;
    }
}

/* Дополнительная оптимизация для очень маленьких экранов в портретной ориентации */
@media (max-width: 480px) and (orientation: portrait) {
    .chat-header {
        padding: 6px 8px;
        gap: 6px;
    }
    
    .chat-user-info h2 {
        font-size: 14px;
    }
    
    .back-button,
    .client-card-button,
    .reminders-button,
    .vk-link {
        width: 32px;
        height: 32px;
    }
    
    .back-button::before,
    .client-card-button::before,
    .reminders-button::before,
    .vk-link::before {
        font-size: 14px;
    }
}

/* Скроллбар */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #c5c5c5;
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
/* Pagination Styles */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
    margin-top: 20px;
    border-top: 1px solid #e7e8ec;
}

.pagination .page-item {
    margin: 0 4px;
    padding: 8px 12px;
    text-decoration: none;
    color: #2a5885; /* VK blue links */
    background-color: #fff;
    border: 1px solid #dae1e8;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
    font-size: 14px;
}

.pagination .page-item:hover:not(.disabled):not(.active) {
    background-color: #f0f2f5; /* Light hover */
    color: #000;
}

.pagination .page-item.active {
    background-color: #5181b8; /* VK primary blue */
    color: white;
    border-color: #5181b8;
    cursor: default;
}

.pagination .page-item.disabled {
    color: #99a2ad; /* VK disabled text color */
    background-color: #f5f7fa; /* Lighter disabled background */
    border-color: #e7e8ec;
    cursor: not-allowed;
}

/* Стили для модального окна */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 25px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal h2 {
    margin-bottom: 20px;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.modal h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #555;
}

.profile-section p, .purchases-section p {
    margin-bottom: 8px;
    line-height: 1.6;
}

.profile-section p strong {
    color: #000;
    min-width: 150px;
    display: inline-block;
}

.summary-box {
    background-color: #f8f8f8;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 4px;
    white-space: pre-wrap;
    max-height: 150px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 13px;
}

.purchase-list {
    list-style-type: none;
    padding-left: 0;
}

.purchase-list li {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.purchase-list li:last-child {
    border-bottom: none;
}