/* ==========================================================================
   Top Iceland AI Assistant — Frontend Chat Widget
   Modern, Intercom/Tidio-style floating assistant.
   All colors are driven by CSS variables set inline by chat-widget.js
   from the admin-configured brand colors.
   ========================================================================== */

#tia-chat-root {
	--tia-primary: #0B5FA5;
	--tia-secondary: #FFFFFF;
	--tia-accent: #F2622E;
	--tia-highlight: #17B8A6;
	--tia-text: #1a2433;
	--tia-text-muted: #667085;
	--tia-bg: #ffffff;
	--tia-bg-soft: #f6f8fb;
	--tia-border: rgba(20, 30, 50, 0.08);
	--tia-radius-lg: 22px;
	--tia-radius-md: 14px;
	--tia-radius-sm: 10px;
	--tia-shadow: 0 20px 60px rgba(10, 30, 60, 0.22), 0 4px 16px rgba(10,30,60,.12);
	--tia-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	all: initial;
	font-family: var(--tia-font);
	direction: ltr;
}

#tia-chat-root[data-theme="dark"] {
	--tia-text: #eef2f7;
	--tia-text-muted: #9aa7ba;
	--tia-bg: #12192b;
	--tia-bg-soft: #1a2338;
	--tia-border: rgba(255,255,255,0.08);
}

#tia-chat-root *,
#tia-chat-root *::before,
#tia-chat-root *::after {
	box-sizing: border-box;
	font-family: var(--tia-font);
}

#tia-chat-root button {
	cursor: pointer;
	background: none;
	border: none;
	font: inherit;
	color: inherit;
}

#tia-chat-root a {
	color: inherit;
	text-decoration: none;
}

/* ---------------------------------------------------------------------
   Launcher button
   --------------------------------------------------------------------- */
.tia-launcher {
	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: 999999;
	width: 60px;
	height: 60px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(135deg, var(--tia-primary), var(--tia-highlight));
	color: #fff;
	border-radius: 50%;
	box-shadow: var(--tia-shadow);
	transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s ease, opacity .2s ease;
	padding: 0;
	overflow: hidden;
}

.tia-launcher:hover {
	transform: translateY(-3px) scale(1.02);
}

.tia-launcher-icon {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.tia-launcher-icon img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tia-launcher-icon svg {
	width: 24px;
	height: 24px;
}

/* Dismissible greeting bubble — shown briefly instead of a permanent text label */
.tia-greeting {
	position: fixed;
	right: 22px;
	bottom: 92px;
	z-index: 999999;
	max-width: 240px;
	background: var(--tia-bg);
	color: var(--tia-text);
	border-radius: var(--tia-radius-md);
	box-shadow: var(--tia-shadow);
	padding: 12px 32px 12px 14px;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.4;
	opacity: 0;
	transform: translateY(10px) scale(.96);
	transition: opacity .25s ease, transform .25s ease;
	pointer-events: none;
}

.tia-greeting.tia-visible {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: all;
	cursor: pointer;
}

.tia-greeting-close {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--tia-text-muted);
	background: var(--tia-bg-soft);
}

.tia-greeting-close svg {
	width: 10px;
	height: 10px;
}

@media (max-width: 520px) {
	.tia-greeting { right: 14px; max-width: calc(100vw - 90px); }
	.tia-launcher { right: 14px; bottom: 14px; }
}

.tia-launcher-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	background: var(--tia-accent);
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 5px;
	border: 2px solid #fff;
}

.tia-launcher.tia-pulse::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50px;
	background: var(--tia-primary);
	animation: tiaPulseRing 1.6s ease-out;
	z-index: -1;
}

@keyframes tiaPulseRing {
	0% { opacity: .55; transform: scale(1); }
	100% { opacity: 0; transform: scale(1.35); }
}

.tia-launcher.tia-hidden,
.tia-panel.tia-hidden {
	display: none !important;
}

.tia-launcher.tia-launcher-hidden {
	opacity: 0;
	transform: translateY(10px) scale(.9);
	pointer-events: none;
}

/* ---------------------------------------------------------------------
   Panel
   --------------------------------------------------------------------- */
.tia-panel {
	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: 999999;
	width: 392px;
	max-width: calc(100vw - 24px);
	height: 640px;
	max-height: calc(100vh - 100px);
	background: var(--tia-bg);
	border-radius: var(--tia-radius-lg);
	box-shadow: var(--tia-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(24px) scale(.96);
	transition: opacity .28s cubic-bezier(.2,.8,.2,1), transform .28s cubic-bezier(.2,.8,.2,1);
	pointer-events: none;
}

.tia-panel.tia-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: all;
}

