/* ═══════════════════════════════════════════════════════════════
   Newstour AI Asistan — Sohbet Widget Stilleri
   Mobile-first, fluid typography, safe-area, dokunmatik hedef ≥44px,
   prefers-reduced-motion destekli, [dir="rtl"] hazır (W6 i18n).
   ═══════════════════════════════════════════════════════════════ */

/* Renkler PHP tarafından :root'a enjekte edilir (bkz. PublicSide::enqueue_scripts). */
:root {
	--nai-primary: #5191fa;
	--nai-secondary: #1a2e50;
	--nai-radius: 18px;
	--nai-bubble-size: 60px;
}

#nai-chat-container {
	position: fixed;
	bottom: max(16px, env(safe-area-inset-bottom));
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	line-height: 1.5;
}
#nai-chat-container * {
	box-sizing: border-box;
}
#nai-chat-container.nai-right {
	right: max(16px, env(safe-area-inset-right));
}
#nai-chat-container.nai-left {
	left: max(16px, env(safe-area-inset-left));
}

/* ── Sohbet Balonu ── */
#nai-chat-bubble {
	width: var(--nai-bubble-size);
	height: var(--nai-bubble-size);
	min-width: 44px;
	min-height: 44px;
	border-radius: 50%;
	border: none;
	background: var(--nai-primary);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	padding: 0;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
	transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
#nai-chat-bubble:hover {
	transform: scale(1.06);
	box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26);
}
#nai-chat-bubble:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
}
.nai-bubble-icon {
	width: 26px;
	height: 26px;
}
.nai-icon-close {
	display: none;
}

/* ── Sohbet Penceresi ── */
#nai-chat-window {
	position: absolute;
	bottom: calc(var(--nai-bubble-size) + 16px);
	width: min(380px, 92vw);
	height: min(600px, 75vh);
	background: #fff;
	border-radius: var(--nai-radius);
	box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
	display: none;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(0.96);
	transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
	border: 1px solid rgba(0, 0, 0, 0.06);
}
.nai-right #nai-chat-window {
	right: 0;
}
.nai-left #nai-chat-window {
	left: 0;
}
#nai-chat-window.nai-window-open {
	opacity: 1;
	transform: translateY(0) scale(1);
}

/* ── Başlık ── */
#nai-chat-header {
	background: linear-gradient(135deg, var(--nai-secondary), var(--nai-primary));
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
	gap: 8px;
}
.nai-header-info {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}
.nai-header-avatar {
	width: 38px;
	height: 38px;
	min-width: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
}
.nai-header-avatar svg {
	width: 20px;
	height: 20px;
}
.nai-header-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
}
.nai-header-name {
	font-weight: 700;
	font-size: clamp(0.9rem, 0.85rem + 0.2vw, 1rem);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.nai-header-status {
	font-size: 0.75rem;
	opacity: 0.85;
	display: flex;
	align-items: center;
	gap: 5px;
}
.nai-status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	animation: naiPulse 2s ease infinite;
}
@keyframes naiPulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.5; }
}
#nai-chat-close {
	width: 40px;
	height: 40px;
	min-width: 40px;
	border-radius: 50%;
	border: none;
	background: rgba(255, 255, 255, 0.15);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.2s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
#nai-chat-close:hover {
	background: rgba(255, 255, 255, 0.28);
}
#nai-chat-close svg {
	width: 18px;
	height: 18px;
}

/* ── Mesaj Alanı ── */
#nai-chat-messages {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #f7f9fc;
	scroll-behavior: smooth;
}
#nai-chat-messages::-webkit-scrollbar {
	width: 4px;
}
#nai-chat-messages::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.12);
	border-radius: 4px;
}

