/* ==========================================================================
   Stefan Buchholz Modern - Omnipresent "Chat With Stef" Live Widget
   Featuring Dynamic Availability, Liquid-Glass Floating Badge & Live Chat
   ========================================================================== */

:root {
  --sb-chat-green: #10b981;
  --sb-chat-green-glow: rgba(16, 185, 129, 0.4);
  --sb-chat-green-light: #34d399;
  --sb-chat-grey: #64748b;
  --sb-chat-grey-bg: rgba(30, 41, 59, 0.85);
  --sb-chat-grey-border: rgba(148, 163, 184, 0.25);
  --sb-chat-dark-bg: rgba(15, 23, 42, 0.60);
  --sb-chat-bubble-stef: rgba(255, 255, 255, 0.12);
  --sb-chat-bubble-visitor: linear-gradient(135deg, rgba(5, 150, 105, 0.88) 0%, rgba(16, 185, 129, 0.88) 100%);
}

/* --------------------------------------------------------------------------
   Omnipresent Floating Badge Container
   -------------------------------------------------------------------------- */
.sb-chat-badge-wrap {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 24px;
  right: auto;
  z-index: 9990;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 768px) {
  .sb-chat-badge-wrap {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: auto;
    align-items: flex-start;
  }
}

.sb-chat-badge-wrap * {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Badge Trigger Button (Base)
   -------------------------------------------------------------------------- */
.sb-chat-badge-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 7px;
  border-radius: 9999px;
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  text-decoration: none;
  position: relative;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Badge Trigger Button Visibility:
   Hidden ONLY when the Chat Window is open or floating around collapsed.
   Otherwise, it remains parked in the lower left corner.
   -------------------------------------------------------------------------- */
.sb-chat-badge-wrap.is-open .sb-chat-badge-btn,
.sb-chat-badge-btn.is-hidden,
.sb-chat-window.is-open ~ .sb-chat-badge-btn,
.sb-chat-window.is-collapsed ~ .sb-chat-badge-btn,
body.is-chat-open .sb-chat-badge-btn,
body.is-chat-collapsed .sb-chat-badge-btn,
body:has(#sbChatWindow.is-open) .sb-chat-badge-btn,
body:has(#sbChatWindow.is-collapsed) .sb-chat-badge-btn {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(14px) scale(0.9) !important;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s !important;
}

/* Avatar Wrap with Status Dot */
.sb-chat-avatar-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sb-chat-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  transition: all 0.28s ease;
}

.sb-chat-status-dot {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #0f172a;
  transition: background 0.25s ease;
}

/* Info Labels */
.sb-chat-badge-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  line-height: 1.2;
}

.sb-chat-badge-title {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   State: UNAVAILABLE / OFFLINE
   -------------------------------------------------------------------------- */
.sb-chat-badge-btn.is-unavailable {
  background: rgba(30, 41, 59, 0.75);
  border: 1.5px solid var(--sb-chat-grey-border);
  color: #cbd5e1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0.9;
}

.sb-chat-badge-btn.is-unavailable .sb-chat-avatar-img {
  filter: grayscale(0.8) opacity(0.85);
  border-color: rgba(148, 163, 184, 0.3);
}

.sb-chat-badge-btn.is-unavailable .sb-chat-status-dot {
  background: var(--sb-chat-grey);
}

.sb-chat-badge-btn.is-unavailable .sb-chat-badge-title {
  color: #e2e8f0;
}

.sb-chat-badge-btn.is-unavailable:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  border-color: rgba(255, 255, 255, 0.3);
}

/* --------------------------------------------------------------------------
   State: AVAILABLE / ONLINE
   -------------------------------------------------------------------------- */
.sb-chat-badge-btn.is-available {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.82) 0%, rgba(30, 41, 59, 0.78) 100%);
  border: 1.5px solid rgba(52, 211, 153, 0.4);
  color: #f8fafc;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(16, 185, 129, 0.28);
}

.sb-chat-badge-btn.is-available .sb-chat-avatar-img {
  border-color: var(--sb-chat-green-light);
}

.sb-chat-badge-btn.is-available .sb-chat-status-dot {
  background: var(--sb-chat-green);
  box-shadow: 0 0 8px var(--sb-chat-green);
  animation: sbChatPulse 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes sbChatPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

.sb-chat-badge-btn.is-available .sb-chat-badge-title {
  color: #ffffff;
}

.sb-chat-badge-btn.is-available:hover {
  border-color: #34d399;
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6), 0 0 28px rgba(52, 211, 153, 0.55);
}

.sb-chat-badge-btn.is-available:active {
  transform: translateY(0) scale(0.98);
}

/* --------------------------------------------------------------------------
   Unread Message Badge on Trigger
   -------------------------------------------------------------------------- */
