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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

/* =========================
   Чат: фиксируем layout на высоту экрана (composer всегда снизу)
   ========================= */
body.chat-page {
    height: 100dvh;   /* корректнее на мобилках (адресная строка) */
    min-height: 100vh; /* fallback */
    overflow: hidden; /* чтобы страница не скроллилась, скролл только внутри диалогов/переписки */
}

.chat-page .container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chat-page main {
    flex: 1;
    overflow: hidden;
    display: block;
    margin-bottom: 0; /* важно: у main по умолчанию есть margin-bottom, он ломает “composer всегда снизу” */
}

.chat-page .messenger {
    height: 100%;
}

.chat-page .messenger-layout {
    height: 100%;
    min-height: 0; /* важно для корректного overflow в flex/grid */
}

.chat-page .messenger-thread {
    min-height: 0;
}

.chat-page .thread-messages {
    min-height: 0;
    overflow-y: auto;
}

.chat-page .thread-composer {
    flex: 0 0 auto;
    position: sticky; /* держим composer внизу даже при нестабильном vh на мобилках */
    bottom: 0;
    z-index: 5;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* База знаний (и страницы, которые хотят такой же стиль контейнера/секций) */
.knowledge-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.knowledge-section {
    scroll-margin-top: 100px;
    background: white;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Рассылки: layout управляется общим `main` (2 колонки на десктопе, 1 на мобилке) */

/* =========================
   Семинары
   ========================= */

.seminars-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.seminar-card {
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    padding: 14px;
    background: #fff;
}

.seminar-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 8px;
}

.seminar-section {
    margin-bottom: 18px;
}

.seminar-section-title {
    font-size: 15px;
    font-weight: 600;
    color: #2c3e50;
    margin: 6px 0 10px 0;
}

.seminar-badge {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    vertical-align: middle;
}

.badge-scheduled {
    background: #e8f5e9;
    color: #1b5e20;
}

.badge-cancelled {
    background: #ffebee;
    color: #b71c1c;
}

.badge-upcoming {
    background: #e3f2fd;
    color: #0d47a1;
}

.badge-past {
    background: #f3e5f5;
    color: #4a148c;
}

.seminars-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 12px 0 14px 0;
}

.promotions-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 12px 0 14px 0;
}

.promotions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Компактные фильтры (2 селекта вместо табов) */
.filters-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin: 12px 0 14px 0;
    flex-wrap: wrap;
}

.filters-bar .filter-item {
    flex: 1 1 220px;
    min-width: 200px;
}

.filters-bar .filter-label {
    display: block;
    margin-bottom: 6px;
    color: #555;
    font-weight: 500;
    font-size: 13px;
}

/* =========================
   Доска руководителя (главная)
   ========================= */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
    margin-top: 12px;
}

.dashboard-grid-2 {
    grid-template-columns: 2fr 1fr;
}

.dashboard-card {
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #667eea;
    padding: 16px;
}

.dash-title {
    color: #2c3e50;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
}

.dash-value {
    font-size: 22px;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1.2;
}

.dash-sub {
    margin-top: 8px;
    color: #666;
    font-size: 13px;
    line-height: 1.4;
}

.dash-bars {
    height: 120px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 8px;
    padding: 10px;
}

.dash-bar {
    flex: 1 1 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px 4px 0 0;
    min-width: 6px;
    opacity: 0.9;
}

.dash-bar:hover {
    opacity: 1;
}

.dash-list {
    margin: 0;
    padding-left: 18px;
    color: #333;
}

.dash-list li {
    margin: 6px 0;
    line-height: 1.35;
}

.promotions-tab.active {
    background: #4caf50;
    color: white;
    border: none;
}

.seminars-tab.active {
    background: #4caf50;
    color: white;
    border: none;
}

.seminar-title {
    font-weight: 600;
    color: #2c3e50;
}

.seminar-date {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
}

.seminar-meta {
    font-size: 14px;
    color: #333;
    margin-bottom: 10px;
}

.seminar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.seminar-lists-tabs {
    display: flex;
    gap: 10px;
    margin: 15px 0;
}

.seminar-lists-tabs .tab-btn.active {
    background: #4caf50;
    color: white;
    border: none;
}

.seminar-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.seminar-table th,
.seminar-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: top;
}

.seminar-table th {
    background: #f7f7f7;
    color: #444;
    font-weight: 600;
}

.seminar-table .actions-cell {
    white-space: nowrap;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
    text-align: center;
}

header h1 {
    color: #2c3e50;
    font-size: 28px;
    font-weight: 300;
    margin-bottom: 15px;
}

.main-nav {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 15px;
}

.nav-link {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.2s;
    font-size: 14px;
}

.nav-link:hover {
    background: #5568d3;
}