.nai-msg {
	display: flex;
	max-width: 86%;
	min-width: 0;
	animation: naiMsgIn 0.22s ease;
}
@keyframes naiMsgIn {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}
.nai-msg-user {
	align-self: flex-end;
}
.nai-msg-ai {
	align-self: flex-start;
}
.nai-msg-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	word-break: break-word;
	min-width: 0;
}
.nai-msg-user .nai-msg-bubble {
	background: var(--nai-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}
.nai-msg-ai .nai-msg-bubble {
	background: #fff;
	color: #1f2937;
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.nai-msg-text {
	font-size: clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);
	line-height: 1.55;
	white-space: pre-wrap; /* \n satır sonlarını textContent ile güvenle korumak için */
}
.nai-msg-link-btn {
	display: inline-block;
	margin-top: 8px;
	padding: 8px 16px;
	min-height: 36px;
	background: var(--nai-secondary);
	color: #fff !important;
	text-decoration: none !important;
	border-radius: 20px;
	font-size: 0.8125rem;
	font-weight: 600;
	transition: opacity 0.15s ease, transform 0.15s ease;
	touch-action: manipulation;
}
.nai-msg-link-btn:hover {
	opacity: 0.9;
	transform: translateY(-1px);
}
.nai-msg-secondary {
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	font-size: 0.8125rem;
	opacity: 0.85;
	white-space: pre-wrap;
}
.nai-msg-time {
	font-size: 0.6875rem;
	opacity: 0.55;
	margin-top: 4px;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.nai-system-message {
	align-self: center;
	max-width: 90%;
	text-align: center;
	font-size: 0.8125rem;
	color: #9ca3af;
	background: rgba(0, 0, 0, 0.05);
	padding: 6px 12px;
	border-radius: 12px;
}
/* Opus review fix (W8-8b) — bilgilendirme (hata OLMAYAN) sistem mesajları
   için nötr-ama-marka-renkli görsel ayrım (ör. "kayıt çok uzun, otomatik
   durduruldu", "önceki ek değiştirildi"). appendSystemError'dan (gri, .nai-system-message)
   AYRIDIR. */
.nai-system-message-info {
	color: var(--nai-primary);
	background: rgba(0, 0, 0, 0.05);
}

/* ── Yazıyor Göstergesi ── */
#nai-typing-indicator {
	display: none;
	padding: 0 16px 10px;
	flex-shrink: 0;
	background: #f7f9fc;
}
.nai-typing-bubble {
	display: inline-flex;
	align-items: center;
	background: #fff;
	padding: 10px 14px;
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.nai-typing-dots {
	display: flex;
	gap: 4px;
}
.nai-typing-dots span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--nai-primary);
	opacity: 0.4;
	animation: naiDot 1.3s infinite;
}
.nai-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.nai-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes naiDot {
	0%, 60%, 100% { opacity: 0.35; transform: scale(1); }
	30% { opacity: 1; transform: scale(1.25); }
}

/* ── Dosya/Görsel Eki Önizlemesi (W7) ── */
#nai-attachment-preview {
	display: flex;
	align-items: center;
	flex-wrap: wrap; /* Opus fix (W7-4): KVKK notu tam genişlikte alt satıra sarsın diye. */
	gap: 8px;
	padding: 8px 16px;
	background: #eef2f9;
	border-top: 1px solid rgba(0, 0, 0, 0.06);
	flex-shrink: 0;
}
#nai-attachment-preview[hidden] {
	display: none;
}
.nai-attach-thumb {
	width: 36px;
	height: 36px;
	min-width: 36px;
	border-radius: 8px;
	object-fit: cover;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, 0.08);
}
.nai-attach-file-icon {
	width: 36px;
	height: 36px;
	min-width: 36px;
	border-radius: 8px;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, 0.08);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--nai-primary);
}
.nai-attach-file-icon svg {
	width: 18px;
	height: 18px;
}
.nai-attach-name {
	flex: 1;
	min-width: 0;
	font-size: 0.8125rem;
	color: #374151;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.nai-attach-error,
.nai-attach-uploading {
	flex: 1;
	min-width: 0;
	font-size: 0.8125rem;
	color: #6b7280;
}
.nai-attach-error {
	color: #b91c1c;
}
.nai-attach-remove {
	width: 28px;
	height: 28px;
	min-width: 28px;
	border: none;
	background: rgba(0, 0, 0, 0.06);
	border-radius: 50%;
	cursor: pointer;
	font-size: 12px;
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	touch-action: manipulation;
}
.nai-attach-remove:hover {
	background: rgba(0, 0, 0, 0.12);
}
/* Opus kalite kapısı fix (W7-4, KVKK) — dosya/görsel eklendiğinde gösterilen
   kısa bilgilendirme notu (engelleyici modal DEĞİL, hafif bir alt satır). */
.nai-attach-kvkk {
	flex: 1 0 100%;
	font-size: 0.6875rem;
	line-height: 1.4;
	color: #6b7280;
	padding-top: 6px;
	margin-top: 2px;
	border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* ── Giriş Alanı ── */
#nai-chat-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	padding-bottom: max(10px, env(safe-area-inset-bottom));
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	background: #fff;
	flex-shrink: 0;
	margin: 0;
}
#nai-attach-btn {
	width: 44px;
	height: 44px;
	min-width: 44px;
	border-radius: 50%;
	border: none;
	background: transparent;
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s ease, color 0.15s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
#nai-attach-btn:hover {
	background: rgba(0, 0, 0, 0.06);
	color: var(--nai-primary);
}
#nai-attach-btn svg {
	width: 20px;
	height: 20px;
}

