/* ===== Цвета ===== */
:root {
    /* Основной (фирменный) синий */
    --color-primary: #1e3c72;
    --color-primary-light: #2a5298;
    --gradient-primary: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    --color-primary-translucent: rgba(30, 60, 114, 0.55); /* плашка даты в чате */

    /* Статусы */
    --color-success: #32d296;
    --color-warning: #faa05a;
    --color-danger: #f0506e;
    --color-danger-bg: #fef4f6; /* фон пункта "Выйти" при наведении */

    /* Фоны */
    --color-white: #fff;
    --color-page-bg: #f8f9fa;
    --color-chat-bg: #f0f2f5;
    --color-hover-bg: #f5f7fa;

    /* Текст */
    --color-text: #333;
    --color-text-muted: #888;

    /* Рамки и тени */
    --color-border: #e5e5e5;
    --shadow-header: 0 2px 10px rgba(0, 0, 0, 0.1);

    /* Скроллбар */
    --color-scrollbar: #ccc;
    --color-scrollbar-hover: #aaa;
}

/* Стили для интерфейса на весь экран без прокрутки всей страницы */
html, body {
    height: 100%;
    overflow: hidden;
    background: var(--color-page-bg);
    margin: 0;
}
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Шапка */
.app-header {
    background: var(--gradient-primary) !important;
    box-shadow: var(--shadow-header);
}

/* Пользователь в шапке */
.header-user {
    text-transform: none;
    text-align: left;
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
}
.header-user:hover { color: var(--color-white); }

/* Меню пользователя: шапка с uk-light красит ссылки в белый - возвращаем тёмные на белом фоне меню */
.app-header .header-user-menu {
    min-width: 200px;
    padding: 12px 0;
}
.app-header .header-user-menu .uk-nav > li > a {
    display: flex;
    align-items: center;
    padding: 6px 20px;
    color: var(--color-text);
}
.app-header .header-user-menu .uk-nav > li > a:hover {
    color: var(--color-primary);
    background: var(--color-hover-bg);
}
/* «Выйти» - кнопка формы (выход только по POST), выглядит как остальные пункты меню */
.app-header .header-user-menu .uk-nav > li > form { margin: 0; }
.app-header .header-user-menu .uk-nav > li > form button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 20px;
    border: 0;
    background: none;
    font: inherit;
    text-align: left;
    color: var(--color-text);
    cursor: pointer;
}
.app-header .header-user-menu .uk-nav > li > form button:hover {
    color: var(--color-primary);
    background: var(--color-hover-bg);
}
.app-header .header-user-menu .uk-nav-divider {
    margin: 6px 0;
    border-top-color: var(--color-border);
}

/* "Выйти" при наведении - красный текст и иконка (иконка берёт цвет текста через currentColor) */
.app-header .header-user-menu .uk-nav > li.logout-colors > a:hover,
.app-header .header-user-menu .uk-nav > li.logout-colors > form button:hover {
    color: var(--color-danger);
    background: var(--color-danger-bg);
}
.header-user-role {
    display: block;
    font-size: 11px;
    opacity: 0.7;
}

/* Страница входа */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
}
.auth-card {
    width: 100%;
    max-width: 360px;
    margin: 16px;
}

/* Служебные страницы админа (прокручиваются - у body overflow: hidden) */
.admin-page {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px 40px;
}

/* Чек-лист */
.checklist > li { margin-top: 0; }
.checklist-item {
    display: flex;
    gap: 14px;
    padding: 16px 20px;
}
.checklist-icon {
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
}
.checklist-done .checklist-icon { background: var(--color-success); }
.checklist-partial .checklist-icon { background: var(--color-warning); }
.checklist-todo .checklist-icon { background: var(--color-danger); }
.checklist-body {
    flex: 1;
    min-width: 0;
}
.checklist-label { flex: none; }
.checklist-quote {
    margin: 4px 0 6px;
    font-size: 13px;
    font-style: italic;
    color: var(--color-text-muted);
}
.checklist-progress {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--color-danger);
}
.checklist-progress-done { background: var(--color-success); }
.checklist-progress-partial { background: var(--color-warning); }