.nav-link.active {
    background: #4caf50;
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

/* Утилита: принудительно одна колонка */
main.single-column {
    grid-template-columns: 1fr;
}

/* CRM: основной main работает как колонка, чтобы шапка была сверху, а блоки занимали всю ширину */
body.crm-page main.main-content {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Для страницы чата - одна колонка на всю ширину */
.chat-page main {
    grid-template-columns: 1fr;
    max-width: 100%;
}

.chat-page .messages-section {
    width: 100%;
    max-width: 100%;
}

section {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

section h2 {
    color: #2c3e50;
    margin-bottom: 25px;
    font-size: 22px;
    font-weight: 400;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

/* Редактор текста */
.editor-toolbar {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
}

.editor-toolbar button {
    padding: 6px 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.editor-toolbar button:hover {
    background: #e0e0e0;
}

.editor-toolbar button#aiGenerateBtn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    font-weight: 600;
}

.editor-toolbar button#aiGenerateBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5568d3 0%, #6a3d8f 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.editor-toolbar button#aiGenerateBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.editor-toolbar button#aiCheckErrorsBtn,
.editor-toolbar button#aiAnalyzeBtn {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
    border: none;
    font-weight: 600;
    font-size: 13px;
}

.editor-toolbar button#aiPromoCheckErrorsBtn,
.editor-toolbar button#aiPromoAnalyzeBtn {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
    border: none;
    font-weight: 600;
    font-size: 13px;
}

.editor-toolbar button#aiCheckErrorsBtn:hover:not(:disabled),
.editor-toolbar button#aiAnalyzeBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.editor-toolbar button#aiPromoCheckErrorsBtn:hover:not(:disabled),
.editor-toolbar button#aiPromoAnalyzeBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.editor-toolbar button#aiCheckErrorsBtn:disabled,
.editor-toolbar button#aiAnalyzeBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.editor-toolbar button#aiPromoCheckErrorsBtn:disabled,
.editor-toolbar button#aiPromoAnalyzeBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.message-editor {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    transition: border-color 0.2s;
}

.message-editor:focus {
    outline: none;
    border-color: #4a90e2;
}

.text-analysis-display {
    width: 100%;
    min-height: 450px;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    background: #f8f9fa;
    overflow-y: auto;
    line-height: 1.6;
    color: #333;
}

.text-analysis-display p {
    margin: 0 0 12px 0;
}

.text-analysis-display b {
    font-weight: 600;
    color: #2c3e50;
}

/* Загрузка изображения */
#imageUpload {
    width: 100%;
    padding: 8px;
    border: 2px dashed #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
}

.image-preview {
    margin-top: 15px;
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
}

.remove-image {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.remove-image:hover {
    background: rgba(231, 76, 60, 1);
}

/* Выбор пользователей */
.user-select-container {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
}

.user-select-header {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.filter-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

.user-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

.user-select option {
    padding: 8px;
}

.selected-count {
    margin-top: 10px;
    font-size: 13px;
    color: #666;
    font-style: italic;
}

/* Кнопки */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-select-all {
    background: #4a90e2;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn-select-all:hover {
    background: #357abd;
}

.result-message {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    display: none;
}

.result-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.result-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Список пользователей */
.users-header {
    margin-bottom: 20px;
}

.users-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.user-card:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-info {
    flex: 1;
}

.user-info strong {
    color: #2c3e50;
    display: block;
    margin-bottom: 5px;
}

.user-info span {
    color: #666;
    font-size: 13px;
    display: block;
    margin-top: 3px;
}

.user-actions {
    display: flex;
    gap: 8px;
}

.btn-edit, .btn-delete {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: opacity 0.2s;
}

.btn-edit {
    background: #4a90e2;
    color: white;
}

.btn-delete {
    background: #e74c3c;
    color: white;
}

.btn-edit:hover, .btn-delete:hover {
    opacity: 0.8;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #999;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
    /* важно: длинные формы (товары/семинары) должны прокручиваться */
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
}

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

.close:hover, .close-reply:hover {
    color: #333;
}

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

#userForm input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

#userForm input:focus {
    outline: none;
    border-color: #4a90e2;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.form-actions button {
    flex: 1;
}

/* Секция сообщений */
.messages-section {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-top: 30px;
}

.messages-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.user-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.user-tab {
    padding: 10px 20px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-tab:hover {
    background: #e9ecef;
    border-color: #3498db;
}

.user-tab.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.user-tab .unread-count {
    background: #ff4444;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.messages-header h2 {
    color: #2c3e50;
    font-size: 22px;
    font-weight: 400;
    margin: 0;
}

.btn-refresh {
    background: #4a90e2;
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 999px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.btn-refresh:hover {
    background: #357abd;
}

.btn-refresh:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.25);
}

/* Заголовки секций со значком обновления (семинары/акции) */
.seminars-header,
.promotions-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 10px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 600px;
    overflow-y: auto;
}

/* =========================
   Мессенджер (как Telegram/VK)
   ========================= */
.messenger {
    /* Контейнер без общей “коробки”: обе колонки будут отдельными карточками */
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

.messenger-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 70vh;
    gap: 10px; /* отступ между “Диалоги” и правой частью */
}

.messenger-sidebar {
    background: #fff;
    display: flex;
    flex-direction: column;
    min-width: 280px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.messenger-sidebar-header {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(248, 250, 252, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    min-height: 84px; /* выравниваем по высоте с .thread-header */
}

.messenger-title {
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
    font-size: 14px;
}

.messenger-search {
    height: 40px;
    border-radius: 10px;
}

.dialogs-list {
    overflow-y: auto;
    padding: 6px;
    flex: 1;
    scrollbar-gutter: stable;
}

.dialog-item {
    width: 100%;
    display: flex;
    gap: 10px;
    padding: 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    border-radius: 10px;
}

.dialog-item:hover {
    background: #f5f7ff;
}

.dialog-item.active {
    background: #e8f0ff;
}

.dialog-avatar {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: #667eea;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex: 0 0 auto;
}

.dialog-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    object-fit: cover;
    display: block;
}

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

.dialog-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
}