/* ── Mikrofon Butonu (Sesli Mesaj — W8) ── */
#nai-mic-btn {
	width: 44px;
	height: 44px;
	min-width: 44px;
	border-radius: 50%;
	border: none;
	background: transparent;
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s ease, color 0.15s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
#nai-mic-btn:hover {
	background: rgba(0, 0, 0, 0.06);
	color: var(--nai-primary);
}
#nai-mic-btn svg {
	width: 20px;
	height: 20px;
}
#nai-mic-btn[hidden] {
	display: none;
}

/* ── Sesli Mesaj Kayıt Çubuğu (W8) ──
   #nai-chat-input-area zaten dokunmatik girişlerin bulunduğu form; kayıt
   sırasında bu çubuk bir OVERLAY olarak biner (mevcut markup/DOM sırasına
   dokunulmadan) — diğer alt öğeler visibility:hidden olur (layout korunur,
   yalnızca görünmez + tıklanamaz hale gelir). */
#nai-chat-input-area {
	position: relative;
}
#nai-chat-input-area.nai-recording > *:not(#nai-voice-recording-bar) {
	visibility: hidden;
}
#nai-voice-recording-bar {
	display: none;
	position: absolute;
	inset: 0;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	padding-bottom: max(10px, env(safe-area-inset-bottom));
	background: #fff;
}
#nai-chat-input-area.nai-recording #nai-voice-recording-bar {
	display: flex;
}
.nai-voice-action-btn {
	width: 40px;
	height: 40px;
	min-width: 40px;
	border-radius: 50%;
	border: none;
	background: rgba(0, 0, 0, 0.06);
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s ease, color 0.15s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
.nai-voice-action-btn:hover {
	background: rgba(0, 0, 0, 0.12);
}
.nai-voice-action-btn svg {
	width: 18px;
	height: 18px;
}
.nai-voice-send-btn {
	background: var(--nai-primary);
	color: #fff;
}
.nai-voice-send-btn:hover {
	background: var(--nai-primary);
	opacity: 0.9;
}
.nai-voice-indicator {
	flex: 1;
	min-width: 0;
	display: flex;
	align-items: center;
	gap: 8px;
}
.nai-voice-dot {
	width: 10px;
	height: 10px;
	min-width: 10px;
	border-radius: 50%;
	background: #ef4444;
	animation: naiVoicePulse 1.1s ease infinite;
}
@keyframes naiVoicePulse {
	0%, 100% { opacity: 1; transform: scale(1); }
	50% { opacity: 0.45; transform: scale(0.85); }
}
.nai-voice-timer {
	font-size: 0.875rem;
	font-variant-numeric: tabular-nums;
	color: #374151;
}

#nai-message-input {
	flex: 1;
	min-width: 0;
	border: 1.5px solid #e5e7eb;
	border-radius: 20px;
	padding: 10px 16px;
	font-size: max(16px, 1rem); /* iOS Safari otomatik zoom önleme */
	font-family: inherit;
	resize: none;
	outline: none;
	/* Boş/kısa metinde kaydırma çubuğu/ok butonları görünmesin; autoResize()
	   yalnızca içerik 120px sınırını aştığında dikey kaydırmayı 'auto' yapar. */
	overflow-y: hidden;
	min-height: 44px;
	max-height: 120px;
	background: #f9fafb;
	color: #1f2937;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#nai-message-input:focus {
	border-color: var(--nai-primary);
	background: #fff;
	box-shadow: 0 0 0 3px rgba(81, 145, 250, 0.15);
}
#nai-message-input::placeholder {
	color: #9ca3af;
}
#nai-send-btn {
	width: 44px;
	height: 44px;
	min-width: 44px;
	border-radius: 50%;
	border: none;
	background: var(--nai-primary);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: opacity 0.15s ease, transform 0.15s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
