/* ===========================================================================
   ZAM Report Assistant
   Global stylesheet. Styles here must stay global (not Blazor-scoped) because
   the assistant's answer HTML is injected via MarkupString and therefore never
   receives a scoped-CSS attribute.
   =========================================================================== */

:root {
	--primary: #10b981;
	--primary-dim: #0d9668;
	--accent: #06b6d4;
	--background: #0b1120;
	--surface: #131c2f;
	--surface-2: #1b2740;
	--surface-hover: #24334f;
	--border: #2a3854;
	--text-primary: #eef2f8;
	--text-secondary: #93a3bd;
	--danger: #f87171;
	--warning: #fbbf24;
	--radius: 14px;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html, body {
	height: 100%;
	background: var(--background);
	color: var(--text-primary);
}

h1:focus {
	outline: none;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */

.chat-app {
	display: flex;
	flex-direction: column;
	height: 100vh;
	background: var(--background);
}

.chat-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	padding: 14px 24px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	flex-wrap: wrap;
}

.header-left {
	display: flex;
	align-items: center;
	gap: 14px;
	min-width: 0;
}

.logo {
	width: 42px;
	height: 42px;
	flex-shrink: 0;
	display: grid;
	place-items: center;
	font-size: 20px;
	color: #04121a;
	border-radius: 12px;
	background: linear-gradient(135deg, var(--primary), var(--accent));
}

.app-title h1 {
	font-size: 18px;
	font-weight: 650;
	letter-spacing: -0.01em;
}

.app-subtitle {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 12.5px;
	color: var(--text-secondary);
	margin-top: 2px;
	flex-wrap: wrap;
}

.coverage-pill {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 2px 9px;
	border-radius: 999px;
	background: rgba(16, 185, 129, 0.12);
	border: 1px solid rgba(16, 185, 129, 0.3);
	color: var(--primary);
	font-weight: 600;
	font-size: 11.5px;
	white-space: nowrap;
}

.header-actions {
	display: flex;
	align-items: center;
	gap: 10px;
}

.icon-btn {
	width: 40px;
	height: 40px;
	display: grid;
	place-items: center;
	font-size: 16px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 10px;
	color: var(--text-secondary);
	cursor: pointer;
	transition: all 0.15s;
}

.icon-btn:hover:not(:disabled) {
	background: var(--surface-hover);
	color: var(--text-primary);
}

.icon-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.mode-toggle {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 9px 14px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 10px;
	font-size: 13px;
	font-weight: 550;
	color: var(--text-secondary);
	cursor: pointer;
	user-select: none;
	transition: all 0.15s;
}

.mode-toggle:hover {
	background: var(--surface-hover);
}

.mode-toggle:has(input:checked) {
	background: rgba(16, 185, 129, 0.14);
	border-color: var(--primary);
	color: var(--primary);
}

.mode-toggle input {
	accent-color: var(--primary);
	cursor: pointer;
}

.language-selector {
	padding: 9px 12px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 10px;
	color: var(--text-primary);
	font-size: 13px;
	cursor: pointer;
	outline: none;
}

.init-error {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	margin: 16px 24px 0;
	padding: 14px 18px;
	background: rgba(248, 113, 113, 0.1);
	border: 1px solid rgba(248, 113, 113, 0.4);
	border-radius: var(--radius);
	color: var(--danger);
	font-size: 14px;
}

/* ── Messages ───────────────────────────────────────────────────────────── */

.messages-container {
	flex: 1;
	overflow-y: auto;
	padding: 28px 24px 150px;
}

.messages-wrapper {
	max-width: 1080px;
	margin: 0 auto;
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	padding: 60px 20px;
}

.empty-icon {
	font-size: 52px;
	color: var(--primary);
	margin-bottom: 18px;
}

.empty-title {
	font-size: 30px;
	font-weight: 700;
	letter-spacing: -0.02em;
	margin-bottom: 10px;
}

.empty-subtitle {
	font-size: 15px;
	color: var(--text-secondary);
	max-width: 520px;
	margin-bottom: 36px;
}

.feature-list {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 14px;
	width: 100%;
	max-width: 860px;
}

.feature-item {
	text-align: left;
	background: var(--surface);
	padding: 18px;
	border-radius: var(--radius);
	border: 1px solid var(--border);
	cursor: pointer;
	transition: all 0.18s;
	font: inherit;
	color: inherit;
}

.feature-item:hover:not(:disabled) {
	transform: translateY(-2px);
	border-color: var(--primary);
	background: var(--surface-2);
}

.feature-item:disabled {
	opacity: 0.5;
	cursor: wait;
}

.feature-icon {
	font-size: 20px;
	color: var(--primary);
	margin-bottom: 10px;
}

.feature-title {
	font-size: 14.5px;
	font-weight: 650;
	margin-bottom: 5px;
}

.feature-desc {
	font-size: 13px;
	color: var(--text-secondary);
	line-height: 1.5;
}

.message-wrapper {
	margin-bottom: 28px;
	animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
	from { opacity: 0; transform: translateY(12px); }
	to   { opacity: 1; transform: translateY(0); }
}

.user-message {
	display: flex;
	justify-content: flex-end;
	margin-bottom: 16px;
}

.user-bubble {
	background: linear-gradient(135deg, var(--primary), var(--primary-dim));
	color: #04121a;
	padding: 12px 18px;
	border-radius: 16px 16px 4px 16px;
	max-width: 70%;
	font-size: 15px;
	font-weight: 550;
	line-height: 1.55;
}

.ai-message {
	display: flex;
	gap: 14px;
}

.ai-avatar {
	width: 38px;
	height: 38px;
	flex-shrink: 0;
	display: grid;
	place-items: center;
	font-size: 17px;
	color: #04121a;
	border-radius: 11px;
	background: linear-gradient(135deg, var(--accent), var(--primary));
}

.ai-bubble {
	background: var(--surface);
	border: 1px solid var(--border);
	padding: 20px 24px;
	border-radius: 4px 16px 16px 16px;
	flex: 1;
	min-width: 0;
	font-size: 15px;
	line-height: 1.7;
}

.ai-bubble.is-error {
	border-color: rgba(248, 113, 113, 0.5);
	background: rgba(248, 113, 113, 0.06);
}

.ai-bubble-header {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 10px;
	margin-bottom: 14px;
	padding-bottom: 12px;
	border-bottom: 1px solid var(--border);
}

.meta-pill {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	font-weight: 600;
	color: var(--text-secondary);
	padding: 4px 10px;
	border-radius: 999px;
	background: var(--surface-2);
}

.speaker-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: transparent;
	border: 1px solid var(--border);
	border-radius: 999px;
	color: var(--text-secondary);
	cursor: pointer;
	padding: 4px 12px;
	font-size: 12px;
	font-weight: 600;
	transition: all 0.15s;
}

