/* Chat — Run or Die palette (red/black, Barlow). */
.chat-page { padding: 24px 0; }

.chat {
    display: flex;
    height: calc(100vh - 220px);
    min-height: 460px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Sidebar ── */
.chat__sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--white);
    border: 1px solid #e3e6ea;
    border-right: none;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat__sidebar-title {
    padding: 16px;
    font-family: var(--font-h);
    font-size: 13px; font-weight: 700;
    color: var(--gray);
    text-transform: uppercase; letter-spacing: .08em;
    border-bottom: 1px solid var(--light);
}
.chat__sidebar-empty { padding: 16px; color: var(--gray); font-size: 14px; }
.chat__client-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat__client-item { border-bottom: 1px solid var(--light); }
.chat__client-link {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; text-decoration: none; color: var(--dark);
    transition: background var(--trans);
}
.chat__client-link:hover,
.chat__client-item.is-active .chat__client-link { background: rgba(232,0,29,.06); }
.chat__client-item.is-active .chat__client-link { box-shadow: inset 3px 0 0 var(--red); }
.chat__client-avatar {
    width: 34px; height: 34px; border-radius: var(--radius);
    background: var(--dark); color: var(--white);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-h); font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.chat__client-meta { display: flex; flex-direction: column; overflow: hidden; }
.chat__client-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__client-role { font-size: 12px; color: var(--gray); }

/* ── Main ── */
.chat__main {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    background: var(--white);
    border: 1px solid #e3e6ea;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    overflow: hidden;
}
.chat__header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--light); background: #fafafa;
}
.chat__header-avatar {
    width: 40px; height: 40px; border-radius: var(--radius);
    background: var(--red); color: var(--white);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-h); font-weight: 800; flex-shrink: 0;
}
.chat__header-info { flex: 1; min-width: 0; }
.chat__header-name { font-family: var(--font-h); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.chat__header-sub { font-size: 13px; color: var(--gray); }
.chat__header-profile-link {
    font-family: var(--font-h); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--red); border: 2px solid rgba(232,0,29,.3); padding: 6px 14px;
    border-radius: var(--radius); white-space: nowrap; transition: border-color var(--trans);
}
.chat__header-profile-link:hover { border-color: var(--red); text-decoration: none; }
.chat__no-client { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--gray); }