#nai-send-btn:hover {
	transform: scale(1.06);
}
#nai-send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}
#nai-send-btn svg {
	width: 18px;
	height: 18px;
}

/* ── Bildirim Balonu (mikro-etkileşim) ── */
#nai-notify-bubble {
	position: absolute;
	bottom: calc(var(--nai-bubble-size) + 14px);
	right: 0;
	width: min(280px, 80vw);
	background: #fff;
	border-radius: 16px 16px 4px 16px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
	border: 1px solid rgba(0, 0, 0, 0.06);
	padding: 12px 34px 12px 14px;
	cursor: pointer;
	animation: naiNotifyIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.nai-left #nai-notify-bubble {
	right: auto;
	left: 0;
	border-radius: 16px 16px 16px 4px;
}
@keyframes naiNotifyIn {
	from { opacity: 0; transform: translateY(12px) scale(0.94); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}
#nai-notify-bubble.nai-notify-out {
	animation: naiNotifyOut 0.28s ease forwards;
}
@keyframes naiNotifyOut {
	to { opacity: 0; transform: translateY(8px) scale(0.95); }
}
.nai-notify-text {
	margin: 0;
	font-size: 0.85rem;
	line-height: 1.5;
	color: #1f2937;
	/* Okan isteği: karşılama mesajının tamamı okunabilsin — 3 satır kırpma
	   (line-clamp) kaldırıldı. Satır sonları korunur; çok uzun mesajda baloncuk
	   ekranı taşmasın diye sınırlı yükseklik + kendi içinde kaydırma. */
	white-space: pre-line;
	max-height: 40vh;
	overflow-y: auto;
}
.nai-notify-close {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 28px;
	height: 28px;
	min-width: 28px;
	border: none;
	background: #f3f4f6;
	border-radius: 50%;
	cursor: pointer;
	font-size: 12px;
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	touch-action: manipulation;
}

/* ── Erişilebilirlik Yardımcıları ── */
.nai-sr-only {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/* ── Mobil (≤767px): neredeyse tam ekran + safe-area ── */
@media (max-width: 767px) {
	#nai-chat-container {
		bottom: max(12px, env(safe-area-inset-bottom));
	}
	#nai-chat-container.nai-right {
		right: max(12px, env(safe-area-inset-right));
	}
	#nai-chat-container.nai-left {
		left: max(12px, env(safe-area-inset-left));
	}
	#nai-chat-window {
		position: fixed;
		top: max(10px, env(safe-area-inset-top));
		left: 10px;
		right: 10px;
		bottom: 10px;
		width: auto;
		height: auto;
		max-height: 100dvh;
	}
	.nai-header-name {
		font-size: 0.9375rem;
	}
}

/* ── RTL hazırlığı (W6 i18n — Arapça vb. için) ── */
[dir="rtl"] .nai-msg-user {
	align-self: flex-start;
}
[dir="rtl"] .nai-msg-ai {
	align-self: flex-end;
}
[dir="rtl"] .nai-msg-user .nai-msg-bubble {
	border-bottom-right-radius: 16px;
	border-bottom-left-radius: 4px;
}
[dir="rtl"] .nai-msg-ai .nai-msg-bubble {
	border-bottom-left-radius: 16px;
	border-bottom-right-radius: 4px;
}
[dir="rtl"] .nai-right #nai-chat-window,
[dir="rtl"] #nai-notify-bubble {
	right: auto;
	left: 0;
}
[dir="rtl"] .nai-msg-time {
	text-align: left;
}

/* ── prefers-reduced-motion: tüm hareketi kapat ── */
@media (prefers-reduced-motion: reduce) {
	#nai-chat-container,
	#nai-chat-container * {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}
