/* =========================================================================
   Экран «Чат» с юристом.
   Layout: шапка (sticky сверху) + история (скроллится) +
           поле ввода (sticky снизу) + bottom-nav.
   На корневом .screen--chat overflow выключен — управление
   прокруткой делегировано .chat__history.
   ========================================================================= */

.screen--chat {
	/* .chat__input-wrap и .bottom-nav оба position: fixed снаружи потока,
	   поэтому здесь padding-bottom не нужен. Сам экран — flex column с
	   header сверху и scrollable history, занимающей всю оставшуюся высоту. */
	padding: 0;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

/* ---------- Шапка чата ---------- */
.chat__header {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3) var(--sp-4);
	background: rgba(255, 255, 255, 0.65);
	border-bottom: 1px solid var(--color-divider);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	position: sticky;
	top: 0;
	z-index: var(--z-header);
	flex-shrink: 0;
}

.chat__back {
	width: 36px;
	height: 36px;
	min-height: 36px;
	border-radius: 50%;
	background: var(--color-glass-bg-strong);
	border: 1px solid var(--color-glass-border);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-primary);
	font-size: var(--fs-md);
	flex-shrink: 0;
	cursor: pointer;
	transition: background var(--t-fast);
}

.chat__back:hover { background: white; }

/* ---------- Кнопка «Aa» — переключатель размера шрифтов ----------
   Расположена справа в шапке чата. По тапу — выпадающее меню
   с тремя размерами (см. .chat__fs-menu ниже). */
.chat__fs-toggle {
	width: 36px;
	height: 36px;
	min-height: 36px;
	border-radius: 50%;
	background: var(--color-glass-bg-strong);
	border: 1px solid var(--color-glass-border);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-primary);
	font-family: var(--font-family);
	font-size: 13px;
	font-weight: var(--fw-semibold);
	flex-shrink: 0;
	cursor: pointer;
	transition: background var(--t-fast);
	letter-spacing: -0.02em;
}

.chat__fs-toggle:hover { background: white; }

/* Маленький символ внутри кнопки — две буквы Aa разного размера */
.chat__fs-toggle__sym-small { font-size: 9px; }
.chat__fs-toggle__sym-large { font-size: 15px; }

/* ---------- Выпадающее меню «размер шрифта» ----------
   Создаётся динамически в body (position: fixed) через утилиту
   chat-font-size.js, чтобы не было проблем с overflow: hidden у
   .screen--chat. */
.chat__fs-menu {
	position: fixed;
	z-index: var(--z-dropdown);
	min-width: 180px;
	padding: var(--sp-2);
	background: var(--color-glass-bg-strong);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-lg);
	backdrop-filter: blur(28px) saturate(180%);
	-webkit-backdrop-filter: blur(28px) saturate(180%);
	box-shadow: var(--shadow-lg);
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.chat__fs-option {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: 8px 12px;
	background: transparent;
	border: none;
	border-radius: var(--radius-md);
	font-family: var(--font-family);
	color: var(--color-primary);
	cursor: pointer;
	text-align: left;
	transition: background var(--t-fast);
}

.chat__fs-option:hover {
	background: rgba(198, 142, 48, 0.08);
}

.chat__fs-option.is-active {
	background: rgba(198, 142, 48, 0.16);
	color: var(--color-accent);
	font-weight: var(--fw-semibold);
}

.chat__fs-symbol {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	font-weight: var(--fw-semibold);
	color: inherit;
	letter-spacing: -0.02em;
}

.chat__brand {
	width: 36px;
	height: 36px;
	border-radius: var(--radius-md);
	flex-shrink: 0;
	display: block;
}

.chat__lawyer {
	flex: 1;
	min-width: 0;
}

.chat__lawyer-name {
	font-size: var(--fs-md);
	font-weight: var(--fw-semibold);
	color: var(--color-primary);
	line-height: 1.2;
}

.chat__lawyer-status {
	font-size: var(--fs-xs);
	color: var(--color-secondary);
	display: flex;
	align-items: center;
	gap: 5px;
	margin-top: 2px;
	font-weight: var(--fw-medium);
}

.chat__lawyer-status::before {
	content: '';
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--color-secondary);
}