.dialog-name {
    font-weight: 600;
    color: #2c3e50;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog-time {
    font-size: 12px;
    color: #999;
    flex: 0 0 auto;
    white-space: nowrap;
}

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

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

.dialog-badge {
    background: #3498db;
    color: #fff;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 700;
    flex: 0 0 auto;
}

.messenger-thread {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.thread-header {
    background: rgba(248, 250, 252, 0.9);
    border-bottom: 1px solid rgba(148, 163, 184, 0.35);
    padding: 12px 14px;
    display: flex;
    gap: 10px;
    align-items: center;
    min-height: 84px; /* одинаково с шапкой диалогов */
}

.thread-back {
    display: none;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    width: 40px;
    height: 40px;
    padding: 0;
    cursor: pointer;
}

.thread-back:hover {
    background: #fff;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.10);
}

.thread-peer {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.thread-peer-name {
    font-weight: 700;
    color: #2c3e50;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-peer-meta {
    color: #888;
    font-size: 12px;
    margin-top: 2px;
}

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    scrollbar-gutter: stable;
    background: #f7f8fa;
}

.thread-load-older {
    display: block;
    width: 100%;
    border: 1px dashed #d0d7e2;
    background: #ffffff;
    color: #2c3e50;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 0 0 12px 0;
    cursor: pointer;
    font-size: 13px;
}

.thread-load-older:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.msg-row {
    display: flex;
    margin: 6px 0;
}

.msg-row.in {
    justify-content: flex-start;
}

.msg-row.out {
    justify-content: flex-end;
}

.msg-bubble {
    max-width: min(720px, 85%);
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 14px;
    padding: 10px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.msg-row.out .msg-bubble {
    background: #e8f0ff;
    border-color: #d8e5ff;
}

.msg-text {
    font-size: 14px;
    color: #2c3e50;
    line-height: 1.35;
    word-break: break-word;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 6px;
    color: #777;
    font-size: 11px;
}

.thread-composer {
    background: rgba(248, 250, 252, 0.9);
    border-top: 1px solid rgba(148, 163, 184, 0.35);
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr 46px 130px;
    gap: 10px;
    align-items: end;
}

.composer-attach {
    width: 46px;
    height: 44px;
    padding: 0;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.composer-file-hidden {
    display: none;
}

.composer-text {
    width: 100%;
    min-height: 44px;
    max-height: 140px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

.composer-send {
    margin: 0;
    width: 100%;
}

.message-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    cursor: pointer;
}

.message-content-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.message-avatar-container {
    flex-shrink: 0;
}

.message-avatar,
.message-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.message-avatar-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

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

.message-card.message-unread {
    background: #fff9e6;
    border-left: 4px solid #ff9800;
    font-weight: 500;
}

.message-card.message-read {
    background: #f8f9fa;
    border-left: 4px solid #4caf50;
    opacity: 0.9;
}

.message-card:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: #f0f2f5;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.message-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.message-status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.message-status-badge.status-unread {
    background: #ff9800;
    color: white;
}

.message-status-badge.status-read {
    background: #4caf50;
    color: white;
}

.message-author {
    font-weight: 600;
    color: #2c3e50;
}

.message-author-link {
    color: #4a90e2;
    text-decoration: none;
    transition: color 0.2s;
}

.message-author-link:hover {
    color: #357abd;
    text-decoration: underline;
}

.message-time {
    color: #999;
    font-size: 12px;
    margin-left: auto;
}

.message-text {
    color: #333;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-meta {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.btn-reply {
    background: #667eea;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.btn-reply:hover {
    background: #5568d3;
}

.btn-delete-message {
    background: #f44336;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.btn-delete-message:hover {
    background: #d32f2f;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    body {
        padding: 10px;
        overflow-x: hidden; /* чтобы “скролл” не появлялся на формах/страницах */
    }

    .container {
        max-width: 100%;
        padding: 0;
        overflow-x: hidden;
    }

    header {
        padding: 15px;
        margin-bottom: 15px;
    }

    header h1 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    /* Навигация: горизонтальный скролл как “табы”, чтобы не занимать весь экран */
    .main-nav {
        flex-direction: row;
        justify-content: flex-start;
        gap: 8px;
        margin-top: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: none;
    }
    .main-nav::-webkit-scrollbar { display: none; }

    .nav-link {
        flex: 0 0 auto;
        width: auto;
        text-align: center;
        padding: 10px 12px;
        font-size: 13px;
        border-radius: 999px;
        white-space: nowrap;
    }

    main {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 15px;
    }

    section {
        padding: 15px;
        overflow-x: hidden;
    }

    section h2 {
        font-size: 18px;
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    /* Формы */
    .form-group {
        margin-bottom: 15px;
    }

    .form-input,
    .message-editor,
    textarea {
        font-size: 16px; /* Предотвращает зум на iOS */
    }

    /* Фильтры (2 селекта): на мобилке в колонку */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .filters-bar .filter-item {
        min-width: 0;
        width: 100%;
    }

    /* Доска руководителя */
    .dashboard-grid-2 {
        grid-template-columns: 1fr;
    }

    .dash-bars {
        height: 110px;
    }

    .dashboard-card {
        padding: 14px;
    }

    .dash-value {
        font-size: 20px;
    }

    .editor-toolbar {
        flex-wrap: wrap;
        gap: 5px;
    }

    .editor-toolbar button {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* =========================
       Часы работы: мобильная адаптация
       ========================= */
    .working-hours-page .editor-toolbar button#aiCheckErrorsBtn,
    .working-hours-page .editor-toolbar button#aiAnalyzeBtn {
        width: 100%;
        text-align: center;
    }

    .working-hours-page .form-actions {
        margin-top: 10px;
    }

    /* Кнопки */
    .btn-primary,
    .btn-secondary,
    .btn-edit,
    .btn-delete {
        width: 100%;
        padding: 12px;
        font-size: 14px;
        margin-bottom: 8px;
    }

    .btn-primary:last-child,
    .btn-secondary:last-child {
        margin-bottom: 0;
    }

    /* Семинары */
    .seminar-card {
        padding: 12px;
    }

    .seminar-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .seminar-actions {
        flex-direction: column;
        gap: 8px;
    }

    .seminar-actions button {
        width: 100%;
    }

    /* Табы семинаров: горизонтальный скролл вместо колонки */
    .seminars-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: none;
    }
    .seminars-tabs::-webkit-scrollbar { display: none; }

    .seminars-tab {
        width: auto;
        flex: 0 0 auto;
        text-align: center;
        white-space: nowrap;
    }

    /* Табы акций: горизонтальный скролл вместо “лесенки” */
    .promotions-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: none;
    }
    .promotions-tabs::-webkit-scrollbar { display: none; }

    .promotions-tab {
        width: auto;
        flex: 0 0 auto;
        text-align: center;
        white-space: nowrap;
    }

    /* Пользователи */
    .user-select-header {
        flex-direction: column;
        gap: 10px;
    }

    .btn-select-all {
        width: 100%;
    }

    .user-select {
        font-size: 16px; /* Предотвращает зум на iOS */
    }

    /* Сообщения */
    .messages-list {
        max-height: 400px;
    }

    .message-card {
        padding: 12px;
    }

    /* Сообщения: оставляем аватар + контент в строку, так читаемее */
    .message-content-wrapper {
        flex-direction: row;
        gap: 10px;
    }

    /* Чаты: длинные метаданные не должны ломать карточку */
    .message-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .message-meta span {
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .message-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .message-actions {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .message-actions button {
        width: 100%;
    }

    /* Табы пользователей в чате: горизонтальный скролл */
    .user-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px;
        scrollbar-width: none;
    }
    .user-tabs::-webkit-scrollbar { display: none; }

    .user-tab {
        width: auto;
        text-align: center;
        flex: 0 0 auto;
    }

    /* Messenger mobile: sidebar <-> thread */
    .messenger-layout {
        grid-template-columns: 1fr;
    }

    .thread-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    body.messenger-thread-open .messenger-sidebar {
        display: none;
    }

    body:not(.messenger-thread-open) .messenger-thread {
        display: none;
    }

    .thread-composer {
        grid-template-columns: 1fr;
    }

    .composer-text {
        font-size: 16px; /* iOS */
    }

    /* Модальные окна */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 10px auto;
        padding: 15px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-large {
        width: 95%;
        max-width: 95%;
    }

    .reply-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
    }

    /* Таблицы */
    table {
        font-size: 12px;
    }

    table th,
    table td {
        padding: 8px 4px;
    }

    /* Пагинация */
    .pagination-controls {
        flex-wrap: wrap;
        gap: 5px;
    }

    .pagination-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 35px;
    }

    /* База знаний: табы тоже скроллятся горизонтально */
    .knowledge-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px;
        scrollbar-width: none;
    }
    .knowledge-tabs::-webkit-scrollbar { display: none; }

    .knowledge-tab {
        width: auto;
        text-align: center;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .knowledge-section {
        padding: 15px;
    }

    .feature-grid {
        grid-template-columns: 1fr;
    }

    /* Изображения */
    .image-preview {
        grid-template-columns: 1fr;
    }

    .preview-item {
        width: 100%;
    }

    /* Уведомления */
    .notification {
        width: 95%;
        max-width: 95%;
    }

    /* Таблицы семинаров: НЕ ломаем в блоки, а даём горизонтальный скролл */
    .seminar-registrations-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .seminar-table {
        min-width: 720px;
    }

    /* Форма семинара */
    .seminar-form-section {
        padding: 15px;
    }

    /* Списки регистраций */
    .seminar-lists-tabs {
        flex-direction: column;
    }

    .seminar-lists-tabs .tab-btn {
        width: 100%;
    }

    /* Заголовки сообщений */
    .messages-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .messages-header h2 {
        margin: 0;
    }

    /* Форма ответа */
    .form-actions {
        flex-direction: column;
        gap: 10px;
    }

    .form-actions button {
        width: 100%;
    }

    /* История сообщений в модалке */
    .reply-messages-history {
        max-height: 200px;
    }

    /* Логин */
    .login-container {
        padding: 10px;
    }

    .login-box {
        padding: 20px;
    }

    /* База знаний */
    .knowledge-container {
        padding: 10px;
    }

    .step-box,
    .warning-box,
    .info-box {
        padding: 12px;
        font-size: 14px;
    }

    /* Пагинация информации */
    .pagination-info {
        font-size: 12px;
        text-align: center;
        margin-top: 10px;
    }
}