.tia-panel-backdrop {
	position: fixed;
	inset: 0;
	background: transparent;
	z-index: 999998;
	opacity: 0;
	pointer-events: none;
}

.tia-panel-backdrop.tia-open {
	opacity: 1;
	pointer-events: all;
}

@media (max-width: 520px) {
	.tia-panel {
		right: 8px;
		bottom: 8px;
		left: 8px;
		width: auto;
		height: calc(100vh - 90px);
		max-height: none;
	}
}

/* ---------------------------------------------------------------------
   Header
   --------------------------------------------------------------------- */
.tia-header {
	position: relative;
	padding: 20px 20px 22px;
	background: linear-gradient(135deg, var(--tia-primary) 0%, #0a4d8a 60%, var(--tia-highlight) 140%);
	color: #fff;
	flex-shrink: 0;
}

.tia-header-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	position: relative;
	z-index: 1;
}

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

.tia-header-logo {
	width: 38px;
	height: 38px;
	border-radius: 10px;
	background: rgba(255,255,255,.2);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	flex-shrink: 0;
}

.tia-header-logo img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tia-header-title {
	font-size: 15px;
	font-weight: 700;
	line-height: 1.2;
}

.tia-header-status {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 12px;
	opacity: .92;
	margin-top: 2px;
}

.tia-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #26d17a;
	box-shadow: 0 0 0 2px rgba(38,209,122,.35);
	flex-shrink: 0;
}

.tia-dot.offline {
	background: #b8c0cc;
	box-shadow: none;
}

.tia-header-actions {
	display: flex;
	gap: 6px;
}

.tia-icon-btn {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #ffffff;
	color: var(--tia-primary);
	box-shadow: 0 2px 8px rgba(0,0,0,.25);
	border: 2px solid rgba(255,255,255,.9);
	margin-right: 2px;
	transition: transform .15s ease, background .15s ease;
}

.tia-icon-btn:hover {
	background: #f2f4f7;
	transform: scale(1.08);
}

.tia-icon-btn svg {
	width: 18px;
	height: 18px;
	stroke-width: 3;
}

/* ---------------------------------------------------------------------
   Body / screens
   --------------------------------------------------------------------- */
.tia-body {
	flex: 1;
	overflow-y: auto;
	background: var(--tia-bg-soft);
	position: relative;
	min-height: 0;
}

/* ---------------------------------------------------------------------
   Bottom navigation bar — always visible once the panel is open, so the
   visitor can get back to the Home/options screen from anywhere.
   --------------------------------------------------------------------- */
.tia-navbar {
	display: flex;
	flex-shrink: 0;
	border-top: 1px solid var(--tia-border);
	background: var(--tia-bg);
}

.tia-navitem {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	padding: 8px 4px 9px;
	color: var(--tia-text-muted);
	font-size: 10.5px;
	font-weight: 700;
	transition: color .15s ease;
}

.tia-navitem svg {
	width: 19px;
	height: 19px;
}

.tia-navitem:hover {
	color: var(--tia-text);
}

.tia-navitem.active {
	color: var(--tia-primary);
}

/* Back link used on drill-down screens (e.g. offline form) */
.tia-back-link {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--tia-primary);
	font-size: 12.5px;
	font-weight: 700;
	margin-bottom: 12px;
	padding: 4px 0;
}

.tia-back-link svg {
	width: 15px;
	height: 15px;
}

.tia-back-link:hover {
	opacity: .8;
}

.tia-search-empty {
	color: var(--tia-text-muted);
	font-size: 12.5px;
	text-align: center;
	margin-top: 20px;
}

.tia-screen {
	display: none;
	flex-direction: column;
	height: 100%;
}

.tia-screen.tia-active {
	display: flex;
	animation: tiaScreenIn .22s ease;
}

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

/* --- Options screen --- */
.tia-options-screen {
	padding: 18px;
	gap: 12px;
	overflow-y: auto;
}

.tia-welcome-msg {
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: var(--tia-radius-md);
	padding: 14px 16px;
	font-size: 13.5px;
	line-height: 1.5;
	color: var(--tia-text);
	margin-bottom: 6px;
}

