/**
 * Страницы «Сообщения» (SERVICE / USER / SYSTEM): список бесед + тред.
 */

.msg-page {
    box-sizing: border-box;
}

.msg-page__title {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.35;
    font-weight: 600;
    color: #1a3a52;
}

/* Шапка карточки: заголовок строкой, кнопки отдельной строкой на всю ширину — иначе при узкой колонке
   и overflow:hidden у .msg-layout обрезалась левая кнопка («Новое сообщение»), оставался только «Обновить». */
.msg-layout__head {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid #e8ecf0;
}

.msg-layout__head .msg-toolbar {
    margin-bottom: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
}

.msg-layout {
    display: grid;
    grid-template-columns: min(100%, 320px) 1fr;
    grid-template-rows: auto 1fr;
    gap: 0;
    min-height: min(480px, calc(100vh - 200px));
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.msg-list-panel {
    grid-column: 1;
    grid-row: 2;
    width: auto;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid #e8ecf0;
    display: flex;
    flex-direction: column;
    background: #fafbfc;
}

.msg-list-panel__head {
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8899aa;
    border-bottom: 1px solid #e8ecf0;
}

.msg-folder-tabs {
    display: flex;
    gap: 0;
    padding: 0 8px 6px;
    border-bottom: 1px solid #e8ecf0;
    background: #fafbfc;
}

.msg-folder-tab {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #d5dde6;
    background: #fff;
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.35;
    color: #5c6b7a;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.msg-folder-tab:first-of-type {
    border-radius: 8px 0 0 8px;
    border-right-width: 0;
}

.msg-folder-tab:last-of-type {
    border-radius: 0 8px 8px 0;
}

.msg-folder-tab--active {
    background: #e8f4fc;
    color: #0d5c6b;
    border-color: #a8d4e0;
    box-shadow: inset 0 -1px 0 #138496;
}

.msg-folder-tab:not(.msg-folder-tab--active):hover {
    background: #f4f8fb;
    color: #334;
}

.msg-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.msg-list > li.msg-empty {
    padding: 12px 12px;
    color: #8899aa;
    font-size: 12px;
    line-height: 1.35;
    list-style: none;
}

.msg-list__li {
    list-style: none;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #eef1f4;
}

.msg-list__row {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.msg-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: 1;
    min-width: 0;
    text-align: left;
    padding: 7px 8px 7px 12px;
    border: none;
    border-bottom: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    color: #333;
    transition: background 0.15s;
}

.msg-list__archive-btn {
    flex-shrink: 0;
    align-self: stretch;
    min-width: 52px;
    max-width: 60px;
    padding: 6px 4px;
    border: none;
    border-left: 1px solid #eef1f4;
    background: #f5f7f9;
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.25;
    color: #5c6b7a;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.msg-list__archive-btn:hover {
    background: #e8ecf0;
    color: #1a3a52;
}

.msg-list__item__text {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.msg-list__item__title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    color: #1a3a52;
}

.msg-list__item--has-unread .msg-list__item__title {
    font-weight: 600;
}

.msg-list__item__unread-dot {
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    margin-top: 0;
    border-radius: 50%;
    background: #e53935;
    box-shadow: 0 0 0 2px #fafbfc;
}

.msg-list__item:hover {
    background: #f0f4f8;
}

.msg-list__item--active {
    background: #e8f4fc;
    border-left: 3px solid #138496;
    padding-left: 9px;
}

.msg-list__item--active .msg-list__item__unread-dot {
    box-shadow: 0 0 0 2px #e8f4fc;
}

.msg-list__sub {
    display: block;
    font-size: 10px;
    line-height: 1.35;
    color: #8899aa;
    margin-top: 2px;
}

.msg-thread-panel {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.msg-thread__head {
    padding: 7px 12px;
    border-bottom: 1px solid #e8ecf0;
    font-weight: 600;
    font-size: 12px;
    line-height: 1.35;
    color: #1a3a52;
}

.msg-thread__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg-thread-composer {
    flex-shrink: 0;
    padding: 8px 12px 10px;
    border-top: 1px solid #e8ecf0;
    background: #fafbfc;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-thread-composer[hidden] {
    display: none !important;
}

.msg-thread-composer textarea {
    width: 100%;
    min-height: 48px;
    max-height: 120px;
    padding: 7px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
    line-height: 1.4;
    resize: vertical;
    box-sizing: border-box;
}

.msg-thread-composer__actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.msg-thread-composer .btn-msg-primary {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.msg-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    /* Выше вложенных CRM-POP (32xx) и настроек портала (38xx), иначе оверлей виден, а клики уходят слоям выше. */
    z-index: 5000;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.45);
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.msg-modal-overlay.msg-modal--open {
    display: flex;
}

.msg-modal-box {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    width: min(100%, 520px);
    max-height: min(92vh, 640px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.msg-modal-box__head {
    padding: 16px 20px;
    border-bottom: 1px solid #e8ecf0;
    font-weight: 600;
    font-size: 16px;
    color: #1a3a52;
}

.msg-modal-box__body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.msg-modal-box__foot {
    padding: 12px 20px 16px;
    border-top: 1px solid #e8ecf0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.msg-form-field {
    margin-bottom: 14px;
}

.msg-form-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.msg-form-field input,
.msg-form-field select,
.msg-form-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
}

.msg-form-field textarea {
    min-height: 100px;
    resize: vertical;
}

.msg-form-field input[readonly] {
    background: #f1f3f5;
    color: #333;
    cursor: default;
}

.msg-form-field textarea[readonly] {
    background: #f1f3f5;
    color: #333;
    cursor: default;
    resize: none;
}

.msg-form-field--hidden {
    display: none !important;
}

.btn-msg-primary {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    background: #138496;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

.btn-msg-primary:hover {
    opacity: 0.92;
}

.btn-msg-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.msg-bubble {
    max-width: 94%;
    padding: 7px 10px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-bubble--system {
    align-self: flex-start;
    background: #eef2f6;
    color: #334;
}

.msg-bubble--self {
    align-self: flex-end;
    background: #138496;
    color: #fff;
}

.msg-bubble--other {
    align-self: flex-start;
    background: #e3f2f5;
    color: #1a3a52;
}

.msg-bubble__meta {
    display: block;
    font-size: 10px;
    opacity: 0.88;
    margin-bottom: 4px;
    line-height: 1.3;
}

.msg-actions {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.msg-actions button {
    padding: 5px 10px;
    border-radius: 6px;
    border: none;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.msg-actions button[data-action='accept'] {
    background: #1e7e34;
    color: #fff;
}

.msg-actions button[data-action='decline'] {
    background: #c82333;
    color: #fff;
}

.msg-empty,
.msg-error {
    padding: 24px;
    text-align: center;
    color: #6c757d;
    font-size: 14px;
}

/* Подсказка в правой колонке до выбора беседы */
.msg-thread__hint {
    text-align: left;
    align-self: flex-start;
    max-width: 36em;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.35;
    color: #5c6b7a;
}

.msg-error {
    color: #721c24;
    background: #f8d7da;
    border-radius: 8px;
    margin: 12px;
}

.msg-error:empty {
    display: none;
}

.msg-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 12px;
}

.msg-page > .msg-toolbar {
    margin-bottom: 12px;
}

.msg-toolbar button {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid #ced4da;
    background: #fff;
    color: #1a3a52;
    font-size: 12px;
    line-height: 1.35;
    cursor: pointer;
}

.msg-toolbar button:hover {
    background: #f8f9fa;
}

/* Специфичнее чем `.msg-toolbar button`, иначе белый фон + белый текст */
.msg-toolbar button.btn-msg-primary {
    background: #117a8a;
    color: #fff;
    border: 1px solid #0c6474;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(12, 100, 116, 0.35);
}

.msg-toolbar button.btn-msg-primary:hover {
    background: #0f6d7c;
    color: #fff;
    border-color: #095a68;
    opacity: 1;
}

@media (max-width: 720px) {
    .msg-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
    }

    .msg-list-panel {
        grid-column: 1;
        grid-row: 2;
        width: 100%;
        max-height: 220px;
        border-right: none;
        border-bottom: 1px solid #e8ecf0;
    }

    .msg-thread-panel {
        grid-column: 1;
        grid-row: 3;
        min-height: 220px;
    }
}