/* Адаптивность для очень маленьких экранов */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    header {
        padding: 10px;
    }

    header h1 {
        font-size: 18px;
    }

    section {
        padding: 10px;
    }

    section h2 {
        font-size: 16px;
    }

    .seminar-card {
        padding: 10px;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 5px;
        padding: 10px;
    }

    .knowledge-section {
        padding: 10px;
    }

    .knowledge-section h2 {
        font-size: 18px;
    }

    .knowledge-section h3 {
        font-size: 16px;
    }

    .knowledge-section h4 {
        font-size: 14px;
    }

    .pagination-btn {
        padding: 5px 8px;
        font-size: 11px;
        min-width: 30px;
    }

    .editor-toolbar button {
        padding: 5px 8px;
        font-size: 11px;
    }

    /* Доска руководителя */
    .dashboard-grid {
        gap: 12px;
    }

    .dashboard-card {
        padding: 12px;
    }

    .dash-title {
        font-size: 13px;
    }

    .dash-value {
        font-size: 18px;
    }

    .dash-sub {
        font-size: 12px;
    }

    .dash-bars {
        height: 95px;
        padding: 8px;
        gap: 3px;
    }

    .dash-bar {
        min-width: 4px;
    }
}

/* Адаптивность для планшетов */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 100%;
        padding: 15px;
    }

    header {
        padding: 20px;
    }

    .main-nav {
        flex-wrap: wrap;
    }

    main {
        gap: 20px;
    }

    section {
        padding: 20px;
    }

    .seminar-actions {
        flex-wrap: wrap;
    }

    .seminar-actions button {
        flex: 1;
        min-width: 120px;
    }
}