.speaker-btn:hover:not(:disabled) {
	color: var(--primary);
	border-color: var(--primary);
}

.speaker-btn.speaking {
	color: var(--primary);
	border-color: var(--primary);
}

.speaker-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ── Assistant answer content ───────────────────────────────────────────── */

.ai-bubble h2 {
	font-size: 21px;
	font-weight: 700;
	letter-spacing: -0.015em;
	margin: 4px 0 14px;
	color: var(--text-primary);
}

.ai-bubble h3 {
	font-size: 16px;
	font-weight: 650;
	margin: 26px 0 10px;
	color: var(--primary);
}

.ai-bubble p {
	margin: 10px 0;
	color: #d6deea;
}

.ai-bubble ul,
.ai-bubble ol {
	margin: 10px 0 10px 22px;
	color: #d6deea;
}

.ai-bubble li {
	margin: 5px 0;
}

.ai-bubble strong {
	color: var(--text-primary);
	font-weight: 650;
}

.ai-bubble table,
.data-table {
	width: 100%;
	border-collapse: collapse;
	margin: 14px 0;
	font-size: 13.5px;
	background: var(--background);
	border-radius: 10px;
	overflow: hidden;
	border: 1px solid var(--border);
}

.ai-bubble th {
	background: var(--surface-2);
	color: var(--text-secondary);
	padding: 10px 14px;
	text-align: left;
	font-weight: 650;
	font-size: 11.5px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	white-space: nowrap;
}

.ai-bubble td {
	padding: 10px 14px;
	border-top: 1px solid var(--border);
	color: #d6deea;
}