/* ── Messages ── */
.chat__messages { flex: 1; overflow-y: auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.chat__messages-empty { text-align: center; color: var(--gray); margin: auto; }
.chat__message { display: flex; flex-direction: column; max-width: 74%; }
.chat__message:has(.chat__embed-wrap), .chat__message:has(.chat__video-wrap), .chat__message:has(.chat__image-wrap) { max-width: 92%; }
.chat__message--mine { align-self: flex-end; align-items: flex-end; }
.chat__message--theirs { align-self: flex-start; align-items: flex-start; }
.chat__message-sender { font-size: 12px; color: var(--gray); margin-bottom: 3px; padding: 0 4px; }
.chat__message-bubble { padding: 10px 14px; border-radius: 14px; max-width: 100%; word-break: break-word; position: relative; }
.chat__message--mine .chat__message-bubble { background: var(--red); color: var(--white); border-bottom-right-radius: 4px; }
.chat__message--theirs .chat__message-bubble { background: var(--light); color: var(--dark); border-bottom-left-radius: 4px; }
.chat__message-text { font-size: 15px; line-height: 1.5; }
.chat__message-attachment { margin-top: 6px; font-size: 13px; }
.chat__message-meta { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.chat__message-time { font-size: 11px; color: rgba(255,255,255,.7); }
.chat__message--theirs .chat__message-time { color: var(--gray); }
.chat__message-read { font-size: 11px; color: rgba(255,255,255,.55); }
.chat__message-read.is-read { color: #bfffd0; }
.chat__message-delete {
    position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%;
    border: none; background: var(--dark); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
    display: none; align-items: center; justify-content: center; padding: 0; z-index: 1;
}
.chat__message--theirs .chat__message-delete { right: auto; left: -8px; }
.chat__message:hover .chat__message-delete { display: flex; }
@media (pointer: coarse) { .chat__message-delete { display: flex; } }

/* ── Video / embed ── */
.chat__video-wrap, .chat__embed-wrap { margin-top: 6px; width: 100%; }
.chat__video, .chat__embed { width: 100%; aspect-ratio: 16/9; min-height: 240px; border-radius: var(--radius); display: block; background: #000; border: 0; }
.chat__link { color: inherit; text-decoration: underline; }

/* ── Image ── */
.chat__image-wrap { display: block; margin-top: 6px; }
.chat__image { display: block; max-width: 100%; max-height: 320px; border-radius: var(--radius); cursor: pointer; }

/* ── Missing attachment (file gone from disk, message stays) ── */
.chat__attachment-missing {
    margin-top: 6px; padding: 10px 12px; border-radius: var(--radius);
    background: rgba(0,0,0,.06); color: inherit; opacity: .7; font-size: 13px; font-style: italic;
}

/* ── Compose ── */
.chat__compose { border-top: 1px solid var(--light); padding: 12px 16px; background: #fafafa; }
.chat__compose-input {
    width: 100%; box-sizing: border-box; padding: 10px 12px;
    border: 2px solid #e0e0e0; border-radius: var(--radius);
    font-size: 15px; font-family: var(--font-b); resize: none; background: var(--white); color: var(--dark);
}
.chat__compose-input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-glow); }
.chat__compose-footer { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.chat__attach-toggle {
    font-family: var(--font-h); font-size: 13px; font-weight: 700; letter-spacing: .04em;
    color: var(--red); background: none; border: none; cursor: pointer; padding: 4px 0;
}
.chat__attach-toggle:hover { text-decoration: underline; }
.chat__compose-send {
    margin-left: auto; padding: 9px 24px; background: var(--red); color: var(--white);
    border: none; border-radius: var(--radius); font-family: var(--font-h); font-weight: 700;
    letter-spacing: .06em; text-transform: uppercase; cursor: pointer; transition: background var(--trans);
}
.chat__compose-send:hover { background: var(--red-h); }
.chat__compose-send:disabled { opacity: .5; cursor: not-allowed; }
.chat__attach-row { margin-top: 8px; }
.chat__attach-input {
    width: 100%; box-sizing: border-box; padding: 8px 12px;
    border: 2px solid #e0e0e0; border-radius: var(--radius); font-size: 14px; background: var(--white);
}
.chat__attach-input:focus { outline: none; border-color: var(--red); }

/* ── Pending attachment (pasted image or picked exercise, staged until send) ── */
.chat__pending-attach { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.chat__pending-attach-img { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius); border: 2px solid #e0e0e0; }
.chat__pending-attach-label {
    padding: 8px 12px; border-radius: var(--radius); background: var(--light); font-size: 14px;
}
.chat__pending-attach-remove {
    background: none; border: none; cursor: pointer; color: var(--gray); font-size: 20px; line-height: 1; padding: 4px;
}
.chat__pending-attach-remove:hover { color: var(--red); }

/* ── Upload progress ── */
.chat__upload-progress { display: flex; align-items: center; gap: 10px; padding: 8px 4px 0; }
.chat__upload-bar { flex: 1; height: 6px; background: var(--light); border-radius: 3px; overflow: hidden; }
.chat__upload-fill { height: 100%; background: var(--red); width: 0%; transition: width .2s ease; }
.chat__upload-label { font-size: 13px; color: var(--gray); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.chat__upload-cancel { background: none; border: none; cursor: pointer; color: var(--gray); font-size: 16px; }
.chat__upload-cancel:hover { color: var(--red); }

/* ── Responsive ── */
@media (max-width: 760px) {
    .chat { flex-direction: column; height: auto; padding: 0 16px; }
    .chat__sidebar { width: 100%; border-right: 1px solid #e3e6ea; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 200px; }
    .chat__main { border-radius: 0 0 var(--radius-lg) var(--radius-lg); height: 70vh; }

    /* Compose footer has several attach-toggle buttons + send; they don't fit one row on mobile */
    .chat__compose-footer { flex-wrap: wrap; }
    .chat__compose-send { margin-left: 0; width: 100%; order: 10; }
}

/* ── Упражнения и комплексы ───────────────────────────────────────────────
   Галерея упражнения и карточки программы клиента. Стили здесь, а не в
   trainings.css, потому что chat.css подключают все страницы, где упражнения
   показываются: профиль, кабинет, чат и настройки. */
.ex__gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
    gap: 12px;
    margin-top: 12px;
}
.ex__gallery-item {
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #fafafa;
}
.ex__gallery-item figcaption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--gray);
}
.ex__gallery-item img,
.ex__gallery-item video,
.ex__gallery-item iframe { width: 100%; display: block; }

.ex__empty { color: var(--gray); font-size: 13px; margin: 8px 0 0; }

.ex__card {
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 16px;
}
.ex__card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.ex__card-title { margin: 0; font-size: 16px; }

/* Комплекс — рамка вокруг своих упражнений, чтобы состав читался как одно целое */
.ex__set {
    border: 1px solid var(--gray-l);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
}
.ex__set-title { margin: 0; font-size: 18px; }
.ex__set-count {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 10px;
    background: var(--light);
    color: var(--gray);
    font-size: 13px;
}
.ex__set-notes { color: var(--gray); margin: 8px 0 12px; }
.ex__set .ex__card { background: #fff; }

/* Строка библиотеки в настройках: свёрнутое упражнение или комплекс */
.ex__row {
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    margin-top: 12px;
}
.ex__row > summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
}
.ex__row > summary::-webkit-details-marker { display: none; }
.ex__row > summary::before { content: '▸'; color: var(--gray); }
.ex__row[open] > summary::before { content: '▾'; }
.ex__row-name { font-weight: 600; }

/* Подзаголовок внутри раскрытой строки («Состав»). Свой, а не tr__subhead из
   trainings.css: настройки этот файл не подключают. */
.ex__subhead {
    font-family: var(--font-h);
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray);
    margin: 28px 0 12px;
}

/* ── Профиль клиента: оплаченные занятия и срок (панель администратора) ── */
.bal__row { display: flex; flex-wrap: wrap; gap: 24px; }
.bal__form {
    flex: 1 1 260px;
    border: 1px solid var(--light);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
}
.bal__kind {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray);
    margin-bottom: 8px;
}
.bal__fields { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.bal__fields label { display: flex; flex-direction: column; gap: 4px; }
.bal__fields label span { font-size: 12px; color: var(--gray); }
.bal__fields input[type="number"] { width: 90px; }
/* Кнопки — своей строкой под полями и прижаты вправо. Не внутри .bal__fields:
   там они переносились бы вместе с полями и вставали слева. */
.bal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
/* .btn задаёт display, а это перебивает браузерное [hidden] { display:none } —
   без этой строки скрытые кнопки остаются на экране. */
.bal__actions button[hidden] { display: none; }
.bal__fields input:disabled {
    background: var(--light);
    color: var(--dark, #222);
    border-color: transparent;
    cursor: default;
}
.bal__hint { color: var(--gray); font-size: 13px; margin: 16px 0 0; }