/* Стили для пагинации */
.pagination {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.pagination-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    color: #333;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    min-width: 40px;
}

.pagination-btn:hover:not(:disabled) {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.pagination-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
    font-weight: 600;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 8px 4px;
    color: #999;
}

.pagination-info {
    text-align: center;
    color: #666;
    font-size: 12px;
    margin-top: 10px;
}

/* Стили для страницы рассылок */
.broadcasts-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.broadcast-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.broadcast-card:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.broadcast-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.broadcast-card-header h3 {
    color: #2c3e50;
    font-size: 18px;
    margin: 0;
}

.broadcast-date {
    color: #999;
    font-size: 12px;
}

.broadcast-card-text {
    color: #666;
    margin-bottom: 10px;
    line-height: 1.5;
}

.broadcast-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

.broadcast-recipients {
    color: #666;
    font-size: 12px;
}

.btn-view {
    background: #667eea;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.btn-view:hover {
    background: #5568d3;
}

.modal-large {
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.broadcast-info {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.info-item {
    margin-bottom: 10px;
}

.info-item strong {
    color: #2c3e50;
    margin-right: 10px;
}

.broadcast-text-container {
    margin-bottom: 20px;
}

.broadcast-text-container h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 18px;
}

.broadcast-text {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.readers-section {
    margin-top: 20px;
}

.readers-section h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 18px;
}

.readers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.reader-card {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    border-left: 3px solid #4caf50;
}

.reader-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}

.reader-link {
    color: #4a90e2;
    text-decoration: none;
    font-weight: 600;
}

.reader-link:hover {
    text-decoration: underline;
}

.reader-chat-id {
    color: #999;
    font-size: 11px;
}

.reader-date {
    color: #666;
    font-size: 12px;
}

.form-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* Нормализация select (стрелка внутри поля, без “уезда” вправо) */
select.form-input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: #fff;
    padding-right: 38px; /* место под стрелку */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
}

select.form-input::-ms-expand {
    display: none;
}

/* Стили для уведомлений */
.notifications-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    pointer-events: none;
}

.notification {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    padding: 15px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease;
    pointer-events: all;
    border-left: 4px solid #667eea;
}