/* offline-вариант (на будущее) */
.chat__lawyer-status.is-offline {
	color: var(--color-text-muted);
}
.chat__lawyer-status.is-offline::before {
	background: var(--color-text-muted);
}

/* ---------- История сообщений ----------
   Padding-bottom задаёт нижний запас, чтобы последнее сообщение не
   оказывалось под зафиксированными снизу .chat__input-wrap и .bottom-nav.
   Стартовое значение рассчитано на input минимальной высоты ~52px;
   при росте textarea JS-обработчик в chat.js (ResizeObserver на input-wrap)
   подкручивает padding-bottom динамически. */
.chat__history {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	padding: var(--sp-4);
	padding-bottom: calc(
		52px                            /* минимальная высота input-wrap */
		+ var(--bottom-nav-height)
		+ var(--sp-3) * 2               /* зазоры nav-bottom и input/nav */
		+ var(--safe-bottom)
		+ var(--sp-3)                   /* доп. воздух между сообщением и инпутом */
	);
}

/* ---------- Пузырьки сообщений ---------- */
.bubble {
	max-width: var(--bubble-max);
	padding: var(--sp-2) var(--sp-3) 6px;
	border-radius: var(--radius-lg);
	font-size: var(--fs-base);
	line-height: var(--lh-normal);
	position: relative;
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
}

.bubble__text {
	margin: 0;
	/* Размер шрифта в чате управляется CSS-переменной --chat-fs,
	   которую устанавливает js/utils/chat-font-size.js на корневой
	   .screen--chat (или .screen--management-chat). По умолчанию
	   наследуется --fs-base (13px). */
	font-size: var(--chat-fs, var(--fs-base));
}

.bubble__meta {
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: var(--fs-xs);
	color: var(--color-text-faint);
	margin-top: 4px;
}

/* От юриста — стеклянный пузырёк, тёмный текст, скруг хвоста слева */
.bubble--agent {
	align-self: flex-start;
	background: rgba(255, 255, 255, 0.75);
	border: 1px solid var(--color-glass-border);
	border-bottom-left-radius: var(--radius-sm);
	color: var(--color-primary);
	box-shadow: 0 2px 8px rgba(19, 23, 42, 0.04);
}

/* От клиента — золотой градиент, белый текст, скруг хвоста справа */
.bubble--client {
	align-self: flex-end;
	background: var(--grad-gold);
	border: 1px solid rgba(217, 161, 74, 0.5);
	border-bottom-right-radius: var(--radius-sm);
	color: var(--color-text-on-accent);
	box-shadow: 0 4px 14px rgba(198, 142, 48, 0.22);
}

.bubble--client .bubble__meta {
	color: rgba(255, 255, 255, 0.82);
}

/* Иконки галочек статуса.
   Подгружаются как CSS mask-image из assets/icons/ (Олег нарисовал).
   Цвет наследуется через background-color: currentColor — для белых
   галок на золотых пузырьках клиента, и для любого другого цвета,
   если когда-нибудь захотим сделать «прочитано бирюзовое в стиле
   Telegram» — это будет одно правило в CSS. */

.read-tick {
	display: inline-block;
	width: 16px;
	height: 12px;
	flex-shrink: 0;
	background-color: currentColor;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-position: center;
	mask-position: center;
	-webkit-mask-size: contain;
	mask-size: contain;
}

.read-tick--sent {
	-webkit-mask-image: url('/assets/icons/tick-sent.svg');
	mask-image: url('/assets/icons/tick-sent.svg');
}

.read-tick--read {
	-webkit-mask-image: url('/assets/icons/tick-read.svg');
	mask-image: url('/assets/icons/tick-read.svg');
}

.read-tick--sending {
	-webkit-mask-image: url('/assets/icons/tick-sending.svg');
	mask-image: url('/assets/icons/tick-sending.svg');
	animation: tick-sending-spin 1.6s linear infinite;
}

.read-tick--failed {
	-webkit-mask-image: url('/assets/icons/tick-failed.svg');
	mask-image: url('/assets/icons/tick-failed.svg');
}

@keyframes tick-sending-spin {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}