/* Основная рабочая область */
.chat-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Левая колонка (Список чатов) */
.chat-sidebar {
    width: 320px;
    min-width: 320px;
    border-right: 1px solid var(--color-border);
    background: var(--color-white);
    overflow-y: auto;
}

/* Правая колонка (Окно диалога) */
.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-chat-bg);
}
.messages-area {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 0 20px 20px;
}

/* Сообщения одного дня и плашка с датой, как в Telegram:
   плашка прилипает к верху, пока виден её день, и уезжает вместе с ним */
.day-group { position: relative; }
.day-separator {
    position: sticky;
    top: 8px;
    z-index: 1;
    margin: 8px 0 12px;
    text-align: center;
    pointer-events: none;
}
.day-separator span {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 12px;
    background: var(--color-primary-translucent);
    color: var(--color-white);
    font-size: 12px;
    font-weight: 500;
}

/* Заголовок открытого чата */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 20px;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
}
.chat-header[hidden], .chat-assign[hidden] { display: none; }
.chat-header-title { min-width: 0; }
.chat-assign {
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-assign .uk-select { width: 220px; }
.load-older { align-self: center; margin: 10px auto; display: block; }
.chat-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
}
.chat-search-row { display: flex; align-items: center; gap: 6px; }
.chat-search-row .uk-input { flex: 1; min-width: 0; }
.filters-toggle {
    position: relative;
    flex: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: transparent;
    color: #999;
    cursor: pointer;
}
.filters-toggle:hover { color: #274c8e; }
/* Фильтры включены - кнопка подсвечена, на ней число выбранных */
.filters-toggle.on { color: #fff; background: #274c8e; border-color: #274c8e; }
.filters-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #f0506e;
    color: #fff;
    font-size: 11px;
    line-height: 16px;
    text-align: center;
}
.filters-count[hidden], .chat-filters[hidden], .filters-reset[hidden] { display: none; }
.chat-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters-reset { flex: 1 1 100%; text-align: left; }
.chat-filters .uk-select { flex: 1 1 45%; min-width: 0; }
.chat-filters .uk-select[hidden] { display: none; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #999;
    cursor: pointer;
}
.icon-btn:hover { background: rgba(0, 0, 0, .06); color: #274c8e; }
.icon-btn-danger:hover { color: #f0506e; }
.icon-btn[hidden], .icon-btn [hidden] { display: none; }
.chat-header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-header-name { display: flex; align-items: center; gap: 4px; }
.icon-btn-small { width: 26px; height: 26px; }

/* Блокировка и закрытие чата - отдельная группа за вертикальной чертой, с промежутком между кнопками */
.chat-header-danger {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: 16px;
    padding-left: 20px;
    border-left: 1px solid var(--color-border);
}
.chat-header-danger[hidden] { display: none; }

/* Пометка "Не назначен" в списке чатов */
.chat-unassigned { color: var(--color-danger); }

/* Заглушка "Выберите диалог" - по центру области сообщений, не выходит за её границы */
.chat-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Узкие экраны: список чатов уже */
@media (max-width: 640px) {
    .chat-sidebar {
        width: 200px;
        min-width: 200px;
    }
}

/* Текст и время сообщения */
.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    text-align: left;
}
.message-time {
    margin-top: 4px;
    font-size: 11px;
    text-align: right;
    opacity: 0.6;
}

/* Строка сообщения: входящие - слева, наши - справа */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    margin-bottom: 10px;
}
.message-row-in { justify-content: flex-start; }
.message-row-out { justify-content: flex-end; }
/* У наших сообщений время внутри, в левом нижнем углу */
.message-row-out .message-time { text-align: left; }

.message-row .message-bubble {
    max-width: 70%;
    padding: 10px;
    position: relative;
    border-radius: 8px;
}

.message-row .message-bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    width: 9px;
    height: 12px;
    background: inherit;
}
/* наши (справа): хвостик внизу справа */
.message-row-out { margin-right: 9px; }
.message-row-out .message-bubble { 
    border-bottom-right-radius: 0;
    background-color: #274c8e;
    color: #ffffff;
}
.message-row-out .message-bubble::after {
    right: -9px;
    clip-path: polygon(0 0, 0 100%, 100% 100%);
}
/* входящие (слева): хвостик внизу слева */
.message-row-in { margin-left: 9px; }
.message-row-in .message-bubble { border-bottom-left-radius: 0; }
.message-row-in .message-bubble::after {
    left: -9px;
    clip-path: polygon(100% 0, 0 100%, 100% 100%);
}

