/**
 * Chat styles for WP LLM Live.
 *
 * Messages, bubbles, input area, spectator/replay modes,
 * transcript, error states, model selector.
 * Part of BACK-932 CSS split.
 *
 * @package WPLLMLive
 * @since BACK-932
 */


/* Messages area with proper font size */
.wpllmlive-chat-messages {
	flex: 1;
	padding: var(--space-3);
	overflow-y: auto;
	overscroll-behavior: contain; /* Prevent scroll chaining to page */
	font-size: var(--fs-lg);
	line-height: 1.4;
}

/* Individual message styling — custom properties consolidate variant rules */
.wpllmlive-message {
	--wpllmlive-msg-bg: #f5f5f5;
	--wpllmlive-msg-accent: transparent;
	--wpllmlive-msg-accent-width: 0;
	--wpllmlive-msg-margin-left: 0;
	--wpllmlive-msg-margin-right: 20%;
	--wpllmlive-msg-text-align: left;
	--wpllmlive-msg-author-color: var(--wp-blue);

	margin-bottom: 8px;
	padding: var(--space-2) 10px;
	border-radius: var(--radius-lg);
	font-size: var(--fs-lg);
	line-height: 1.4;
	background-color: var(--wpllmlive-msg-bg);
	border-left: var(--wpllmlive-msg-accent-width) solid var(--wpllmlive-msg-accent);
	margin-left: var(--wpllmlive-msg-margin-left);
	margin-right: var(--wpllmlive-msg-margin-right);
	text-align: var(--wpllmlive-msg-text-align);
	transition: opacity 0.2s ease-in-out; /* Smooth transition for message replacement */
}