.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-content {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.notification-avatar-container {
    flex-shrink: 0;
}

.notification-avatar,
.notification-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.notification-avatar-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

.notification-body {
    flex: 1;
    min-width: 0;
}

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

.notification-author {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.notification-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    line-height: 1;
    transition: color 0.2s;
}

.notification-close:hover {
    color: #333;
}

.notification-text {
    color: #333;
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 6px;
    word-wrap: break-word;
}

.notification-time {
    color: #999;
    font-size: 11px;
    margin-bottom: 10px;
}

.notification-actions {
    display: flex;
    gap: 8px;
}

.btn-quick-reply,
.btn-view-chat {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-quick-reply {
    background: #667eea;
    color: white;
}

.btn-quick-reply:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.btn-view-chat {
    background: #f0f0f0;
    color: #333;
}

.btn-view-chat:hover {
    background: #e0e0e0;
}

/* Стили для модального окна ответа с историей сообщений */
.reply-modal-content {
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.reply-messages-history {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    background: #f8f9fa;
    margin-top: 8px;
}

.reply-message-item {
    background: white;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    border-left: 3px solid #667eea;
    transition: box-shadow 0.2s;
}

.reply-message-content-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.reply-message-avatar-container {
    flex-shrink: 0;
}

.reply-message-avatar,
.reply-message-avatar-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.reply-message-avatar-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

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

.reply-message-item:last-child {
    margin-bottom: 0;
}

.reply-message-item:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.reply-message-item.user-message {
    border-left-color: #667eea;
    background: #f0f4ff;
}

.reply-message-item.bot-message {
    border-left-color: #4caf50;
    background: #f0f9f0;
}

.reply-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.reply-message-sender {
    font-weight: 600;
    font-size: 12px;
    color: #2c3e50;
}

.reply-message-item.user-message .reply-message-sender {
    color: #667eea;
}

.reply-message-item.bot-message .reply-message-sender {
    color: #4caf50;
}

.reply-message-time {
    color: #999;
    font-size: 11px;
    font-style: italic;
}

.reply-message-text {
    color: #333;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 14px;
}

/* =========================
   Супер админ: улучшенная верстка
   ========================= */
.super-admin-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.super-admin-page .container {
    max-width: 1400px;
    margin: 0 auto;
}

.super-admin-page header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 20px 30px;
    margin-bottom: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.super-admin-page header h1 {
    color: #2c3e50;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.super-admin-page header h1::before {
    content: "👑";
    font-size: 32px;
}

.super-admin-page .main-nav {
    display: flex;
    gap: 10px;
    align-items: center;
}

.super-admin-page .main-nav .nav-link {
    padding: 10px 20px;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.super-admin-page .main-nav .nav-link.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.super-admin-page .dashboard-section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.super-admin-page .dashboard-section h2 {
    color: #2c3e50;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    border-bottom: 3px solid #667eea;
    padding-bottom: 15px;
}

.super-admin-page .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.super-admin-page .dashboard-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(102, 126, 234, 0.1);
}

.super-admin-page .dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2);
}

.super-admin-page .dashboard-card .dash-title {
    color: #666;
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.super-admin-page .dashboard-card .dash-value {
    color: #2c3e50;
    font-size: 36px;
    font-weight: 700;
    line-height: 1.2;
}

.super-admin-page .users-section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.super-admin-page .section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.super-admin-page .section-header h2 {
    color: #2c3e50;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    border: none;
    padding: 0;
}

.super-admin-page .section-header .subtext {
    color: #666;
    font-size: 14px;
    margin: 0;
}

.super-admin-page .filters-inline {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.super-admin-page .filters-inline label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

.super-admin-page .filters-inline select,
.super-admin-page .filters-inline input {
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    min-width: 200px;
}

.super-admin-page .filters-inline select:focus,
.super-admin-page .filters-inline input:focus {
    outline: none;
    border-color: #667eea;
}

.super-admin-page .table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.super-admin-page .data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.super-admin-page .data-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.super-admin-page .data-table th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.super-admin-page .data-table td {
    padding: 15px 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    color: #333;
}

.super-admin-page .data-table tbody tr {
    transition: background-color 0.2s ease;
}

.super-admin-page .data-table tbody tr:hover {
    background-color: #f8f9ff;
}

.super-admin-page .data-table tbody tr:last-child td {
    border-bottom: none;
}

.super-admin-page .data-table .loading {
    text-align: center;
    padding: 40px;
    color: #999;
    font-style: italic;
}

.super-admin-page .btn-edit {
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.super-admin-page .btn-edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.super-admin-page .btn-secondary {
    padding: 10px 20px;
    background: #f0f0f0;
    color: #333;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.super-admin-page .btn-secondary:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

.super-admin-page .pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.super-admin-page .pagination-btn {
    padding: 8px 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    min-width: 40px;
}

.super-admin-page .pagination-btn:hover:not(:disabled) {
    background: #f8f9ff;
    border-color: #667eea;
    color: #667eea;
}

.super-admin-page .pagination-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.super-admin-page .pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.super-admin-page .result-message.error {
    background: #fee;
    color: #c33;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #fcc;
    margin-bottom: 20px;
}

.super-admin-page h3 {
    color: #2c3e50;
    font-size: 20px;
    font-weight: 600;
    margin: 30px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.super-admin-page .filter-icon {
    cursor: pointer;
    font-size: 12px;
    margin-left: 6px;
    opacity: 0.6;
    transition: all 0.3s ease;
    display: inline-block;
    padding: 2px 4px;
    border-radius: 4px;
}

.super-admin-page .filter-icon:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.2);
}

.super-admin-page .filter-icon.filter-active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.3);
    color: #ffd700;
}

.super-admin-page .data-table th {
    position: relative;
    user-select: none;
}

.super-admin-page .filter-modal-content {
    max-width: 500px;
    width: 90%;
}

.super-admin-page .filter-modal-content .form-control {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

.super-admin-page .filter-modal-content .form-control:focus {
    outline: none;
    border-color: #667eea;
}

.super-admin-page .filter-modal-content .form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}

.super-admin-page .filter-modal-content .form-actions .btn-primary {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.super-admin-page .filter-modal-content .form-actions .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

@media (max-width: 768px) {
    .super-admin-page .section-header {
        flex-direction: column;
    }
    
    .super-admin-page .filters-inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .super-admin-page .filters-inline select,
    .super-admin-page .filters-inline input {
        min-width: 100%;
    }
    
    .super-admin-page .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .super-admin-page .table-wrapper {
        overflow-x: scroll;
    }
    
    .super-admin-page .filter-modal-content {
        width: 95%;
        max-width: none;
    }
}

/* =========================
   CRM Красотуля: Боковое меню и современный дизайн
   ========================= */

/* Применяем CRM-стиль только там, где мы явно включили его классом crm-page */
body.crm-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 0;
    margin: 0;
    color: #1f2937;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.crm-page .container {
    display: flex;
    min-height: 100vh;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Боковое меню */
.sidebar {
    width: 260px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 10px;
    top: 10px;
    height: calc(100vh - 20px);
    z-index: 1000;
    transition: transform 0.3s ease;
    border-radius: 18px;
    overflow: hidden;
}

.sidebar-header {
    position: relative;
}

.sidebar-collapse {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    cursor: pointer;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.sidebar-collapse:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.sidebar-collapse:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 2px solid rgba(102, 126, 234, 0.1);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.sidebar-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-header h1::before {
    content: "💅";
    font-size: 28px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    scrollbar-gutter: stable;
    margin: 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.6);
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 25px;
    color: #2c3e50;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-nav-item .nav-icon {
    width: 24px;
    min-width: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.sidebar-nav-item .nav-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav-item:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    border-left-color: #667eea;
}

.sidebar-nav-item:focus-visible {
    outline: 3px solid rgba(102, 126, 234, 0.35);
    outline-offset: -3px;
    background: rgba(102, 126, 234, 0.12);
}

.sidebar-nav-item.active {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.1) 100%);
    color: #667eea;
    border-left-color: #667eea;
    font-weight: 600;
}

.sidebar-nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sidebar-footer {
    padding: 20px;
    border-top: 2px solid rgba(102, 126, 234, 0.1);
}

.sidebar-footer .btn-logout {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-footer .btn-logout:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

/* Основной контент */
.main-content {
    flex: 1;
    margin-left: 280px; /* 260 sidebar + 20 (отступы слева/справа по 10px) */
    /* Важно: шапка должна быть "у самого верха", поэтому убираем верхний padding */
    padding: 10px 30px 30px;
    min-height: 100vh;
    overflow-x: hidden;
    max-width: none;
    width: calc(100% - 280px);
}

.main-content-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 14px 18px;
    margin-bottom: 18px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 10px; /* отступ сверху 10px */
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid rgba(102, 126, 234, 0.10);
}

.main-content-header h1 {
    color: #2c3e50;
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

/* (topbar-collapse removed) */

/* Свёрнутый сайдбар (desktop) */
body.crm-page.sidebar-collapsed .sidebar {
    width: 84px;
}

body.crm-page.sidebar-collapsed .sidebar-nav-item {
    justify-content: center;
    padding-left: 16px;
    padding-right: 16px;
}

body.crm-page.sidebar-collapsed .sidebar-nav-item .nav-text {
    display: none;
}

/* Tooltip в свернутом режиме */
body.crm-page.sidebar-collapsed .sidebar-nav-item {
    position: relative;
}

body.crm-page.sidebar-collapsed .sidebar-nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-2px) scale(0.98);
    background: rgba(15, 23, 42, 0.90);
    color: #fff;
    padding: 8px 10px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.26s cubic-bezier(.2,.9,.2,1), transform 0.26s cubic-bezier(.2,.9,.2,1);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
    z-index: 1200;
}