.sb-chat-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #0f172a;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.6);
  animation: sbChatBounce 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sbChatBounce {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Floating Live Chat Window Modal
   Highest stacking order (z-index: 2147483647), highly translucent frosted glass
   -------------------------------------------------------------------------- */
.sb-chat-window {
  position: fixed;
  bottom: 84px;
  left: 24px;
  right: auto;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100dvh - 110px);
  z-index: 2147483647 !important;
  pointer-events: auto !important;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.60) 0%, rgba(30, 41, 59, 0.50) 100%);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-top: 2px solid rgba(52, 211, 153, 0.75);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), 0 0 40px rgba(16, 185, 129, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s, height 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  isolation: isolate;
}

.sb-chat-window * {
  pointer-events: auto;
}

.sb-chat-window.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Collapsed State: Only show header bar */
.sb-chat-window.is-collapsed {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6), 0 0 24px rgba(16, 185, 129, 0.15);
}

.sb-chat-window.is-collapsed .sb-chat-feed,
.sb-chat-window.is-collapsed .sb-chat-footer {
  display: none !important;
}

.sb-chat-window.is-collapsed .sb-chat-header {
  border-bottom: none;
}

/* Active Dragging */
.sb-chat-window.is-dragging {
  cursor: grabbing !important;
  user-select: none !important;
  transition: none !important;
}

.sb-chat-window.is-dragging * {
  user-select: none !important;
  pointer-events: none !important;
}

/* Header (Draggable Handle) */
.sb-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: rgba(11, 17, 32, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.sb-chat-header:active {
  cursor: grabbing;
}

.sb-chat-header button,
.sb-chat-header a {
  cursor: pointer;
  pointer-events: auto;
}

.sb-chat-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sb-chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--sb-chat-green-light);
}

.sb-chat-header-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sb-chat-header-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
}

.sb-chat-header-status {
  font-size: 0.72rem;
  color: var(--sb-chat-green-light);
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.sb-chat-header-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sb-chat-green);
  box-shadow: 0 0 6px var(--sb-chat-green);
}

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

.sb-chat-btn-header {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  font-size: 1.15rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
  line-height: 1;
}

.sb-chat-btn-header:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Chat Messages Feed */
.sb-chat-feed {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}

/* Custom Scrollbar for Chat Feed */
.sb-chat-feed::-webkit-scrollbar {
  width: 5px;
}
.sb-chat-feed::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* Bubble Messages */
.sb-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: sbChatFadeIn 0.22s ease-out;
}

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

.sb-chat-msg.msg-stef {
  align-self: flex-start;
}

.sb-chat-msg.msg-visitor {
  align-self: flex-end;
}

.sb-chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.86rem;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.sb-chat-msg.msg-stef .sb-chat-bubble {
  background: var(--sb-chat-bubble-stef);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
  border-bottom-left-radius: 4px;
}

.sb-chat-msg.msg-visitor .sb-chat-bubble {
  background: var(--sb-chat-bubble-visitor);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.35);
}

.sb-chat-msg-time {
  font-size: 0.65rem;
  color: #94a3b8;
  margin-top: 4px;
  padding: 0 4px;
}

.sb-chat-msg.msg-stef .sb-chat-msg-time {
  text-align: left;
}

.sb-chat-msg.msg-visitor .sb-chat-msg-time {
  text-align: right;
  color: #cbd5e1;
}

/* Typing Indicator */
.sb-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.sb-chat-typing-dot {
  width: 6px;
  height: 6px;
  background: #cbd5e1;
  border-radius: 50%;
  animation: sbChatDotBlink 1.4s infinite ease-in-out both;
}

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

@keyframes sbChatDotBlink {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Composer / Input Area */
.sb-chat-footer {
  padding: 12px 14px;
  background: rgba(11, 17, 32, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sb-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sb-chat-input {
  flex: 1;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.86rem;
  font-family: inherit;
  resize: none;
  height: 42px;
  max-height: 100px;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.sb-chat-input:focus {
  background: rgba(15, 23, 42, 0.65);
  border-color: var(--sb-chat-green-light);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.25);
}

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

.sb-chat-btn-send {
  background: var(--sb-chat-green);
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.sb-chat-btn-send:hover {
  background: var(--sb-chat-green-light);
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 6px 16px rgba(52, 211, 153, 0.5);
}

.sb-chat-btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   Mobile Responsiveness
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .sb-chat-badge-wrap {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    left: 14px;
    right: auto;
    align-items: flex-start;
  }

  .sb-chat-badge-btn {
    padding: 5px 12px 5px 6px;
    gap: 8px;
  }

  .sb-chat-avatar-wrap {
    width: 32px;
    height: 32px;
  }

  .sb-chat-badge-title {
    font-size: 0.78rem;
  }

  .sb-chat-window {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: 80dvh;
    max-height: 80dvh;
    border-radius: 20px;
  }

  .sb-chat-window.is-collapsed {
    height: auto !important;
    max-height: none !important;
  }
}