/* Семантика 5 состояний (Вариант B):
   - sending   → часики, медленно вращаются         (отправляется)
   - sent      → одна галка, полная видимость       (доставлено серверу)
   - delivered → две галки, приглушённые            (доставлено клиенту)
   - read      → две галки, полная видимость        (прочитано юристом)
   - failed    → треугольник «⚠», красный           (не отправилось)
*/

.bubble__tick--sending   { opacity: 0.7; }
.bubble__tick--sent      { opacity: 1; }
.bubble__tick--delivered { opacity: 0.55; }
.bubble__tick--read      { opacity: 1; }
.bubble__tick--failed    { color: var(--color-error); opacity: 1; }

/* Состояние пузырька «отправляется»: лёгкая полупрозрачность,
   чтобы пользователь видел разницу с уже отправленным. */
.bubble--sending {
	opacity: 0.78;
}

/* Состояние пузырька «не отправлено»: красный левый бордер +
   кнопка «Повторить» под текстом */
.bubble--failed {
	border-color: rgba(154, 42, 42, 0.45);
	box-shadow: 0 4px 14px rgba(154, 42, 42, 0.15);
}

.bubble__retry {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin-top: 6px;
	padding: 4px 10px;
	background: transparent;
	border: 1px solid rgba(255, 255, 255, 0.45);
	border-radius: var(--radius-pill);
	color: white;
	font-family: var(--font-family);
	font-size: var(--fs-xs);
	font-weight: var(--fw-semibold);
	cursor: pointer;
	transition: background var(--t-fast), border-color var(--t-fast);
}

.bubble__retry:hover {
	background: rgba(255, 255, 255, 0.18);
	border-color: rgba(255, 255, 255, 0.7);
}

/* ---------- Инлайн-редактирование сообщения ---------- */
.bubble--editing {
	box-shadow: 0 0 0 2px rgba(198, 142, 48, 0.5);
}

.bubble__edit-area {
	width: 100%;
	min-height: 60px;
	max-height: 200px;
	padding: 6px 8px;
	background: rgba(255, 255, 255, 0.92);
	color: var(--color-primary);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-sm);
	outline: none;
	font-family: var(--font-family);
	font-size: max(var(--chat-fs, var(--fs-base)), 16px);
	line-height: var(--lh-normal);
	resize: none;
}

.bubble__edit-actions {
	display: flex;
	gap: var(--sp-2);
	margin-top: 6px;
}

.bubble__edit-btn {
	padding: 4px 12px;
	background: transparent;
	border: 1px solid rgba(255, 255, 255, 0.45);
	border-radius: var(--radius-pill);
	color: white;
	font-family: var(--font-family);
	font-size: var(--fs-xs);
	font-weight: var(--fw-semibold);
	cursor: pointer;
	transition: background var(--t-fast), border-color var(--t-fast);
}

.bubble__edit-btn:hover {
	background: rgba(255, 255, 255, 0.18);
	border-color: rgba(255, 255, 255, 0.8);
}

.bubble__edit-btn--save {
	background: rgba(255, 255, 255, 0.96);
	color: var(--color-accent);
	border-color: rgba(255, 255, 255, 0.96);
}

.bubble__edit-btn--save:hover {
	background: white;
}

/* Метка «изменено» в bubble__meta — для отредактированных сообщений */
.bubble__edited {
	font-style: italic;
	margin-right: 4px;
	font-size: var(--fs-xs);
	color: rgba(255, 255, 255, 0.7);
}

.bubble--agent .bubble__edited {
	color: var(--color-text-faint);
}

/* ---------- Reply / цитирование ---------- */

/* Превью цитаты над input-wrap (когда пользователь нажал «Ответить») */
.reply-preview {
	display: flex;
	align-items: flex-start;
	gap: var(--sp-2);
	padding: var(--sp-2) var(--sp-3);
	background: rgba(255, 255, 255, 0.85);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-md);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	margin-bottom: var(--sp-2);
	box-shadow: 0 -4px 12px rgba(19, 23, 42, 0.05);
}

.reply-preview__bar {
	width: 3px;
	align-self: stretch;
	background: var(--color-accent);
	border-radius: 2px;
	flex-shrink: 0;
}

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

