/* ==========================================================================
   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;
  }
}

/* Proactive chat suggestions */
.chat-suggestion-bubble {
  position: absolute;
  right: 4px;
  bottom: 76px;
  width: max-content;
  max-width: min(310px, calc(100vw - 48px));
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px 9px 9px;
  border: 1px solid rgba(0, 51, 102, .14);
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: #17324d;
  box-shadow: 0 10px 30px rgba(15, 42, 68, .2);
  font: inherit;
  text-align: left;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(.96);
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}
.chat-suggestion-bubble[hidden] { display: none; }
.chat-suggestion-bubble.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.chat-suggestion-bubble:hover { transform: translateY(-2px) scale(1); }
.chat-suggestion-bubble:focus-visible { outline: 3px solid rgba(255, 155, 31, .5); outline-offset: 3px; }
.chat-suggestion-agent {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #003366;
  color: #ffb700;
  font-size: 10px;
  font-weight: 800;
}
.chat-suggestion-text { max-width: 220px; font-size: 13px; line-height: 1.35; font-weight: 650; }
.chat-suggestion-bubble > i { color: #ff7a00; font-size: 11px; }
@media (max-width: 576px) {
  .chat-suggestion-bubble { right: 0; bottom: 68px; max-width: min(280px, calc(100vw - 32px)); }
  .chat-suggestion-text { max-width: 190px; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-suggestion-bubble { transition: opacity .01ms linear; transform: none; }
  .chat-suggestion-bubble:hover { transform: none; }
}

/* Realtime message preview above the launcher */
.chat-message-alert {
  position: absolute;
  right: 4px;
  bottom: 76px;
  width: min(326px, calc(100vw - 48px));
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 10px;
  border: 1px solid rgba(0, 51, 102, .16);
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: #17324d;
  box-shadow: 0 14px 36px rgba(15, 42, 68, .24);
  font: inherit;
  text-align: left;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateX(calc(100% + 32px));
  transition: opacity .28s ease, transform .32s cubic-bezier(.22, 1, .36, 1), visibility .32s;
  overflow: hidden;
}
.chat-message-alert[hidden] { display: none; }
.chat-message-alert.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}
.chat-message-alert:hover { transform: translateX(0) translateY(-2px); }
.chat-message-alert:focus-visible { outline: 3px solid rgba(255, 155, 31, .55); outline-offset: 3px; }
.chat-message-alert-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #003366;
  color: #ffb700;
  font-size: 10px;
  font-weight: 800;
}
.chat-message-alert-content { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.chat-message-alert-sender { color: #003366; font-size: 12px; line-height: 1.25; }
.chat-message-alert-text {
  display: -webkit-box;
  overflow: hidden;
  color: #334155;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 550;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.chat-message-alert > i { flex: 0 0 auto; color: #ff7a00; font-size: 11px; }

@media (max-width: 576px) {
  .chat-message-alert { right: 0; bottom: 68px; width: min(300px, calc(100vw - 32px)); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-message-alert { transition: opacity .01ms linear; transform: none; }
  .chat-message-alert.is-visible, .chat-message-alert:hover { transform: none; }
  .unread-badge-counter { animation: none; }
}

/* ========================================================================== 
   RESPONSIVE HARDENING — customer chat widget 1920px to 320px
   ========================================================================== */
.cskh-widget-container{right:max(16px,env(safe-area-inset-right));bottom:max(16px,env(safe-area-inset-bottom));max-width:calc(100vw - 24px)}.chat-box-popup{width:min(380px,calc(100vw - 32px));height:min(600px,calc(100dvh - 110px));max-height:calc(100dvh - 110px)}.chat-header,.agent-profile,.agent-info,.chat-header-actions{min-width:0}.agent-profile{flex:1}.agent-info{flex:1}.agent-name,.agent-status-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.header-action-btn,.btn-send-message{min-width:44px;min-height:44px}.chat-register-view,.messages-container{overscroll-behavior:contain}.register-form input,.register-form textarea{min-height:44px;font-size:16px}.input-actions-bar input{min-width:0;font-size:16px}.msg-content-bubble{overflow-wrap:anywhere}.msg-content-bubble img{max-width:100%;height:auto}.quick-chips-wrapper{scroll-snap-type:x proximity}.chip-item{min-height:36px;display:inline-flex;align-items:center;scroll-snap-align:start}.chat-message-alert,.chat-suggestion-bubble{max-width:calc(100vw - 24px)}
@media(max-width:576px){.cskh-widget-container{right:max(10px,env(safe-area-inset-right));bottom:max(10px,env(safe-area-inset-bottom));max-width:calc(100vw - 20px)}.chat-box-popup{inset:0;position:fixed;width:100%;height:100dvh;max-height:100dvh;border-radius:0;padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom)}.chat-header{padding:8px 10px}.agent-avatar-box{width:36px;height:36px;flex:0 0 36px}.agent-profile{gap:7px}.agent-name{font-size:.86rem}.agent-status-text{font-size:.65rem}.chat-header-actions{gap:2px}.chat-register-view{padding:14px}.register-hero{margin-bottom:12px}.hero-icon-circle{width:42px;height:42px}.register-form .form-group{margin-bottom:10px}.messages-container{padding:10px}.msg-item{max-width:90%}.chat-input-form{padding:8px 8px max(8px,env(safe-area-inset-bottom))}.input-actions-bar{min-height:48px;padding-left:12px}.btn-send-message{width:44px;height:44px}.active-session-bar{gap:8px}.conversation-closed-banner{gap:8px;flex-wrap:wrap}.chat-message-alert,.chat-suggestion-bubble{right:0;max-width:calc(100vw - 20px)}}
@media(max-width:380px){.launcher-text-bubble{display:none}.chat-launcher-btn{width:52px;height:52px;padding:5px;border-radius:50%;justify-content:center}.launcher-avatar-wrapper{width:38px;height:38px}.chat-message-alert{width:calc(100vw - 20px)}.chat-suggestion-bubble{width:max-content;max-width:calc(100vw - 20px)}.chat-register-view{padding:12px}.register-hero p{font-size:.76rem}.agent-avatar-box{display:none}.agent-status-text{max-width:150px}.header-action-btn{min-width:40px;min-height:40px}.msg-item{max-width:94%}.quick-chips-wrapper{padding-inline:8px}.active-session-bar{font-size:.68rem}}
@media(max-width:340px){.agent-name{font-size:.78rem}.agent-status-text{max-width:125px}.header-action-btn{min-width:38px;min-height:38px}.chat-header{padding-inline:7px}.chat-register-view{padding-inline:10px}.messages-container{padding-inline:8px}.msg-content-bubble{padding:9px 11px;font-size:.84rem}}
@media(max-height:620px) and (min-width:577px){.chat-box-popup{height:calc(100dvh - 88px);max-height:calc(100dvh - 88px);bottom:64px}.chat-register-view{padding:12px}.register-hero{margin-bottom:8px}.hero-icon-circle{width:38px;height:38px;margin-bottom:5px}.register-form .form-group{margin-bottom:7px}}
@media(prefers-reduced-motion:reduce){.chat-box-popup,.msg-item,.chat-launcher-btn{animation:none;transition:none}.chat-launcher-btn:hover{transform:none}}
