/* Sphereflux industrial chat desk */

.sf-chat {
  --sf-chat-w: min(100vw - 1.5rem, 26.5rem);
  --sf-chat-h: min(78vh, 38rem);
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 400;
  font-family: var(--font-body);
  color: #e8eef8;
}

.sf-chat * { box-sizing: border-box; }

/* Proactive notification toast */
.sf-chat__toast {
  position: absolute;
  right: 0;
  bottom: calc(4.25rem + 0.75rem);
  width: min(100vw - 2rem, 20rem);
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0;
  background: #0a274f;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-left: 3px solid #c8102e;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(6, 24, 51, 0.45);
  animation: sfChatToastIn 420ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

.sf-chat__toast[hidden] { display: none !important; }

.sf-chat__toast-body {
  flex: 1;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0.9rem 0.35rem 0.9rem 0.9rem;
  cursor: pointer;
  font: inherit;
}

.sf-chat__toast-body strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.sf-chat__toast-body span span {
  display: block;
  font-size: 0.8rem;
  color: rgba(232, 238, 248, 0.72);
  line-height: 1.4;
}

.sf-chat__toast-pulse {
  width: 10px;
  height: 10px;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: #25d366;
  box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55);
  animation: sfChatPulse 1.8s ease-out infinite;
  flex-shrink: 0;
}