.reply-preview__author {
	font-size: var(--fs-xs);
	font-weight: var(--fw-semibold);
	color: var(--color-accent);
	letter-spacing: 0.02em;
}

.reply-preview__text {
	font-size: var(--fs-sm);
	color: var(--color-text-muted);
	line-height: 1.4;
	margin-top: 2px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.reply-preview__close {
	width: 28px;
	height: 28px;
	flex-shrink: 0;
	border-radius: 50%;
	background: transparent;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-text-muted);
	cursor: pointer;
	transition: background var(--t-fast);
}

.reply-preview__close:hover {
	background: rgba(19, 23, 42, 0.08);
	color: var(--color-primary);
}

/* Цитата внутри пузырька (показывает, на что был ответ) */
.bubble__quote {
	display: flex;
	gap: 8px;
	align-items: stretch;
	padding: 6px 10px 6px 8px;
	background: rgba(255, 255, 255, 0.18);
	border: none;
	border-radius: var(--radius-sm);
	color: inherit;
	font-family: var(--font-family);
	text-align: left;
	cursor: pointer;
	margin-bottom: 6px;
	width: 100%;
	transition: background var(--t-fast);
}

.bubble--agent .bubble__quote {
	background: rgba(19, 23, 42, 0.05);
}

.bubble__quote:hover {
	background: rgba(255, 255, 255, 0.32);
}

.bubble--agent .bubble__quote:hover {
	background: rgba(19, 23, 42, 0.10);
}

.bubble__quote-bar {
	width: 3px;
	flex-shrink: 0;
	background: currentColor;
	opacity: 0.7;
	border-radius: 2px;
}

.bubble--client .bubble__quote-bar {
	background: rgba(255, 255, 255, 0.85);
}

.bubble--agent .bubble__quote-bar {
	background: var(--color-accent);
}

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

.bubble__quote-author {
	font-size: var(--fs-xs);
	font-weight: var(--fw-semibold);
	opacity: 0.92;
}

.bubble__quote-text {
	font-size: var(--fs-xs);
	opacity: 0.78;
	line-height: 1.35;
	margin-top: 1px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Подсветка цитируемого сообщения при тапе на цитату */
.bubble--quoted-highlight {
	animation: quote-flash 1.2s ease;
}

@keyframes quote-flash {
	0%   { box-shadow: 0 0 0 0 rgba(198, 142, 48, 0); }
	30%  { box-shadow: 0 0 0 4px rgba(198, 142, 48, 0.45); }
	100% { box-shadow: 0 0 0 0 rgba(198, 142, 48, 0); }
}

/* =========================================================================
   ВЛОЖЕНИЯ — превью над input + миниатюры в пузырьках
   ========================================================================= */

/* Превью-карточка над input-wrap (выбран файл, готов к отправке) */
.att-preview {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2);
	background: rgba(255, 255, 255, 0.85);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-md);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	margin-bottom: var(--sp-2);
}

.att-preview__thumb {
	width: 44px;
	height: 44px;
	object-fit: cover;
	border-radius: var(--radius-sm);
	flex-shrink: 0;
}

.att-preview__icon {
	width: 44px;
	height: 44px;
	border-radius: var(--radius-sm);
	background: var(--grad-gold-soft);
	border: 1px solid rgba(198, 142, 48, 0.22);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-accent);
	flex-shrink: 0;
}

.att-preview__icon svg {
	width: 22px;
	height: 22px;
}

.att-preview__body {
	flex: 1;
	min-width: 0;
}