.ai-bubble tbody tr:hover {
	background: var(--surface-2);
}

.ai-bubble td:not(:first-child) {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.ai-bubble th:not(:first-child) {
	text-align: right;
}

.stat-row {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
	gap: 12px;
	margin: 18px 0;
}

.stat-card {
	background: var(--background);
	padding: 16px 18px;
	border-radius: 12px;
	border: 1px solid var(--border);
}

.stat-value {
	font-size: 24px;
	font-weight: 700;
	color: var(--primary);
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
}

.stat-label {
	font-size: 11.5px;
	color: var(--text-secondary);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	margin-top: 6px;
}

.callout {
	margin: 16px 0;
	padding: 14px 18px;
	border-left: 3px solid var(--primary);
	background: rgba(16, 185, 129, 0.07);
	border-radius: 0 10px 10px 0;
	color: #d6deea;
	font-size: 14.5px;
}

/* Charts are injected by erpCharts after render. */
.erp-chart {
	position: relative;
	height: 340px;
	margin: 20px 0;
	padding: 18px;
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: 12px;
}

.erp-chart .erp-chart-title {
	font-size: 13px;
	font-weight: 650;
	color: var(--text-secondary);
	text-align: center;
	margin-bottom: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.erp-chart .erp-chart-canvas-wrap {
	position: relative;
	height: calc(100% - 32px);
}

/* ── SQL diagnostics ────────────────────────────────────────────────────── */

.sql-panel {
	margin-top: 22px;
	border-top: 1px solid var(--border);
	padding-top: 14px;
}

.sql-panel summary {
	cursor: pointer;
	font-size: 12.5px;
	font-weight: 600;
	color: var(--text-secondary);
	list-style: none;
	display: flex;
	align-items: center;
	gap: 7px;
}

.sql-panel summary::-webkit-details-marker {
	display: none;
}

.sql-panel summary:hover {
	color: var(--primary);
}

.sql-entry {
	margin-top: 12px;
	padding: 12px 14px;
	background: var(--background);
	border: 1px solid var(--border);
	border-radius: 10px;
}

.sql-question {
	font-size: 12.5px;
	color: var(--text-secondary);
	font-style: italic;
	margin-bottom: 8px;
}

.sql-entry pre {
	font-family: 'Cascadia Code', 'Consolas', monospace;
	font-size: 12px;
	line-height: 1.6;
	color: #9fe8c8;
	white-space: pre-wrap;
	word-break: break-word;
	margin: 0 0 8px;
}

.sql-meta {
	display: flex;
	gap: 14px;
	font-size: 11.5px;
	font-weight: 600;
	flex-wrap: wrap;
}

.sql-ok    { color: var(--primary); }
.sql-bad   { color: var(--danger); }
.sql-retry { color: var(--warning); }

/* ── Thinking indicator ─────────────────────────────────────────────────── */

.thinking-indicator {
	display: flex;
	gap: 14px;
	margin-bottom: 20px;
}

.thinking-bubble {
	display: flex;
	align-items: center;
	gap: 14px;
	background: var(--surface);
	border: 1px solid var(--border);
	padding: 16px 22px;
	border-radius: 4px 16px 16px 16px;
}

.thinking-text {
	font-size: 14px;
	font-weight: 600;
	color: var(--primary);
}

.thinking-dots {
	display: flex;
	gap: 6px;
}

.thinking-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--primary);
	animation: bounce 1.4s infinite;
}

.thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
	0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
	40%           { transform: scale(1);   opacity: 1; }
}

/* ── Input ──────────────────────────────────────────────────────────────── */

.text-input-panel {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(to top, var(--background) 62%, transparent);
	padding: 22px 24px 20px;
	z-index: 100;
}

.text-input-container {
	max-width: 1080px;
	margin: 0 auto;
	display: flex;
	gap: 10px;
	align-items: center;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	padding: 8px 8px 8px 6px;
}

.text-input-container:focus-within {
	border-color: var(--primary);
}

.text-input-field {
	flex: 1;
	padding: 12px 16px;
	border: none;
	background: transparent;
	color: var(--text-primary);
	font-size: 15px;
	outline: none;
	min-width: 0;
}