.tia-option-card {
	display: flex;
	align-items: center;
	gap: 14px;
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: var(--tia-radius-md);
	padding: 14px 16px;
	text-align: left;
	transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.tia-option-card:hover {
	transform: translateY(-2px);
	box-shadow: 0 8px 20px rgba(10,30,60,.08);
	border-color: transparent;
}

.tia-option-icon {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	color: #fff;
}

.tia-option-icon svg { width: 20px; height: 20px; }

.tia-option-icon.ai { background: linear-gradient(135deg, var(--tia-primary), var(--tia-highlight)); }
.tia-option-icon.whatsapp { background: #25D366; }
.tia-option-icon.call { background: var(--tia-accent); }
.tia-option-icon.email { background: var(--tia-primary); }
.tia-option-icon.custom { background: linear-gradient(135deg, var(--tia-accent), var(--tia-highlight)); }

.tia-option-text strong {
	display: block;
	font-size: 13.5px;
	color: var(--tia-text);
}

.tia-option-text span {
	display: block;
	font-size: 12px;
	color: var(--tia-text-muted);
	margin-top: 1px;
}

/* --- Chat screen --- */
.tia-chat-screen {
	overflow: hidden;
}

.tia-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.tia-msg-row {
	display: flex;
	gap: 8px;
	max-width: 88%;
	animation: tiaMsgIn .22s ease;
}

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

.tia-msg-row.user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.tia-bubble {
	padding: 10px 14px;
	border-radius: var(--tia-radius-sm);
	font-size: 13.5px;
	line-height: 1.5;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.tia-msg-row.assistant .tia-bubble,
.tia-msg-row.agent .tia-bubble {
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	color: var(--tia-text);
	border-bottom-left-radius: 4px;
}

.tia-msg-row.user .tia-bubble {
	background: linear-gradient(135deg, var(--tia-primary), #0a4d8a);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.tia-msg-status {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 3px;
	font-size: 10.5px;
	color: var(--tia-text-muted);
	margin-top: 3px;
	padding-right: 2px;
}

.tia-msg-status svg {
	width: 11px;
	height: 11px;
	color: var(--tia-highlight);
}

.tia-msg-row.agent .tia-bubble {
	border-color: var(--tia-highlight);
}

.tia-avatar {
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--tia-primary), var(--tia-highlight));
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
}

.tia-suggestions-inline {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 6px;
}

.tia-suggestion-link {
	background: var(--tia-bg);
	border: 1px solid var(--tia-highlight);
	color: var(--tia-primary);
	border-radius: var(--tia-radius-sm);
	padding: 8px 12px;
	font-size: 12.5px;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: space-between;
	transition: background .15s ease;
}

.tia-suggestion-link:hover {
	background: var(--tia-bg-soft);
}

.tia-typing {
	display: flex;
	gap: 4px;
	padding: 12px 14px;
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: var(--tia-radius-sm);
	width: fit-content;
}

.tia-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--tia-text-muted);
	animation: tiaTypingBounce 1.2s infinite ease-in-out;
}

.tia-typing span:nth-child(2) { animation-delay: .15s; }
.tia-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes tiaTypingBounce {
	0%, 60%, 100% { transform: translateY(0); opacity: .5; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick reply chips */
.tia-chips-wrap {
	padding: 10px 14px 4px;
	flex-shrink: 0;
}

.tia-chips-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--tia-text-muted);
	margin-bottom: 8px;
	font-weight: 700;
}

.tia-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	max-height: 84px;
	overflow-y: auto;
}

.tia-chip {
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	color: var(--tia-text);
	padding: 6px 12px;
	border-radius: 20px;
	font-size: 12px;
	font-weight: 600;
	transition: background .15s ease, border-color .15s ease;
}

.tia-chip:hover {
	background: var(--tia-bg-soft);
	border-color: var(--tia-highlight);
}

.tia-human-request {
	text-align: center;
	padding: 4px 14px 10px;
	flex-shrink: 0;
}

.tia-human-request button {
	font-size: 12px;
	color: var(--tia-primary);
	font-weight: 700;
	text-decoration: underline;
}

/* --- Input bar --- */
.tia-input-bar {
	position: relative;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	background: var(--tia-bg);
	border-top: 1px solid var(--tia-border);
	flex-shrink: 0;
}

.tia-input-bar textarea {
	flex: 1;
	resize: none;
	border: 1px solid var(--tia-border);
	background: var(--tia-bg-soft);
	color: var(--tia-text);
	border-radius: 18px;
	padding: 10px 40px 10px 16px;
	font-size: 13.5px;
	line-height: 1.4;
	max-height: 90px;
	outline: none;
	transition: border-color .15s ease;
}

