#topemby-support-chat {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 70;
  color: var(--text-primary, #f5f5f3);
  font-family: Inter, Manrope, "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topemby-chat-launcher {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #09090b;
  background: #f5f5f3;
  box-shadow: 0 18px 46px var(--brand-glow, rgba(255, 84, 74, .16));
  cursor: pointer;
}

.topemby-chat-launcher svg {
  width: 26px;
  height: 26px;
}

.topemby-chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(380px, calc(100vw - 32px));
  max-height: min(680px, calc(100vh - 120px));
  display: none;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--border-strong, rgba(255,255,255,.14));
  border-radius: 22px;
  background: var(--surface, rgba(14,14,17,.82));
  box-shadow: var(--shadow-card, 0 28px 90px rgba(0,0,0,.52));
  backdrop-filter: blur(18px);
}

#topemby-support-chat.is-open .topemby-chat-panel {
  display: grid;
}

.topemby-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,.08));
}

.topemby-chat-title {
  font-weight: 900;
  font-size: 16px;
}

.topemby-chat-subtitle {
  margin-top: 4px;
  color: var(--text-secondary, #aaa5a7);
  font-size: 12px;
  line-height: 1.45;
}

.topemby-chat-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-subtle, rgba(255,255,255,.08));
  border-radius: 999px;
  background: rgba(255,255,255,.045);
  color: var(--text-primary, #f5f5f3);
  cursor: pointer;
}

.topemby-chat-fields {
  display: grid;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,.08));
}

.topemby-chat-input,
.topemby-chat-textarea {
  width: 100%;
  border: 1px solid var(--border-strong, rgba(255,255,255,.14));
  border-radius: 13px;
  outline: none;
  background: rgba(255,255,255,.04);
  color: var(--text-primary, #f5f5f3);
  font: inherit;
}

.topemby-chat-input {
  height: 42px;
  padding: 0 12px;
}

.topemby-chat-textarea {
  min-height: 86px;
  max-height: 150px;
  padding: 12px;
  resize: vertical;
}

.topemby-chat-input::placeholder,
.topemby-chat-textarea::placeholder {
  color: var(--text-muted, #747074);
}

.topemby-chat-log {
  min-height: 180px;
  overflow-y: auto;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.035), transparent);
}

.topemby-chat-empty {
  color: var(--text-secondary, #aaa5a7);
  font-size: 13px;
  line-height: 1.65;
}

.topemby-chat-row {
  display: flex;
  margin: 10px 0;
}

.topemby-chat-row.is-user {
  justify-content: flex-end;
}

.topemby-chat-row.is-admin {
  justify-content: flex-start;
}

.topemby-chat-bubble {
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 15px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.topemby-chat-row.is-user .topemby-chat-bubble {
  background: var(--brand-red, #ff544a);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.topemby-chat-row.is-admin .topemby-chat-bubble,
.topemby-chat-row.is-system .topemby-chat-bubble {
  background: rgba(255,255,255,.07);
  color: var(--text-primary, #f5f5f3);
  border-bottom-left-radius: 5px;
}

.topemby-chat-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted, #747074);
}

.topemby-chat-actions {
  display: flex;
  gap: 10px;
  padding: 14px 18px 18px;
}

.topemby-chat-send {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 999px;
  color: #09090b;
  background: #f5f5f3;
  font-weight: 900;
  cursor: pointer;
}

.topemby-chat-escalate {
  flex: 1;
  height: 44px;
  border: 1px solid var(--border-strong, rgba(255,255,255,.14));
  border-radius: 999px;
  color: var(--text-primary, #f5f5f3);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.topemby-chat-send:disabled {
  cursor: wait;
  opacity: .68;
}

.topemby-chat-escalate:disabled {
  cursor: wait;
  opacity: .68;
}

.topemby-chat-error {
  padding: 0 18px 14px;
  color: var(--brand-red, #ff544a);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 520px) {
  #topemby-support-chat {
    right: 14px;
    bottom: 14px;
  }

  .topemby-chat-panel {
    width: calc(100vw - 28px);
    max-height: calc(100vh - 90px);
    bottom: 68px;
  }
}
