/* ООКЛ — Віджет зв'язку з пацієнтом. Усі правила обмежені простором .ookl-cw. */

.ookl-cw {
	--ookl-cw-primary: #1d3f7a;
	--ookl-cw-accent: #2f6fd0;
	--ookl-cw-bottom: 24px;
	--ookl-cw-side: 24px;
	--ookl-cw-ink: #1f2937;
	--ookl-cw-muted: #6b7280;
	--ookl-cw-line: #e5e7eb;
	--ookl-cw-bg: #ffffff;
	--ookl-cw-soft: #f4f6fa;

	position: fixed;
	bottom: calc(var(--ookl-cw-bottom) + env(safe-area-inset-bottom, 0px));
	z-index: 99990;
	font-family: inherit;
	line-height: 1.45;
	color: var(--ookl-cw-ink);
}

.ookl-cw--right { right: var(--ookl-cw-side); }
.ookl-cw--left  { left: var(--ookl-cw-side); }

.ookl-cw *,
.ookl-cw *::before,
.ookl-cw *::after { box-sizing: border-box; }

/* ---------- Кнопка ---------- */

.ookl-cw__fab {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	max-width: min(300px, calc(100vw - 32px));
	margin: 0;
	padding: 9px 22px 9px 9px;
	border: 0;
	border-radius: 999px;
	background: var(--ookl-cw-primary);
	color: #fff;
	font-family: inherit;
	cursor: pointer;
	box-shadow: 0 12px 30px rgba(16, 34, 68, .34);
	transition: transform .18s ease, background-color .18s ease, box-shadow .18s ease;
}

.ookl-cw--right .ookl-cw__fab { margin-left: auto; }

.ookl-cw__fab:hover {
	background: var(--ookl-cw-accent);
	transform: translateY(-2px);
	box-shadow: 0 16px 36px rgba(16, 34, 68, .4);
}
.ookl-cw__fab:focus-visible { outline: 3px solid #ffcc4d; outline-offset: 3px; }

.ookl-cw__fab-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	flex: 0 0 46px;
	border-radius: 50%;
	background: #fff;
	color: var(--ookl-cw-primary);
}

.ookl-cw__fab-text {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	min-width: 0;
	text-align: left;
}

.ookl-cw__fab-title {
	font-size: 15px;
	font-weight: 700;
	line-height: 1.25;
	white-space: nowrap;
}

.ookl-cw__fab-sub {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	line-height: 1.3;
	color: rgba(255, 255, 255, .82);
	white-space: nowrap;
}

.ookl-cw__fab-sub.is-online::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 3px rgba(74, 222, 128, .25);
}

/* Привертання уваги: три хвилі одразу після завантаження сторінки. */
.ookl-cw__fab::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 999px;
	border: 2px solid var(--ookl-cw-accent);
	opacity: 0;
	pointer-events: none;
	animation: ookl-cw-pulse 2.4s ease-out 2s 3;
}

@keyframes ookl-cw-pulse {
	0%   { opacity: .75; transform: scale(1); }
	70%  { opacity: 0; transform: scale(1.14); }
	100% { opacity: 0; transform: scale(1.14); }
}

.ookl-cw__fab-close { display: none; }

/* У розгорнутому стані кнопка стискається до кола із хрестиком. */
.ookl-cw[data-state="open"] .ookl-cw__fab {
	width: 56px;
	height: 56px;
	padding: 0;
	justify-content: center;
}
.ookl-cw[data-state="open"] .ookl-cw__fab::after { animation: none; }
.ookl-cw[data-state="open"] .ookl-cw__fab-icon,
.ookl-cw[data-state="open"] .ookl-cw__fab-text { display: none; }
.ookl-cw[data-state="open"] .ookl-cw__fab-close { display: flex; }

.ookl-cw__badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 24px;
	height: 24px;
	padding: 0 7px;
	border-radius: 12px;
	background: #d92d20;
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 24px;
	text-align: center;
	box-shadow: 0 0 0 2px #fff;
}

/* ---------- Панель ---------- */

.ookl-cw__panel {
	position: absolute;
	bottom: 78px;
	width: 360px;
	max-width: calc(100vw - 32px);
	max-height: min(640px, calc(100vh - 120px));
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border-radius: 16px;
	background: var(--ookl-cw-bg);
	box-shadow: 0 24px 60px rgba(16, 34, 68, .26), 0 2px 8px rgba(16, 34, 68, .12);
	animation: ookl-cw-in .18s ease-out;
}

.ookl-cw--right .ookl-cw__panel { right: 0; }
.ookl-cw--left  .ookl-cw__panel { left: 0; }

