/* ============================================
   ROOMYCO CHATBOT - MODERN & RESPONSIVE UI
   ============================================ */

/* ===== Global Reset for Message Width ===== */
.chat-msg * {
  box-sizing: border-box !important;
}

/* ===== Base Container ===== */
.chatbot-container {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9999;
  font-family: "Tajawal", sans-serif;
  direction: rtl;
}

html[dir="ltr"] .chatbot-container {
  direction: ltr;
  right: auto;
  left: 0;
}

/* ===== Chatbot Button (Floating Action Button) ===== */
.chatbot-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 76px;
  height: 76px;
  font-size: 28px;
  cursor: pointer;
  box-shadow: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: pulse 2s infinite;
}

html[dir="ltr"] .chatbot-button {
  right: auto;
  left: 24px;
}

.chatbot-button:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: none;
}

.chatbot-button:active {
  transform: scale(0.95);
}

@keyframes pulse {
  0%, 100% {
    box-shadow: none;
  }
  50% {
    box-shadow: none;
  }
}

/* ===== Chatbot Window ===== */
.chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 48px);
  height: 600px;
  max-height: calc(100vh - 140px);
  max-height: calc(100dvh - 140px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: none;
  border: 1px solid rgba(14, 165, 233, 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  animation: slideInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html[dir="ltr"] .chatbot-window {
  right: auto;
  left: 24px;
}

.chatbot-window.open {
  display: flex;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ===== Header ===== */
.chatbot-header {
  background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  box-shadow: none;
}

.chatbot-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
  pointer-events: none;
}

.chatbot-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 1;
}

.chatbot-title::before {
  content: '🤖';
  font-size: 20px;
}

.chatbot-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  font-size: 24px;
  color: #fff;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  z-index: 1;
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* ===== Chat Log (Messages Container) ===== */
.chat-log {
  flex: 1;
  padding: 24px 20px;
  background: #ffffff;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 10px;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ===== Chat Messages ===== */
.chat-msg {
  display: flex;
  margin-bottom: 16px;
  animation: messageSlideIn 0.2s ease-out;
  clear: both;
  width: 100%;
  max-width: 100%;
  align-items: flex-end;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg.ai {
  justify-content: flex-start;
}

.chat-msg.error {
  justify-content: center;
}

html[dir="rtl"] .chat-msg.user {
  justify-content: flex-start;
}

html[dir="rtl"] .chat-msg.ai {
  justify-content: flex-end;
}

/* ===== Message Bubbles - Modern Design ===== */
.msg {
  max-width: 70% !important;
  width: auto !important;
  min-width: 50px !important;
  flex: 0 0 auto !important;
  padding: 14px 20px;
  border-radius: 20px !important;
  line-height: 1.65;
  font-size: 15px;
  font-weight: 400;
  word-break: break-word;
  box-shadow: none !important;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block !important;
  white-space: normal;
  overflow-wrap: break-word;
  letter-spacing: 0.02em;
  overflow: hidden !important;
  vertical-align: top;
}

/* إزالة أي ذيل أو عناصر إضافية */
.msg::before,
.msg::after {
  display: none !important;
  content: none !important;
}

.msg:hover {
  transform: scale(1.01);
}

/* رسائل المستخدم - بالون أزرق */
.chat-msg.user .msg {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #ffffff;
  border-radius: 20px !important;
  width: auto !important;
  max-width: 70% !important;
  flex: 0 0 auto !important;
  display: inline-block !important;
  box-shadow: none !important;
  font-weight: 500;
  overflow: hidden !important;
  text-align: right;
}

/* إزالة أي ذيل من رسائل المستخدم */
.chat-msg.user .msg::before,
.chat-msg.user .msg::after {
  display: none !important;
  content: none !important;
}

/* رسائل المستخدم RTL */
html[dir="rtl"] .chat-msg.user .msg {
  border-radius: 20px !important;
  width: auto !important;
  max-width: 70% !important;
  flex: 0 0 auto !important;
  display: inline-block !important;
  overflow: hidden !important;
  text-align: left;
}

/* رسائل البوت - بالون رمادي فاتح */
.chat-msg.ai .msg {
  background: #f1f5f9;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-radius: 20px !important;
  width: auto !important;
  max-width: 70% !important;
  flex: 0 0 auto !important;
  display: inline-block !important;
  box-shadow: none !important;
  overflow: hidden !important;
  text-align: left;
}

/* إزالة أي ذيل من رسائل البوت */
.chat-msg.ai .msg::before,
.chat-msg.ai .msg::after {
  display: none !important;
  content: none !important;
}

/* رسائل البوت RTL */
html[dir="rtl"] .chat-msg.ai .msg {
  border-radius: 20px !important;
  width: auto !important;
  max-width: 70% !important;
  flex: 0 0 auto !important;
  display: inline-block !important;
  overflow: hidden !important;
  text-align: right;
}

.chat-msg.error .msg {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 20px !important;
}



/* Loading state */
.chat-msg.ai.loading .msg {
  background: #ffffff;
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
}

.chat-msg.ai.loading .msg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ===== Input Box ===== */
.chat-input-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  box-shadow: none;
}

html[dir="rtl"] .chat-input-box {
  flex-direction: row-reverse;
}

.chat-input-box input {
  flex: 1;
  border: 2px solid #e5e7eb;
  border-radius: 25px;
  padding: 13px 20px;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  background: #f9fafb;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: #1e293b;
  font-weight: 400;
}

.chat-input-box input:focus {
  background: #ffffff;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.08);
}

.chat-input-box input::placeholder {
  color: #94a3b8;
}

html[dir="rtl"] .chat-input-box input {
  text-align: right;
}

html[dir="ltr"] .chat-input-box input {
  text-align: left;
}

.chat-input-box button {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: none;
}

.chat-input-box button:hover {
  transform: scale(1.08) rotate(-5deg);
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  box-shadow: none;
}

.chat-input-box button:active {
  transform: scale(0.95);
}

/* ===== Room Cards & Links ===== */
.room-card {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  box-shadow: none;
  padding: 14px 16px;
  margin-bottom: 12px;
  transition: all 0.2s ease;
}

.room-card:hover {
  transform: translateY(-2px);
  box-shadow: none;
  border-color: #0ea5e9;
}

.room-title {
  font-weight: 700;
  color: #0ea5e9;
  font-size: 16px;
  margin-bottom: 8px;
}

.room-details div {
  padding: 4px 0;
  color: #475569;
  font-size: 14px;
  line-height: 1.5;
}

.room-details-link {
  display: inline-block;
  padding: 8px 16px;
  margin-top: 8px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0ea5e9 0%, #3b82f6 100%);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: none;
}

.room-details-link:hover {
  transform: translateY(-1px);
  box-shadow: none;
}

.intro,
.end-text,
.no-results {
  text-align: center;
  color: #64748b;
  font-weight: 500;
  font-size: 14px;
  padding: 12px;
  margin: 8px 0;
}

.no-results {
  background: #f1f5f9;
  border-radius: 12px;
  padding: 16px;
}

/* ===== Responsive Design ===== */

/* Tablet and below */
@media (max-width: 768px) {
  .chatbot-button {
    width: 56px;
    height: 56px;
    font-size: 26px;
    bottom: 20px;
    right: 20px;
  }

  html[dir="ltr"] .chatbot-button {
    right: auto;
    left: 20px;
  }

  .chatbot-window {
    right: 16px;
    bottom: 88px;
    width: calc(100vw - 32px);
    max-width: 420px;
    height: calc(100vh - 120px);
    height: calc(100dvh - 120px);
    max-height: 600px;
  }

  html[dir="ltr"] .chatbot-window {
    right: auto;
    left: 16px;
  }

  .chatbot-header {
    padding: 16px 18px;
  }

  .chatbot-title {
    font-size: 17px;
  }

  .chat-log {
    padding: 16px;
  }

  .msg {
    max-width: 85% !important;
    width: fit-content !important;
    flex: 0 0 auto !important;
    display: table !important;
    font-size: 14px;
    padding: 12px 16px;
    border-radius: 18px;
  }

  .chat-msg.user .msg,
  html[dir="rtl"] .chat-msg.user .msg {
    width: fit-content !important;
    max-width: 85% !important;
    flex: 0 0 auto !important;
    display: table !important;
    border-radius: 18px;
  }

  .chat-msg.ai .msg,
  html[dir="rtl"] .chat-msg.ai .msg {
    width: fit-content !important;
    max-width: 85% !important;
    flex: 0 0 auto !important;
    display: table !important;
    border-radius: 18px;
  }

  .chat-input-box {
    padding: 14px 16px;
    gap: 8px;
  }

  .chat-input-box input {
    font-size: 14px;
    padding: 11px 16px;
  }

  .chat-input-box button {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .chatbot-button {
    width: 52px;
    height: 52px;
    font-size: 24px;
    bottom: 16px;
    right: 16px;
  }

  html[dir="ltr"] .chatbot-button {
    right: auto;
    left: 16px;
  }

  .chatbot-window {
    right: 12px;
    bottom: 80px;
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    height: calc(100dvh - 100px);
    max-height: 560px;
    border-radius: 16px;
  }

  html[dir="ltr"] .chatbot-window {
    right: auto;
    left: 12px;
  }

  .chatbot-header {
    padding: 14px 16px;
  }

  .chatbot-title {
    font-size: 16px;
  }

  .chatbot-close {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .chat-log {
    padding: 12px;
  }

  .chat-msg {
    margin-bottom: 12px;
  }

  .msg {
    max-width: 85% !important;
    width: fit-content !important;
    flex: 0 0 auto !important;
    display: table !important;
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 16px;
  }

  .chat-msg.user .msg,
  html[dir="rtl"] .chat-msg.user .msg {
    width: fit-content !important;
    max-width: 85% !important;
    flex: 0 0 auto !important;
    display: table !important;
  }

  .chat-msg.ai .msg,
  html[dir="rtl"] .chat-msg.ai .msg {
    width: fit-content !important;
    max-width: 85% !important;
    flex: 0 0 auto !important;
    display: table !important;
  }

  .chat-input-box {
    padding: 12px 14px;
  }

  .chat-input-box input {
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-input-box button {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .room-card {
    padding: 12px 14px;
  }

  .room-title {
    font-size: 15px;
  }

  .room-details div {
    font-size: 13px;
  }
}

@media (max-width: 380px) {
  .chatbot-button {
    width: 48px;
    height: 48px;
    font-size: 22px;
    bottom: 12px;
    right: 12px;
  }

  html[dir="ltr"] .chatbot-button {
    right: auto;
    left: 12px;
  }

  .chatbot-window {
    right: 8px;
    bottom: 72px;
    width: calc(100vw - 16px);
    height: calc(100vh - 92px);
    height: calc(100dvh - 92px);
    max-height: 520px;
  }

  html[dir="ltr"] .chatbot-window {
    right: auto;
    left: 8px;
  }

  .chatbot-header {
    padding: 12px 14px;
  }

  .chatbot-title {
    font-size: 15px;
  }

  .chat-log {
    padding: 10px;
  }

  .msg {
    max-width: 90% !important;
    width: fit-content !important;
    flex: 0 0 auto !important;
    display: table !important;
    font-size: 13px;
    padding: 9px 11px;
  }

  .chat-msg.user .msg,
  html[dir="rtl"] .chat-msg.user .msg {
    width: fit-content !important;
    max-width: 90% !important;
    flex: 0 0 auto !important;
    display: table !important;
  }

  .chat-msg.ai .msg,
  html[dir="rtl"] .chat-msg.ai .msg {
    width: fit-content !important;
    max-width: 90% !important;
    flex: 0 0 auto !important;
    display: table !important;
  }

  .chat-input-box {
    padding: 10px 12px;
  }

  .chat-input-box input {
    font-size: 13px;
    padding: 9px 12px;
  }

  .chat-input-box button {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .chatbot-window {
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
    bottom: 48px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .chatbot-button,
  .chatbot-close,
  .chat-input-box button {
    min-width: 44px;
    min-height: 44px;
  }

  .msg {
    padding: 12px 16px;
  }

  .room-details-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}


@supports (padding: max(0px)) {
  .chatbot-button {
    bottom: max(24px, env(safe-area-inset-bottom) + 8px);
    right: max(24px, env(safe-area-inset-right) + 8px);
  }

  html[dir="ltr"] .chatbot-button {
    right: auto;
    left: max(24px, env(safe-area-inset-left) + 8px);
  }

  .chatbot-window {
    bottom: max(100px, env(safe-area-inset-bottom) + 84px);
    right: max(24px, env(safe-area-inset-right) + 8px);
  }

  html[dir="ltr"] .chatbot-window {
    right: auto;
    left: max(24px, env(safe-area-inset-left) + 8px);
  }

  .chat-input-box {
    padding-bottom: max(16px, env(safe-area-inset-bottom) + 8px);
  }
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .msg {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

@media print {
  .chatbot-container {
    display: none !important;
  }
}
.chat-input-box button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chatbot-button{
  overflow: visible;
  font-size: 0;
  line-height: 0;
}

.chatbot-icon-wrap{
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  display: block;
}

.chatbot-icon{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 55%;
  transform: scale(1.12);
}
.chatbot-button.chatbot-has-hint{ position: fixed; }

.chatbot-button.chatbot-has-hint::after{
  content: attr(data-hint);
  position: absolute;
  bottom: 100%;
  margin-bottom: 10px;

  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.88);
  color: #fff;

  font-size: 12px;
  line-height: 1.3;

  max-width: 260px;
  white-space: normal;

  opacity: 0;
  transform: translateY(6px);
  transition: 0.18s ease;
  pointer-events: none;
  z-index: 10001;
}

.chatbot-button.chatbot-has-hint::before{
  content: "";
  position: absolute;
  bottom: 100%;
  margin-bottom: 4px;

  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-top-color: rgba(0,0,0,0.88);

  opacity: 0;
  transform: translateY(6px);
  transition: 0.18s ease;
  pointer-events: none;
  z-index: 10001;
}

html[dir="rtl"] .chatbot-button.chatbot-has-hint::after,
html[dir="rtl"] .chatbot-button.chatbot-has-hint::before{
  right: 0;
  left: auto;
}

html[dir="ltr"] .chatbot-button.chatbot-has-hint::after,
html[dir="ltr"] .chatbot-button.chatbot-has-hint::before{
  left: 0;
  right: auto;
}

.chatbot-button.chatbot-has-hint:hover::after,
.chatbot-button.chatbot-has-hint:hover::before,
.chatbot-button.chatbot-has-hint:focus-visible::after,
.chatbot-button.chatbot-has-hint:focus-visible::before{
  opacity: 1;
  transform: translateY(0);
}