/* Панель ввода текста */
.chat-input-area {
    background: var(--color-white);
    padding: 15px;
    border-top: 1px solid var(--color-border);
}

/* Кастомный скроллбар для красоты */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--color-scrollbar-hover); }

/* Таблица иерархии (страница /admin/managers): уровень показывается отступом слева */
.hierarchy-branch-row td {
    background: var(--color-hover-bg);
    font-weight: 600;
}
.hierarchy-level-1 { padding-left: 36px !important; }
.hierarchy-level-2 { padding-left: 72px !important; }
.hierarchy-count {
    margin-left: 6px;
    padding: 0 7px;
    border-radius: 10px;
    background: var(--color-primary);
    color: var(--color-white);
    font-size: 11px;
}
.hierarchy-blocked { opacity: 0.55; }

/* Критерии надёжного пароля - всплывающая подсказка справа от поля в стиле тултипа UIkit:
   серые пункты, выполненные - зелёные с галочкой */
.password-rules {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    z-index: 1020; /* выше окна UIkit (modal - 1010) */
    margin: 0 0 0 10px;
    padding: 8px 14px;
    list-style: none;
    background: #666;
    border-radius: 3px;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.25);
    font-size: 12px;
    line-height: 1.6;
    white-space: nowrap;
}
/* стрелка тултипа влево, к полю */
.password-rules::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -5px;
    margin-top: -5px;
    border: 5px solid transparent;
    border-left: 0;
    border-right-color: #666;
}
.password-rules li {
    margin: 0;
    padding-left: 18px;
    position: relative;
    color: rgba(255, 255, 255, 0.7);
}
.password-rules li::before {
    content: '○';
    position: absolute;
    left: 0;
}
.password-rules li.password-rule-met { color: #5be3ae; } /* зелёный, читаемый на тёмном фоне */
.password-rules li.password-rule-met::before { content: '✓'; }

/* Редактирование прямо в таблице менеджеров: ячейки, которые можно менять кликом */
.editable { cursor: pointer; }
.editable:hover { background: var(--color-hover-bg); }
.user-name-input { min-width: 140px; }
.category-tag-remove {
    margin-left: 6px;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
}
.category-tag-remove:hover { color: var(--color-danger); }
.category-add {
    display: inline-block;
    padding: 0 8px;
    border: 1px dashed var(--color-border);
    border-radius: 3px;
    color: var(--color-text-muted);
    text-decoration: none;
}
.category-add:hover { color: var(--color-primary); border-color: var(--color-primary); }

/* Поля редактирования внутри ячеек таблицы - без рамок, в том числе в фокусе */
.cell-name .uk-input,
.cell-role .uk-select,
.cell-categories .uk-select,
.cell-name .uk-input:focus,
.cell-role .uk-select:focus,
.cell-categories .uk-select:focus {
    border: 0;
    outline: 0;
    box-shadow: none;
}

/* Имя менеджера над его сообщением в чате */
.message-author {
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 600;
    opacity: 0.8;
}

/* Картинка в сообщении чата: иконка-ссылка, файл открывается из Telegram через прокси хаба */
.message-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    margin-bottom: 4px;
    color: inherit;
    text-decoration: underline;
}