@keyframes ookl-cw-in {
	from { opacity: 0; transform: translateY(10px); }
	to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
	.ookl-cw__panel { animation: none; }
	.ookl-cw__fab { transition: none; }
	.ookl-cw__fab::after { animation: none; }
}

.ookl-cw__head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 14px 14px 18px;
	background: var(--ookl-cw-primary);
	color: #fff;
}

.ookl-cw__head-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }

.ookl-cw__title { font-size: 15px; font-weight: 700; }
.ookl-cw__subtitle { font-size: 12px; opacity: .8; }
.ookl-cw__subtitle:empty { display: none; }

.ookl-cw__back,
.ookl-cw__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	cursor: pointer;
}

.ookl-cw__back:hover,
.ookl-cw__close:hover { background: rgba(255, 255, 255, .24); }
.ookl-cw__back:focus-visible,
.ookl-cw__close:focus-visible { outline: 2px solid #ffcc4d; outline-offset: 2px; }

.ookl-cw__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* У режимі чату панель має сталу висоту: стрічка повідомлень прокручується
   всередині себе, а поле вводу завжди лишається на видноті внизу. */
.ookl-cw[data-view="chat"] .ookl-cw__panel { height: min(600px, calc(100vh - 140px)); }
.ookl-cw[data-view="chat"] .ookl-cw__body { overflow: hidden; display: flex; flex-direction: column; }
.ookl-cw[data-view="chat"] .ookl-cw__view--chat { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.ookl-cw[data-view="chat"] .ookl-cw__prechat { overflow-y: auto; }

/* ---------- Меню ---------- */

.ookl-cw__view--menu { padding: 12px; display: flex; flex-direction: column; gap: 8px; }

.ookl-cw__item {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	padding: 14px;
	border: 1px solid var(--ookl-cw-line);
	border-radius: 12px;
	background: #fff;
	color: inherit;
	font: inherit;
	text-align: left;
	text-decoration: none;
	cursor: pointer;
	transition: border-color .15s ease, background-color .15s ease;
}

.ookl-cw__item:hover { border-color: var(--ookl-cw-accent); background: var(--ookl-cw-soft); }
.ookl-cw__item:focus-visible { outline: 2px solid var(--ookl-cw-accent); outline-offset: 2px; }

.ookl-cw__item-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	flex: 0 0 42px;
	border-radius: 50%;
	background: var(--ookl-cw-accent);
	color: #fff;
}

.ookl-cw__item-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.ookl-cw__item-title { font-size: 14.5px; font-weight: 600; }
.ookl-cw__item-note { font-size: 12.5px; color: var(--ookl-cw-muted); }
.ookl-cw__item-arrow { color: var(--ookl-cw-muted); flex: 0 0 auto; }

.ookl-cw__status {
	width: 10px;
	height: 10px;
	flex: 0 0 10px;
	border-radius: 50%;
	background: #d1d5db;
}
.ookl-cw__status.is-online { background: #16a34a; box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.ookl-cw__status.is-offline { background: #9ca3af; }

.ookl-cw__phone {
	display: block;
	padding: 10px;
	border-radius: 10px;
	background: var(--ookl-cw-soft);
	color: var(--ookl-cw-primary);
	font-size: 13.5px;
	font-weight: 600;
	text-align: center;
	text-decoration: none;
}

/* ---------- Форма запитання ---------- */

.ookl-cw__view--question { padding: 12px; }
.ookl-cw__loading { padding: 24px 12px; color: var(--ookl-cw-muted); font-size: 13.5px; text-align: center; }

/* Форма сусіднього плагіна всередині вузької панелі */
.ookl-cw__view--question .ookl-q-card { box-shadow: none; border: 0; padding: 0; }
.ookl-cw__view--question .ookl-q-grid { grid-template-columns: 1fr; }

/* ---------- Чат: перший крок ---------- */

.ookl-cw__prechat { padding: 14px; }
.ookl-cw__greeting { margin: 0 0 12px; font-size: 13.5px; color: var(--ookl-cw-muted); }

.ookl-cw__label { display: block; margin: 10px 0 4px; font-size: 13px; font-weight: 600; }
.ookl-cw__opt { font-weight: 400; color: #9ca3af; }

.ookl-cw__input,
.ookl-cw__textarea {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--ookl-cw-line);
	border-radius: 9px;
	background: #fff;
	color: inherit;
	font: inherit;
	font-size: 14px;
}

.ookl-cw__textarea { resize: vertical; min-height: 76px; }
.ookl-cw__input:focus,
.ookl-cw__textarea:focus { outline: 0; border-color: var(--ookl-cw-accent); box-shadow: 0 0 0 3px rgba(47, 111, 208, .15); }

.ookl-cw__hint { margin: 6px 0 0; font-size: 12px; color: var(--ookl-cw-muted); }

.ookl-cw__warning {
	margin: 12px 0 0;
	padding: 10px 12px;
	border-left: 3px solid #f59e0b;
	border-radius: 0 8px 8px 0;
	background: #fffbeb;
	font-size: 12.5px;
	color: #78350f;
}

.ookl-cw__consent {
	display: flex;
	gap: 8px;
	align-items: flex-start;
	margin: 12px 0 0;
	font-size: 12px;
	color: var(--ookl-cw-muted);
	cursor: pointer;
}
.ookl-cw__consent input { margin-top: 2px; flex: 0 0 auto; }

.ookl-cw__hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.ookl-cw__submit {
	width: 100%;
	margin-top: 14px;
	padding: 12px;
	border: 0;
	border-radius: 10px;
	background: var(--ookl-cw-primary);
	color: #fff;
	font: inherit;
	font-size: 14.5px;
	font-weight: 600;
	cursor: pointer;
}
.ookl-cw__submit:hover { background: var(--ookl-cw-accent); }
.ookl-cw__submit:disabled { opacity: .6; cursor: default; }
.ookl-cw__submit--ghost { background: #fff; color: var(--ookl-cw-primary); border: 1px solid var(--ookl-cw-primary); }
.ookl-cw__submit--ghost:hover { background: var(--ookl-cw-soft); color: var(--ookl-cw-primary); }

.ookl-cw__error {
	margin-top: 12px;
	padding: 10px 12px;
	border-radius: 8px;
	background: #fef2f2;
	color: #991b1b;
	font-size: 13px;
}

/* ---------- Чат: діалог ---------- */

.ookl-cw__live { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

.ookl-cw__log {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	padding: 14px;
	background: var(--ookl-cw-soft);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.ookl-cw__msg { max-width: 84%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; word-wrap: break-word; }
.ookl-cw__msg--visitor { align-self: flex-end; background: var(--ookl-cw-primary); color: #fff; border-bottom-right-radius: 4px; }
.ookl-cw__msg--operator { align-self: flex-start; background: #fff; border: 1px solid var(--ookl-cw-line); border-bottom-left-radius: 4px; }
.ookl-cw__msg--system { align-self: center; max-width: 100%; background: transparent; color: var(--ookl-cw-muted); font-size: 12px; text-align: center; }

.ookl-cw__msg-meta { display: block; margin-top: 3px; font-size: 11px; opacity: .7; }

.ookl-cw__composer { display: flex; gap: 8px; align-items: flex-end; flex: 0 0 auto; padding: 10px; border-top: 1px solid var(--ookl-cw-line); }

.ookl-cw__composer-input {
	flex: 1 1 auto;
	height: 42px;
	min-height: 42px;
	max-height: 110px;
	padding: 10px 12px;
	border: 1px solid var(--ookl-cw-line);
	border-radius: 10px;
	font: inherit;
	font-size: 14px;
	line-height: 1.35;
	overflow-y: auto;
	resize: none;
}
.ookl-cw__composer-input:focus { outline: 0; border-color: var(--ookl-cw-accent); }

.ookl-cw__composer-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	flex: 0 0 42px;
	border: 0;
	border-radius: 10px;
	background: var(--ookl-cw-primary);
	color: #fff;
	cursor: pointer;
}
.ookl-cw__composer-send:hover { background: var(--ookl-cw-accent); }
.ookl-cw__composer-send:disabled { opacity: .5; cursor: default; }

.ookl-cw__end {
	margin: 0;
	flex: 0 0 auto;
	padding: 9px;
	border: 0;
	border-top: 1px solid var(--ookl-cw-line);
	background: #fff;
	color: var(--ookl-cw-muted);
	font: inherit;
	font-size: 12.5px;
	cursor: pointer;
}
.ookl-cw__end:hover { color: #991b1b; }

.ookl-cw__offline { padding: 18px 14px; text-align: center; }
.ookl-cw__offline-text { margin: 0 0 8px; font-size: 13.5px; }

/* ---------- Мобільні ---------- */

@media (max-width: 520px) {
	.ookl-cw__panel {
		position: fixed;
		inset: 0;
		bottom: 0;
		width: 100vw;
		max-width: 100vw;
		max-height: 100vh;
		border-radius: 0;
	}
	.ookl-cw[data-view="chat"] .ookl-cw__panel { height: 100vh; }
	.ookl-cw[data-state="open"] .ookl-cw__fab { display: none; }

	/* На телефоні напис ховається — залишається компактне коло. */
	.ookl-cw__fab { padding: 7px; }
	.ookl-cw__fab-text { display: none; }
}