body.crm-page.sidebar-collapsed .sidebar-nav-item::before {
    content: "";
    position: absolute;
    left: calc(100% + 4px);
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 6px solid rgba(15, 23, 42, 0.90);
    opacity: 0;
    transition: opacity 0.26s cubic-bezier(.2,.9,.2,1);
    pointer-events: none;
    z-index: 1200;
}

body.crm-page.sidebar-collapsed .sidebar-nav-item:hover::after,
body.crm-page.sidebar-collapsed .sidebar-nav-item:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(2px) scale(1);
}

body.crm-page.sidebar-collapsed .sidebar-nav-item:hover::before,
body.crm-page.sidebar-collapsed .sidebar-nav-item:focus-visible::before {
    opacity: 1;
}

body.crm-page.sidebar-collapsed .sidebar-header h1 .logo-text {
    display: none;
}

body.crm-page.sidebar-collapsed .sidebar-footer {
    padding-left: 12px;
    padding-right: 12px;
}

body.crm-page.sidebar-collapsed .sidebar-footer .btn-logout {
    padding: 10px;
    font-size: 0;
    line-height: 0;
}

body.crm-page.sidebar-collapsed .sidebar-footer .btn-logout::before {
    content: "⎋";
    font-size: 16px;
    line-height: 1;
}

body.crm-page.sidebar-collapsed .main-content {
    margin-left: 104px; /* 84 + 20 */
    width: calc(100% - 104px);
}

/* Секции с новым стилем */
body.crm-page section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

body.crm-page section h2 {
    color: #2c3e50;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 3px solid #667eea;
}

/* Карточки дашборда */
body.crm-page .dashboard-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(102, 126, 234, 0.1);
}

body.crm-page .dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2);
}

/* Кнопки */
body.crm-page .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.crm-page .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

body.crm-page .btn-secondary {
    background: #f0f0f0;
    color: #333;
    border: 2px solid #e0e0e0;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

body.crm-page .btn-secondary:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

body.crm-page input:focus,
body.crm-page textarea:focus,
body.crm-page select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.18);
}

/* Настройки: нормальная CRM-стилизация инпутов/селектов внутри страницы */
body.crm-page #settingsError,
body.crm-page #settingsOk {
    border-radius: 12px;
}

body.crm-page #companyInfo {
    font-size: 14px;
    color: #334155;
}

body.crm-page .filters-bar input,
body.crm-page .filters-bar select,
body.crm-page section input,
body.crm-page section select,
body.crm-page section textarea {
    font-family: inherit;
}

body.crm-page section input:not([type="checkbox"]):not([type="radio"]),
body.crm-page section select,
body.crm-page section textarea {
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.9);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

body.crm-page section input[readonly] {
    background: rgba(248, 250, 252, 0.9);
    color: #475569;
}

body.crm-page section input:not([type="checkbox"]):not([type="radio"]):focus,
body.crm-page section select:focus,
body.crm-page section textarea:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.18);
    background: #fff;
}