.sf-chat__toast-x {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  font-size: 1.25rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

@keyframes sfChatToastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes sfChatPulse {
  0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(37, 211, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

/* Launcher */
.sf-chat__launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(145deg, #0f3a78, #061833);
  color: white;
  cursor: pointer;
  box-shadow:
    0 12px 32px rgba(6, 24, 51, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.sf-chat__launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 16px 40px rgba(6, 24, 51, 0.5);
}

.sf-chat__launcher-ring {
  position: absolute;
  inset: -4px;
  border-radius: 18px;
  border: 1px solid rgba(200, 16, 46, 0.45);
  animation: sfChatRing 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes sfChatRing {
  0% { opacity: 0.8; transform: scale(0.92); }
  100% { opacity: 0; transform: scale(1.18); }
}

.sf-chat.is-open .sf-chat__launcher,
.sf-chat.is-minimized .sf-chat__launcher {
  display: none;
}

.sf-chat__badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #c8102e;
  color: white;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(200, 16, 46, 0.45);
  animation: sfChatBadgePop 320ms ease;
}

.sf-chat__badge[hidden] { display: none !important; }

.sf-chat__badge--dock {
  position: static;
  margin-left: 0.35rem;
}

@keyframes sfChatBadgePop {
  from { transform: scale(0.4); }
  to { transform: scale(1); }
}

/* Dock (minimized) */
.sf-chat__dock {
  display: none;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: linear-gradient(120deg, #061833, #0f3a78);
  color: white;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(6, 24, 51, 0.35);
}

.sf-chat.is-minimized .sf-chat__dock { display: inline-flex; }
.sf-chat__dock[hidden] { display: none !important; }
.sf-chat.is-minimized .sf-chat__dock[hidden] { display: inline-flex !important; }

.sf-chat__dock-expand {
  margin-left: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  background: #c8102e;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Panel shell */
.sf-chat__panel {
  width: var(--sf-chat-w);
  height: var(--sf-chat-h);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background:
    linear-gradient(180deg, rgba(15, 58, 120, 0.35), transparent 28%),
    #071a33;
  box-shadow:
    0 28px 80px rgba(3, 12, 28, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: sfChatPanelIn 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sf-chat__panel[hidden] { display: none !important; }

@keyframes sfChatPanelIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.sf-chat__header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.9rem;
  background:
    linear-gradient(135deg, #061833 0%, #0f3a78 70%, #1a2540 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sf-chat__identity {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-width: 0;
}

.sf-chat__avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: -0.04em;
  color: white;
  background: linear-gradient(145deg, #c8102e, #7a0a1c);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sf-chat__eyebrow {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.sf-chat__title {
  margin: 0.15rem 0 0.2rem;
  color: white;
  font-size: 1rem;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sf-chat__status {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: rgba(232, 238, 248, 0.7);
}

.sf-chat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25d366;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.18);
}

.sf-chat__header-actions {
  display: flex;
  gap: 0.25rem;
}

.sf-chat__icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sf-chat__icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Body: critical for scroll — flex column + min-height 0 */
.sf-chat__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(600px 200px at 100% 0%, rgba(200, 16, 46, 0.08), transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 23px,
      rgba(255, 255, 255, 0.015) 23px,
      rgba(255, 255, 255, 0.015) 24px
    ),
    #0a1f3d;
}

.sf-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sf-chat__messages::-webkit-scrollbar { width: 6px; }
.sf-chat__messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 99px;
}

.sf-chat__day {
  align-self: center;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  padding: 0.25rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 99px;
}

.sf-chat__row {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
  max-width: 100%;
  animation: sfChatBubbleIn 260ms ease;
}

.sf-chat__row--user {
  flex-direction: row-reverse;
}

@keyframes sfChatBubbleIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.sf-chat__mini-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(145deg, #164a96, #0a274f);
  color: white;
  font-family: var(--font-display);
  font-size: 0.58rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.sf-chat__bubble {
  max-width: min(85%, 18rem);
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.sf-chat__bubble--bot {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e8eef8;
  border-bottom-left-radius: 4px;
}

.sf-chat__bubble--user {
  background: linear-gradient(135deg, #c8102e, #a50d25);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 8px 20px rgba(200, 16, 46, 0.25);
}

.sf-chat__bubble--typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.9rem 1rem;
}

.sf-chat__bubble--typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  animation: sfChatDot 1.1s infinite ease-in-out;
}

.sf-chat__bubble--typing i:nth-child(2) { animation-delay: 0.15s; }
.sf-chat__bubble--typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes sfChatDot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* Chips */
.sf-chat__chips {
  flex: 0 0 auto;
  display: flex;
  gap: 0.45rem;
  padding: 0 0.85rem 0.65rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.sf-chat__chips::-webkit-scrollbar { display: none; }
.sf-chat__chips[hidden] { display: none !important; }

.sf-chat__chips button {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #d7e3f5;
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease;
}

.sf-chat__chips button:hover {
  background: rgba(200, 16, 46, 0.18);
  border-color: rgba(200, 16, 46, 0.55);
}

/* Composer */
.sf-chat__composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: end;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(6, 24, 51, 0.85);
}

.sf-chat__composer[hidden] { display: none !important; }

.sf-chat__composer textarea {
  width: 100%;
  max-height: 7rem;
  min-height: 42px;
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.7rem 0.8rem;
  line-height: 1.35;
}

.sf-chat__composer textarea::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.sf-chat__composer textarea:focus {
  outline: none;
  border-color: rgba(200, 16, 46, 0.65);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.18);
}

.sf-chat__quote-btn,
.sf-chat__send,
.sf-chat__ghost {
  border: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
}

.sf-chat__quote-btn {
  min-height: 42px;
  padding: 0 0.7rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #d7e3f5;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.sf-chat__send {
  min-width: 42px;
  min-height: 42px;
  border-radius: 12px;
  background: #c8102e;
  color: white;
  display: grid;
  place-items: center;
  padding: 0 0.85rem;
}

.sf-chat__send:hover { background: #a50d25; }
.sf-chat__send:disabled { opacity: 0.55; cursor: wait; }

.sf-chat__ghost {
  min-height: 40px;
  padding: 0 0.9rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: #d7e3f5;
}

/* Lead form — sits under messages during handoff */
.sf-chat__handoff {
  flex: 0 0 auto;
  padding: 0 0.85rem 0.35rem;
}

.sf-chat__handoff[hidden] { display: none !important; }

.sf-chat__handoff-banner {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(200, 16, 46, 0.35);
  background: rgba(200, 16, 46, 0.12);
}

.sf-chat__handoff-banner strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.88rem;
  color: #fff;
  margin-bottom: 0.2rem;
}

.sf-chat__handoff-banner p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: rgba(232, 238, 248, 0.75);
}

.sf-chat__handoff-pulse {
  width: 10px;
  height: 10px;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: #c8102e;
  box-shadow: 0 0 0 0 rgba(200, 16, 46, 0.5);
  animation: sfChatPulse 1.6s ease-out infinite;
  flex-shrink: 0;
}

.sf-chat.is-handoff .sf-chat__messages {
  flex: 0 1 38%;
  max-height: 38%;
}

.sf-chat.is-handoff .sf-chat__lead {
  flex: 1 1 auto;
}

.sf-chat__lead {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: #071a33;
}

.sf-chat__lead[hidden] { display: none !important; }

.sf-chat__lead-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  gap: 0.7rem;
}

.sf-chat__lead-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  color: white;
  font-size: 0.95rem;
}

.sf-chat__lead label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sf-chat__lead input,
.sf-chat__lead select,
.sf-chat__lead textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font: inherit;
  font-size: 0.9rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  padding: 0.65rem 0.75rem;
}

.sf-chat__lead-actions {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

@media (max-width: 480px) {
  .sf-chat {
    right: 0.75rem;
    bottom: 0.75rem;
  }
  .sf-chat__panel {
    width: calc(100vw - 1.5rem);
    height: min(82vh, 40rem);
  }
  .sf-chat__toast {
    width: calc(100vw - 1.5rem);
  }
}
