* { box-sizing: border-box; }

/* ===== Nền trang ===== */
body {
  margin: 0;
  background: #f4f4f5;
  color: #202124;
  font: 16px -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

/* ===== Header trang khách ===== */
body.customer header { padding: 16px 20px 0; }

/* Pill trạng thái hỗ trợ */
.agent-pill {
  margin: 14px auto 0;
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border-radius: 28px;
  padding: 12px 24px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .10);
  font-size: 16px;
}

.online {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #3fbb64;
  flex-shrink: 0;
}

/* ===== Nội dung chính ===== */
main { padding: 18px 20px 0; }

#start,
#chat {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}

/* Avatar cam nằm cùng hàng với thẻ tin nhắn, ngang dòng chat đầu tiên */
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.mini-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e8720c;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mini-avatar svg {
  width: 15px;
  height: 15px;
  fill: #111111;
}

.card {
  background: #ffffff;
  border: 1px solid #e6e6e8;
  border-radius: 16px;
  padding: 26px 24px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  flex: 1;
  min-width: 0;
}

/* ===== Nội dung mở đầu ===== */
.intro p {
  margin: 8px 0;
  line-height: 1.5;
  font-size: 16px;
  color: #202124;
}

/* ===== Form ===== */
form { margin-top: 26px; }

label {
  display: block;
  margin: 18px 0 10px;
  font-size: 16px;
  color: #202124;
}

input,
textarea {
  width: 100%;
  padding: 16px;
  background: #f1f3f4;
  border: 1px solid #d9dce0;
  border-radius: 8px;
  font-size: 16px;
  color: #202124;
  outline-color: #e8720c;
}

/* Ô nhập chat nhiều dòng: tự tăng chiều cao bằng JS, không cho kéo góc */
textarea {
  resize: none;
  overflow: auto;
  line-height: 1.45;
  font-family: inherit;
  min-height: 54px;
  max-height: 150px;
}

.error {
  color: #d52d18;
  font-size: 13px;
  margin: 8px 0 0;
  min-height: 17px;
}

/* Nút cam "Bắt đầu chat" */
button {
  border: 0;
  border-radius: 10px;
  background: #e8720c;
  color: #111111;
  padding: 16px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

button:disabled { opacity: .5; cursor: not-allowed; }

#startForm button {
  width: 100%;
  margin-top: 24px;
  font-size: 17px;
}

.secondary {
  background: #eef3ff;
  color: #1455ba;
  font-size: 13px;
  padding: 10px;
}

.hidden { display: none !important; }

/* ===== Khung chat ===== */
.chat-card {
  height: min(680px, 80vh);
  display: flex;
  flex-direction: column;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}

.messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 0;
  min-height: 100px;
}

.bubble {
  padding: 12px 14px;
  border-radius: 15px;
  background: #edf0f5;
  max-width: 85%;
  align-self: flex-start;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble.mine { align-self: flex-end; background: #ffe6c7; }

/* Ảnh paste trong bong bóng (chỉ giới hạn kích thước, không đổi layout) */
.bubble img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.bubble small {
  display: block;
  font-size: 11px;
  color: #667;
  margin-top: 5px;
}

.send { display: flex; gap: 8px; margin: 12px 0 0; }
.send .input-wrap { flex: 1; min-width: 0; position: relative; }
.input-wrap > input,
.input-wrap > textarea { width: 100%; padding-right: 56px; } /* chừa chỗ cho icon ảnh bên trong input */
.hint { font-size: 12px; color: #667; margin: 8px 0 0; }

/* ===== Thanh gửi: khu vực chứa preview + form ===== */
.send-area { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.send-area .send { margin: 0; }

/* Icon ảnh nằm BÊN TRONG ô nhập, góc phải, căn giữa trục Y */
.attach-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: #5f6368;
}

.attach-btn:hover { background: #e8eefc; color: #e8720c; }
.attach-btn i { font-size: 18px; }

/* Highlight khi kéo ảnh tới gần khung chat */
.drop-hint { outline: 2px dashed #e8720c; outline-offset: -6px; }

/* ===== Footer trang khách ===== */
body.customer footer {
  text-align: center;
  color: #9aa0a6;
  font-size: 12px;
  padding: 18px 0 26px;
}

/* ===== Trang admin ===== */
.login {
  margin: 10vh auto;
  width: min(420px, 92vw);
  background: #ffffff;
  border: 1px solid #e6e6e8;
  border-radius: 16px;
  padding: 34px;
}

.login h2 { font-size: 21px; margin: 0 0 22px; }

.admin {
  /* fixed全屏: loại bỏ hoàn toàn khả năng body/layout phải cuộn theo tin nhắn */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: minmax(0, 1fr);   /* 0 thay cho auto: row không bị nội dung tin nhắn kéo giãn */
  overflow: hidden;
}

.admin aside {
  background: white;
  border-right: 1px solid #ddd;
  overflow: auto;
}

.aside-head {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
}

.aside-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #eee;
  font-size: 13px;
}

.notif-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notif-setting {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.notif-setting input {
  width: auto;
  padding: 0;
  margin: 0;
  accent-color: #e8720c;
}

.chat-item .row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-item .row strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fbb64;
  flex-shrink: 0;
}

.badge {
  background: #e8720c;
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-item {
  padding: 16px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.chat-item:hover, .chat-item.active { background: #eaf2ff; }

/* Nút xóa chat ở góc trái danh sách */
.chat-del {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: #9aa0a6;
  font-size: 13px;
  font-weight: 400;
}

.chat-del:hover { background: #ffe1dc; color: #d52d18; }

.chat-item small {
  display: block;
  color: #667;
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 20px 30px;
  background: #f4f4f5;
}

.admin-chat .messages { min-height: 0; }
.admin-chat .chat-head { min-height: 50px; flex-shrink: 0; }
.admin-chat .send { flex-shrink: 0; }
.admin-chat .hint { flex-shrink: 0; }

/* ===== Popup in-page cho admin (hoạt động mọi Windows, không cần quyền OS) ===== */
#toastHost {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 99;
}

.toast {
  background: #fff;
  border: 1px solid #e6e6e8;
  border-left: 4px solid #e8720c;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
  font-size: 14px;
  cursor: pointer;
  max-width: 320px;
  opacity: 0;
  transform: translateX(12px);
  transition: .25s;
}

.toast.show { opacity: 1; transform: none; }
.toast strong { display: block; margin-bottom: 3px; }

/* ===== Responsive ===== */
@media (max-width: 650px) {
  main { padding: 12px 14px 0; }
  body.customer header { padding: 12px 14px 0; }
  .card { padding: 20px 16px; }
  .admin { grid-template-columns: 135px 1fr; }
  .admin-chat { padding: 12px; }
  .aside-head { display: block; }
  .aside-head button { margin-top: 10px; }
  .chat-item { padding: 10px; font-size: 13px; }
}
