/*
 * TabIS — chat widget (ala Facebook Messenger)
 * Plovoucí tlačítko dole vpravo -> vysouvací seznam místností/lidí -> chat popup.
 * Vzor pozicování/vrstvení stejný jako notifPopup v @layout.latte (fixed divy, ne
 * Bootstrap dropdown/toast — appka je nepoužívá).
 */

#chatToggleBtn {
	position: fixed;
	bottom: 16px;
	right: 16px;
	z-index: 9997;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: #0d6efd;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.2rem;
	text-decoration: none;
	box-shadow: 0 .25rem .5rem rgba(0, 0, 0, .3);
	transition: transform .15s ease;
}

#chatBadge {
	position: absolute;
	top: -4px;
	right: -4px;
	font-size: .6rem;
	padding: .15rem .35rem;
	border-radius: 50%;
	display: none;
}

#chatToggleBtn:hover,
#chatToggleBtn:focus {
	color: #fff;
	transform: scale(1.08);
}

#chatDrawer {
	display: none;
	position: fixed;
	right: 72px;
	bottom: 16px;
	z-index: 9998;
	width: 320px;
	max-height: 60vh;
	flex-direction: column;
	overflow: hidden;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, .15);
	border-radius: .5rem;
	box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175);
}

#chatDrawer.chat-open {
	display: flex;
}

/* .chat-popup — jedno dokované okno konverzace, klonované z <template id="chatPopupTemplate">
 * v @layout.latte; může jich být otevřených víc vedle sebe, dokovaných VEDLE #chatToggleBtn
 * (stejné bottom:16px jako tlačítko, right posunuté o jeho šířku + mezeru — viz DOCK_START/
 * DOCK_BOTTOM v chat-widget.js, který přepočítává inline right/bottom pro každou instanci).
 * Základní right/bottom tu zůstávají jako fallback pro pozici prvního okna, než JS proběhne. */
.chat-popup {
	display: flex;
	position: fixed;
	right: 72px;
	bottom: 16px;
	z-index: 9999;
	width: 320px;
	height: 380px;
	flex-direction: column;
	overflow: hidden;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, .15);
	border-radius: .5rem;
	box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175);
}

/* Sbalená bublina (přetečení nad kapacitu obrazovky, jen na desktopu — viz enforceOverflowCap()
 * v chat-widget.js) — WS zůstává živý, klik na hlavičku okno rozbalí zpět. */
.chat-popup-collapsed {
	width: 40px;
	height: 40px;
	border-radius: 50%;
}

.chat-popup-collapsed .chat-messages,
.chat-popup-collapsed .chat-popup-footer,
.chat-popup-collapsed .chat-invite-panel,
.chat-popup-collapsed .chat-members-panel {
	display: none;
}

.chat-popup-collapsed .chat-popup-header {
	position: relative;
	height: 100%;
	padding: 0;
	justify-content: center;
	border-bottom: none;
	border-radius: 50%;
	background: #0d6efd;
	background-size: cover;
	background-position: center;
	color: #fff;
	font-size: .8rem;
	cursor: pointer;
}

/* Tečka nepřečtené zprávy na sbalené bublině — přidává/odebírá updateBubbleUnreadIndicator()
 * v chat-widget.js. Pozice uvnitř kruhu (ne přes okraj), ať ji neuřízne .chat-popup{overflow:hidden}. */
.chat-bubble-unread {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #dc3545;
	border: 1.5px solid #fff;
}

.chat-popup-collapsed .chat-popup-title {
	font-size: .9rem;
	font-weight: 700;
	flex: none;
	width: auto;
}

.chat-popup-collapsed .chat-popup-header-actions {
	display: none;
}

.chat-tabs {
	display: flex;
	border-bottom: 1px solid rgba(0, 0, 0, .1);
	flex: none;
}

.chat-tab-btn {
	flex: 1;
	border: none;
	background: none;
	padding: .5rem;
	cursor: pointer;
	font-weight: 600;
	font-size: .875rem;
	color: #6c757d;
}

.chat-tab-btn.active {
	color: #0d6efd;
	border-bottom: 2px solid #0d6efd;
}

.chat-tab-pane {
	padding: .5rem;
	overflow-y: auto;
	flex: 1;
}

.chat-tab-pane.d-none-pane {
	display: none;
}

.chat-list-item {
	padding: .4rem .5rem;
	border-radius: .25rem;
	cursor: pointer;
	font-size: .875rem;
}

.chat-list-item:hover {
	background: rgba(0, 0, 0, .05);
}

.chat-list-item .chat-list-meta {
	display: block;
	font-size: .72rem;
	color: #6c757d;
}

.chat-list-name {
	display: block;
}

.chat-list-status {
	display: block;
	font-size: .72rem;
}

.chat-list-status-online {
	color: #198754;
	font-weight: 600;
}

.chat-list-status-offline {
	color: #6c757d;
}

