﻿/* --- e-Stations Chat Module: SignalR --- */

#es-chat-dock {
  position: fixed;
  bottom: 25px;
  right: 90px !important;
  display: flex;
  align-items: flex-end;
  gap: 15px;
  z-index: 1050;
  pointer-events: none;
}

.es-chat-panel {
  width: 320px;
  background-color: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px 10px 0 0;
  box-shadow: 0 -2px 15px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  transition: height 0.2s ease-in-out;
  box-sizing: border-box !important;
}

  .es-chat-panel.minimized {
    height: 44px !important;
    overflow: hidden;
  }

.es-chat-header {
  background-color: var(--bs-primary);
  color: #ffffff;
  padding: 10px 15px;
  border-radius: 9px 9px 0 0;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  box-sizing: border-box !important;
}

.es-chat-body {
  height: 350px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 15px;
  background-color: var(--bs-secondary-bg);
  display: flex;
  flex-direction: column;
  box-sizing: border-box !important;
}

.es-chat-footer {
  padding: 6px 10px !important;
  border-top: 1px solid var(--bs-border-color);
  background-color: var(--bs-tertiary-bg);
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box !important;
}

.es-chat-input {
  background-color: var(--bs-body-bg) !important;
  color: var(--bs-body-color) !important;
  border: 1px solid var(--bs-border-color) !important;
  border-radius: 20px !important;
  padding: 6px 15px !important;
  box-shadow: none !important;
  width: 100% !important;
}

  .es-chat-input:focus {
    border-color: var(--bs-primary) !important;
    outline: none !important;
  }

.es-btn-icon {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 4px 6px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bs-secondary-color) !important;
  cursor: pointer;
  transition: color 0.2s;
}

  .es-btn-icon:hover {
    color: var(--bs-primary) !important;
  }

.es-btn-send {
  color: var(--bs-primary) !important;
}

.es-chat-bubble {
  box-sizing: border-box !important;
  clear: both !important;
  float: none !important;
  display: flex !important;
  flex-direction: column !important;
  width: -moz-fit-content !important;
  width: fit-content !important;
  max-width: 85% !important;
  min-width: 90px !important;
  padding: 5px 10px !important;
  border-radius: 10px !important;
  margin-bottom: 10px !important;
  font-size: 0.9rem !important;
}

.es-chat-sent {
  align-self: flex-end !important;
  background-color: var(--bs-primary-bg-subtle) !important;
  color: var(--bs-primary-text-emphasis) !important;
  border: 1px solid var(--bs-primary-border-subtle) !important;
  border-bottom-right-radius: 0px !important;
}

.es-chat-received {
  align-self: flex-start !important;
  background-color: var(--bs-tertiary-bg) !important;
  color: var(--bs-body-color) !important;
  border: 1px solid var(--bs-border-color) !important;
  border-bottom-left-radius: 0px !important;
}

.es-chat-text {
  box-sizing: border-box !important;
  display: block !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  word-break: break-word !important;
  line-height: 1.4 !important;
  color: inherit !important;
  margin: 0 !important;
  padding: 0 !important;
  text-align: left !important;
}

.es-chat-time {
  box-sizing: border-box !important;
  align-self: flex-end !important;
  display: flex !important;
  align-items: center !important;
  gap: 4px !important;
  margin-top: 2px !important;
  font-size: 0.70rem !important;
  opacity: 0.8 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

  .es-chat-time i {
    color: #98a5b3 !important;
    font-size: 0.75rem !important;
  }

    .es-chat-time i.es-chat-read {
      color: #4db8ff !important;
    }

/* --- INBOX & FAB --- */

/* FIX: The missing Base Desktop Inbox Styles */
#es-chat-inbox {
  position: fixed;
  bottom: 95px;
  right: 20px;
  width: 360px;
  background-color: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  box-shadow: 0 5px 25px rgba(0,0,0,0.15);
  display: none;
  z-index: 1050;
  /* FIX: Enable vertical scrolling and prevent overflowing the desktop screen */
  max-height: 75vh;
  overflow-y: auto;
  overflow-x: hidden;
}

#es-chat-fab {
  position: fixed;
  bottom: 29px;
  right: 6px;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background-color: var(--bs-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  cursor: pointer;
  z-index: 1060;
  transition: transform 0.2s;
}

  #es-chat-fab:hover {
    transform: scale(1.05);
  }

.es-inbox-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--bs-border-color);
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
}

  .es-inbox-item:hover {
    background-color: var(--bs-tertiary-bg);
  }

.es-inbox-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  margin-right: 12px;
  flex-shrink: 0;
}

/* --- GROUP CHAT THEMES --- */
.es-theme-admin .es-chat-header {
  background-color: var(--bs-danger) !important;
}

.es-theme-official .es-chat-header {
  background-color: var(--bs-success) !important;
}

.es-theme-system .es-chat-header {
  background-color: var(--bs-dark) !important;
  border-bottom: 2px solid var(--bs-warning);
}

.es-chat-sender-label {
  font-size: 0.70rem;
  font-weight: 600;
  color: var(--bs-secondary-color);
  margin-bottom: 2px;
  margin-left: 5px;
}

/* =========================================
   e-Stations Chat: Mobile Responsiveness
   ========================================= */
@media (max-width: 767.98px) {
  /* 1. Fluid Inbox Popup */
  #es-chat-inbox {
    width: calc(100% - 30px) !important;
    right: 15px !important;
    left: auto !important;
    bottom: 85px !important;
    max-height: 70vh !important;
    z-index: 104000 !important;
    overflow-y: auto !important; /* FIX: Force scrolling on mobile */
    overflow-x: hidden !important;
  }

  /* 2. Full-Screen Chat Experience (Native App Style) */
  .es-chat-panel:not(.minimized) {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important; /* FIX: 100% instead of 100vw for iOS */

    height: 100% !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    z-index: 105000 !important;
    display: flex;
    flex-direction: column;
  }

    .es-chat-panel:not(.minimized) .es-chat-body {
      flex-grow: 1 !important;
      height: auto !important;
      max-height: none !important;
    }

  /* 3. Minimized Chat Bars */
  .es-chat-panel.minimized {
    position: fixed !important;
    width: calc(100% - 30px) !important; /* FIX: 100% instead of 100vw for iOS */
    right: 15px !important;
    left: auto !important;
    bottom: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    z-index: 104000 !important;
  }
}