.att-preview__name {
	font-size: var(--fs-sm);
	font-weight: var(--fw-medium);
	color: var(--color-primary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.att-preview__meta {
	font-size: var(--fs-xs);
	color: var(--color-text-muted);
	margin-top: 2px;
}

.att-preview__close {
	width: 28px;
	height: 28px;
	flex-shrink: 0;
	border-radius: 50%;
	background: transparent;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-text-muted);
	cursor: pointer;
	transition: background var(--t-fast);
}

.att-preview__close:hover {
	background: rgba(19, 23, 42, 0.08);
	color: var(--color-primary);
}

/* Вложение внутри пузырька */
.att-msg {
	margin-bottom: 6px;
	border-radius: var(--radius-sm);
	overflow: hidden;
	position: relative;
}

.att-msg__img {
	display: block;
	max-width: 100%;
	max-height: 280px;
	width: auto;
	height: auto;
	border-radius: var(--radius-sm);
	cursor: zoom-in;
}

.att-msg__file {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	padding: 8px;
	background: rgba(255, 255, 255, 0.18);
	border-radius: var(--radius-sm);
	cursor: pointer;
}

.bubble--agent .att-msg__file {
	background: rgba(19, 23, 42, 0.05);
}

.att-msg__file-icon {
	width: 36px;
	height: 36px;
	border-radius: var(--radius-sm);
	background: rgba(255, 255, 255, 0.92);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--color-accent);
	flex-shrink: 0;
}

.att-msg__file-icon svg {
	width: 22px;
	height: 22px;
}

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

.att-msg__file-name {
	font-size: var(--fs-sm);
	font-weight: var(--fw-medium);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.att-msg__file-meta {
	font-size: var(--fs-xs);
	opacity: 0.78;
	margin-top: 2px;
}

/* Прогресс-бар поверх attachment во время загрузки */
.att-msg__progress {
	position: absolute;
	left: 0;
	bottom: 0;
	right: 0;
	height: 3px;
	background: rgba(255, 255, 255, 0.25);
}

.att-msg__progress-bar {
	height: 100%;
	background: white;
	transition: width 120ms ease;
}

.bubble--agent .att-msg__progress-bar {
	background: var(--color-accent);
}

/* Lightbox для просмотра изображения в полноэкранном режиме */
.lightbox-backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.92);
	z-index: var(--z-modal);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: zoom-out;
	opacity: 0;
	transition: opacity var(--t-normal);
	padding: var(--sp-5);
}

.lightbox-backdrop.is-open { opacity: 1; }

.lightbox-img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