.tia-input-bar textarea:focus {
	border-color: var(--tia-highlight);
}

.tia-send-btn {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: linear-gradient(135deg, #FFC94A, #E08E0B);
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	box-shadow: 0 3px 10px rgba(224,142,11,.4);
	transition: transform .15s ease, box-shadow .15s ease;
}

.tia-send-btn:hover { transform: scale(1.06); box-shadow: 0 5px 14px rgba(224,142,11,.5); }
.tia-send-btn svg { width: 19px; height: 19px; }

.tia-autocomplete {
	position: absolute;
	bottom: 62px;
	left: 14px;
	right: 14px;
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: var(--tia-radius-sm);
	box-shadow: 0 10px 30px rgba(10,30,60,.14);
	overflow: hidden;
	display: none;
	z-index: 5;
}

.tia-autocomplete.tia-active { display: block; }

.tia-autocomplete-item {
	padding: 9px 14px;
	font-size: 12.5px;
	color: var(--tia-text);
	cursor: pointer;
	border-bottom: 1px solid var(--tia-border);
}

.tia-autocomplete-item:last-child { border-bottom: none; }
.tia-autocomplete-item:hover,
.tia-autocomplete-item.tia-highlighted { background: var(--tia-bg-soft); }

.tia-autocomplete-item mark {
	background: transparent;
	color: var(--tia-primary);
	font-weight: 700;
}

/* --- Search screen --- */
.tia-search-screen { padding: 14px; overflow-y: auto; }

.tia-search-input-wrap {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: 20px;
	padding: 8px 14px;
	margin-bottom: 12px;
}

.tia-search-input-wrap svg { width: 15px; height: 15px; color: var(--tia-text-muted); flex-shrink: 0; }

.tia-search-input-wrap input {
	border: none;
	outline: none;
	background: transparent;
	flex: 1;
	font-size: 13px;
	color: var(--tia-text);
}

.tia-search-result {
	display: block;
	background: var(--tia-bg);
	border: 1px solid var(--tia-border);
	border-radius: var(--tia-radius-sm);
	padding: 12px 14px;
	margin-bottom: 8px;
	transition: border-color .15s ease;
}

.tia-search-result:hover { border-color: var(--tia-highlight); }

.tia-search-result strong { display: block; font-size: 13px; color: var(--tia-text); }
.tia-search-result span { font-size: 11px; color: var(--tia-text-muted); text-transform: capitalize; }

/* --- Offline form screen --- */
.tia-offline-screen { padding: 18px; overflow-y: auto; }

.tia-offline-screen .tia-welcome-msg { margin-bottom: 14px; }

.tia-form-field { margin-bottom: 12px; }

.tia-form-field label {
	display: block;
	font-size: 12px;
	font-weight: 700;
	color: var(--tia-text);
	margin-bottom: 5px;
}

.tia-form-field input,
.tia-form-field textarea {
	width: 100%;
	border: 1px solid var(--tia-border);
	background: var(--tia-bg);
	color: var(--tia-text);
	border-radius: var(--tia-radius-sm);
	padding: 9px 12px;
	font-size: 13px;
	outline: none;
	transition: border-color .15s ease;
}

.tia-form-field input:focus,
.tia-form-field textarea:focus { border-color: var(--tia-highlight); }

.tia-submit-btn {
	width: 100%;
	padding: 11px;
	border-radius: var(--tia-radius-sm);
	background: linear-gradient(135deg, var(--tia-primary), var(--tia-highlight));
	color: #fff;
	font-weight: 700;
	font-size: 13.5px;
	margin-top: 4px;
	transition: opacity .15s ease;
}

.tia-submit-btn:hover { opacity: .92; }

.tia-form-success {
	text-align: center;
	padding: 30px 10px;
}

.tia-form-success svg { width: 46px; height: 46px; color: var(--tia-highlight); margin-bottom: 10px; }

/* Scrollbars */
#tia-chat-root ::-webkit-scrollbar { width: 6px; }
#tia-chat-root ::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 10px; }
#tia-chat-root[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

/* Focus visibility for accessibility */
#tia-chat-root button:focus-visible,
#tia-chat-root a:focus-visible,
#tia-chat-root input:focus-visible,
#tia-chat-root textarea:focus-visible {
	outline: 2px solid var(--tia-highlight);
	outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	#tia-chat-root * {
		animation-duration: 0.001ms !important;
		transition-duration: 0.001ms !important;
	}
}