.wpllmlive-message-user {
	--wpllmlive-msg-bg: var(--wpllmlive-user-color, #e3f2fd);
	--wpllmlive-msg-margin-left: 20%;
	--wpllmlive-msg-margin-right: 0;
	--wpllmlive-msg-text-align: right;
	--wpllmlive-msg-author-color: var(--wp-blue);
	color: #333;
	/* Seat accent (custom properties set by the script from the roster): a
	   stripe and the author name in the seat's hue, so two seats never read
	   the same even where the bubble background is flat (dark mode). */
	border-left: 4px solid var(--wpllmlive-seat-accent, transparent);
}

.wpllmlive-message-user .wpllmlive-message-author {
	color: var(--wpllmlive-seat-accent, var(--wpllmlive-msg-author-color, #555));
}

.wpllmlive-message-llm {
	/* Defaults: --wpllmlive-msg-bg: #f5f5f5, --wpllmlive-msg-margin-right: 20% */
}

.wpllmlive-message-agent {
	--wpllmlive-msg-bg: #fff3e0;
	--wpllmlive-msg-accent: #ff9800;
	--wpllmlive-msg-accent-width: 4px;
	--wpllmlive-msg-author-color: #e65100;
	margin-top: 10px;
}

/* Enhanced LLM message formatting for markdown content */
.wpllmlive-message-llm .wpllmlive-message-content {
	line-height: 1.5;
}

/* LLM-specific dark code blocks */
.wpllmlive-message-llm .wpllmlive-message-content pre {
	background: #2d2d2d;
	color: #f8f8f2;
}

.wpllmlive-message-llm .wpllmlive-message-content pre code {
	background: transparent;
	color: inherit;
}

/* User message markdown — left-align block content inside right-aligned bubble */
.wpllmlive-message-user .wpllmlive-message-content :is(ul, ol, h1, h2, h3, pre) {
	text-align: left;
}

.wpllmlive-message-user .wpllmlive-message-content hr {
	background: rgba(0, 0, 0, 0.15);
}

.wpllmlive-message-author {
	font-size: var(--fs-base);
	font-weight: var(--fw-semibold);
	margin-bottom: 4px;
	opacity: 0.8;
	color: var(--wpllmlive-msg-author-color, #555);
}

/* Round label inline on the author line ("Host, Round 12") */
.wpllmlive-message-round {
	font-weight: normal;
	color: #888;
	letter-spacing: 0.5px;
}

/* Round header in host messages */
/* The engine's one-line hand-off ("Next: name") — quiet, like a round header.
   The class lands on the message bubble (from the `engine_line` metadata,
   BACK-1459), so the content rule is what the reader sees. */
.wpllmlive-next-player,
.wpllmlive-next-player .wpllmlive-message-content {
	text-align: center;
	color: #888;
	font-size: var(--fs-base);
	letter-spacing: 0.5px;
}

.wpllmlive-round-header {
	text-align: center;
	font-weight: var(--fw-semibold);
	color: #888;
	margin-bottom: 6px;
	font-size: var(--fs-base);
	letter-spacing: 0.5px;
	text-transform: uppercase;
}

/* Game Banner - visual break for major events */
.wpllmlive-game-banner {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	margin: 12px 0;
	padding: 0;
}

.wpllmlive-game-banner-line {
	flex: 1;
	height: 2px;
	background: linear-gradient(90deg, transparent 0%, #ff9800 30%, #f44336 50%, #ff9800 70%, transparent 100%);
}

.wpllmlive-game-banner-text {
	font-weight: var(--fw-bold);
	font-size: 15px; /* no token: between --fs-lg (14px) and --fs-xl (16px) */
	color: #d32f2f;
	text-transform: uppercase;
	letter-spacing: 1.5px;
	white-space: nowrap;
	padding: 6px var(--space-4);
	background: #fff3e0;
	border: 2px solid #ff9800;
	border-radius: var(--radius-xl);
	text-align: center;
}

/* Game HR - simple separator */
hr.wpllmlive-game-hr {
	border: none;
	height: 1px;
	background: linear-gradient(90deg, transparent 0%, #ccc 20%, #ccc 80%, transparent 100%);
	margin: 16px 0;
}

/* Round divider - announces new round/theme in chat flow (BACK-196) */
.wpllmlive-round-divider {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 18px 8px;
	padding: 0;
}

.wpllmlive-round-divider-line {
	flex: 1;
	height: 1px;
	background: linear-gradient(90deg, transparent 0%, #ccc 40%, #ccc 60%, transparent 100%);
}

.wpllmlive-round-divider-label {
	font-size: var(--fs-sm);
	font-weight: var(--fw-semibold);
	color: #999;
	text-transform: uppercase;
	letter-spacing: 1px;
	white-space: nowrap;
	padding: 2px 0;
}

/* Agent contribution styling */
.wpllmlive-agent-contribution {
	margin-top: 10px;
}

.wpllmlive-agent-header {
	font-weight: var(--fw-semibold);
	margin-bottom: 8px;
	color: #e65100;
}

/* =========================================================================
   Consolidated Message Content Styles
   Base styles for all message types. Type-specific overrides above.
   ========================================================================= */

.wpllmlive-message-content {
	font-size: var(--fs-lg);
	line-height: 1.4;
	word-wrap: break-word;
}

/* Paragraph and list spacing - applies to message-content and analysis-content */
:is(.wpllmlive-message-content, .wpllmlive-analysis-content) p {
	margin: 0 0 6px 0;
}

:is(.wpllmlive-message-content, .wpllmlive-analysis-content) p:last-child {
	margin-bottom: 0;
}

/* Inline code */
.wpllmlive-message-content code {
	background: rgba(0, 0, 0, 0.06);
	padding: 0.15em 0.4em;
	border-radius: var(--radius-md);
	font-size: 0.9em;
	font-family: 'Courier New', Consolas, monospace;
}

/* Code blocks - light theme default, LLM overrides to dark above */
.wpllmlive-message-content pre {
	background: rgba(0, 0, 0, 0.05);
	padding: 1em;
	border-radius: var(--radius-lg);
	overflow-x: auto;
	margin: 0.75em 0;
	font-size: var(--fs-lg);
	font-family: 'Courier New', Consolas, monospace;
}

.wpllmlive-message-content pre code {
	background: transparent;
	padding: 0;
}

/* Blockquotes for markdown="true" games (e.g. einstein 4a) */
.wpllmlive-message-content blockquote {
	margin: 0.75em 0;
	padding: 6px 10px;
	border-left: 3px solid #d0b878;
	background: rgba(208, 184, 120, 0.08);
	font-style: italic;
	color: #5a4a2a;
	border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.wpllmlive-message-content blockquote p:last-child {
	margin-bottom: 0;
}

.wpllmlive-message-content img {
	max-width: 100%;
	height: auto;
	border-radius: var(--radius-md);
}

/* Links */
.wpllmlive-message-content a {
	color: #0073aa;
	text-decoration: underline;
}

.wpllmlive-message-content a:hover {
	color: #005177;
}

/* Headings */
.wpllmlive-message-content :is(h1, h2, h3) {
	margin: 0.5em 0 0.25em;
	font-weight: var(--fw-semibold);
	color: #333;
	border-bottom: 1px solid #e0e0e0;
	padding-bottom: 0.15em;
}

.wpllmlive-message-content :is(h1, h2, h3):first-child {
	margin-top: 0;
}

.wpllmlive-message-content h1 { font-size: var(--fs-3xl); }
.wpllmlive-message-content h2 { font-size: 17px; /* no token: between --fs-xl (16px) and --fs-2xl (18px) */ }
.wpllmlive-message-content h3 { font-size: 15px; /* no token: between --fs-lg (14px) and --fs-xl (16px) */ }

/* Lists - Tight spacing for stack/inventory lists */
.wpllmlive-message-content :is(ul, ol) {
	margin: 0.4em 0;
	padding-left: 1.5em;
}

.wpllmlive-message-content li {
	margin: 0.1em 0;
	line-height: 1.4;
}

/* Text emphasis */
.wpllmlive-message-content strong {
	font-weight: var(--fw-bold);
	color: #222;
}

.wpllmlive-message-content em {
	font-style: italic;
}

/* Horizontal rules */
.wpllmlive-message-content hr {
	border: none;
	height: 1px;
	background: #e0e0e0;
	margin: 0.75em 0;
}

/* Analysis content inherits from message-content, just needs margin */
.wpllmlive-analysis-content {
	margin-top: 8px;
	line-height: 1.6;
}

/* Chat input area */
.wpllmlive-chat-input-area {
	padding: 15px var(--space-5);
	border-top: 1px solid var(--wp-border);
	background-color: var(--wp-chrome-bg);
}

.wpllmlive-message-form {
	display: flex;
	gap: 10px;
	align-items: flex-end;
}

/* Entry-rules tooltip on the input area (input_hint attribute) */
.wpllmlive-input-hint {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 22px;
	height: 22px;
	margin-bottom: 6px;
	border-radius: 50%;
	background: #e0e0e0;
	color: #555;
	font-size: var(--fs-base);
	font-weight: var(--fw-semibold);
	cursor: help;
}

.wpllmlive-input-hint-tip {
	display: none;
	position: absolute;
	bottom: calc(100% + 8px);
	right: 0;
	width: max-content;
	max-width: 340px;
	padding: 8px 12px;
	border-radius: 6px;
	background: #333;
	color: #fff;
	font-size: var(--fs-small, 12px);
	font-weight: normal;
	line-height: 1.5;
	text-align: left;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
	z-index: 100;
}

.wpllmlive-input-hint:hover .wpllmlive-input-hint-tip,
.wpllmlive-input-hint:focus .wpllmlive-input-hint-tip {
	display: block;
}

.wpllmlive-input-hint-line {
	display: block;
}

.wpllmlive-input-hint-line + .wpllmlive-input-hint-line {
	margin-top: 4px;
}

.wpllmlive-message-input {
	flex: 1;
	padding: var(--space-3);
	border: 1px solid var(--wp-border);
	border-radius: var(--radius-sm);
	font-size: var(--fs-xl);
	line-height: 1.5;
	font-family: inherit;
	resize: vertical;
	min-height: 50px;
}

.wpllmlive-message-input:focus {
	outline: none;
	border-color: var(--wp-blue);
	box-shadow: 0 0 0 1px var(--wp-blue);
}

/* Buttons */
.wpllmlive-button {
	padding: 6px var(--space-3);
	font-size: var(--fs-md);
	line-height: 1.4;
	border: 1px solid var(--wp-border);
	border-radius: var(--radius-sm);
	background: var(--wp-white);
	color: var(--wp-text);
	cursor: pointer;
	font-weight: var(--fw-medium);
	transition: background-color var(--transition-base);
}

.wpllmlive-button:hover {
	border-color: var(--wp-blue);
	color: var(--wp-blue);
}

.wpllmlive-button-primary {
	background-color: var(--wp-blue);
	border-color: var(--wp-blue);
	color: #fff;
}

.wpllmlive-button-primary:hover {
	background-color: var(--wp-blue-hover);
	border-color: var(--wp-blue-hover);
}

.wpllmlive-send-button {
	background-color: var(--wp-blue);
	color: #fff;
	padding: var(--space-3) var(--space-6);
	font-size: var(--fs-xl);
	white-space: nowrap;
	border-radius: var(--radius-sm);
}

.wpllmlive-send-button:hover {
	background-color: var(--wp-blue-hover);
}

.wpllmlive-send-button:disabled {
	background-color: #ccc;
	cursor: not-allowed;
}

/* Identity form */
.wpllmlive-identity-form {
	padding: 30px;
	text-align: center;
}

.wpllmlive-identity-form h3 {
	font-size: 24px; /* no token: display heading above --fs-3xl (20px) */
	margin-bottom: 20px;
	font-weight: var(--fw-semibold);
}

.wpllmlive-identity-form label {
	display: block;
	margin-bottom: 8px;
	font-size: var(--fs-xl);
	font-weight: var(--fw-medium);
	text-align: left;
}

.wpllmlive-identity-form input[type="text"] {
	width: 100%;
	padding: 10px;
	border: 1px solid #ddd;
	border-radius: var(--radius-md);
	font-size: var(--fs-xl);
	line-height: 1.5;
	font-family: inherit;
	margin-bottom: 15px;
}

.wpllmlive-identity-form textarea {
	width: 100%;
	padding: 10px;
	border: 1px solid #ddd;
	border-radius: var(--radius-md);
	font-size: var(--fs-xl);
	line-height: 1.5;
	font-family: inherit;
	margin-bottom: 15px;
	resize: vertical;
	min-height: 80px;
}

.wpllmlive-join-info {
	background-color: #e3f2fd;
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius-md);
	margin-bottom: 20px;
	font-size: var(--fs-lg);
	color: #1976d2;
}

/* Rate limit warning */
.wpllmlive-rate-limit-warning {
	padding: var(--space-3) var(--space-5);
	background-color: #fff3cd;
	border-top: 1px solid #ffc107;
	color: #856404;
	font-size: var(--fs-lg);
}

.wpllmlive-rate-limit-warning p {
	margin: 0;
}

/* Loading and empty states */
.wpllmlive-messages-loading,
.wpllmlive-no-messages {
	text-align: center;
	padding: var(--space-10) var(--space-5);
	color: #666;
	font-size: var(--fs-xl);
}

.wpllmlive-chat-login-required {
	padding: var(--space-10) var(--space-5);
	text-align: center;
	font-size: var(--fs-xl);
}

.wpllmlive-chat-login-required p {
	margin-bottom: 15px;
}

.wpllmlive-chat-login-required a {
	color: #0073aa;
	text-decoration: underline;
}

/* Spectator Mode */
.wpllmlive-spectator-banner {
	padding: 10px var(--space-3);
	background: #f5f5f5;
	border-top: 1px solid #dee2e6;
	text-align: center;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
}

.wpllmlive-spectator-message {
	margin: 0;
	color: #495057;
	display: flex;
	align-items: center;
	gap: 6px;
}

.wpllmlive-spectator-icon {
	font-size: var(--fs-lg);
}

.wpllmlive-spectator-message.wpllmlive-game-full {
	color: #6c757d;
	font-style: italic;
}

.wpllmlive-login-to-play {
	padding: 6px var(--space-3);
	font-size: var(--fs-md);
	font-weight: var(--fw-semibold);
	text-decoration: none;
	border-radius: var(--radius-md);
}



.wpllmlive-spectator-container .wpllmlive-game-controls {
	display: none !important; /* Hide game controls for spectators */
}

/* Replay Mode */
.wpllmlive-replay-banner {
	padding: var(--space-3) var(--space-5);
	background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
	color: #fff;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3);
	border-radius: var(--radius-xl) var(--radius-xl) 0 0;
	margin-bottom: -1px;
}

.wpllmlive-replay-title {
	font-size: 15px; /* no token: between --fs-lg (14px) and --fs-xl (16px) */
	font-weight: var(--fw-semibold);
	letter-spacing: 0.5px;
}

.wpllmlive-replay-controls {
	display: flex;
	gap: var(--space-2);
}

.wpllmlive-replay-btn {
	background: rgba(255, 255, 255, 0.15);
	border: 1px solid rgba(255, 255, 255, 0.2);
	color: #fff;
	padding: 6px var(--space-3);
	border-radius: var(--radius-md);
	cursor: pointer;
	font-size: var(--fs-lg);
	transition: all var(--transition-base);
}

.wpllmlive-replay-btn:hover {
	background: rgba(255, 255, 255, 0.25);
}

.wpllmlive-replay-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.wpllmlive-replay-progress {
	width: 100%;
	display: flex;
	align-items: center;
	gap: var(--space-3);
}

.wpllmlive-replay-progress-bar {
	flex: 1;
	height: 6px;
	background: linear-gradient(90deg, #00d9ff, #00ff88);
	border-radius: var(--radius-sm);
	overflow: hidden;
	transition: width 0.3s ease;
	/* Width set via JS to show progress (0% → 100%) */
}

.wpllmlive-replay-progress-text {
	font-size: var(--fs-base);
	color: rgba(255, 255, 255, 0.8);
	white-space: nowrap;
}

/* Transcript view */
.wpllmlive-transcript {
	max-width: 1200px;
	margin: 0 auto 60px auto; /* Add bottom margin to prevent footer overlap */
	padding: var(--space-5);
	font-size: var(--fs-xl);
	line-height: 1.6;
}

/* Ensure page content area has proper spacing when shortcode is present */
/* Simplified with :is() */
:is(.entry-content, .post-content, .page-content, .site-content, #content, .content-area) .wpllmlive-chat-interface {
	margin-bottom: 60px;
}

/* Thinking indicator */
.wpllmlive-thinking {
	background-color: #f5f5f5;
}

.wpllmlive-thinking-dots {
	display: inline-block;
	padding: var(--space-2) 0;
}

.wpllmlive-thinking-dots span {
	animation: blink 1.4s infinite both;
	will-change: opacity;
	font-size: 24px; /* no token: icon/display size above --fs-3xl (20px) */
	line-height: 1;
	color: #666;
}

.wpllmlive-thinking-dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.wpllmlive-thinking-dots span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes blink {
	0%, 80%, 100% {
		opacity: 0.2;
	}
	40% {
		opacity: 1;
	}
}

/* Error message display */
.wpllmlive-error-message {
	background-color: #ffebee;
	border: 1px solid #ef9a9a;
	border-radius: var(--radius-xl);
	padding: var(--space-3) var(--space-4);
	margin: 8px 0;
	color: #c62828;
	font-size: var(--fs-lg);
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: var(--space-2);
}

.wpllmlive-error-icon {
	margin-right: 8px;
	font-size: var(--fs-2xl);
}

/* Config error banner injected above the input area when API/config is broken */
.wpllmlive-config-error-inline {
	padding: 15px;
	background: #fff3cd;
	border: 1px solid #ffc107;
	border-radius: var(--radius-md);
	margin-bottom: 10px;
	color: #856404;
}

.wpllmlive-retry-btn {
	padding: 6px var(--space-4);
	background: #1976d2;
	color: white;
	border: none;
	border-radius: var(--radius-md);
	cursor: pointer;
	font-size: var(--fs-lg);
	font-weight: var(--fw-medium);
	transition: background-color var(--transition-base);
	margin-left: auto;
}

.wpllmlive-retry-btn:hover {
	background: #1565c0;
}

.wpllmlive-retry-btn:active {
	background: #0d47a1;
}

/* Session status message */
.wpllmlive-session-status-message {
	background-color: #fff3cd;
	border: 1px solid #ffc107;
	border-radius: var(--radius-xl);
	padding: var(--space-4) var(--space-5);
	margin: 8px 0;
	color: #856404;
	font-size: var(--fs-lg);
	text-align: center;
	font-weight: var(--fw-medium);
}

/* Model selector — visibility controlled by show_model_selector shortcode attribute (BACK-320) */
.wpllmlive-model-selector {
	margin-bottom: 12px;
	padding-bottom: var(--space-3);
	border-bottom: 1px solid #e0e0e0;
}

.wpllmlive-model-selector label {
	font-weight: var(--fw-medium);
	margin-right: 8px;
	color: #555;
}

.wpllmlive-model-dropdown {
	padding: 6px var(--space-3);
	border: 1px solid #ccc;
	border-radius: var(--radius-md);
	font-size: var(--fs-lg);
	min-width: 250px;
	background-color: white;
}

.wpllmlive-model-dropdown:disabled {
	background-color: #f5f5f5;
	cursor: not-allowed;
	opacity: 0.6;
}

/* BACK-994: Slot booking area is hidden by default via inline style="display:none"
   in game-setup.php. JS showSlotBooking() toggles visibility for authenticated users.
   The !important override was removed so that jQuery .show() can control visibility. */

/* BACK-1008: Overflow panel — parallel game cards when session is full */
.wpllmlive-overflow-panel {
	margin: 1rem 0;
	padding: 1rem;
	background: var(--color-bg-secondary, #f9f9f9);
	border: 1px solid var(--color-border, #ddd);
	border-radius: var(--radius-md, 6px);
}

.wpllmlive-overflow-heading {
	margin: 0 0 0.75rem;
	font-weight: 600;
}

.wpllmlive-overflow-cards {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin-bottom: 0.75rem;
}

.wpllmlive-overflow-session-card {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	padding: 0.75rem 1rem;
	background: #fff;
	border: 1px solid var(--color-border, #ddd);
	border-radius: var(--radius-md, 6px);
	min-width: 180px;
}

.wpllmlive-overflow-session-title {
	font-weight: 600;
}

.wpllmlive-overflow-session-slots {
	font-size: 0.85em;
	color: var(--color-text-muted, #666);
}

.wpllmlive-overflow-join-link,
.wpllmlive-overflow-watch-link {
	align-self: flex-start;
	margin-top: 0.25rem;
}

.wpllmlive-overflow-new-game {
	display: inline-block;
	margin-top: 0.5rem;
}

.wpllmlive-overflow-fallback {
	margin: 0;
	color: var(--color-text-muted, #666);
	font-style: italic;
}