.chat-popup-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: .4rem .6rem;
	background: #f8f9fa;
	border-bottom: 1px solid rgba(0, 0, 0, .1);
	cursor: pointer;
	font-size: .875rem;
	flex: none;
}

.chat-popup-close {
	color: #6c757d;
	text-decoration: none;
	font-size: 1.1rem;
	line-height: 1;
}

.chat-popup-close:hover {
	color: #343a40;
}

.chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: .5rem;
	font-size: .85rem;
}

.chat-msg {
	margin-bottom: .4rem;
	max-width: 80%;
	padding: .35rem .55rem;
	border-radius: .75rem;
	word-wrap: break-word;
	clear: both;
}

.chat-msg-other {
	background: #e9ecef;
	margin-right: auto;
}

.chat-msg-own {
	background: #0d6efd;
	color: #fff;
	margin-left: auto;
	text-align: right;
}

.chat-msg-name {
	display: block;
	font-size: .68rem;
	font-weight: 600;
	opacity: .8;
}

.chat-msg-meta {
	display: block;
	font-size: .68rem;
	opacity: .7;
	margin-top: .15rem;
}

.chat-msg-error {
	color: #dc3545;
	font-style: italic;
	font-size: .8rem;
	text-align: center;
	margin: .5rem 0;
}

.chat-msg-system {
	color: #6c757d;
	font-size: .72rem;
	text-align: center;
	margin: .3rem 0;
	clear: both;
}

.chat-tick-wrap {
	margin-left: .25rem;
}

.chat-tick {
	font-size: .68rem;
}

.chat-tick-sent {
	opacity: .7;
}

.chat-tick-delivered {
	opacity: .85;
}

.chat-tick-read {
	color: #4fc3f7;
}

.chat-list-item {
	position: relative;
	padding-right: 2.2rem;
}

.chat-room-lock {
	font-size: .7rem;
	opacity: .7;
	margin-right: .15rem;
}

.chat-create-panel {
	border: 1px solid rgba(0, 0, 0, .1);
	border-radius: .35rem;
	padding: .5rem;
	margin-bottom: .5rem;
	background: rgba(0, 0, 0, .02);
}

.chat-create-visibility label {
	display: block;
	font-size: .8rem;
	font-weight: normal;
	margin-bottom: .15rem;
	cursor: pointer;
}

.chat-create-invitees {
	max-height: 120px;
	overflow-y: auto;
	border: 1px solid rgba(0, 0, 0, .1);
	border-radius: .25rem;
	padding: .35rem;
	margin: .35rem 0;
	background: #fff;
}

.chat-invitee-item {
	display: block;
	font-size: .8rem;
	font-weight: normal;
	margin-bottom: .1rem;
	cursor: pointer;
}

.chat-create-actions {
	display: flex;
	gap: .35rem;
	margin-top: .35rem;
}

.chat-popup-header-actions {
	display: flex;
	align-items: center;
	gap: .5rem;
}

.chat-invite-btn,
.chat-members-btn {
	color: #6c757d;
	text-decoration: none;
}

.chat-invite-btn:hover,
.chat-members-btn:hover {
	color: #343a40;
}

.chat-invite-panel,
.chat-members-panel {
	padding: .5rem;
	border-bottom: 1px solid rgba(0, 0, 0, .1);
	background: rgba(0, 0, 0, .02);
	flex: none;
}

.chat-list-badge {
	position: absolute;
	top: 50%;
	right: .5rem;
	transform: translateY(-50%);
	background: #dc3545;
	color: #fff;
	font-size: .68rem;
	line-height: 1;
	padding: .2rem .4rem;
	border-radius: 1rem;
	min-width: 1.2rem;
	text-align: center;
}

.chat-members-list {
	max-height: 200px;
	overflow-y: auto;
}

.chat-popup-footer {
	display: flex;
	align-items: center;
	border-top: 1px solid rgba(0, 0, 0, .1);
	flex: none;
}

.chat-attachment-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	flex: none;
	color: #6c757d;
	text-decoration: none;
}

.chat-attachment-btn:hover {
	color: #343a40;
}

.chat-msg-image {
	display: block;
	max-width: 100%;
	max-height: 200px;
	border-radius: .5rem;
	margin-bottom: .25rem;
}

.chat-input {
	border: none;
	border-radius: 0;
	box-shadow: none !important;
}

.chat-send-btn {
	border-radius: 0;
}

@media (max-width: 576px) {
	#chatDrawer,
	.chat-popup {
		left: 8px;
		right: 8px;
		width: auto;
	}

	.chat-popup {
		height: 70vh;
		bottom: 8px;
	}

	#chatDrawer {
		bottom: 72px;
	}

	/* Na mobilu se bubliny nezobrazují — enforceOverflowCap() na úzké obrazovce
	 * přebytečné okno rovnou zavře (viz chat-widget.js), takže .chat-popup-collapsed
	 * sem v praxi nikdy nedorazí. Pravidlo je tu jen jako neškodná pojistka. */
	.chat-popup-collapsed {
		width: 40px;
		height: 40px;
		left: auto;
	}
}
