:root {
  --public-chat-bg: rgba(255, 255, 255, 0.94);
  --public-chat-panel: rgba(15, 23, 42, 0.95);
  --public-chat-surface: rgba(255, 255, 255, 0.92);
  --public-chat-text: #0f172a;
  --public-chat-muted: #64748b;
  --public-chat-primary: #dc2626;
  --public-chat-primary-dark: #991b1b;
  --public-chat-shadow: 0 28px 60px rgba(15, 23, 42, 0.22);
}

.public-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  left: auto;
  top: auto;
  z-index: 99999;
  width: min(400px, calc(100vw - 1.5rem));
  max-width: 400px;
  height: 650px;
  display: grid;
  place-items: end;
  pointer-events: none;
}

.chat-toggle-btn {
  pointer-events: auto;
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #dc2626, #991b1b);
  color: white;
  box-shadow: var(--public-chat-shadow);
  cursor: pointer;
  transition: box-shadow 0.25s ease;
  position: relative;
  transform: none;
}

.chat-toggle-btn:hover {
  box-shadow: 0 36px 72px rgba(220, 38, 38, 0.3);
}

.chat-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.chat-badge {
  position: absolute;
  right: -6px;
  top: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.2);
}

.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  left: auto;
  top: auto;
  width: 400px;
  max-width: calc(100vw - 1.5rem);
  height: 650px;
  border-radius: 30px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: var(--public-chat-panel);
  box-shadow: var(--public-chat-shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px);
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease,
    transform 0.25s ease;
  pointer-events: auto;
  z-index: 99998;
}

.chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(15, 23, 42, 0.98);
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  position: sticky;
  top: 0;
  z-index: 1;
}

.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
}

.chat-header-subtitle {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.chat-close-btn {
  border: none;
  background: transparent;
  color: #e2e8f0;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-content {
  flex: 1;
  min-height: 0;
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
  overflow-y: auto;
  background: white;
}

.chat-bubble {
  max-width: 100%;
  border-radius: 24px;
  padding: 0.95rem 1rem;
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.12);
  line-height: 1.5;
}

.chat-bubble.bot {
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  align-self: start;
}

.chat-bubble.user {
  background: var(--public-chat-surface);
  color: var(--public-chat-text);
  align-self: end;
}

.chat-actions {
  display: grid;
  gap: 0.75rem;
}

.chat-actions input {
  width: 100%;
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255, 255, 255, 0.95);
  color: var(--public-chat-text);
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
}

.chat-actions input:focus {
  outline: none;
  border-color: rgba(220, 38, 38, 0.8);
  box-shadow: 0 0 0 0.14rem rgba(220, 38, 38, 0.16);
}

.chat-action-btn {
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, #dc2626, #991b1b);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    filter 0.2s ease;
}

.chat-action-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.chat-footer {
  padding: 0.9rem 1rem 1rem;
  font-size: 0.82rem;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.95);
  position: sticky;
  bottom: 0;
}

.chat-composer {
  display: none;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.chat-composer input {
  width: 100%;
  min-height: 44px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255, 255, 255, 0.98);
  color: var(--public-chat-text);
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
}

.chat-composer input:focus {
  outline: none;
  border-color: rgba(220, 38, 38, 0.8);
  box-shadow: 0 0 0 0.14rem rgba(220, 38, 38, 0.16);
}

.chat-composer button {
  min-width: 88px;
}

.chat-status {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

.chat-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
}

@media (max-width: 520px) {
  body.chat-widget-open {
    overflow: hidden;
  }

  .public-chat-widget {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
  }

  .chat-toggle-btn {
    width: 60px;
    height: 60px;
    position: fixed;
    right: 16px;
    bottom: 16px;
  }

  .chat-panel {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    border-radius: 0;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
  }

  .chat-content {
    padding-bottom: 1.25rem;
  }
}