/* Иконки: скрепка и отправка - кнопки без рамки; рисунки - icons.css (.icon + .send-icon) и спрайт /img/icons.svg */
.clip,
.send {
    border: 0;
    background: transparent;
    color: #999;
    cursor: pointer;
    padding: 0 8px;
    height: 40px;
}

.clip:hover:not(:disabled),
.send:hover:not(:disabled) { color: #274c8e; }

.clip:disabled,
.send:disabled { opacity: .4; cursor: default; }


.clip svg,
.send svg,
.message-file svg {
    width: 30px;
    height: 35px;
    /* width: 22px;
    height: 22px; */
    fill: currentColor;
    display: block;
}

.message-file svg { width: 18px; height: 18px; }

/* Превью картинки в сообщении */
.message-file:has(.message-preview) { display: block; text-decoration: none; }
.message-preview {
    display: block;
    max-width: 240px;
    max-height: 200px;
    border-radius: 6px;
    cursor: zoom-in;
}

.templates-dropdown { min-width: 240px; max-height: 320px; overflow-y: auto; }

/* Поле сообщения с крестиком очистки */
.input-wrap { position: relative; }
.input-wrap .uk-input { padding-right: 36px; }
.input-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: #999;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
}
.input-clear:hover { color: #274c8e; }
/* Пустое или недоступное поле - крестика нет */
#messageInput:placeholder-shown ~ .input-clear,
#messageInput:disabled ~ .input-clear { display: none; }

.resolved-badge { background: #32d296; }

/* Число непрочитанных сообщений клиента в списке чатов */
.unread-badge { background: #f0506e; margin-left: 4px; }

/* Чек-лист: описание пункта скрыто и плавно раскрывается по клику на заголовок */
.checklist-head { cursor: pointer; user-select: none; }
.checklist-head:focus-visible { outline: 2px solid var(--color-primary, #324a61); outline-offset: 2px; border-radius: 4px; }
.checklist-head-end { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.checklist-chevron { color: #999; transition: transform .3s ease; }
.checklist-item.open .checklist-chevron { transform: rotate(180deg); }
.checklist-detail {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transition: grid-template-rows .3s ease, opacity .3s ease, margin-top .3s ease;
}
.checklist-detail > div { overflow: hidden; min-height: 0; }
.checklist-item.open .checklist-detail { grid-template-rows: 1fr; opacity: 1; margin-top: 6px; }

/* Страница статистики */
.stats-period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stats-period input[type="date"] { width: auto; }
.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.stats-value { font-size: 28px; font-weight: 600; line-height: 1.2; color: var(--color-primary, #324a61); }
.stats-table th { white-space: nowrap; font-size: 12px; }

/* Окно закрытия чата: выбор итога диалога */
.close-results { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.close-result { cursor: pointer; }

/* Сообщение, найденное поиском по тексту: вспышка при открытии чата и выделенное слово */
.message-bubble.message-found { animation: message-found 3s ease-out; }
.message-text mark { background: #ffe066; color: #222; border-radius: 2px; padding: 0 1px; }
@keyframes message-found {
    0%   { box-shadow: 0 0 0 0 rgba(255, 193, 7, .9); transform: scale(1); }
    12%  { box-shadow: 0 0 0 8px rgba(255, 193, 7, .55); transform: scale(1.03); }
    30%  { box-shadow: 0 0 0 4px rgba(255, 193, 7, .45); transform: scale(1); }
    50%  { box-shadow: 0 0 0 8px rgba(255, 193, 7, .35); }
    100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
}

/* Ответ менеджера не дошёл до клиента: подпись и «Отправить ещё раз» */
.message-delivery { margin-top: 6px; font-size: 12px; color: #f0506e; }
.message-bubble.uk-light .message-delivery { color: #ffc2cd; }
.message-delivery a { color: inherit; text-decoration: underline; }

#source-connect-modal .uk-text-meta { font-size: 0.75rem; }