#aapa-chat-root {
	position: fixed;
	z-index: 999999;
	right: 0;
	bottom: 0;
	left: 0;
	display: flex;
	justify-content: stretch;
	pointer-events: none;
}

/* Cô lập widget khỏi CSS của theme website — chỉ ép box-sizing (luôn an toàn, không xung đột với
   style riêng của widget), KHÔNG reset margin/padding tràn lan vì sẽ đè luôn padding widget tự set. */
#aapa-chat-root, #aapa-chat-root * {
	box-sizing: border-box !important;
}

.aapa-box {
	pointer-events: auto;
	width: 100%;
	max-width: 100%;
	background: #fff;
	border-radius: 14px 14px 0 0;
	box-shadow: 0 -4px 24px rgba(0,0,0,.18);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	transition: height .28s ease, border-radius .2s ease;
	margin: 0 auto;
}

/* Trạng thái mặc định: full width, 45% chiều cao màn hình */
.aapa-box.state-default {
	height: 45vh;
}

/* Trạng thái mở rộng: click vào ô nhập -> full width, full 100% height */
.aapa-box.state-expanded {
	height: 100vh;
	border-radius: 0;
}

/* Trạng thái thu gọn: chỉ ẩn lịch sử tin nhắn, VẪN giữ khung nhập liệu để mời khách trao đổi tiếp */
.aapa-box.state-minimized {
	height: 118px;
	border-radius: 0;
}
.aapa-box.state-minimized .aapa-msgs { display: none; }

.aapa-header {
	background: #1d4ed8;
	color: #fff;
	padding: 10px 18px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	cursor: pointer;
	flex: 0 0 auto;
}
.aapa-header .title { font-weight: 600; font-size: 14px; display:flex; align-items:center; gap:8px; }
.aapa-header .dot { width:8px; height:8px; border-radius:50%; background:#22c55e; }
.aapa-header .dot.paused { background:#f59e0b; }
.aapa-header .actions button {
	background: transparent; border: none; color: #fff; cursor: pointer; font-size: 16px; padding: 2px 6px;
}

.aapa-msgs {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 14px 18px;
	background: #f5f7fb;
}

.aapa-msg { max-width: 640px; margin: 0 auto 10px; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; }
.aapa-msg.customer { margin-left: auto; margin-right: 0; background: #1d4ed8; color: #fff; border-bottom-right-radius: 2px; }
.aapa-msg.ai { margin-right: auto; margin-left: 0; background: #fff; border: 1px solid #e5e7eb; border-bottom-left-radius: 2px; }
.aapa-msg.staff { margin-right: auto; margin-left: 0; background: #fef3c7; border: 1px solid #fcd34d; border-bottom-left-radius: 2px; }
.aapa-msg.system { background: transparent; color: #888; font-size: 12px; text-align: center; margin: 6px auto; }
.aapa-msg-text { white-space: pre-wrap; }

/* Lưới ảnh 3 cột — dùng cho cả ảnh AI gửi (sản phẩm) lẫn ảnh khách tự đính kèm */
.aapa-img-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 6px;
	margin-top: 6px;
}
.aapa-msg.customer .aapa-img-grid { margin-top: 0; }
.aapa-img-grid img {
	width: 100%;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	border-radius: 8px;
	cursor: zoom-in;
	display: block;
	background: rgba(0,0,0,.05);
}

/* Lightbox phóng to ảnh — click ra ngoài ảnh (nền tối) hoặc bấm nút ✕ hoặc Esc để đóng */
#aapa-lightbox {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,.85);
	z-index: 9999999;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 24px;
	box-sizing: border-box;
	pointer-events: auto; /* #aapa-chat-root (cha) có pointer-events:none, phải bật lại ở đây thì mới click được nút đóng/nền */
}
#aapa-lightbox.open { display: flex; }
#aapa-lightbox img {
	max-width: 100%;
	max-height: 100%;
	border-radius: 8px;
	box-shadow: 0 8px 40px rgba(0,0,0,.5);
	cursor: default;
}
#aapa-lightbox-close {
	position: absolute;
	top: 18px;
	right: 20px;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255,255,255,.15);
	border: none;
	color: #fff;
	font-size: 18px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}
#aapa-lightbox-close:hover { background: rgba(255,255,255,.28); }

/* Khu vực xem trước ảnh khách vừa chọn, trước khi bấm Gửi */
.aapa-attach-preview {
	align-items: center;
	gap: 10px;
	padding: 8px 18px;
	border-top: 1px solid #eee;
	background: #f5f7fb;
	max-width: 680px;
	width: 100%;
	margin: 0 auto;
	box-sizing: border-box;
}
.aapa-attach-thumb { position: relative; width: 52px; height: 52px; flex: 0 0 auto; }
.aapa-attach-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }
.aapa-attach-thumb button {
	position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
	background: #d63638; color: #fff; border: 2px solid #fff; font-size: 11px; cursor: pointer;
	display: flex; align-items: center; justify-content: center; padding: 0;
}
.aapa-attach-hint { font-size: 12px; color: #666; }

.aapa-inputbar {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 18px;
	border-top: 1px solid #eee;
	background: #fff;
	max-width: 680px;
	width: 100%;
	margin: 0 auto;
	box-sizing: border-box;
}
.aapa-inputbar textarea {
	flex: 1;
	resize: none;
	border: 1px solid #ddd;
	border-radius: 10px;
	padding: 8px 10px;
	font-size: 13.5px;
	height: 40px !important;
	min-height: 40px !important;
	max-height: 40px !important;
	line-height: 1.3;
	box-sizing: border-box !important;
	margin: 0;
}
.aapa-inputbar button {
	height: 40px !important;
	min-height: 40px !important;
	box-sizing: border-box !important;
	background: #1d4ed8; color: #fff; border: none; border-radius: 10px; padding: 0 16px; cursor: pointer; font-weight: 600;
	margin: 0;
}
#aapa-btn-attach {
	background: transparent !important;
	color: #555 !important;
	border: 1px solid #ddd !important;
	padding: 0 10px !important;
	font-size: 17px;
	flex: 0 0 auto;
}
#aapa-btn-attach:hover { background: #f0f2f5 !important; }


@media (max-width: 480px) {
	.aapa-msgs { padding: 12px; }
	.aapa-inputbar { padding: 10px 12px; }
}