body.crm-page section label {
    color: #475569;
    font-weight: 600;
    font-size: 13px;
}

body.crm-page a:focus-visible,
body.crm-page button:focus-visible {
    outline: 3px solid rgba(102, 126, 234, 0.35);
    outline-offset: 2px;
}

/* Мобильное меню */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 20px;
}

@media (max-width: 768px) {
    .sidebar {
        left: 0;
        top: 0;
        height: 100vh;
        border-radius: 0;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
        padding-top: 70px;
        width: 100%;
    }
    
    .main-content-header {
        padding: 20px;
        top: 10px;
    }
    
    body.crm-page section {
        padding: 20px;
        margin-bottom: 14px;
    }

    /* Меньше воздуха в фильтрах/формах (Настройки/Логи и т.п.) */
    .filters-bar {
        gap: 6px;
        margin: 8px 0 10px 0;
    }

    .filters-bar .filter-label {
        margin-bottom: 4px;
        font-size: 12px;
    }

    .filters-bar .filter-item {
        flex: 1 1 auto;
    }

    /* Кнопки в фильтрах тоже в одну колонку и без лишних отступов */
    body.crm-page .filters-bar button,
    body.crm-page .filters-bar .nav-link {
        width: 100%;
        margin-bottom: 0;
        border-radius: 12px;
    }

    /* Уменьшаем общий gap между элементами внутри main-content (шапка/секции) */
    body.crm-page main.main-content {
        gap: 10px;
    }

    /* CRM: на мобилке не используем collapsed-состояние */
    body.crm-page.sidebar-collapsed .sidebar {
        width: 260px;
    }

    body.crm-page.sidebar-collapsed .sidebar-nav-item {
        justify-content: flex-start;
        padding-left: 18px;
        padding-right: 18px;
    }

    body.crm-page.sidebar-collapsed .sidebar-nav-item .nav-text {
        display: inline;
    }

    body.crm-page.sidebar-collapsed .sidebar-header h1 .logo-text {
        display: inline;
    }

    body.crm-page.sidebar-collapsed .sidebar-footer .btn-logout {
        font-size: 14px;
        line-height: 1.2;
        padding: 12px;
    }

    body.crm-page.sidebar-collapsed .sidebar-footer .btn-logout::before {
        content: none;
    }

    body.crm-page.sidebar-collapsed .main-content {
        margin-left: 0;
        width: 100%;
    }

    /* CRM: сайдбар внутри на мобилке без внутренних "карточек" и отступов */
    .sidebar-header {
        padding: 18px 16px;
    }

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

    .sidebar-nav {
        margin: 0;
        border-radius: 0;
        background: transparent;
        padding: 12px 0;
    }

    .sidebar-nav-item {
        padding: 12px 18px;
        gap: 10px;
    }

    .sidebar-footer {
        padding: 14px 16px;
    }

    /* CRM: компактнее контент и шапка */
    body.crm-page .main-content {
        padding-left: 14px;
        padding-right: 14px;
        padding-bottom: 22px;
    }

    body.crm-page .main-content-header {
        margin-bottom: 12px;
        border-radius: 14px;
    }

    /* Таблицы/переполнение */
    body.crm-page .table-wrapper,
    body.crm-page table {
        max-width: 100%;
    }
}

/* Чат: делаем "как мессенджер" — секция занимает весь экран и нормально скроллится */
body.crm-page.chat-page main.main-content {
    flex: 1 1 auto;
    min-height: 0;
}

body.crm-page.chat-page .messenger {
    flex: 1 1 auto;
    min-height: 0;
    border-radius: 14px;
}

body.crm-page.chat-page .messenger-layout {
    height: 100%;
    min-height: 0;
}

body.crm-page.chat-page .messenger-thread {
    min-height: 0;
}

body.crm-page.chat-page .thread-messages {
    min-height: 0;
    overflow-y: auto;
}

@media (max-width: 768px) {
    body.crm-page.chat-page .main-content {
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: 12px;
    }

    body.crm-page.chat-page .main-content-header {
        margin-bottom: 10px;
    }

    body.crm-page.chat-page .messenger {
        border-radius: 14px;
    }

    /* Composer: удобнее на мобилке, с safe-area */
    body.crm-page.chat-page .thread-composer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* Очень маленькие экраны */
@media (max-width: 420px) {
    body.crm-page .main-content {
        padding-left: 12px;
        padding-right: 12px;
        padding-top: 66px;
    }

    .sidebar-toggle {
        top: 14px;
        left: 14px;
        padding: 10px;
        border-radius: 10px;
    }
}

/* На мобилке кнопку сворачивания не показываем (там гамбургер + выезжающее меню) */
@media (max-width: 768px) {
    .sidebar-collapse {
        display: none;
    }
}

/* Оверлей при открытом сайдбаре на мобилке */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 999;
}

@media (max-width: 768px) {
    .sidebar-overlay.open {
        display: block;
    }
}

/* Чат внутри CRM: отключаем старые правила chat-page, которые предполагали layout без сайдбара */
body.crm-page.chat-page {
    padding: 0;
    overflow: hidden;
    height: 100dvh;
}

body.crm-page.chat-page .container {
    display: flex;
    height: 100%;
}

body.crm-page.chat-page .main-content {
    height: 100%;
    overflow: hidden;
}

body.crm-page.chat-page main.main-content > section.messenger {
    height: calc(100% - 0px);
}
