:root {
  --tpai-bg: #0b1220;
  --tpai-surface: #111b2f;
  --tpai-surface-2: #17233b;
  --tpai-text: #ecf2ff;
  --tpai-muted: #94a3b8;
  --tpai-accent: #22d3ee;
  --tpai-accent-2: #7c3aed;
  --tpai-border: rgba(148, 163, 184, 0.18);
}

[data-tpai-widget] {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  font-family: inherit;
}

.tpai-widget-trigger {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  color: var(--tpai-text);
  background: linear-gradient(135deg, var(--tpai-accent), var(--tpai-accent-2));
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.35);
  cursor: pointer;
}

.tpai-widget-panel {
  width: min(380px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 90px));
  margin-top: 14px;
  border: 1px solid var(--tpai-border);
  border-radius: 24px;
  background: radial-gradient(circle at top, rgba(34, 211, 238, 0.08), transparent 32%), var(--tpai-bg);
  color: var(--tpai-text);
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.45);
  display: flex;
  flex-direction: column;
  animation: tpai-rise 180ms ease-out;
}

.tpai-widget-header {
  padding: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent);
  border-bottom: 1px solid var(--tpai-border);
}

.tpai-widget-brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.tpai-widget-brand img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
}

.tpai-widget-body {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tpai-message {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.tpai-message-user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(124, 58, 237, 0.18));
  border: 1px solid rgba(34, 211, 238, 0.2);
}

.tpai-message-assistant {
  align-self: flex-start;
  background: var(--tpai-surface-2);
  border: 1px solid var(--tpai-border);
}

.tpai-widget-form,
.tpai-widget-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--tpai-border);
  background: rgba(255, 255, 255, 0.02);
}

.tpai-widget-form {
  display: flex;
  gap: 10px;
}

.tpai-widget-form input {
  flex: 1;
  border-radius: 14px;
  border: 1px solid var(--tpai-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--tpai-text);
  padding: 12px 14px;
}

.tpai-widget-form button,
.tpai-secondary-action {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--tpai-text);
  background: linear-gradient(135deg, var(--tpai-accent), var(--tpai-accent-2));
  cursor: pointer;
}

.tpai-widget-footer {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.tpai-secondary-action {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--tpai-border);
}

.tpai-typing {
  opacity: 0.7;
}

@keyframes tpai-rise {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 640px) {
  [data-tpai-widget] {
    right: 12px;
    left: 12px;
    bottom: 12px;
  }

  .tpai-widget-panel {
    width: 100%;
    height: min(76vh, 560px);
  }
}