.lightbox-close {
	position: absolute;
	top: calc(var(--sp-4) + var(--safe-top));
	right: var(--sp-4);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background var(--t-fast);
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-close svg   { width: 22px; height: 22px; }

/* DOWNLOAD-FIX 2026-05-05: кнопка скачивания картинки в лайтбоксе */
.lightbox-download {
	position: absolute;
	top: calc(var(--sp-4) + var(--safe-top));
	right: calc(var(--sp-4) + 56px);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background var(--t-fast);
}
.lightbox-download:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-download svg   { width: 22px; height: 22px; }

/* =========================================================================
   ОФЛАЙН-ИНДИКАТОР — плашка под шапкой чата
   Появляется когда navigator.onLine === false. Уходит со slide-up
   при появлении сети. Сообщения отправленные в этот момент попадают
   в IndexedDB pending-queue (см. js/utils/pending-queue.js).
   ========================================================================= */
.chat__offline {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	padding: 8px var(--sp-4);
	background: rgba(154, 42, 42, 0.10);
	border-bottom: 1px solid rgba(154, 42, 42, 0.22);
	color: var(--color-error);
	font-size: var(--fs-sm);
	font-weight: var(--fw-medium);
	flex-shrink: 0;
	animation: offline-slide-down var(--t-normal);
}

.chat__offline[hidden] {
	display: none;
}

.chat__offline-icon {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.chat__offline-icon svg {
	width: 16px;
	height: 16px;
}

.chat__offline-text {
	flex: 1;
	min-width: 0;
	line-height: 1.35;
}

@keyframes offline-slide-down {
	from { opacity: 0; transform: translateY(-8px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Pill «N новых сообщений ↓» ---------- */
/* Sticky bottom внутри .chat__history — прилипает к нижней границе
   видимой области пока пользователь скроллит историю вверх. Скрыт
   когда нет ожидающих сообщений (атрибут hidden = display: none).
   При каждом appendBubble JS-утилита возвращает pill в конец .chat__history. */
.chat__new-msg-pill {
	position: sticky;
	bottom: var(--sp-2);
	align-self: center;
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	padding: 8px 14px;
	background: var(--color-glass-bg-strong);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-pill);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	box-shadow: 0 6px 20px rgba(19, 23, 42, 0.12);
	color: var(--color-accent);
	font-family: var(--font-family);
	font-size: var(--fs-sm);
	font-weight: var(--fw-semibold);
	cursor: pointer;
	z-index: 2;       /* поверх пузырьков, под input-wrap */
	transition: transform var(--t-fast), opacity var(--t-fast);
}

.chat__new-msg-pill:hover {
	background: white;
	transform: translateY(-1px);
}

.chat__new-msg-pill svg {
	width: 14px;
	height: 14px;
}

/* ---------- Разделитель дня ---------- */
.chat__day {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	font-size: var(--fs-xs);
	color: var(--color-text-faint);
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide);
	font-weight: var(--fw-medium);
	padding: var(--sp-2) 0;
	margin: var(--sp-2) 0;
}

.chat__day::before,
.chat__day::after {
	content: '';
	flex: 1;
	height: 1px;
	background: var(--color-divider);
}

/* ---------- Поле ввода (стеклянная пилюля) ----------
   Position: fixed как и .bottom-nav, но выше неё. Привязано к ширине
   app-контейнера (центрирование как у nav). Сам .chat__input внутри —
   стеклянная пилюля, у обёртки фон transparent. */
.chat__input-wrap {
	position: fixed;
	bottom: calc(
		var(--bottom-nav-height)
		+ var(--sp-3)                   /* nav bottom-offset (sp-3 + safe) — sp-3 часть */
		+ var(--safe-bottom)
		+ var(--sp-3)                   /* вертикальный зазор между nav и инпутом */
	);
	left: 50%;
	transform: translateX(-50%);
	width: 100%;
	max-width: var(--app-max-width);
	padding: 0 var(--sp-4);
	z-index: var(--z-nav);
	background: transparent;
}

.chat__input {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	padding: 6px;
	background: var(--color-glass-bg-strong);
	border: 1px solid var(--color-glass-border);
	border-radius: var(--radius-2xl);
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	box-shadow: 0 4px 16px rgba(19, 23, 42, 0.06);
}

.chat__input-area {
	flex: 1;
	background: transparent;
	border: none;
	outline: none;
	color: var(--color-primary);
	padding: 8px 10px;
	/* Размер шрифта поля ввода синхронизирован с пузырьками
	   (CSS-переменная --chat-fs из chat-font-size.js).
	   Минимум 14px чтобы iOS не делал автозум при фокусе. */
	font-size: max(var(--chat-fs, var(--fs-base)), 16px);
	font-family: var(--font-family);
	resize: none;
	min-height: 36px;
	max-height: 120px;
	line-height: var(--lh-normal);
}

.chat__input-area::placeholder {
	color: var(--color-text-faint);
}

.chat__input-attach,
.chat__input-send {
	width: 38px;
	height: 38px;
	min-height: 38px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	cursor: pointer;
	border: none;
}

.chat__input-attach {
	background: transparent;
	color: var(--color-text-muted);
}

.chat__input-send {
	background: var(--grad-gold);
	color: var(--color-text-on-accent);
	box-shadow: var(--shadow-cta);
}

.chat__input-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ---------- Загрузка и ошибка ---------- */
.chat__loading,
.chat__error {
	text-align: center;
	padding: var(--sp-6) var(--sp-4);
	color: var(--color-text-muted);
	font-size: var(--fs-sm);
	line-height: 1.5;
}

.chat__error {
	color: var(--color-error, #d32f2f);
}

/* =========================================================================
   TASK 4 — Read receipts: синяя галочка «прочитано».

   Дополняет существующий css/screens/chat.css.
   Если есть собственное правило .bubble__tick--read — переопределить.
   Применяется через append к chat.css или вставкой ПОСЛЕ существующих
   правил .bubble__tick--*.
   ========================================================================= */

/* Двойная галочка прочитано — синий цвет (Telegram-style).
   До этого была золотая — теперь read = синий, чтобы визуально отличать
   от delivered (две галочки в текущем цвете темы). */
.bubble__tick--read {
	color: #2196F3 !important;
}

/* На всякий — увеличить opacity если где-то ниже её занижают */
.bubble--client .bubble__tick--read {
	opacity: 1;
}

/* =========================================================================
   TASK 7 — Offline queue: статус 'queued' для пузырьков, ожидающих сети.

   Пузырёк остаётся обычного outgoing-цвета, но галочка заменяется на
   маленькие «часики» сероватого оттенка — чтобы юзер понимал, что
   сообщение в очереди, а не отправлено.
   ========================================================================= */

/* Пузырёк в очереди — лёгкая полупрозрачность, как у sending,
   но без ондалинга «отправляется прямо сейчас». */
.bubble--queued {
	opacity: 0.85;
}

/* Сам индикатор-часики — тонкий circle с двумя стрелками.
   Цвет — нейтральный серый (а не accent), чтобы визуально отличать
   от sent/delivered. */
.bubble__tick--queued,
.read-tick--queued {
	display: inline-block;
	width: 14px;
	height: 14px;
	background-color: transparent;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><circle cx='8' cy='8' r='6'/><path d='M8 5v3l2 1.5'/></svg>");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 14px 14px;
	color: transparent !important;
	opacity: 1;
}

/* =========================================================================
   TASK UX 2026-05-04 — Sticky header fix + infinite-scroll loader.

   ПРОБЛЕМА (только Android Chrome / PWA):
     base.css задаёт html/body/#app/.screen через MIN-height: 100dvh.
     На Android Chrome в PWA-режиме 100dvh нестабильна (адресная
     строка/системный nav-bar меняют visual viewport, layout viewport
     остаётся прежним). Из-за этого .chat__history с flex:1 пытается
     растянуться, но родитель (#app) тоже растягивается под контент,
     и скроллится <html> целиком, а не .chat__history.

   РЕШЕНИЕ:
     1. JS считает window.visualViewport.height и пишет в --app-vh
        на <html>. visualViewport — единственный надёжный источник
        реальной высоты на Android Chrome.
     2. JS добавляет класс .is-chat-screen на <html> при входе на чат
        и снимает при выходе.
     3. Этот CSS форсит ровную высоту chain html → body → #app →
        [data-screen="chat"] → .screen--chat при is-chat-screen.
        Никакого min-height — только height. .chat__history становится
        ЕДИНСТВЕННЫМ скрол-контейнером, sticky-шапка работает как должна.

   КАК НЕ СЛОМАТЬ ОСТАЛЬНЫЕ ЭКРАНЫ:
     Все правила scoped через .is-chat-screen на <html>. Когда юзер на
     home/profile/welcome — этого класса нет, layout остаётся прежним.
   ========================================================================= */

html.is-chat-screen,
html.is-chat-screen body {
	height: var(--app-vh, 100dvh) !important;
	min-height: var(--app-vh, 100dvh) !important;
	max-height: var(--app-vh, 100dvh) !important;
	overflow: hidden !important;
}

/* iOS-специфика: touch-scroll inertia должна работать только внутри
   chat__history, на body/html — нет. */
html.is-chat-screen body {
	-webkit-overflow-scrolling: auto;
	overscroll-behavior: none;
}

html.is-chat-screen #app {
	height: 100% !important;
	min-height: 0 !important;
	max-height: 100% !important;
	overflow: hidden;
}

html.is-chat-screen [data-screen="chat"].is-active {
	height: 100% !important;
	min-height: 0 !important;
	overflow: hidden;
	flex: 1 1 auto;
}

/* Сама история — должна занимать всё что осталось ПОСЛЕ шапки.
   flex:1 уже задан в базе chat.css; здесь добавляем overscroll-behavior
   contain — чтобы overscroll внутри истории не «прокидывался» вверх
   на body (на iOS это проявляется как rubber-band всей страницы). */
html.is-chat-screen .chat__history {
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}

/* TASK UX — top-loader для infinite scroll up.
   JS вставляет <div class="chat__history-top-loader"> первым ребёнком
   .chat__history перед запросом и удаляет после. */
.chat__history-top-loader {
	align-self: center;
	font-size: var(--fs-xs, 11px);
	color: var(--color-text-muted, #6b6b6b);
	background: rgba(255, 255, 255, 0.6);
	border: 1px solid var(--color-glass-border, rgba(0, 0, 0, 0.06));
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	padding: 6px 14px;
	border-radius: 999px;
	margin: 4px auto 8px;
	flex-shrink: 0;
}
