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

:root {
    --primary-color: #00a046;
    --primary-hover: #00c853;
    --secondary-color: #6c757d;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Login Page */
.container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 48px;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.logo h1 {
    color: var(--primary-color);
    font-size: 32px;
    margin-bottom: 8px;
}

.logo p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 32px;
}

.login-content .description {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-icon {
    background: transparent;
    padding: 8px;
    color: var(--text-primary);
}

.btn-icon:hover {
    background: var(--background);
}

/* Messages Page */
.messages-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    color: var(--primary-color);
    font-size: 24px;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.messages-layout {
    position: fixed;
    top: 73px;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    height: 100%;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 2px;
    display: flex;
    gap: 12px;
    align-items: start;
}

.chat-item:hover {
    background: var(--background);
}

.chat-item.active {
    background: #e8f5e9;
    border-left: 3px solid var(--primary-color);
}

/* Непрочитанные чаты - выделяются жирным шрифтом */
.chat-item.unread {
    background: #f8f9fa;
}

.chat-item.unread .chat-item-name {
    font-weight: 700; /* Жирный только для непрочитанных */
}

.chat-item.unread .chat-item-preview {
    font-weight: 600; /* Полужирный для превью непрочитанных */
    color: #212529; /* Темнее для лучшей видимости */
}

.chat-item-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #00a046;
    color: white;
    border-radius: 12px;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    padding: 0 6px;
    box-shadow: 0 2px 4px rgba(0, 160, 70, 0.3);
}

.chat-item-avatar, .chat-item-avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.chat-item-avatar-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

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

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 4px;
}

.chat-item-name-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.chat-item-name {
    font-weight: 400;
    color: var(--text-primary);
    font-size: 15px;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    line-height: 1;
}

.source-badge svg {
    width: 10px;
    height: 10px;
}

.source-badge-avito {
    background: #00a046;
    color: white;
}

.source-badge-telegram {
    background: #0088cc;
    color: white;
}

.source-badge-whatsapp {
    background: #25D366;
    color: white;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 8px;
}

.chat-item-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-preview {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Messages Main */
.messages-main {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    position: relative;
    overflow: hidden;
}

.messages-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-header-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-text {
    flex: 1;
}

.messages-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

.chat-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: normal;
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    padding-bottom: 120px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

/* Скелетон загрузки сообщений */
.messages-skeleton {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
}

.skeleton-message {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 12px;
    height: 60px;
    width: 70%;
}

.skeleton-message.own {
    align-self: flex-end;
    width: 60%;
    background: linear-gradient(90deg, #e8f5e9 25%, #d0f0d9 50%, #e8f5e9 75%);
    background-size: 200% 100%;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.date-delimiter {
    text-align: center;
    margin: 24px 0 16px 0;
}

.date-delimiter span {
    display: inline-block;
    padding: 6px 16px;
    background: #f0f2f5;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.message-item {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-start;
}

.message-item.own {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--background);
    max-width: 60%;
}

.message-item.own .message-content {
    background: #d4edda;
    align-items: flex-end;
}

.message-item-header {
    display: flex;
    gap: 8px;
    align-items: center;
}

.message-item.own .message-item-header {
    flex-direction: row-reverse;
}

.message-item-author {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.message-item.own .message-item-author {
    display: none;
}

.message-item-time {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Галочки статуса доставки */
.delivery-status {
    font-size: 12px;
    line-height: 1;
    display: inline-block;
}

.delivery-status.pending {
    color: #9e9e9e; /* Серая - отправляется */
}

.delivery-status.delivered {
    color: #9e9e9e; /* Серая - доставлено */
}

.delivery-status.read {
    color: #0088cc; /* Синяя - прочитано */
}

/* Сообщение в процессе отправки */
.message-item.pending {
    opacity: 0.7;
}

.message-item-text {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.4;
    word-wrap: break-word;
}

.btn-delete-message {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-delete-message:hover {
    opacity: 1;
}

.scroll-to-bottom {
    position: absolute;
    bottom: 140px;
    right: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 999;
}

.scroll-to-bottom:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Reply Form - Avito Style */
.reply-form {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--surface);
    position: fixed;
    bottom: 0;
    left: 320px;
    right: 0;
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

.input-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.input-icon-btn:hover {
    background: var(--background);
}

.input-send-btn {
    display: none;
}

.message-input-field {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #d9e1e8;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background: #f8f9fa;
    transition: all 0.2s;
}

.message-input-field:focus {
    outline: none;
    border-color: #4a9eff;
    background: white;
}

.message-input-field::placeholder {
    color: #9ca3af;
}

/* Loading */
.loading {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

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

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .messages-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .message-item {
        max-width: 85%;
    }
}

/* Медиа сообщения (изображения, голосовые, видео) */
.media-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.media-message:hover {
    background: rgba(0, 0, 0, 0.05);
}

.message-item.own .media-message {
    background: rgba(255, 255, 255, 0.2);
}

.message-item.own .media-message:hover {
    background: rgba(255, 255, 255, 0.3);
}

.media-message svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.media-message span {
    font-size: 14px;
    font-weight: 500;
}

.image-message svg {
    stroke: #0088cc;
}

.voice-message svg {
    stroke: #00a046;
}

.video-message svg {
    stroke: #9c27b0;
}

.document-message svg {
    stroke: #ff9800;
}


/* Медиа сообщения (изображения, голосовые, видео) */
.media-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.media-message:hover {
    background: rgba(0, 0, 0, 0.05);
}

.message-item.own .media-message {
    background: rgba(255, 255, 255, 0.2);
}

.message-item.own .media-message:hover {
    background: rgba(255, 255, 255, 0.3);
}

.media-message svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.media-message span {
    font-size: 14px;
    font-weight: 500;
}

.image-message svg {
    stroke: #0088cc;
}

.voice-message svg {
    stroke: #00a046;
}

.video-message svg {
    stroke: #9c27b0;
}

.document-message svg {
    stroke: #ff9800;
}


/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--background);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-input[readonly] {
    background: var(--background);
    color: var(--text-secondary);
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

/* Кнопки действий в заголовке чата */
.chat-header-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* Информация о клиенте в заголовке */
.customer-info-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.customer-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f8f9fa;
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.customer-badge:hover {
    background: #e9ecef;
}

/* Инлайн редактирование информации о клиенте */
.customer-info-editable {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.customer-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-icon {
    font-size: 16px;
    flex-shrink: 0;
    width: 20px;
}

.inline-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: white;
    transition: all 0.2s;
}

.inline-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 160, 70, 0.1);
}

.inline-input::placeholder {
    color: #adb5bd;
}

.inline-input:not(:placeholder-shown) {
    background: #f8f9fa;
    font-weight: 500;
}

/* Маленькая кнопка для записи */
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    width: 100%;
}