.text-input-field::placeholder {
	color: var(--text-secondary);
}

.submit-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 22px;
	background: var(--primary);
	color: #04121a;
	border: none;
	border-radius: 11px;
	font-size: 14px;
	font-weight: 650;
	cursor: pointer;
	transition: all 0.15s;
}

.submit-btn:hover:not(:disabled) {
	background: #34d9a4;
}

.submit-btn:disabled {
	background: var(--surface-hover);
	color: var(--text-secondary);
	cursor: not-allowed;
}

.voice-btn {
	width: 44px;
	height: 44px;
	display: grid;
	place-items: center;
	background: var(--surface-2);
	color: var(--text-secondary);
	border: 1px solid var(--border);
	border-radius: 11px;
	font-size: 16px;
	cursor: pointer;
	transition: all 0.15s;
}

.voice-btn:hover:not(:disabled) {
	color: var(--text-primary);
}

.voice-btn.recording {
	background: var(--danger);
	border-color: var(--danger);
	color: #fff;
	animation: pulse-recording 1.5s ease-in-out infinite;
}

.voice-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

@keyframes pulse-recording {
	0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.5); }
	50%      { box-shadow: 0 0 0 9px rgba(248, 113, 113, 0); }
}

.voice-status {
	position: fixed;
	bottom: 96px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--surface);
	border: 1px solid var(--primary);
	padding: 9px 18px;
	border-radius: 999px;
	z-index: 101;
	font-size: 13px;
	font-weight: 600;
	color: var(--primary);
}

.voice-pulse {
	width: 9px;
	height: 9px;
	background: var(--danger);
	border-radius: 50%;
	animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
	0%, 100% { opacity: 1; transform: scale(1); }
	50%      { opacity: 0.4; transform: scale(1.25); }
}

/* ── Print / PDF ────────────────────────────────────────────────────────── */

@media print {
	.chat-header,
	.text-input-panel,
	.voice-status,
	.ai-bubble-header,
	.sql-panel,
	.thinking-indicator {
		display: none !important;
	}

	html, body, .chat-app, .messages-container {
		height: auto;
		overflow: visible;
		background: #fff;
		color: #111;
	}

	.messages-container { padding: 0; }

	.ai-message { display: block; }
	.ai-avatar  { display: none; }

	.ai-bubble {
		background: #fff;
		border: none;
		padding: 0;
		color: #111;
		page-break-inside: avoid;
	}

	.ai-bubble h2,
	.ai-bubble h3,
	.ai-bubble p,
	.ai-bubble td,
	.ai-bubble strong,
	.ai-bubble li { color: #111; }

	.ai-bubble th {
		background: #f1f5f9;
		color: #334155;
	}

	.ai-bubble table { border-color: #cbd5e1; }
	.ai-bubble td    { border-color: #e2e8f0; }

	.user-bubble {
		background: #f1f5f9;
		color: #0f172a;
		max-width: 100%;
		border-radius: 8px;
	}

	.stat-card, .erp-chart {
		background: #fff;
		border-color: #cbd5e1;
		page-break-inside: avoid;
	}

	.stat-value { color: #059669; }
	.callout    { background: #f0fdf4; color: #111; }
}

/* ── Blazor error UI ────────────────────────────────────────────────────── */

.blazor-error-boundary {
	background: #b32121;
	padding: 1rem;
	color: white;
	border-radius: 8px;
}

#blazor-error-ui {
	color-scheme: light only;
	background: lightyellow;
	bottom: 0;
	box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
	display: none;
	left: 0;
	padding: 0.6rem 1.25rem 0.7rem 1.25rem;
	position: fixed;
	width: 100%;
	z-index: 1000;
	color: #111;
}

#blazor-error-ui .dismiss {
	cursor: pointer;
	position: absolute;
	right: 0.75rem;
	top: 0.5rem;
}

@media (max-width: 768px) {
	.chat-header { padding: 12px 16px; }
	.messages-container { padding: 20px 14px 160px; }
	.text-input-panel { padding: 14px; }
	.user-bubble, .ai-bubble { max-width: 100%; }
	.ai-bubble { padding: 16px; }
	.feature-list { grid-template-columns: 1fr; }
	.app-subtitle { display: none; }
}
