/* Chat widget - bottom right */
#chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: inherit;
}

#chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(13, 110, 253, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
}
#chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(13, 110, 253, 0.5);
}

#chat-panel {
  display: none;
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 520px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  flex-direction: column;
  overflow: hidden;
}
#chat-panel.open {
  display: flex;
}

#chat-header {
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#chat-header h6 {
  margin: 0;
  font-size: 1rem;
}
#chat-close-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px 12px;
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 6px;
  min-width: 36px;
}
#chat-close-btn:hover { background: rgba(255,255,255,0.3); }

/* Admin: session list + conversation */
#chat-admin-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
#chat-admin-sidebar {
  width: 180px;
  border-right: 1px solid #dee2e6;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.chat-sidebar-section {
  flex-shrink: 0;
  padding-top: 8px;
}
.chat-sidebar-section strong {
  font-size: 0.75rem;
  color: #6c757d;
  display: block;
  margin-bottom: 4px;
}
#chat-online-users,
#chat-session-list {
  max-height: 140px;
  overflow-y: auto;
}
#chat-session-list {
  border-top: 1px solid #eee;
  padding-top: 4px;
}
.chat-online-user-item,
.chat-session-item {
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  font-size: 0.85rem;
}
.chat-online-user-item:hover,
.chat-session-item:hover { background: #f8f9fa; }
.chat-online-user-item.active,
.chat-session-item.active { background: #e7f1ff; font-weight: 600; }
.chat-online-user-item .name,
.chat-session-item .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-online-user-item .time,
.chat-session-item .time { font-size: 0.75rem; color: #6c757d; }
.chat-online-user-item .time { color: #198754; }

#chat-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#chat-visitor-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f8f9fa;
}
.chat-msg {
  max-width: 85%;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  word-break: break-word;
}
.chat-msg.visitor {
  margin-left: 0;
  margin-right: auto;
  background: #fff;
  border: 1px solid #dee2e6;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.chat-msg.admin {
  margin-left: auto;
  margin-right: 0;
  background: #0d6efd;
  color: #fff;
}
.chat-msg .time { font-size: 0.7rem; opacity: 0.8; margin-top: 4px; }
.chat-msg a { color: #0d6efd; }
.chat-msg.admin a { color: #fff; text-decoration: underline; }

#chat-no-session {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
  font-size: 0.9rem;
  padding: 20px;
  text-align: center;
}

#chat-input-area {
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 1px solid #dee2e6;
  background: #fff;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
#chat-input-area input[type="file"] {
  display: none;
}
#chat-input {
  flex: 1;
  min-width: 120px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  resize: none;
  min-height: 42px;
  max-height: 100px;
  background: #fff;
  color: #212529;
}
#chat-input::placeholder {
  color: #6c757d;
}
#chat-input:focus {
  outline: none;
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}
#chat-send-btn, #chat-file-btn, #chat-clear-chat-btn, #chat-close-session-btn {
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
#chat-send-btn {
  background: #0d6efd;
  color: #fff;
}
#chat-send-btn:hover { background: #0b5ed7; }
#chat-file-btn {
  background: #e9ecef;
  color: #495057;
}
#chat-file-btn:hover { background: #dee2e6; }
#chat-clear-chat-btn {
  background: #fd7e14;
  color: #fff;
}
#chat-clear-chat-btn:hover { background: #e8590c; }
#chat-clear-chat-btn:disabled { opacity: 0.6; cursor: not-allowed; }
#chat-close-session-btn {
  background: #dc3545;
  color: #fff;
  margin-left: auto;
}
#chat-close-session-btn:hover { background: #bb2d3b; }
#chat-close-session-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Visitor: optional name/email (first time) */
#chat-visitor-info {
  padding: 10px 12px;
  border-bottom: 1px solid #dee2e6;
  background: #f8f9fa;
  font-size: 0.85rem;
}
#chat-visitor-info input {
  width: 100%;
  padding: 6px 8px;
  margin-top: 4px;
  margin-bottom: 8px;
  border: 1px solid #ced4da;
  border-radius: 4px;
}
