/* Chat dock, signal banners, and real-time score indicators.
   Depends on design tokens declared in Material.css (:root).
   Loaded after Material.css on pages that include the chat feature. */

/* ======================================================================
   1. Chat FAB
   ====================================================================== */

.chat-fab {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 1000;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	border: none;
	background: var(--md-primary);
	color: var(--md-on-primary);
	box-shadow: var(--md-elevation-3);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: box-shadow 200ms, transform 200ms;
}

.chat-fab:hover {
	box-shadow: var(--md-elevation-4);
	transform: scale(1.05);
}

.chat-fab .material-symbols-outlined {
	font-size: 28px;
	transition: transform 200ms;
}

.chat-fab--open {
	z-index: 1002;
}

.chat-fab--open .material-symbols-outlined {
	transform: rotate(90deg);
}

/* Unread badge — red circle, hidden when data-count is 0 or absent */
.chat-fab__badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	background: var(--md-error);
	color: #ffffff;
	font-size: 11px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
	padding: 0 5px;
	box-sizing: border-box;
	pointer-events: none;
}

.chat-fab__badge:empty,
.chat-fab__badge[data-count="0"] {
	display: none;
}

/* ======================================================================
   2. Chat dock container
   ====================================================================== */

.chat-dock {
	position: fixed;
	bottom: 96px;
	right: 24px;
	z-index: 1001;
	width: 360px;
	min-height: 200px;
	max-height: min(520px, calc(100vh - 120px));
	background: var(--md-surface);
	border-radius: 16px;
	box-shadow: var(--md-elevation-3);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* ======================================================================
   3. Header (shared by threads view and conversation view)
   ====================================================================== */

.chat-header {
	min-height: 48px;
	padding: 12px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 1px solid var(--md-outline);
	box-sizing: border-box;
}

.chat-header__title {
	flex: 1 1 auto;
	font-weight: 500;
	font-size: 16px;
	color: var(--md-on-surface);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-header__action {
	font-size: 13px;
	color: var(--md-primary);
	cursor: pointer;
	background: none;
	border: none;
	font-family: inherit;
	padding: 4px 8px;
	border-radius: var(--md-radius);
	text-decoration: underline;
	transition: background-color 150ms;
}

.chat-header__action:hover {
	background: var(--md-primary-light);
}

.chat-header__back {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: none;
	background: transparent;
	border-radius: 50%;
	cursor: pointer;
	color: var(--md-on-surface);
	padding: 0;
	margin-left: -8px;
	transition: background-color 150ms;
}

.chat-header__back:hover {
	background: var(--md-surface-variant);
}

.chat-header__back .material-symbols-outlined {
	font-size: 22px;
}

/* ======================================================================
   4. Thread list
   ====================================================================== */

.chat-view {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	overflow: hidden;
	min-height: 0;
}

.chat-threads {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

.chat-thread-list {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	min-height: 0;
}

.chat-thread-section {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--md-on-surface-muted);
	padding: 12px 16px 4px;
	font-weight: 600;
}

.chat-thread-row {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 10px;
	padding: 10px 16px;
	cursor: pointer;
	transition: background-color 120ms;
	position: relative;
	box-sizing: border-box;
}

.chat-thread-row:hover {
	background: var(--md-surface-variant);
}

/* Greyed-out rows (available contacts with no messages) */
.chat-thread-row--greyed .chat-thread__preview {
	font-style: italic;
	opacity: 0.6;
}

/* Avatar circle */
.chat-thread__avatar {
	flex: 0 0 36px;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--md-primary);
	color: var(--md-on-primary);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 600;
	font-size: 14px;
	line-height: 1;
}

.chat-thread__avatar--broadcast {
	background: transparent;
	font-size: 22px;
}

/* Text body */
.chat-thread__body {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.chat-thread__top {
	display: flex;
	flex-direction: row;
	align-items: baseline;
	gap: 6px;
}

.chat-thread__name {
	font-weight: 500;
	font-size: 14px;
	color: var(--md-on-surface);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-thread__time {
	font-size: 11px;
	color: var(--md-on-surface-muted);
	white-space: nowrap;
}

.chat-thread__bottom {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 6px;
}

.chat-thread__preview {
	font-size: 13px;
	color: var(--md-on-surface-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.chat-thread__unread {
	min-width: 18px;
	height: 18px;
	border-radius: 9px;
	background: var(--md-error);
	color: #ffffff;
	font-size: 10px;
	font-weight: 700;
	line-height: 18px;
	text-align: center;
	padding: 0 4px;
	box-sizing: border-box;
}

.chat-thread__unread:empty {
	display: none;
}

/* Dismiss button -- hidden until row hover */
.chat-thread__dismiss {
	position: absolute;
	right: 8px;
	top: 50%;
	transform: translateY(-50%);
	width: 20px;
	height: 20px;
	border: none;
	background: transparent;
	color: var(--md-on-surface-muted);
	font-size: 16px;
	line-height: 20px;
	text-align: center;
	cursor: pointer;
	padding: 0;
	border-radius: 50%;
	opacity: 0;
	transition: opacity 150ms, background-color 150ms;
}

.chat-thread-row:hover .chat-thread__dismiss {
	opacity: 1;
}

.chat-thread__dismiss:hover {
	background: var(--md-primary-light);
	color: var(--md-on-surface);
}

/* ======================================================================
   5. Conversation view
   ====================================================================== */

.chat-convo {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	overflow: hidden;
}

.chat-convo__messages {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 8px 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

/* Chat bubbles — layout on parent, visuals on __body */
.chat-bubble {
	max-width: 80%;
	margin-bottom: 8px;
	clear: both;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.chat-bubble--in {
	float: left;
	text-align: left;
}

.chat-bubble--out {
	float: right;
	text-align: right;
}

.chat-bubble__sender {
	font-size: 11px;
	font-weight: 700;
	color: var(--md-primary-dark);
	margin-bottom: 2px;
}

.chat-bubble__body {
	display: inline-block;
	padding: 8px 12px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.4;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.chat-bubble--in .chat-bubble__body {
	background: var(--md-surface-variant);
	color: var(--md-on-surface);
	border-bottom-left-radius: 4px;
}

.chat-bubble--out .chat-bubble__body {
	background: var(--md-primary);
	color: var(--md-on-primary);
	border-bottom-right-radius: 4px;
}

.chat-bubble__time {
	font-size: 10px;
	color: var(--md-on-surface-muted);
	margin-top: 2px;
}

/* Compose bar */
.chat-compose {
	flex: 0 0 auto;
	border-top: 1px solid var(--md-outline);
	padding: 8px 12px;
	display: flex;
	flex-direction: row;
	align-items: flex-end;
	gap: 4px;
	box-sizing: border-box;
}

.chat-compose__input {
	flex: 1 1 auto;
	border: 1px solid var(--md-outline);
	border-radius: 8px;
	padding: 8px 10px;
	max-height: 120px;
	resize: none;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	color: var(--md-on-surface);
	background: var(--md-surface);
	box-sizing: border-box;
	outline: none;
	transition: border-color 150ms;
}

.chat-compose__input:focus {
	border-color: var(--md-primary);
}

.chat-compose__send {
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: transparent;
	color: var(--md-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background-color 150ms;
	padding: 0;
}

.chat-compose__send:hover {
	background: var(--md-primary-light);
}

.chat-compose__send .material-symbols-outlined {
	font-size: 22px;
}

/* ======================================================================
   6. Signal banners
   ====================================================================== */

.signal-banner {
	position: fixed;
	top: 56px;                /* below the 56px app-bar */
	left: 0;
	right: 0;
	z-index: 500;
	padding: 8px 16px;
	font-weight: 500;
	font-size: 14px;
	display: flex;
	align-items: center;
	gap: 8px;
	animation: signalSlideIn 300ms ease-out both;
}

.signal-banner--warning {
	background: #fff3cd;
	color: #664d03;
	border-bottom: 1px solid #ffecb5;
}

.signal-banner--error {
	background: var(--md-error);
	color: #ffffff;
}

.signal-banner--info {
	background: var(--md-primary-container);
	color: var(--md-on-primary-container);
}

@keyframes signalSlideIn {
	from { transform: translateY(-100%); opacity: 0; }
	to   { transform: translateY(0);     opacity: 1; }
}

/* ======================================================================
   7. Score flash animation
   ====================================================================== */

@keyframes scoreFlash {
	0%   { font-weight: 700; color: var(--md-primary); }
	100% { font-weight: 400; color: inherit; }
}

td.score-flash {
	animation: scoreFlash 5s ease-out forwards;
}

/* ======================================================================
   8. Targeted chat indicator (on score cells)
   ====================================================================== */

.chat-indicator {
	position: absolute;
	top: 2px;
	left: 2px;
	cursor: pointer;
	color: var(--md-primary);
	animation: indicatorPulse 2s ease-in-out infinite;
	line-height: 1;
}

.chat-indicator .material-symbols-outlined,
.chat-indicator.material-symbols-outlined {
	font-size: 16px;
}

@keyframes indicatorPulse {
	0%, 100% { opacity: 1; }
	50%      { opacity: 0.4; }
}

/* ======================================================================
   9. Empty state
   ====================================================================== */

.chat-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 32px;
	text-align: center;
	color: var(--md-on-surface-muted);
	flex: 1 1 auto;
}

.chat-empty .material-symbols-outlined {
	font-size: 48px;
	opacity: 0.35;
	margin-bottom: 12px;
}

.chat-empty__hint {
	font-size: 14px;
	font-style: italic;
	line-height: 1.5;
	color: var(--md-on-surface-muted);
}

/* ======================================================================
   10. Responsive -- narrow viewports
   ====================================================================== */

@media (max-width: 480px) {
	.chat-dock {
		left: 16px;
		right: 16px;
		width: auto;
		bottom: 80px;
	}

	.chat-fab {
		bottom: 16px;
		right: 16px;
	}
}

/* ======================================================================
   Print -- hide all chat and signal UI
   ====================================================================== */

@media print {
	.chat-fab,
	.chat-dock,
	.signal-banner,
	.chat-indicator {
		display: none !important;
	}
}
