/* ==========================================================================
   CUSTOMER LIVE CHAT WIDGET STYLES
   Modern floating bubble & popup chat box
   ========================================================================== */

.cskh-widget-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* --------------------------------------------------------------------------
   FLOATING LAUNCHER BUTTON
   -------------------------------------------------------------------------- */
.chat-launcher-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #003366 0%, #004b93 100%);
  color: #ffffff;
  border: 2px solid #ff9b1f;
  padding: 8px 16px 8px 8px;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(0, 51, 102, 0.4), 0 0 15px rgba(255, 155, 31, 0.4);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
}

.chat-launcher-btn:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 12px 30px rgba(0, 51, 102, 0.5), 0 0 20px rgba(255, 155, 31, 0.6);
}

.launcher-avatar-wrapper {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid #ff9b1f;
  background-color: #ffffff;
  overflow: visible;
}

.launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.online-indicator-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background-color: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-green 2s infinite;
}

.launcher-text-bubble {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.launcher-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: #ffb700;
  letter-spacing: 0.3px;
}

.launcher-sub {
  font-size: 0.75rem;
  color: #e2e8f0;
}

.unread-badge-counter {
  position: absolute;
  top: -6px;
  right: -6px;
  background-color: #ef4444;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  animation: bounce 1.5s infinite;
}

/* --------------------------------------------------------------------------
   CHAT POPUP WINDOW
   -------------------------------------------------------------------------- */
.chat-box-popup {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 34, 68, 0.28), 0 0 0 1px rgba(0, 51, 102, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUpScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

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

/* Header */
.chat-header {
  background: linear-gradient(135deg, #003366 0%, #004b93 100%);
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #ff9b1f;
}

.agent-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-avatar-box {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #ff9b1f;
}

.agent-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.agent-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background-color: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.agent-name {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.agent-status-text {
  font-size: 0.72rem;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 4px;
}

.text-success {
  color: #10b981 !important;
}

.font-xs {
  font-size: 0.65rem;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-action-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s ease;
}

.header-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --------------------------------------------------------------------------
   STATE 1: REGISTRATION FORM
   -------------------------------------------------------------------------- */
.chat-register-view {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.register-hero {
  text-align: center;
  margin-bottom: 18px;
}

.hero-icon-circle {
  width: 50px;
  height: 50px;
  background: #fff8f0;
  border: 2px solid #ff9b1f;
  color: #ff6600;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.register-hero h3 {
  font-size: 1.15rem;
  font-weight: 800;
  color: #003366;
  margin-bottom: 4px;
}

.register-hero p {
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.4;
}

.alert-error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 12px;
}

.register-form .form-group {
  margin-bottom: 12px;
}

.register-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
}

.register-form label i {
  color: #003366;
  width: 14px;
}

.register-form .required {
  color: #ef4444;
}

.register-form input, .register-form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  transition: all 0.2s ease;
  background-color: #f8fafc;
}

.register-form input:focus, .register-form textarea:focus {
  border-color: #003366;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

.btn-start-chat {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #ff9b1f 0%, #ff6600 100%);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(255, 102, 0, 0.35);
  transition: all 0.2s ease;
  margin-top: 10px;
}

.btn-start-chat:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 102, 0, 0.45);
}

.privacy-note {
  text-align: center;
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 14px;
}

/* --------------------------------------------------------------------------
   STATE 2: LIVE CHAT VIEW
   -------------------------------------------------------------------------- */
.chat-messages-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f8fafc;
}

.active-session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #eef2f6;
  padding: 6px 12px;
  font-size: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

.conv-id-tag {
  color: #64748b;
  margin-left: 6px;
}

.btn-end-session {
  background: none;
  border: none;
  color: #ef4444;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
}

.btn-end-session:hover {
  text-decoration: underline;
}

/* Quick chips */
.quick-chips-wrapper {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  white-space: nowrap;
  background: #ffffff;
  border-bottom: 1px solid #edf2f7;
  scrollbar-width: none;
}

.quick-chips-wrapper::-webkit-scrollbar {
  display: none;
}

.chip-item {
  display: inline-block;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #003366;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.chip-item:hover {
  background: #003366;
  color: #ffffff;
  border-color: #003366;
}

/* Messages stream */
.messages-container {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-item {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: fadeInMsg 0.2s ease;
}

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

.msg-item.customer {
  align-self: flex-end;
}

.msg-item.admin {
  align-self: flex-start;
}

.msg-item.system {
  align-self: center;
  max-width: 95%;
}

.msg-sender-tag {
  font-size: 0.68rem;
  color: #64748b;
  margin-bottom: 2px;
}

.msg-item.customer .msg-sender-tag {
  text-align: right;
}

.msg-content-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.msg-item.customer .msg-content-bubble {
  background: #003366;
  color: #ffffff;
  border-bottom-right-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 51, 102, 0.2);
}

.msg-item.admin .msg-content-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.msg-item.system .msg-content-bubble {
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  color: #64748b;
  font-size: 0.78rem;
  text-align: center;
  border-radius: 8px;
}

.msg-timestamp {
  font-size: 0.65rem;
  color: #94a3b8;
  margin-top: 3px;
}

.msg-item.customer .msg-timestamp {
  text-align: right;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 0.75rem;
  color: #64748b;
}

.typing-avatar-mini {
  background: #003366;
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 4px;
}

.typing-bubble {
  background: #e2e8f0;
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  background-color: #64748b;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-bubble .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

/* Closed Banner */
.conversation-closed-banner {
  background: #fef3c7;
  border-top: 1px solid #fde68a;
  padding: 8px 14px;
  font-size: 0.8rem;
  color: #92400e;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-restart-chat {
  background: #d97706;
  color: #ffffff;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

/* Chat Input Bar */
.chat-input-form {
  padding: 10px 12px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.input-actions-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: all 0.2s ease;
}

.input-actions-bar:focus-within {
  border-color: #003366;
  background-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(0, 51, 102, 0.12);
}

.input-actions-bar input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 0.88rem;
  color: #1e293b;
}

.btn-send-message {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #003366 0%, #004b93 100%);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-send-message:hover {
  background: #ff6600;
  transform: scale(1.05);
}

/* Animation utilities */
@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
  60% { transform: translateY(-3px); }
}

/* Mobile responsive */
@media (max-width: 576px) {
  .chat-box-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    z-index: 100000;
  }
  .cskh-widget-container {
    bottom: 16px;
    right: 14px;
  }
  .chat-launcher-btn {
    padding: 6px 14px 6px 6px;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 51, 102, 0.4);
  }
  .launcher-avatar-wrapper {
    width: 38px;
    height: 38px;
  }
  .launcher-title {
    font-size: 0.82rem;
  }
  .launcher-sub {
    display: none;
  }
}
