/* R10 Iter C: UI чата teacher<->student.
   Брендбук: 24px card radius, 100px pill radius, orange accent, Outfit/Space Grotesk.
   Two-pane >=1024px, list|thread на мобилке через modifier .msg-root--mobile-thread. */

.msg-root {
    display: grid;
    grid-template-columns: minmax(320px, 380px) 1fr;
    gap: 1.5rem;
    /* Высота = viewport - topbar - главный padding. Подобрано под main-dash-inner. */
    height: calc(100vh - 180px);
    min-height: 560px;
}

.msg-list,
.msg-thread {
    background: var(--bg-card);
    border-radius: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== СПИСОК БЕСЕД ===== */

.msg-list__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.msg-list__head h1 {
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

.msg-list__unread-total {
    min-width: 24px;
    height: 24px;
    padding: 0 0.5rem;
    border-radius: 100px;
    background: var(--accent);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.msg-list__items {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
}

.msg-list-item {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem;
    border: none;
    background: transparent;
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
    align-items: center;
    min-height: 64px;
}

.msg-list-item:hover {
    background: var(--bg-alt);
}

.msg-list-item.is-active {
    background: var(--accent-light);
}

.msg-list-item.has-unread .msg-list-item__name {
    font-weight: 700;
}

.msg-list-item.has-unread .msg-list-item__preview {
    color: var(--text);
    font-weight: 500;
}

.msg-list-item__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    flex-shrink: 0;
}

.msg-list-item__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.msg-list-item__body {
    min-width: 0; /* критично для ellipsis */
}

.msg-list-item__row1,
.msg-list-item__row2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.msg-list-item__row2 {
    margin-top: 0.2rem;
}

.msg-list-item__name {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.msg-list-item__time {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.msg-list-item__preview {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-list-item__unread {
    min-width: 20px;
    height: 20px;
    padding: 0 0.35rem;
    border-radius: 100px;
    background: var(--accent);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ===== ТРЕД ===== */

.msg-thread__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background: var(--bg-card);
}

.msg-thread__back {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.msg-thread__back:hover {
    background: var(--bg-alt);
}

.msg-thread__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
}

.msg-thread__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.msg-thread__head-info {
    min-width: 0;
}

.msg-thread__name {
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-thread__sub {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.msg-thread__scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: var(--bg);
}

.msg-thread__loading,
.msg-thread__empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-light);
}

.msg-day-divider {
    align-self: center;
    margin: 0.5rem 0;
}

.msg-day-divider span {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 100px;
    background: var(--bg-card);
    color: var(--text-light);
    font-size: 0.75rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

.msg-bubble {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.msg-bubble--mine {
    align-self: flex-end;
    align-items: flex-end;
}

.msg-bubble--peer {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-bubble__body {
    padding: 0.65rem 0.9rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.msg-bubble--mine .msg-bubble__body {
    background: var(--accent-gradient);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.msg-bubble--peer .msg-bubble__body {
    background: var(--bg-card);
    color: var(--text);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.msg-bubble__meta {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 0 0.3rem;
}

.msg-bubble--mine .msg-bubble__ticks {
    color: var(--accent);
}

/* ===== COMPOSER ===== */

.msg-thread__composer {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: var(--bg-card);
}

.msg-composer__textarea {
    flex: 1;
    min-height: 44px;
    max-height: 160px;
    padding: 0.7rem 1rem;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 18px;
    font-family: "Outfit", sans-serif;
    font-size: 0.95rem;
    line-height: 1.4;
    resize: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.msg-composer__textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.msg-composer__send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
    box-shadow: var(--shadow-accent);
}

.msg-composer__send:hover:not(:disabled) {
    transform: translateY(-1px);
}

.msg-composer__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.msg-composer-disabled {
    padding: 0.8rem 1rem;
    background: var(--bg-alt);
    color: var(--text-light);
    border-radius: 18px;
    font-size: 0.88rem;
    flex: 1;
}

/* ===== EMPTY STATES ===== */

.msg-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    text-align: center;
    color: var(--text-light);
    padding: 2rem 1rem;
}

.msg-empty--list {
    flex: 1;
}

.msg-empty--thread {
    flex: 1;
    padding: 3rem 2rem;
}

.msg-empty--thread h3 {
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.msg-empty--thread p {
    margin: 0;
    max-width: 320px;
    font-size: 0.9rem;
}

.msg-empty svg {
    color: var(--accent);
    opacity: 0.5;
}

/* ===== SKELETON ===== */

.msg-skeleton-list {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.msg-skeleton-row {
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(90deg, var(--bg-alt) 0%, rgba(0, 0, 0, 0.03) 50%, var(--bg-alt) 100%);
    background-size: 200% 100%;
    animation: msg-skeleton-shimmer 1.4s linear infinite;
}

@keyframes msg-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== RESPONSIVE ===== */

@media (max-width: 1023px) {
    .msg-root {
        grid-template-columns: 1fr;
        height: calc(100vh - 160px);
    }

    /* Desktop-по умолчанию: показываем обе колонки (но грид в 1 колонку их схлопывает).
       На мобилке — показываем одну: список ИЛИ тред. */
    .msg-list {
        display: flex;
    }

    .msg-thread {
        display: none;
    }

    .msg-root--mobile-thread .msg-list {
        display: none;
    }

    .msg-root--mobile-thread .msg-thread {
        display: flex;
    }

    .msg-thread__back {
        display: inline-flex;
    }
}

@media (max-width: 480px) {
    .msg-thread__scroll {
        padding: 0.75rem;
    }

    .msg-bubble {
        max-width: 85%;
    }

    .msg-list__head {
        padding: 1rem 1rem 0.6rem;
    }
}

/* ===== BADGE НЕПРОЧИТАННЫХ В SIDEBAR ===== */

.sb-msg-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 0.35rem;
    border-radius: 100px;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}
